Hello fellow babylonians
I’ve run into a weird behavior : I import a skinned GLTF mesh into a scene, using babylon 4.0.3,
BABYLON.SceneLoader.ImportMeshAsync("", "FOLDER_PATH", "robot.gltf", scene)
Then I modify the bones rotations to a random quaternion.
Note : the robot is made of several mesh, all sharing the same skeleton. So i only change the first mesh skeleton.
mesh.skeleton.bones.forEach((b) => {
b.setRotationQuaternion(BABYLON.Quaternion.FromEulerAngles(0.2, 0.5, 0.3));
});
The mesh is properly following the bones structure (See image on the left)
Now : I need to clone this mesh to have several of these in the scene
let clonedRobot = new BABYLON.AbstractMesh(id, scene);
let clonedSkeleton: BABYLON.Skeleton;
let clonedParts: BABYLON.AbstractMesh[] = []; // used to clone proper hierarchy
meshes.forEach(originalPart => {
let clonedPart = originalPart.clone(id + "." + originalPart.name, clonedRobot );
clonedParts[originalPart.name] = clonedPart;
if (!originalPart.parent) {
clonedPart.parent = clonedRobot ;
} else {
clonedPart.parent = clonedParts[originalPart.parent.name];
}
if (originalPart.skeleton) {
if (!clonedSkeleton) { // use only one skeleton per clone, shared by all meshes
clonedSkeleton = originalPart.skeleton.clone(id + "." + originalPart.skeleton.name, id + "." + originalPart.skeleton.id);
}
clonedPart.skeleton = clonedSkeleton;
}
});
Now, using the same bone rotation as before, the result is weird. The bones are in the same location, but the skinning seems to fail.
See image on the right
I could really use some help. I can’t share the model, I could maybe try to use a similar one to replicate in the playground if needed.
I’m guessing i’m doing something wrong while cloning, OR maybe there is a bug in the clone process of babylonJS.
M.