@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.
65 lines (62 loc) • 2.77 kB
JavaScript
import { aj as resolveAccessor, F as F32, U as U16 } from './index-By0tcgYN.esm.js';
function weightsToFloat32(w) {
if (w instanceof F32) {
return w;
}
const inv = w instanceof U16 ? 1 / 65535 : 1 / 255;
const s = w;
const out = new F32(s.length);
for (let i = 0; i < s.length; i++) {
out[i] = s[i] * inv;
}
return out;
}
function resolveAttr(name, primitive, decoded, json, binChunk) {
if (decoded && decoded._attributes.has(name)) {
return decoded._attributes.get(name);
}
const idx = primitive.attributes?.[name];
if (idx === void 0) {
return null;
}
const accessor = json.accessors[idx];
const bv = accessor.bufferView !== void 0 ? json.bufferViews[accessor.bufferView] : void 0;
const compBytes = accessor.componentType === 5126 || accessor.componentType === 5125 ? 4 : accessor.componentType === 5123 || accessor.componentType === 5122 ? 2 : 1;
const stride = bv?.byteStride;
if (bv === void 0 || stride === void 0 || stride === 4 * compBytes) {
return resolveAccessor(json, binChunk, idx)._data;
}
return import('./gltf-strided-attribute-BaBDvhqc.esm.js').then((m) => m.copyStridedAttribute(accessor, bv, binChunk, 4, compBytes));
}
const feature = {
id: "_skeleton",
async applyMesh(meshData, mesh, ctx) {
const { _json: json, _binChunk: binChunk, _parentMap: parentMap, _worldMatrixCache: worldMatrixCache } = ctx;
const node = json.nodes[meshData._nodeIndex];
if (node.skin === void 0 || !json.skins) {
return;
}
const primitive = meshData._primitive;
const decoded = meshData._decoded;
const joints = await resolveAttr("JOINTS_0", primitive, decoded, json, binChunk);
const weightsRaw = await resolveAttr("WEIGHTS_0", primitive, decoded, json, binChunk);
if (!joints || !weightsRaw) {
return;
}
const weights = weightsToFloat32(weightsRaw);
const joints1 = await resolveAttr("JOINTS_1", primitive, decoded, json, binChunk);
const weights1Raw = await resolveAttr("WEIGHTS_1", primitive, decoded, json, binChunk);
const weights1 = weights1Raw ? weightsToFloat32(weights1Raw) : null;
const [{ extractSkin, computeBoneTextureData }, { createSkeleton }] = await Promise.all([import('./gltf-animation-CvJhPzAe.esm.js'), import('./create-skeleton-CVW5z17x.esm.js')]);
const skin = extractSkin(json, binChunk, node.skin, meshData._worldMatrix, parentMap, worldMatrixCache);
const boneData = computeBoneTextureData(skin);
mesh.skeleton = createSkeleton(ctx._engine, joints, weights, skin.jointNodes.length, boneData, joints1, weights1);
},
async applyAsset(meshes, _root, ctx) {
{
return {};
}
}
};
export { feature as default };
//# sourceMappingURL=gltf-feature-skeleton-RTJMQrTP.esm.js.map