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.

52 lines (50 loc) 2.33 kB
const STAGE_VERTEX = 1; const SKELETON_HELPERS = ` fn readMatrixFromRawSampler(smp: texture_2d<f32>, index: f32) -> mat4x4<f32> { let offset = i32(index) * 4; let m0 = textureLoad(smp, vec2<i32>(offset + 0, 0), 0); let m1 = textureLoad(smp, vec2<i32>(offset + 1, 0), 0); let m2 = textureLoad(smp, vec2<i32>(offset + 2, 0), 0); let m3 = textureLoad(smp, vec2<i32>(offset + 3, 0), 0); return mat4x4f(m0, m1, m2, m3); } `; function makeSkinningCode(has8Bones, worldExpr = "mesh.world") { let code = `var influence: mat4x4<f32> = readMatrixFromRawSampler(boneSampler, f32(joints[0])) * weights[0]; influence = influence + readMatrixFromRawSampler(boneSampler, f32(joints[1])) * weights[1]; influence = influence + readMatrixFromRawSampler(boneSampler, f32(joints[2])) * weights[2]; influence = influence + readMatrixFromRawSampler(boneSampler, f32(joints[3])) * weights[3];`; if (has8Bones) { code += ` influence = influence + readMatrixFromRawSampler(boneSampler, f32(joints1[0])) * weights1[0]; influence = influence + readMatrixFromRawSampler(boneSampler, f32(joints1[1])) * weights1[1]; influence = influence + readMatrixFromRawSampler(boneSampler, f32(joints1[2])) * weights1[2]; influence = influence + readMatrixFromRawSampler(boneSampler, f32(joints1[3])) * weights1[3];`; } return `${code} finalWorld = ${worldExpr} * influence;`; } function createSkeletonFragment(has8Bones) { return { _id: "skeleton", _vertexAttributes: [ { _name: "joints", _type: "vec4<u32>", _gpuFormat: "uint32x4", _arrayStride: 16 }, { _name: "weights", _type: "vec4<f32>", _gpuFormat: "float32x4", _arrayStride: 16 }, ...has8Bones ? [ { _name: "joints1", _type: "vec4<u32>", _gpuFormat: "uint32x4", _arrayStride: 16 }, { _name: "weights1", _type: "vec4<f32>", _gpuFormat: "float32x4", _arrayStride: 16 } ] : [] ], _vertexBindings: [ { _name: "boneSampler", _type: { _kind: "texture", _textureType: "texture_2d<f32>", _sampleType: "unfilterable-float" }, _visibility: STAGE_VERTEX } ], _vertexHelperFunctions: SKELETON_HELPERS, _vertexSlots: { VW: makeSkinningCode(has8Bones) } }; } export { SKELETON_HELPERS as S, createSkeletonFragment as c, makeSkinningCode as m }; //# sourceMappingURL=skeleton-fragment-Dc_gcLMX.esm.js.map