XNA - 通过代码在各个骨骼上执行旋转和转换

时间:2014-01-29 15:21:38

标签: c# xna

我在没有skinnedprocessor的xna框架中使用fbx文件格式。

我关注了this之类的一些关于个体骨骼旋转或平移的帖子,用于在人体中创建手势。我使用XNA样本显示fbx模型,我甚至能够左右移动全身。

现在我的问题是我编写了一个用于旋转一些有效骨骼的代码,但只显示了普通模型,而不是带有旋转骨骼9的模型。

这段代码是用skinnedmodelprocessor.cs编写的 的

   List<Matrix> bindPose = new List<Matrix>();
   List<Matrix> inverseBindPose = new List<Matrix>();
  List<int> skeletonHierarchy = new List<int>();

     foreach (BoneContent bone in bones)
            {
                bindPose.Add(bone.Transform);
                inverseBindPose.Add(Matrix.Invert(bone.AbsoluteTransform));
                skeletonHierarchy.Add(bones.IndexOf(bone.Parent as BoneContent));
            }

 //code for updating the position of a particular bone
        int idbone = 9;
    bindPose[idbone] = bindPose[idbone]*Matrix.CreateRotationX(MathHelper.ToRadians(45.0f));

的 这是我的绘制方法  protected override void Draw(GameTime gameTime)             {                 GraphicsDevice.Clear(Color.CornflowerBlue);

            Matrix[] bones = animationPlayer.GetSkinTransforms();

            Matrix view = Matrix.CreateTranslation(0, -40, 0) * Matrix.CreateRotationY(MathHelper.ToRadians(camerarotation))
                          * Matrix.CreateRotationX(MathHelper.ToRadians(cameraArc))
                          * Matrix.CreateLookAt(new Vector3(0, 0, -cameraArc), new Vector3(0, 0, 0), Vector3.Up);

            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1, 10000);
         //Looping over multiple meshes
            foreach (ModelMesh mesh in firstmodel.Meshes)
            {
                foreach (SkinnedEffect effect in mesh.Effects)
                {
                    effect.SetBoneTransforms(bones);
                    effect.EnableDefaultLighting();
                    effect.World = worldtransformations[mesh.ParentBone.Index];
                    effect.View = view;
                    effect.Projection = projection;
                    effect.SpecularColor = new Vector3(0.25f);
                    effect.SpecularPower = 16;
                }
                mesh.Draw();
            }
}

的 它看起来像是搞砸了。

我有三个型号的第一和第三个模型错误弹出“没有皮肤数据”,但我加载了一切(纹理,更改内容处理器)。

第二个模型只是给了空白屏幕。

0 个答案:

没有答案
相关问题