Some helpful tips from posts in the forum.
Adrian.

---------------------------------------------------------------------------------------------


I am working on a project to animate an avatar using control systems. This is not an application suited to key frame animation.
Is there any easy way to take direct control of the joint angles. At the moment it looks like I will have to generate animation key frames(on a one to one basis with rendered frames) and feed them into cal3d, this seems very in-efficient. Is it?

      By: nobody ( Nobody/Anonymous )
      RE: non-keyframe based animation  
      2002-07-18 15:11
      The subroutine CalMixer::updateSkeleton is the one that updates the bone positions each frame. It is called directly from CalModel::update.

      One approach would be to remove the call to CalModel::update from your application. Instead, use your own code to update the bone positions. This is fairly straightforward:

      1. Call CalModel::getSkeleton to get a pointer to the skeleton object.
      2. Call CalSkeleton::getBone to get the bone object.
      3. Call the following sequence on the bone:

      CalBone::clearState();
      CalBone::blendState(1.0, translation, rotation);
      CalBone::lockState();
      CalBone::calculateState();

After you've updated the bone positions for the frame, use CalPhysique::update to update the vertex positions. 

---------------------------------------------------------------------------------------------

By: nobody ( Nobody/Anonymous )
Bone Translation and TranslationBoneSpace  
2002-06-10 14:42
I'm trying to understand the workings of some of Cal3D as opposed to just making use of it.

There's one thing fundamental thing I'm unsure of though, and that is why each bones has two sets of transforms for Translate and Rotate.

I've previously written code to handle skinned models and each bone would have a rotation and translation relative to it's parent bone.

But with Cal3D, there are two sets, and double the number of calculations going on.
Can someone explain to me why these transforms can't be combined into one. And if there is a way to do it, how would I go about combining them.
I'm interested in converting between my own format to CAL and vice versa - but this is a stumbling block for me.

Thanks for reading.
Muzza

      By: nobody ( Nobody/Anonymous )
      RE: Bone Translation and TranslationBoneSpace  
      2002-06-11 01:08
      Well, as i saw, there only one pass of recaculation of mesh points.

      The purpose of storing twice rotation/translation - the one is for local bone translation/rotation, the second is absolute translation/rotation..
      When mesh recalculates it's state it's needed both - local for updating animated bone position, second for recalculate absolute transform, when preparing mesh for rendering.

      By: nobody ( Nobody/Anonymous )
      RE:Bone Translation and TranslationBoneSpace  
      2002-06-11 12:07
      I can understand why in code there are several rot/trans stored, but the load/save structure actually stores two sets.

      Let me rephrase the query:
      As I understood it, with bones, all you need to know is the rotational and translation offset from the parent bone. With that information alone you can calculate the final position of each bone and therefore the final position of each vertex.

      But Cal3D stores two sets and I don't understand why.

            By: beosil ( Bruno Heidelberger )
            RE:Bone Translation and TranslationBoneSpace  
            2002-06-11 12:58
            You are right, there are two sets of transformations stored in each bone. Let me explain why:

            The first set is composed of the usual relative transformation to the parent, and the resulting absolute transformation. These are used to animate the underlying skeleton of the model.

            The second set of transformations (tagged as 'BoneSpace') is precomputed at the time of the export, and is used to actually deform the mesh vertices. All the mesh data is stored in model space coordinates, so when you want to compute the influence of a bone on a vertex, you need to transform this vertex from model space into the specific space of the influencing bone first.

            I hope this makes any sense at all ... if not, ask again =)

      By: nobody ( Nobody/Anonymous )
      RE: Bone Translation andTranslationBoneSpace  
      2002-06-11 13:22
      Ah OK thanks. I understand now.

      This leads to a further questions though:

      Is there a way I can get this down to one transform?
      I've tried two things:
      1. Precalculating a join between the Anim Bone Transform and the Bone Space Transform into one single Transform which I then use the vertices.
      2. Pretransforming all the vertices to be in bone space. This taking each vertex, find the bones that influence it, and transforming it by their BoneSpace transforms with the correct weighting.

      Neither of these seem to work. Is this just something that will not work or am I just going wrong somewhere?

      -Muzza

      By: nobody ( Nobody/Anonymous )
      RE: Bone Translation continued...  
      2002-06-11 13:46
      Hmmm... I've been thinking, and is this the issue:

      Most skinned models that use blended bone animation are actually made out of a single mesh. Therefore there is no need to transform between Model Space and Bone Space, and you only need one transform per bone.

      But in Cal3D, the skinned models can be made out of many seperate meshes with seperate materials. Therefore, an extra transform is needed.

      I'm not 100% on this one, so am I right?

      -Muzza

      By: nobody ( Nobody/Anonymous )
      RE: Bone Translation cont...  
      2002-06-11 13:51
      Been thinking this through a bit more and I think I may understand why I can't do what I'm trying to do.

      Most systems where you have skinned models with blended bones consist of one single mesh. Therefore there is no need to transform between model space and bone space and only one transform per bone is required.

      Cal3D allows you to have many meshes per model each with it's own material. Therefore two transforms are needed and it is actually impossible to convert it to the other system.

      I'm not 100% on this, but do you think I'm right?

      -Muzza

      By: nobody ( Nobody/Anonymous )
      RE:BoneTranslation and TranslationBoneSpace  
      2002-06-11 13:54
      Forum seems to be a bit screwed up, so sorry if this appears more than once.

      Been thinking this through a bit more and I think I may understand why I can't do what I'm trying to do.

      Most systems where you have skinned models with blended bones consist of one single mesh. Therefore there is no need to transform between model space and bone space and only one transform per bone is required.

      Cal3D allows you to have many meshes per model each with it's own material. Therefore two transforms are needed and it is actually impossible to convert it to the other system.

      I'm not 100% on this, but do you think I'm right?

      -Muzza

      By: nobody ( Nobody/Anonymous )
      RE: Bone TranslationandTranslationBoneSpace  
      2002-06-11 14:39
      Yet more thoughts on the implications of this if I'm correct.

      The has large issues for the speed of any application that needs to display a large number of characters.

      Obviously, having twice the number of matrix multiplications is not especially desirable, but just as bad (for my uses) this means it is probably impossible to do the vertex calculations from inside a vertex shader as is very popular with current graphics cards.

      I'll have to give this one some more thought.
      Cal3D seems to be brilliant in what it does, but this is an unfortunate stumbling block for speed purposes.

      -Muzza

            By: beosil ( Bruno Heidelberger )
            RE: Bone TranslationandTranslationBoneSpace  
            2002-06-12 08:14
            I don't quite agree with your statements above, here is why:

            The skin transformation pipeline which is implemented in Cal3D is about "state-of-the-art". As example, DirectX 8 has a similar architecture (see the D3DXSkinMesh documentation). You will find the said bone space transformation step there too.

            The skinning which is currently done on the CPU could easily be moved over to a vertex shader. You would setup the matrix palette with the final bone transformations (= bone space transformation * current absolute transformation) and feed the shader with the vertex data (bone weights included).

            And last, I don't think that the few additional matrix/quaternion multiplications would bring such a big performance hit as you describe it. Remember that you won't have more than 30 bones on a character, even less when you don't animate all finger elements. So no big speed loss there. Another thing is the switch to a vertex shader approach that would definitively bring a big performance improvement. There are other disadvantages though, as example no access to the final skinned vertex data for cloth animation, but this is a different topic =)

      By: nobody ( Nobody/Anonymous )
      ME: Bone Translation and TranslationBoneSpace  
      2002-06-14 10:30
      I've done some measurement myself. The "calculateState" function take almost zero CPU time. The CPU time is all spent in "calculateVertices" (which only accesses the bonespace transforms).

- Josh 

-----------------------------------------------------------------------------------------


By: nobody ( Nobody/Anonymous )
rotating a models bone  
2002-01-28 12:50
I need to know if their is a good way for me to move a models arm segments while still displaying other animations involving the legs for instance. My reason for wanting to do this is to have my model be able to move its hand to any arbitrary position. It appears that this is achievable using the core bone classes but I am curious as to what this will do if I am using the mixer to handle other animations and whether or not the instances will update when I move a bone on the core model. Is their a better way to do this?

thanks for any help you can give me

      By: beosil ( Bruno Heidelberger )
      RE: rotating a models bone  
      2002-01-30 10:42
      The core classes are not meant to be used for such task, see them more as data containers which are used by every instance of a model. Take a look at the Architecture chapter in the Cal3D User's Guide, if you havent' already.

      While thinking about your question, I noticed that some needed functionality is missing in the current version of the Cal3D library which would be needed to achieve your goal, but here is basically what I would do:

      First of all, do not call the CalModel::update() function each frame to update the model. Take a quick look at this function, and you will see that it just calls a few other update functions itself. Basically, you need to insert your code to adjust the arm after the CalMixer has done its job and before CalPhysique applies the skin to the skeleton.

      So here is the actual modification codewise:

      Replace:

      m_pModel->update(deltaTime);

      with this:

      m_pModel->GetMixer()->updateAnimation(deltaTime);
      m_pModel->GetMixer()->updateSkeleton();

      my_arm_move_function();

      m_pModel->GetPhysique()->update();
      m_pModel->GetSpringSystem()->update(deltaTime);

      With the above change, the my_arm_move_function() gets called at the right moment to set the arm segment yourself, which is the next step.

      Your my_arm_move_function() should now set the transformation of the wanted bones, and calculate the state of the full skeleton again.

      You can get the bones through the CalSkeleton instance of your CalModel (e.g. m_pModel->getSkeleton()->getBone(id);). What is missing right now, is a function to set the transformation directly in the bone, like setTranslation() and setRotation(). Another problem lies in the calculateState() function from the CalSkeleton class that would handle the pose update for the whole skeleton: It calculates the state from the relative transformations, so you would have the set the relative transformation of the bones to make it work, oh well.

      As you can see, it's possible with some hacking, but it's not that easy as it should be. I have put this problem on the TODO list, and I will provide a simple way to do it in the next version of Cal3D.

      By: nobody ( Nobody/Anonymous )
      RE: rotating a models bone  
      2002-01-30 14:31
      thanks very much, I had not thought of that solution and I will be pleased to see an easier method in a future release.

      rosencrantz

      By: nobody ( Nobody/Anonymous )
      cant we ?  
      2002-01-31 01:37
      am i wrong ? can we solve the translation and rotation problem with the "blendState" method in the Calbone class

      dart

            By: beosil ( Bruno Heidelberger )
            RE: cant we ?  
            2002-02-01 10:12
            You're right, I completely forgot about that. Thanks for the hint.

            There is one little pitfall: You have to call clearState() on the bone before setting the new translation/rotation with the blendState() call. This is necessary, because of the internal weight accumulation on each bone.

      By: nobody ( Nobody/Anonymous )
      re:clearState  
      2002-02-02 05:15
      ok that works well i can get real-time translation with the blendState method when i render the skeleton only.

      but i cant see any mesh transformation when i render the model.

      i think because of the updateAnimation takes place first??

      dart

      By: nobody ( Nobody/Anonymous )
      ok done  
      2002-02-02 09:02
      i've solved the problem.

      blendState method affects the values of m_translationAbsolute only so i've added:

      //for translation only
      m_translationBoneSpace = translation;

      under that which had solved the problem well.
      This can be done in another function of the calBone class perhaps !

      p.s. thanks for all Bruno, i hope cal3d will be very cool in near future.

      dart

      By: jahare ( Justin Hare )
      RE: rotating a models bone  
      2002-02-23 14:48
      I've also been wanting to manually set the Cal3d models in certain positions. I used the ideas you've been talking about here, and translating bones works, but I'm having problems rotating them.

      I attempt to get an idle skeleton to turn his head left/right by modifying the bone's quaternion. The quaternion values start out like this:

      X 3.83535e-14
      Y -1.10427e-09
      Z 0.000398831
      W 0.0395647

      And I'm trying to rotate by modifying the W value. However, it seems to act like a scaling factor rather than a rotation. If I increase the W value, the head grows uniformly larger. If I decrease it, the head gets smaller.

      It's possible I have an incorrect understanding of quaternions, and if anyone knows of a good reference that shows how to use them, let me know.

      By: jahare ( Justin Hare )
      Quaternions working  
      2002-02-23 15:07
      Okay, so yeah... it turns out I had the right knowledge about what the values represent, but not how to use quaternions in general.

Everything works now with the quaternion blend function. Problem solved.

--------------------------------------------------------------------------------------------

By: nobody ( Nobody/Anonymous )
Head animation / lookAt  
2002-09-06 15:50
What are people doing to make thier models look an arbitrary direction? I was thinking of exporting to animations. Have one that moves the head from all the way left, front and all right. Use maybe 5 keys. Do the same for up and down. Then find the ratio based on the view angles and blend the animations? Thoughts?

