Dispose MorphTargets #682
-
Hey, is there a way to list MorphTargets and dispose this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Morph targets are associated with mesh primitives, so you can remove them like this: import { prune } from '@gltf-transform/functions';
for (const mesh of document.getRoot().listMeshes()) {
for (const prim of mesh.listPrimitives()) {
prim.listTargets().forEach((target) => target.dispose());
}
}
await document.transform(prune()); The You may additionally want to clean up any weights or names associated with the morph targets. Not all models will have these, but it doesn't hurt to check: document.getRoot().listNodes().forEach((node) => node.setWeights([]));
document.getRoot().listMeshes().forEach((mesh) => {
mesh.setWeights([])
const extras = mesh.getExtras();
delete extras.targetNames;
mesh.setExtras(extras);
}); |
Beta Was this translation helpful? Give feedback.
-
this works fantastic! only problem i see now is the gltf Validation shows me:
|
Beta Was this translation helpful? Give feedback.
-
to fix this i use
|
Beta Was this translation helpful? Give feedback.
Morph targets are associated with mesh primitives, so you can remove them like this:
The
prune()
step will clean up any unused resources (e.g. vertex attributes) left behind by the removed morph targets.You may additionally want to clean up any weights or names associated with the morph targets. Not all models will have these, but it doesn't hurt to check: