I have a human-like rigged 3D model in a DAE file. I want to programmatically build a scene with several instances of this model in different poses.
I can extract the SCNSkinner and skeleton chain from the DAE file without problem.
I have discovered that to have different poses, I need to clone the skeleton chain, and clone the SCNSkinner as well, then modify the skeletons position. Works fine.
This is done this way:
// Read the skinner from the DAE file
let skinnerNode = daeScene.rootNode.childNode(withName: "toto-base", recursively: true)! // skinner
let skeletonNode1 = skinnerNode.skinner!.skeleton!
// Adding the skinner node as a child of the skeleton node makes it easier to
// 1) clone the whole thing
// 2) add the whole thing to a scene
skeletonNode1.addChildNode(skinnerNode)
// Clone first instance to have a second instance
var skeletonNode2 = skeletonNode1.clone()
// Position and move the first instance
skeletonNode1.position.x = -3
let skeletonNode1_rightLeg = skeletonNode1.childNode(withName: "RightLeg", recursively: true)!
skeletonNode1_rightLeg.eulerAngles.x = 0.6
scene.rootNode.addChildNode(skeletonNode1)
// Position and move the second instance
skeletonNode2.position.x = 3
let skeletonNode2_leftLeg = skeletonNode2.childNode(withName: "LeftLeg", recursively: true)!
skeletonNode2_leftLeg.eulerAngles.z = 1.3
scene.rootNode.addChildNode(skeletonNode2)
It seems the boneWeights and boneIndices sources are duplicated for each skinner, so if I have let's say 100 instances, I eat a huge amount of memory, for something that is constant.
Is there any way to avoid the duplication of the boneWeights and boneIndices ?