Note: This question isn’t about thin instances. I use those elsewhere, but this is about cloneTransformNode.
I’ve successfully used animation groups loaded from gltf in my game. Now I’m making a small number of clones via cloneTransformNode. I didn’t find an example in the lite repo. Here’s my initial thoughts. Is this correct, or is there a better way?
- cloneRoot = cloneTransformNode(container.entities[0])
- walk the node tree of container.entities[0] and cloneRoot in parallel, yielding (original, clone)
- for each targetedAnimation in the container.animationGroup[desiredIndex]
- if target === original, create an equivalent TargetedAnimation where target = clone, remember this.
- if any TargetedAnimations were created, clone the animationGroup, using the new targeted animations.
- addScene(clonedAnimationGroups)
Thanks!
Your idea makes sense, but it will not work directly. Changing targetedAnimations[].target does not retarget the bindings used during playback. cloneTransformNode clones the hierarchy, but not its independent animation state.
cloneTransformNode alone is not enough for independently animated clones: changing targetedAnimations[].target does not retarget the runtime bindings.
For a small number of copies, fetch the GLB once as an ArrayBuffer, then call loadGltf(engine, bytes) for each copy. Each load creates an independent hierarchy, skeleton, and animation bindings without downloading the file again.
Then add each hierarchy to the scene and play the animation groups returned by its own container.
Got it.
As an aside, I tried this approach based on the Babylon-full video for how to do this. Ironically, in the case of this functionality, the Babylon-full API feels more consistent with the typical way lite apis are structured, with simpler data types and object relationships that allow direct manipulation.