Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualtrock

Posted 07 November 2012 - 09:02 PM

Ok, I definitely need help, as my mathbrain is simply non-functional here. Now that the root node is properly following my physics entities "body", I am struggling to get the transforms for the rest of the skeleton. I am getting crazy stretching, presumably because I'm not working in the right "space" when calculating those transforms.

This is what I'm doing, starting with how I calculate the offsets of physics entity-to-bone:
[source lang="csharp"] offsets.Add("Armature", Matrix.Invert(bindPose[0]) * Entities["body"].WorldTransform); //Calculate root offset firstfor (int i = 4; i < input.Model.Bones.Count; i++) { int poseIndex = i - 3; string bone = input.Model.Bones[i].Name;if ((bone == "neck")) offsets.Add(bone, Matrix.Invert(bindPose[poseIndex]) * Entities["head"].WorldTransform )... // get each "physics-tied" bone's relative offset[/source]
Now I calculate the boneTransforms:

[source lang="csharp"]Matrix[] boneTransforms = new Matrix[bindPose.Count];Matrix finalOffset = offsets[0] * body.WorldTransform;boneTransforms[0] = finalOffset * Matrix.Invert(actorWorld); //establish rootfor (int i = 1; i < bindPose.Count; i++) //get offsets for other bones { int boneIndex = i + 3; string bone = input.Model.Bones[boneIndex].Name; if (bone == "neck") { offset = Matrix.Invert(offsets[bone]) * Entities["head"].WorldTransform; boneTransforms[i] = offsets[bone] * Matrix.Invert(actorWorld); } else //offsets for non-physics bones { boneTransforms[i] = bindPose[i]; } }[/source]
And finally, converting the bone transforms into world space:

[source lang="csharp"]Matrix[] worldTransforms = new Matrix[modelData.BindPose.Count];Matrix[] skinTransforms = new Matrix[modelData.BindPose.Count];worldTransforms[0] = boneTransforms[0];skinTransforms[0] = inverseBindPose[0] * worldTransforms[0]; // Child bones.for (int bone = 1; bone < worldTransforms.Length; bone++){ int parentBone = skeletonHierarchy[bone]; worldTransforms[bone] = boneTransforms[bone] * worldTransforms[parentBone]; skinTransforms[bone] = inverseBindPose[bone] * worldTransforms[bone];}return skinTransforms; //this gets passed into my shader (identical setup to what the XNA skinning example uses)[/source]

Again, this all works just fine for my root node, but the various bodyparts (in this case the head) ends up stretched and about 15 ft from where it should be. Can anybody help me figure out where I am going wrong in calculating the skintransforms?!

#1trock

Posted 07 November 2012 - 01:09 PM

Ok, I definitely need help, as my mathbrain is simply non-functional here. Now that the root node is properly following my physics entities "body", I am struggling to get the transforms for the rest of the skeleton. I am getting crazy stretching, presumably because I'm not working in the right "space" when calculating those transforms.

This is what I'm doing, starting with how I calculate the offsets of physics entity-to-bone:
[source lang="csharp"] offsets.Add("Armature", Matrix.Invert(bindPose[0]) * Entities["body"].WorldTransform); //Calculate root offset firstfor (int i = 4; i < input.Model.Bones.Count; i++) { int poseIndex = i - 3; string bone = input.Model.Bones[i].Name;if ((bone == "neck")) offsets.Add(bone, Matrix.Invert(bindPose[poseIndex]) * Entities["head"].WorldTransform )... // get each "physics-tied" bone's relative offset[/source]
Now I calculate the boneTransforms:

[source lang="csharp"]Matrix[] boneTransforms = new Matrix[bindPose.Count]; boneTransforms[0] = offset * Matrix.Invert(actorWorld); //establish root for (int i = 1; i < bindPose.Count; i++) //get offsets for other bones { int boneIndex = i + 3; string bone = input.Model.Bones[boneIndex].Name; if (bone == "neck") { offset = Matrix.Invert(offsets[bone]) * Entities["head"].WorldTransform; boneTransforms[i] = offsets[bone] * Matrix.Invert(actorWorld); } else //offsets for non-physics bones { boneTransforms[i] = bindPose[i]; } }[/source]
And finally, converting the bone transforms into world space:

[source lang="csharp"]Matrix[] worldTransforms = new Matrix[modelData.BindPose.Count];Matrix[] skinTransforms = new Matrix[modelData.BindPose.Count];worldTransforms[0] = boneTransforms[0];skinTransforms[0] = inverseBindPose[0] * worldTransforms[0]; // Child bones.for (int bone = 1; bone < worldTransforms.Length; bone++){ int parentBone = skeletonHierarchy[bone]; worldTransforms[bone] = boneTransforms[bone] * worldTransforms[parentBone]; skinTransforms[bone] = inverseBindPose[bone] * worldTransforms[bone];}return skinTransforms; //this gets passed into my shader (identical setup to what the XNA skinning example uses)[/source]

Again, this all works just fine for my root node, but the various bodyparts (in this case the head) ends up stretched and about 15 ft from where it should be. Can anybody help me figure out where I am going wrong in calculating the skintransforms?!

PARTNERS