(_options: UninstanceOptions = UNINSTANCE_DEFAULTS)
| 34 | * @category Transforms |
| 35 | */ |
| 36 | export 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 |
no test coverage detected