Hi @Mario , I've done the following but I still don't know how to position the Object3D to the bone's world position while the skeleton animates. Below is an example of what I'm doing but the Object3D (called box in the sample) ends up no where near where the bone is located. Could you help?
// Init Function
// Load the skeleton
...
atlas = assetManager.require(ATLAS_PATH);
atlasLoader = new AtlasAttachmentLoader(atlas);
skelBinary = new SkeletonBinary(atlasLoader);
skeletonData = skelBinary.readSkeletonData(assetManager.require(SKEL_PATH));
skelMesh = new SkeletonMesh(skeletonData, (params) => {
params.depthTest = true;
params.depthWrite = true;
params.alphaTest = 0.001;
});
// Add the skeleton to the platform at 0,0,0
const platform = new Object3D();
platform.add(skelMesh);
scene.add(platform);
// Create a box and position to where the bone is by eye
const boxHelperMesh = new THREE.Mesh(new THREE.BoxGeometry(0.1, 0.1, 0.1), new THREE.MeshBasicMaterial({ color: 0xFFF, wireframe: true }));
const box = new Object3D();
// Where the hair of the character is located in 3D space which is where the bone is
box.position.set(-0.08, 1.87, 0);
box.add(boxHelperMesh);
scene.add(box);
// Get the bone where the hair is located
const bone = skelMesh.skeleton.findBone('Hair');
// Log the box's position for reference
console.log(box.position) // Vector3 {x: -0.08, y: 1.87, z: 0}
// Here I set the box's localToWorld to the bone's world x and y.
// Is there anything else I should be doing??
box.localToWorld(new THREE.Vector3(bone.worldX, bone.worldY, 0));
skelLoaded = true;
...
// Later in the animate function try and set the box's position to the bone
...
if (skelLoaded) {
skelMesh.update(delta);
const bone = skelMesh.skeleton.findBone('Hair');
// Here is where I want to position the box to the moving bone.
// But the position is VERY wrong!
// The hair and head do not move much, so I'm expecting to see values slightly
// different than the initial position. But values for x and y are in the 100s.
box.position.set(bone.worldX, bone.worldY, 0);
}