io7m / jcalcium

Skeletal animation
ISC License
0 stars 0 forks source link

Mesh preprocessing #3

Closed io7m closed 7 years ago

io7m commented 7 years ago

A mesh exported from Blender will have one vertex attribute per bone, with each element specifying how much that vertex is affected by the bone in question.

These attributes need to be flattened into two attributes: A four-element integer vector stating which four out of all the bones affect this vertex the most, and a four-element floating-point vector that says how much the chosen bones affect the vertex.

------------------------------
| 1    | 3     | 4    | 2    |            <--- vertex 0
| 0.1  | 0.3   | 0.1  | 0.5  |
------------------------------
| 1    | 2     | 5    | 7    |            <--- vertex 1
| 0.6  | 0.2   | 0.2  | 0.0  |
------------------------------
|      |       |      |      |
  ...     ...    ...    ...

In the above, vertex 0 is affected most by bones 1,3,4,2. It is affected by bone 1 by 10%, bone 3 by 30%, etc. Vertex 1 is affected most by bones 1,2,5,7. It is affected by bone 1 by 60%, bone 2 by 20%, etc. The weights do not have to add up to 100%.

Note that creating these vertex attributes means that the mesh has knowledge of the integer indices of bones in a skeleton, and those indices are generated by compilation (#2). Therefore, the integer indices need to be generated in a deterministic and stable manner or every time anyone makes a minor (compatible) change to the skeleton, the integer IDs might change and all of the meshes would have to be re-processed.