0

I am making a simple bone animation library but I stuck in some point.

What I have: Mesh with few bones attached to it with animation. Mesh is properly skinned. It is 3d studio max file.

What I do:

  1. I export this skinned mesh with my plugin. I take first animation frame and multiply every vertex, by this matrix (pseudocode)

    Matrix invertedBoneMatrix = ZeroMatrix;
    invertedBoneMatrix += bone1WorldTransform * weight1;
    invertedBoneMatrix += bone2WorldTransform * weight2;
    invertedBoneMatrix += bone3WorldTransform * weight3;
    invertedBoneMatrix += bone4WorldTransform * weight4;
    invertedBoneMatrix.Invert();
    
    foreach (vertex)
       vertex = invertedBoneMatrix * vertex;
    
  2. When I load this model in my engine, I calculate world transforms for every bone at every animation frame and multiply every vertex by corresponding bone world transforms with proper weights.

Problem: Only first frame looks fine, others frames are distorted.

Maybe I have errors somewhere in my code, but I want to know, if my approach is correct - to bring all vertices to local space of its corresponding bones.

majakthecoder
  • 177
  • 3
  • 14
  • Why do you invert the generated matrix at all? Normally bone transformations are forward, so I don't see why you want to invert it. The right side multiplication of the vertex suggests, that you actually meant to *transpose* the matrix (depending on if you use row or column major ordering you may need to swap the order in the multiplication or add some transposition there). Anyway something with the inversion doesn't make sense here. – datenwolf Sep 10 '14 at 12:16
  • @datenwolf I think I need to multiply by inverse matrix, to bring vertices to bone local space. It is explained in first answer here: http://stackoverflow.com/questions/17127994/opengl-bone-animation-why-do-i-need-inverse-of-bind-pose-when-working-with-gp – majakthecoder Sep 10 '14 at 12:31
  • Ah, I see where your problem is now. In that Q&A you linked that inverse transformation is applied to compensate any "neutral" pose your model has been rigged with, before applying the animation. That's also why the first frame of your animation seems to look fine: Essentially you're bringing the model in the "neutral" pose before the actual animation transformations can be applied. I'm a bit rusty on the definitions of 3DSMax, but I each model format uses a slightly different transformation chain and you have to double check, that what you do matches the semantics of 3DS. – datenwolf Sep 10 '14 at 12:51
  • But why first frame is good and others not? When in my step (1) I use frame from the middle during exporting, then, during animation this is the only frame that looks fine. – majakthecoder Sep 10 '14 at 13:28
  • Hard to tell without seeing the rest of your code. – datenwolf Sep 10 '14 at 13:36

0 Answers0