Attach mesh to bone

Started by
6 comments, last by Alundra 8 years, 5 months ago

I couldn't find anything on google that is related to the subject of attaching a mesh (e.g a sword) to a bone when doing skeletal animation.

What's the popular term of this subject? Is there a good guide you can link me to?

Advertisement

What do you mean? Like, how to go about creating a framework for skeletal animation? Are you using your own engine and mesh/animation format?

Attachment is simply get the world transform of the bone or just a point which is in the skeleton and set your mesh based on it.

You have to param position offset and rotation offset to have it correct visually.

What do you mean? Like, how to go about creating a framework for skeletal animation? Are you using your own engine and mesh/animation format?

I created a framework for skeletal animation, I just haven't implemented "mesh attaching" yet. I'm asking about that.

I use COLLADA animated models made by people on the net.

Attachment is simply get the world transform of the bone or just a point which is in the skeleton and set your mesh based on it.

You have to param position offset and rotation offset to have it correct visually.

You mean I have to manually add these offsets, based on eye?

Every SceneNode in my system may have a Bone object attached to it.

Each bone has its "finalMatrix" which is boneOffsetMatrix * boneToRootMatrix. (boneToRootMatrix is the multiplications of boneAnimationMatrix * boneParent->boneAnimationMatrix to the top of the hierarchy)

When I try to draw a small sphere with an arbitrary bone's finalMatrix I get the wrong position.

Here's an example of what I do:


SceneNode *wrist = rootNode->findFirstNode("wrist_jnt_rt"); //right wrist node
Bone *wristBone = wrist->bone();

shaderProgram->setUniform("ProjectionMatrix", perspectiveProjectionMatrix);
shaderProgram->setUniform("CameraMatrix", CameraMatrix);
shaderProgram->setUniform("ModelMatrix",wristBone->finalMatrix);

RenderSphere sph( Sphere(glm::vec3(0,0,0), 1.f) );
sph.draw();

glutSwapBuffers();

The sphere is drawn in the wrong place. It also doesn't rotate the same as the right wrist.

You mean I have to manually add these offsets, based on eye?

Yes.

When I try to draw a small sphere with an arbitrary bone's finalMatrix I get the wrong position.

Maybe you are not in the same space, you have to use the bone world position + the position of the scene node unless your bone matrix is already in the good space.

I found the solution. The correct matrix is


shaderProgram->setUniform("ModelMatrix", modelTransformationMatrix * wristBone->nodeMatrixToRoot);

You mean I have to manually add these offsets, based on eye?

Yes.

Any helper tools that may help me with this? I don't want to have to build my app 100 times just to adjust a mesh.

If you have an editor or bind key to move in-game to see the result you can adjust visually directly to have the good value, if not, you have no choice.

This topic is closed to new replies.

Advertisement