简体   繁体   English

mOffsetMatrix 在 Assimp 中实际上做了什么?

[英]What does mOffsetMatrix actually do in Assimp?

I am quite sure that mOffsetMatrix transforms vertex from mesh space to bone space, which is confirmed by this one http://assimp.sourceforge.net/lib_html/structai_bone.html我很确定 mOffsetMatrix 将顶点从网格空间转换为骨骼空间,这一点得到了证实http://assimp.sourceforge.net/lib_html/structai_bone.html

But then I saw this, which says that it actually transforms vertices from bone space to mesh space.但是后来我看到了这个,它说它实际上将顶点从骨骼空间转换到网格空间。 https://github.com/assimp/assimp/pull/1803 https://github.com/assimp/assimp/pull/1803

Now I am very confused.现在我很困惑。 So what exactly does mOffsetMatrix do?那么 mOffsetMatrix 究竟是做什么的呢?

The offsetMatrix of a bone is the inverse of that bone's global transform at bind pose .骨骼的offsetMatrix是该骨骼在绑定姿势处的全局变换 In other words, if you traverse the bone/node hierarchy, applying the local transform ( mTransformation in Assimp) of each bone/node hierarchically to its children, we get the global transform for each bone/node.换句话说,如果您遍历骨骼/节点层次结构,将每个骨骼/节点的局部变换( Assimp中的 mTransformation)分层应用于其子项,我们将获得每个骨骼/节点的全局变换。 The inverse of this matrix for a particular bone equals its offsetMatrix.特定骨骼的此矩阵的等于其 offsetMatrix。 As implied here, it can be computed manually - regardless, it is constant and should not be computed per frame.正如此处暗示的那样,它可以手动计算 - 无论如何,它是常数,不应按帧计算。

The name "offsetMatrix", though somewhat confusing (something like inverseBind would be clearer), probably comes from its use. “offsetMatrix”这个名字,虽然有点令人困惑(像inverseBind这样的东西会更清楚),可能来自它的使用。 The transform we use for skinning is ( B_keyframe * offsetMatrix ), where B_keyframe is the global transformation of a bone at some target location, provided eg by an animation clip.我们用于蒙皮的变换是 ( B_keyframe * offsetMatrix ),其中B_keyframe是某个目标位置的骨骼的全局变换,例如由动画剪辑提供。 This composite transformation is effectively an offset , from bind pose (where the mesh vertices are defined) to B_keyframe.这种复合变换实际上是一个偏移量,从绑定姿势(定义网格顶点的位置)到 B_keyframe。 When applied to vertices, (B_keyframe * offsetMatrix) will "move" vertices, from bind positions to whatever position B_keyframe transforms to.当应用于顶点时, (B_keyframe * offsetMatrix) 将“移动”顶点,从绑定位置到 B_keyframe 转换到的任何位置。
Note that if B_keyframe is equal to the bind transform, eg computed from the skeleton's mTransformation:s as above, then (B_keyframe * offsetMatrix) is identity and vertices will not move from their original positions in bind pose.请注意,如果 B_keyframe 等于绑定变换,例如根据上述骨架的 mTransformation:s 计算,则 (B_keyframe * offsetMatrix) 是标识并且顶点不会从绑定姿势中的原始位置移动。

I personally favour the "from mesh space to bone space" definition when it comes to offsetMatrix.当涉及到 offsetMatrix 时,我个人更喜欢“从网格空间到骨骼空间”的定义。 Why?为什么? Because the inverse of offsetMatrix - the (global) bone transform (at bind pose) - is most intuitively understood as a transformation from bone to mesh/model space .因为 offsetMatrix 的逆——(全局)骨骼变换(绑定姿势)——最直观地理解为从骨骼到网格/模型空间变换 Inverting back, offsetMatrix transforms from mesh/model space to bone space .反过来, offsetMatrix从网格/模型空间转换到骨骼空间
Compare with the View matrix in rendering: it is the inverse of the camera's world transform (T*R), and is generally understood to transform from world to view space.对比渲染中的View矩阵:它是相机世界变换(T*R)的逆,一般理解为从世界到视图空间的变换。

Here is the answer for your question ( coming from a solution from the bug ):这是您的问题的答案(来自错误的解决方案):

it depends how you think of the transform.这取决于您如何看待转换。 If the matrix multiplications come after the point (ie point * transform with point being a "row" vector) then it makes sense to say it converts from "mesh space to bone space", as it takes a point in mesh space and outputs a point in bone space.如果矩阵乘法出现在点之后(即点 * 变换,点是“行”向量),那么可以说它从“网格空间到骨骼空间”转换,因为它需要网格空间中的一个点并输出一个点在骨骼空间。 But when using matrix premultiplication as assimp does (tranform * point with point being a "column" vector) it makes more sense to think of it as transforming the space itself, from "bone space to mesh space", whereupon the point in mesh space can be used.但是当像assimp那样使用矩阵预乘时(转换*点,点是“列”向量),更有意义的是将其视为将空间本身从“骨骼空间到网格空间”的变换,因此网格空间中的点可以使用。

This is why the original poster is confused, because they are thinking about it backwards compared to how assimp treats point transformation.这就是原发帖人糊涂的原因,因为与assimp对待点变换的方式相比,他们是在倒推。 This is probably leading directly to their confusion with working out the transformation matrix of the bone and thinking this should be the same as mOffsetMatrix, when in fact it is the inverse.这可能直接导致他们对计算骨骼变换矩阵的混淆,并认为这应该与 mOffsetMatrix 相同,而实际上它是逆矩阵。

This is all especially confusing as DirectX uses postmultiplication, and OpenGL uses premultiplication.这尤其令人困惑,因为 DirectX 使用后乘法,而 OpenGL 使用预乘法。

This all said, i hope that someone can update the documentation so that it makes it clear for everybody.综上所述,我希望有人可以更新文档,以便让每个人都清楚。 It's very difficult to specify clearly without an "official" way of thinking about this sort of thing.如果没有对这类事情的“官方”思考方式,很难明确说明。 I can't even find it documented anywhere how assimp treats transformation matrix multiplication... although the matrix notation used on the "Data Structures" page of the assimp docs implies premultiplication with column vectors.我什至找不到任何地方都记录了 assimp 如何处理变换矩阵乘法......尽管在 assimp 文档的“数据结构”页面上使用的矩阵表示法暗示了与列向量的预乘。

Hope that this will help you.希望这会帮助你。

The documentation is wrong.文档是错误的。 So I need to update our doc.所以我需要更新我们的文档。 See issue 1950第 1950 期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM