Jump to content
  • Advertisement
Sign in to follow this  
ApoelAlex

Attach an object to a bone

This topic is 3750 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I have a headless model with animation. And i want to attach the head (in code), to the headless model. How is this possible using XNA? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
You are going to need to provide quite a bit more explanation than that. How are your models set up. How is your skeleton set up. I'm not too familiar with XNA, but I presume it has some built in skeletal animation support?

Share this post


Link to post
Share on other sites

Yep, it has.

Assuming you've got a typical animation going in XNA for your headless model, you could figure out which bone represents the 'neck stump' and use the transform of that bone to offset the head appropriately each frame. Going from the skinning sample, this transform can be fetched from the bones[] matrices generated in the Draw method and then used as the world matrix when drawing the head (with a seperate effect).

I've been tinkering a bit with this myself and the bone indices in the AnimationData collections don't seem to match the (named) bones in Model.Bones. This made finding the right index into the bones[] matrix a bit of trial and error for me. If anyone can confirm that the indices don't match up consistently, we could register a vote on MS Connect to see if this can be fixed.

Share this post


Link to post
Share on other sites
Ok, thanks for the reply.

For skinnedmesh animation am using the animation library XNAnimation.

I have create a table called trans.

private Matrix[] trans;

Then i copy all the bones of the model to this tranformation table.

this.trans = new Matrix[this.list[0].returnModel().Bones.Count];
this.list[0].returnModel().CopyAbsoluteBoneTransformsTo(trans);

Then what? Say i know the index of the neck bone is "0".
Below is the code for drawing the head:

private void DrawFacial(int index)
{
foreach (ModelMesh mesh in this.list2[index].returnModel().Meshes)
{
foreach (Effect effect in mesh.Effects)
{
if (effect is BasicEffect)
{
BasicEffect basic = (BasicEffect)effect;
basic.View = this.camera.ViewMatrix;
basic.Projection = this.camera.ProjectionMatrix;
basic.EnableDefaultLighting();
basic.DirectionalLight0.Direction = lightPos;
basic.World = Matrix.CreateTranslation(-0.8f, 111f, 0f) *
Matrix.CreateScale(0.073f) *
Matrix.CreateRotationY(33f) *
this.trans[0];
}
}
mesh.Draw();
}
}

Above code draws the head, but nothing else happen. Do i have to keep update the transformation table of the head bone each time?

Thanks for the help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!