How to Calculate skinIndices and skinWeights for Developing SkinnedMesh?

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:

  1. Successfully loaded a human-shaped OBJ file.
  2. Extracted geometry and material from the OBJ file in step 1 to create a skinnedMesh (Success).
  3. Created bone data fitting the size and position of the skinnedMesh in step 2, and added the constructed skeleton (Success).
  4. 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?

When I started using three.js a few years ago, I did some testing with skeleton and bones. Maybe that would be helpful? (Some in German, but easily translatable into English.)

[solved] Problem porting SkinnedMesh from old Geometry to BufferGeometry

Skelett und Knochen V1
Skelett und Knochen V2
Skelett und Knochen V3
skeleton
Mara
https://codepen.io/hofk/pen/eWdZMb

Something more recent:

From the Collection of examples from discourse.threejs.org

Pino

see Pino - a procedurally generated and moved skeleton figure

What you are describing is a process known as “rigging” and is usually handled by 3d artists, in modelling software like Blender/Maya etc.
Rigging something in code is extremely complex for meshes that require more than one blend weight per vertex.

1 Like

That’s exactly what I found out after my tests at the time and therefore didn’t pursue the matter any further.

1 Like