Programmatically setting separate bone transform node transforms for instances?

Hi, I have a glb file with a character model and a skeleton. I want to instance the character model and set transforms on the transform nodes associated with the bone separately for each instance (imagine the minecraft player model - I don’t care about animations)

I have tried instancing the model with instantiateHierarchy and directly accessing the transform nodes with root.getChildTransformNodes() but this doesn’t work - as the bones aren’t associated with the new transform nodes!

What would be the easiest way of doing this for multiple characters with no extra draw calls?

cc @bghgary

The easiest way is to load the glb using an asset container and then call instantiateModelsToScene.

See here: https://doc.babylonjs.com/divingDeeper/importers/assetContainers#duplicating-the-models

I can’t get instantiateModelsToScene working :frowning:

See https://www.babylonjs-playground.com/#25YP25#3 for what I’m doing - loadNewPlayerModel on line 42 uses instantiateModelsToScene but the bone transformnode transforms aren’t applied to the instanced models

uncomment the alternative loadNewPlayerModel on line 24 (which doesn’t use instances) to see what I expect to be happening

any help appreciated :slight_smile:

I think there might be a bug with doNotInstantiate: false. If you don’t pass any arguments, then it works properly.

PG: https://www.babylonjs-playground.com/#25YP25#4

1 Like

I think that’s because it defaults to doNotInstantiate: true, cloning them instead of instancing them :confused:

You have to clone if you want different poses per skinned mesh. I am going to try to make a fix such that even if you pass doNoInstantiate to false, it will still clone for skinned meshes.

1 Like

PR is merged: Always clone skinned meshes for AssetContainer.instantiateModelsToScene by bghgary · Pull Request #12764 · BabylonJS/Babylon.js (github.com)

Your PG should be cloning the skinned mesh now.

1 Like