Leigh

      By: jahare ( Justin Hare )
      RE: Head animation / lookAt  
      2002-09-08 14:23
      Most of the work I'm doing with Cal3D has to do with real-time dynamic motion, so I wrote a function that you simply give an arbitrary point in space (relative to the model's position and rotation), and I figure out the proper CalQuaternion object that the head's bone should be.

      But I had to add some things into Cal3D in order to do that, such as a "SetRotation" function in the CalBone class and a function that calculates the proper quaternion to rotate one vector to another. So it can be done this way, but your way sounds like it would work just as well.

      justin

      By: nobody ( Nobody/Anonymous )
      RE: Head animation / lookAt (2)  
      2002-09-09 20:00
      Justin, it sounds great... could you post your patch into the SourceForge Patch Manager, so everyone could benefit from it? At least until Maxun merges into the official tree...

      Thanks

      By: jahare ( Justin Hare )
      RE: RE: Head animation / lookAt  
      2002-09-10 13:52
      These things that I've changed don't conflict with anything else in Cal3D and could be very useful for other purposes, so I'll merge them back into the CVS version.

      Once that is done, we'll have all the tools we need to do the LookAt function. I should be finished tonight or tomorrow morning. Keep an eye on the cal3d-commits mailing list if you're interested in the gritty details. Then I'll post the code showing exactly how to do it.

      justin

      By: nobody ( Nobody/Anonymous )
      RE: Head animation / lookAt  
      2002-09-06 17:41
      You can find the bone of the head and apply a transformation

            By: nobody ( Nobody/Anonymous )
            RE: Head animation / lookAt  
            2002-09-11 08:24
            Adjusting the head bone sounds pretty good and is most likely the fastest method. I dismissed this because it requires you to know what bone is the head (hard coded) and also it takes the control away from the artist. They hate that. When someone is looking they tend to move more than thier heads. I think you need some shoulder in there. I am not saying that the method you have proposed is no good, as maybe its the best way. Just pointing out what it doesn't do...

            Leigh

      By: jahare ( Justin Hare )
      RE: Code for the lookat functionality  
      2002-09-24 12:34
      I have added a few key functions to the CVS version of Cal3d so that a lookAt function is possible now. The code assumes that the model's default head position points along the negative Y-axis in the first place.

      All of the sample models that were included with Cal3D (the paladin, skeleton, and cally) are modeled this way.

      You should execute this code sometime after updateAnimations but BEFORE updatePhysique.

      This code is kind of hacked, but it does work for most purposes. If anyone has problems with it or has some input on how to make it better or more general, PLEASE let me know.

      So here we go:
      CalModel* model = <your model>;
      int neckBoneID = <your model's neck bone number>;
      CalVector target = <where you want the head to look>;
      //Note that the target vector is relative to your model's base coordinate system - NOT relative to the head


      //Get the neck bone
      CalBone* neckbone = model->getSkeleton()->getBone(neckBoneID);

      //Make the target vector relative to the head
      target = target - neckBone->getTranslationAbsolute();

      //We can't look at the head's position, so return
      if (target == CalVector(0,0,0)) return;

      //Normalize the direction (required for shortestArc calculation)
      target.normalize();

      //This is the head's original direction
      CalVector original (0, -1, 0);

      CalQuaternion headRot = shortestArc( original, target );

      headRot.conjugate();

      //Mess with the quaternion (I'm not sure why we have to do this)
      CalQuaternion tempRot = headRot;
      headRot.x = -tempRot.z;
      headRot.z = -tempRot.x;

      //Set the rotation and recalculate the state
      neckBone->setRotation( headRot );
      neckBone->calculateState();

      And that's all.

justin

---------------------------------------------------------------------------------------


Hi Adrian -

Here is some code that will allow you to point bones in the direction you
want. Note that you need to start out with a target point that is in the
model's coordinate system (ie. relative to the origin point between the
model's feet). Also, the two bones must be directly connected.


void PointAt(  CalBone* parentBone,
               CalBone* childBone,
               CalVector targetPos )
{

   //This is the direction the child bone is pointing now, in the parent
   //bone's coordinate system
   CalVector currentDirection = childBone->getTranslation();

   //Convert target position into the parent bone's coordinate system
   targetPos -= parentBone->getTranslationAbsolute();
   CalQuaternion tempRot = parentBone->getRotationAbsolute();
   tempRot.invert();
   targetPos *= tempRot;

   //Normalize both vectors for shortest arc calculation
   currentDirection.normalize();
   targetPos.normalize();

   //Get the current rotation that results in the child bone's current
   //direction
   CalQuaternion parentRot = parentBone->getRotation();

   //Multiply it by the shortest arc quaternion from the current direction
   //to the desired direction
   //Note: This shorestArc function is in the CalQuaternion class, so
   //      you might have to make it CalQuaternion::shortestArc(...)
   ///     instead.
   parentRot *= shortestArc( currentDirection, targetPos );


   //Set the parent bone and recalculate its children's states
   parentBone->setRotation( parentRot );
   parentBone->calculateState();

}

And that should be it. I know this works for the elbow/wrist and
shoulder/elbow bones. Let me know if you have problems or find an error.
Any feedback is appreciated.

Cheers,

justin


-----------------------------------------
Justin Hare  <jahare@vrac.iastate.edu>
Virtual Reality Applications Center
Iowa State University, Howe Hall
http://www.vrac.iastate.edu
-----------------------------------------


