0

我需要获取关于我的模型(汽车)的骨骼(比如车轮)的位置矩阵或位置向量。

我试过的 -

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

以上没有给出准确的结果。

4

1 回答 1

1

What you want is to calculate the absolute transforms for each bone. The CopyAbsoluteBoneTransformsTo method can do it for you.

It is equivalent to the following code:

    /// <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];
        }
      }

    }

Taken from here.

于 2012-07-18T17:25:00.730 回答