I am working on creating a 3D model file with a skeleton, similar to the example on this page: three.js docs.
Progress so far:
- Successfully loaded a human-shaped OBJ file.
- Extracted geometry and material from the OBJ file in step 1 to create a skinnedMesh (Success).
- Created bone data fitting the size and position of the skinnedMesh in step 2, and added the constructed skeleton (Success).
- Temporarily added the skinnedMesh to the scene as a workaround (Success).
const skinIndices = [];
const skinWeights = [];
for (let i = 0; i < mesh.geometry.attributes.position.count; i++) {
skinIndices.push(0, 0, 0, 0);
skinWeights.push(1, 0, 0, 0);
}
mesh.geometry.setAttribute('skinIndex', new THREE.Uint16BufferAttribute(skinIndices, 4));
mesh.geometry.setAttribute('skinWeight', new THREE.Float32BufferAttribute(skinWeights, 4));
The problem is that the skinnedMesh doesn’t move following the bone, possibly due to incorrect calculations of skinIndices and skinWeights in step 4. When adjusting the position of the bones, only the bones move, but the skinnedMesh does not follow…
How can I resolve this so that the appearance of the 3D model moves according to the movement of the bones?