Hi,
Given:
"meshes": [
{
"name": "my_mesh",
"primitives": [
{
"attributes": {
"POSITION": 0,
"JOINTS_0": 1,
"WEIGHTS_0": 2
},
"indices": 3,
"material": 0
}
]
}
],
...
attribute vec4 a_joint;
attribute vec4 a_weight;
uniform mat4 u_jointMat[2];
...
void main(void)
{
mat4 skinMat =
a_weight.x * u_jointMat[int(a_joint.x)] +
a_weight.y * u_jointMat[int(a_joint.y)] +
a_weight.z * u_jointMat[int(a_joint.z)] +
a_weight.w * u_jointMat[int(a_joint.w)];
vec4 worldPosition = skinMat * vec4(a_position,1.0);
...
}
the worldPosition
should be the vertex world position, but I have a doubt on the meaning of u_jointMat
.
In the tutorial page, it is described as
jointMatrix(j) =
globalTransformOfJointNode(j) *
inverseBindMatrixForJoint(j);
So I could write:
mat4 skinMat =
a_weight.x * globalTransformOfJointNode((a_joint.x) * inverseBindMatrixForJoint((a_joint.x) +
a_weight.y * globalTransformOfJointNode((a_joint.y) * inverseBindMatrixForJoint((a_joint.y) +
a_weight.z * globalTransformOfJointNode((a_joint.z) * inverseBindMatrixForJoint((a_joint.z) +
a_weight.w * globalTransformOfJointNode((a_joint.w) * inverseBindMatrixForJoint((a_joint.w);
vec4 worldPosition = skinMat * vec4(a_position,1.0);
with a_position
the vertice position taken from the mesh attribute POSITION
above, a_weight
the weight from WEIGHT_0 at the proper offset and a_joint
the joint id from JOINT_0 at the proper offset.
Nonetheless I don’t get the proper world vertex position.
My global matrices are gathered like so:
From parent to childs,
local_matrix = T * R * S
, each taken from the animation channel at the proper animation step
and the global
this_global = parent_global_matrix * local_matrix
Reading the vertices info from Blender show a correct result but not in my code. At all.
What’s missing ?
If you need more info I will happily expand to clarify.
Note: I am writing a high level code in C++ to print the info I need, it is not OpenGL related.