MCPcopy
hub / github.com/donmccurdy/glTF-Transform / uninstance

Function uninstance

packages/functions/src/uninstance.ts:36–71  ·  view source on GitHub ↗
(_options: UninstanceOptions = UNINSTANCE_DEFAULTS)

Source from the content-addressed store, hash-verified

34 * @category Transforms
35 */
36export function uninstance(_options: UninstanceOptions = UNINSTANCE_DEFAULTS): Transform {
37 return createTransform(NAME, async (document: Document): Promise<void> => {
38 const logger = document.getLogger();
39 const root = document.getRoot();
40
41 const instanceAttributes = new Set<Accessor>();
42
43 for (const srcNode of document.getRoot().listNodes()) {
44 const batch = srcNode.getExtension<InstancedMesh>('EXT_mesh_gpu_instancing');
45 if (!batch) continue;
46
47 // For each instance, attach a new Node under the source Node.
48 for (const instanceNode of createInstanceNodes(srcNode)) {
49 srcNode.addChild(instanceNode);
50 }
51
52 for (const instanceAttribute of batch.listAttributes()) {
53 instanceAttributes.add(instanceAttribute);
54 }
55
56 srcNode.setMesh(null);
57 batch.dispose();
58 }
59
60 // Clean up unused instance attributes.
61 for (const attribute of instanceAttributes) {
62 if (attribute.listParents().every((parent) => parent === root)) {
63 attribute.dispose();
64 }
65 }
66
67 document.disposeExtension('EXT_mesh_gpu_instancing');
68
69 logger.debug(`${NAME}: Complete.`);
70 });
71}
72
73/**
74 * Given a {@link Node} with an {@link InstancedMesh} extension, returns a list

Callers 1

uninstance.test.tsFile · 0.90

Calls 12

createTransformFunction · 0.85
createInstanceNodesFunction · 0.85
getLoggerMethod · 0.80
getRootMethod · 0.80
listNodesMethod · 0.80
addMethod · 0.80
setMeshMethod · 0.80
disposeExtensionMethod · 0.80
disposeMethod · 0.65
debugMethod · 0.65
addChildMethod · 0.45
listAttributesMethod · 0.45

Tested by

no test coverage detected