Sign in to follow this  
C3rial

Fbx and bone transforms

Recommended Posts

Hi! I'm importing fbx models for my game, but I'm having a hard time trying to figure out how to manipulate the transforms of the individual bones. The model I'm working on is a face-model with 13 bones. I've named two of the bones, the ones that weigh on the eyelids. In my xna-app I'm trying to manipulate the translation of one of the eyelids, but I end up translating the entire model. Here's what I've put in my loadcontent:
[Source]
spriteBatch = new SpriteBatch(GraphicsDevice);
            device = graphics.GraphicsDevice;

            vertexDecl = new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements);
            effect = Content.Load<Effect>("effects");
            model = Content.Load<Model>("FaceTestBinary");
            modelTex = Content.Load<Texture2D>("skinTex");
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    meshPart.Effect = effect.Clone(device);
                }
            }
            originalTransform = model.Bones[0].Transform;
            viewMatrix = Matrix.CreateLookAt(new Vector3(0, 10, 5), new Vector3(0, 0, -30), new Vector3(0, 1, 0));
            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.2f, 500.0f);
[/Source]
And here's what I've put in my Draw:
[Source]
graphics.GraphicsDevice.Clear(Color.Black);
            worldMatrix = Matrix.CreateScale(0.2f, 0.2f, 0.2f) * Matrix.CreateRotationY(MathHelper.ToRadians(modelRotation + 90)) * Matrix.CreateTranslation(new Vector3(0, -10, -50));
            //model.Bones[0].Transform = Matrix.Identity * Matrix.CreateTranslation(new Vector3(0, boneTestingY, -25));
            model.Bones[0].Transform = Matrix.Identity;
            //model.Bones["RightEyelid"].Transform = Matrix.CreateRotationY(-(float)Math.Sin((float)gameTime.TotalGameTime.TotalSeconds)) * originalTransform;
            model.Bones["RightEyelid"].Transform *= Matrix.CreateRotationY(boneTestingY) * originalTransform;
            Matrix[] modelTransforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(modelTransforms);
            //model.Bones[7].Transform = Matrix.Identity * Matrix.CreateTranslation(new Vector3(0, boneTestingY, -25));
            //Matrix[] xwingTransforms = new Matrix[xwingModel.Bones.Count];
             foreach (ModelMesh mesh in model.Meshes)
             {
                 foreach (Effect currentEffect in mesh.Effects)
                 {
                     currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"];
                     currentEffect.Parameters["xTexture"].SetValue(modelTex);
                     currentEffect.Parameters["xEnableLighting"].SetValue(true);
                     currentEffect.Parameters["xLightDirection"].SetValue(lightDirection);
                     currentEffect.Parameters["xAmbient"].SetValue(0.5f);
                     currentEffect.Parameters["xWorld"].SetValue(modelTransforms[mesh.ParentBone.Index] * worldMatrix);
                     currentEffect.Parameters["xView"].SetValue(viewMatrix);
                     currentEffect.Parameters["xProjection"].SetValue(projectionMatrix);
                 }
                 mesh.Draw();
             }

            base.Draw(gameTime);
[/Source]
I'm changing the value of the variables "modelRotation" and "boneTestingY" with the arrowKeys. Do I need to add some bone-weight-handling in the vertex-shader to get it working, or is it possible to manually manipulate the transforms of the bones outside of the shader? Also - does it matter if I export the fbx using binary og ascii? Best Regards! PS: Please let me know if there's some more info you need!

Share this post


Link to post
Share on other sites
First, I'm not an XNA person. However, it appears that you're multiplying the eyelid transform by the rootframe transform ("originalTransform"). I'm sure that's not good.

Try deleting that transform from that equation.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this