骨骼模型的局部位置

时间:2012-07-18 16:45:52

标签: c# xna

我要求相对于我的模型(汽车)获得骨骼的位置矩阵或位置矢量(比如轮子)。

我尝试了什么 -

Vector3.Transform(mesh.BoundingSphere.Center , transforms[mesh.ParentBone.Index]*Matrix.CreateScale(o.Scaling )))

以上并未给出准确的结果。

1 个答案:

答案 0 :(得分:1)

你想要的是计算每个骨骼的绝对变换。 CopyAbsoluteBoneTransformsTo方法可以为您完成。

它等同于以下代码:

    /// <summary>Calculates the absolute bone transformation matrices in model space</summary>
    private void calculateAbsoluteBoneTransforms() {

      // Obtain the local transform for the bind pose of all bones
      this.model.CopyBoneTransformsTo(this.absoluteBoneTransforms);

      // Convert the relative bone transforms into absolute transforms
      ModelBoneCollection bones = this.model.Bones;
      for (int index = 0; index < bones.Count; ++index) {

        // Take over the bone transform and apply its user-specified transformation
        this.absoluteBoneTransforms[index] =
          this.boneTransforms[index] * bones[index].Transform;

        // Calculate the absolute transform of the bone in model space.
        // Content processors sort bones so that parent bones always appear
        // before their children, thus this works like a matrix stack,
        // resolving the full bone hierarchy in minimal steps.
        ModelBone bone = bones[index];
        if (bone.Parent != null) {
          int parentIndex = bone.Parent.Index;
          this.absoluteBoneTransforms[index] *= this.absoluteBoneTransforms[parentIndex];
        }
      }

    }

取自here