Skip to content

Dispose MorphTargets #682

Answered by donmccurdy
arpu asked this question in Q&A
Sep 12, 2022 · 3 comments · 2 replies
Discussion options

You must be logged in to vote

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 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:

document.getRoot().listNodes().forEach((node) => node.setWeights([]));

document.g…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by donmccurdy
Comment options

You must be logged in to vote
2 replies
@donmccurdy
Comment options

@arpu
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants