Currently i store all bones in world space and load them directly from binary file.
目前我将所有骨骼存储在世界空间中并直接从二进制文件加载它们。
I check this skeleton by placing an "arrow object" with the matrix bone_mat as "modelmatrix". Works as expected.
我通过放置一个矩形bone_mat为“modelmatrix”的“箭头对象”来检查这个骨架。按预期工作。
Variable explanations:
1. bone_mat = world_space bone matrix (loaded from file)
2. bind_pose_mat = relative transformation from parent bone to current bone
3. skinning_mat = final joint transformation matrix
The next step is to calculate the bind pose matrix. The relative bone matrix to its parent.
下一步是计算绑定姿势矩阵。相对骨骼矩阵到其父级。
I do it this way:
我是这样做的:
/* bone mat * inverse(parent bone mat) */
mesh->anim_data.skeleton[i].bind_pose_mat =
urdMat4MulMat4( mesh->anim_data.skeleton[i].bone_mat, urdMat4Inverse(parent_bone->bone_mat) );
I check this matrix by getting it into world space again like this:
我通过再次进入世界空间来检查这个矩阵,如下所示:
world_space_mat =
urdMat4MulMat4( mesh->anim_data.skeleton[i].bind_pose_mat, parent_bone->bone_mat);
Which results in the same matrix as bone_mat.
这导致与bone_mat相同的矩阵。
Root bones are stored in world space, as they are not relative to any parent
根骨骼存储在世界空间中,因为它们与任何父级不相关
root_bone.bind_pose_mat = bone_mat
so now that im in local space, i though all i needed to do was
所以现在我在当地的空间,我虽然我需要做的就是
/* interpolated vertex = base_vertex * bones[bone_index].bind_pose_mat */
mesh->interpolated[i].vertex = urdMat4MulVec3(skeleton[bone_index].bind_pose_mat , mesh->base[i].vertex);
which results in a distorted mesh.
这会导致网格扭曲。
Edit: After some thoughts, it looks like im not in local space, but in relative space (bind_pose is currently the relative matrix to its parent).
编辑:经过一些思考,看起来我不是在局部空间,而是在相对空间(bind_pose目前是其父级的相对矩阵)。
But im stuck with theory there.
但我坚持理论。
1 个解决方案
#1
2
Ok, looks like i got it working.
好吧,看起来我搞定了。
Math Equation is (simplified):
数学方程式(简化):
v' = SUM { w * m * v }
where
哪里
- w is the weight (all bones have 1.0 weight currently)
- w是重量(目前所有骨头都有1.0重量)
- m is the world space bone matrix (animation bone)
- m是世界空间骨骼矩阵(动画骨骼)
- v is the relative vertex position of the bind pose
- v是绑定姿势的相对顶点位置
inv_bone_mat = the inverted world space bone matrix
bone_mat = world space bone matrix
to calculate v:
计算v:
vec3 v_relative = bind_bones[bone_index].inv_bone_mat * vertex_object_space
now all that was needed is:
现在所需要的只是:
vec3 skinned_vertex = frame[current_frame].anim_bones[bone_index].bone_mat * v_relative
ofc this can be extended by multiple bones/weight influences
这可以通过多个骨骼/重量影响来扩展
i hope this helps future readers.
我希望这有助于未来的读者。
#1
2
Ok, looks like i got it working.
好吧,看起来我搞定了。
Math Equation is (simplified):
数学方程式(简化):
v' = SUM { w * m * v }
where
哪里
- w is the weight (all bones have 1.0 weight currently)
- w是重量(目前所有骨头都有1.0重量)
- m is the world space bone matrix (animation bone)
- m是世界空间骨骼矩阵(动画骨骼)
- v is the relative vertex position of the bind pose
- v是绑定姿势的相对顶点位置
inv_bone_mat = the inverted world space bone matrix
bone_mat = world space bone matrix
to calculate v:
计算v:
vec3 v_relative = bind_bones[bone_index].inv_bone_mat * vertex_object_space
now all that was needed is:
现在所需要的只是:
vec3 skinned_vertex = frame[current_frame].anim_bones[bone_index].bone_mat * v_relative
ofc this can be extended by multiple bones/weight influences
这可以通过多个骨骼/重量影响来扩展
i hope this helps future readers.
我希望这有助于未来的读者。