UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

78 lines (74 loc) 2.68 kB
import { T as ThrowLiteError, X as MSH_HAS_MORPH_TARGETS } from './index-By0tcgYN.esm.js'; const STAGE_VERTEX = 1; const MORPH_PRE_SKINNING = `var morphedPos = position; var morphedNorm = normal; for (var i = 0u; i < morph.count; i = i + 1u) { let w = morph.weights[i]; let b = (i * morph.vertexCount + vertexIndex) * 6u; morphedPos = morphedPos + w * vec3<f32>(morphDeltas.d[b], morphDeltas.d[b + 1u], morphDeltas.d[b + 2u]); morphedNorm = morphedNorm + w * vec3<f32>(morphDeltas.d[b + 3u], morphDeltas.d[b + 4u], morphDeltas.d[b + 5u]); }`; function patchMorphStorage(composed) { const morphBindings = /* @__PURE__ */ new Set(); let rewrites = 0; const vertexWGSL = composed._vertexWGSL.replace(/@group\(1\)@binding\((\d+)\)\s*var<uniform>\s*(morphDeltas|morph)\s*:/g, (_match, num, name) => { morphBindings.add(Number(num)); rewrites++; return `@group(1)@binding(${num}) var<storage, read> ${name}:`; }); if (rewrites !== 2) { ThrowLiteError(326, rewrites); } const entries = composed._meshBGLDescriptor.entries.map( (e) => morphBindings.has(e.binding) ? { ...e, buffer: { type: "read-only-storage" } } : e ); return { ...composed, _vertexWGSL: vertexWGSL, _meshBGLDescriptor: { ...composed._meshBGLDescriptor, entries } }; } function createMorphFragment() { return { _id: "morph", _vertexBuiltins: [{ _name: "vertexIndex", _builtin: "vertex_index", _type: "u32" }], _vertexHelperFunctions: `struct morphUniforms { count: u32, vertexCount: u32, _p0: u32, _p1: u32, weights: array<f32>, } struct morphDeltasUniforms { d: array<f32>, }`, // Declared as uniform-buffer placeholders; `_postCompose` rewrites them to storage. _vertexBindings: [ { _name: "morphDeltas", _type: { _kind: "uniform-buffer" }, _visibility: STAGE_VERTEX }, { _name: "morph", _type: { _kind: "uniform-buffer" }, _visibility: STAGE_VERTEX } ], _vertexSlots: { VR: MORPH_PRE_SKINNING }, _pc: patchMorphStorage }; } const pbrExt = { id: "morph", phase: "vertex", frag(ctx) { if (!(ctx._meshFeatures & MSH_HAS_MORPH_TARGETS)) { return null; } return createMorphFragment(); }, bind(ctx, entries, b) { const mesh = ctx._mesh; if (!(ctx._meshFeatures & MSH_HAS_MORPH_TARGETS) || !mesh?.morphTargets) { return b; } entries.push({ binding: b++, resource: { buffer: mesh.morphTargets.deltasBuffer } }); if (mesh.morphTargets.weightsBuffer) { entries.push({ binding: b++, resource: { buffer: mesh.morphTargets.weightsBuffer } }); } return b; } }; export { createMorphFragment, pbrExt }; //# sourceMappingURL=morph-fragment-D-Hyduj7.esm.js.map