旋转蒙皮模型';s的骨骼是否正确?XNA

本文关键字:是否 XNA 模型 旋转 | 更新日期: 2023-09-27 18:20:28

如何围绕蒙皮模型本身而不是模型的原点旋转蒙皮模型的骨骼?

SkinningSample中,当我旋转这家伙的前臂时,它会围绕模型的原点旋转。如果可能的话,我想围绕它们自己的原点旋转骨骼。

GetSkinTransforms()的描述是:

"获取相对于蒙皮的当前骨骼变换矩阵绑定姿势。"

所以我怀疑这可能就是问题所在。有人知道如何将这些转变转化为它们需要的样子吗?

这是SkinningSample的一部分。

  float rotation = 0;
    protected override void Update(GameTime gameTime)
    {
        HandleInput();
        UpdateCamera(gameTime);
        animationPlayer.UpdateWorldTransforms(Matrix.Identity);
        animationPlayer.UpdateSkinTransforms();
        Matrix RotationTransform = Matrix.CreateFromYawPitchRoll(rotation, 0, 0) ;
        animationPlayer.GetSkinTransforms().SetValue(RotationTransform, 34); 
        rotation = rotation + .1f;
        base.Update(gameTime);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice device = graphics.GraphicsDevice;
        device.Clear(Color.CornflowerBlue);
        Matrix[] bones = animationPlayer.GetSkinTransforms();
        // Compute camera matrices.
        Matrix view = Matrix.CreateTranslation(0, -40, 0) * 
                      Matrix.CreateRotationY(MathHelper.ToRadians(cameraRotation)) *
                      Matrix.CreateRotationX(MathHelper.ToRadians(cameraArc)) *
                      Matrix.CreateLookAt(new Vector3(0, 0, -cameraDistance), 
                                          new Vector3(0, 0, 0), Vector3.Up);
        Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                device.Viewport.AspectRatio,
                                                                1,
                                                                10000);
        // Render the skinned mesh.
        foreach (ModelMesh mesh in currentModel.Meshes)
        {
            foreach (SkinnedEffect effect in mesh.Effects)
            {
                effect.SetBoneTransforms(bones);
                effect.View = view;
                effect.Projection = projection;
                effect.EnableDefaultLighting();
                effect.SpecularColor = new Vector3(0.25f);
                effect.SpecularPower = 16;
            }
            mesh.Draw();
        }
        base.Draw(gameTime);
    }

旋转蒙皮模型';s的骨骼是否正确?XNA

您必须变换boneTransform,而不是skinTransform。我刚刚在AnimationPlayer类中创建了另一个方法来允许这种操作:

public void TransformBone(Matrix BoneAlteration, int BoneID)
{
    boneTransform[BoneID] = BoneAlteration * bindPose[BoneID];
    UpdateWorldTransforms(Matrix.Identity);
    UpdateSkinTransforms();
}

因此,如果我想旋转骨骼,我会调用此方法来创建正确的skinTransformation矩阵。这假设其他骨骼Transforms设置在其正确的位置。我还认为,如果您希望围绕已经旋转的骨骼进行旋转,可以将bindPose替换为boneTransform。