public void DrawBoundsForJoints(bool boundingBox, bool boundingSphere, IDebugLineDrawer lineDrawer) { IList <SkeletonJoint> boneList = (m_currentBoneAnimation != null) ? JNT1Tag.AnimatedJoints : JNT1Tag.BindJoints; Matrix4[] boneTransforms = new Matrix4[boneList.Count]; ApplyBonePositionsToAnimationTransforms(boneList, boneTransforms); for (int i = 0; i < boneTransforms.Length; i++) { SkeletonJoint curJoint, origJoint; curJoint = origJoint = JNT1Tag.BindJoints[i]; //Matrix4 cumulativeTransform = Matrix4.Identity; //while (true) //{ // Matrix4 jointMatrix = Matrix4.CreateScale(curJoint.Scale) * Matrix4.CreateFromQuaternion(curJoint.Rotation) * Matrix4.CreateTranslation(curJoint.Translation); // cumulativeTransform *= jointMatrix; // if (curJoint.Parent == null) // break; // curJoint = curJoint.Parent; //} //boneTransforms[i] = cumulativeTransform; boneTransforms[i].Transpose(); Vector3 curPos = boneTransforms[i].ExtractTranslation(); Quaternion curRot = boneTransforms[i].ExtractRotation(); WLinearColor jointColor = origJoint.Unknown1 == 0 ? WLinearColor.Yellow : WLinearColor.Blue; if (boundingSphere) { // Many bones have no radius, simply skip them to avoid adding them to the line renderer. if (origJoint.BoundingSphereDiameter == 0f) { continue; } lineDrawer.DrawSphere(curPos, origJoint.BoundingSphereDiameter / 2, 12, jointColor, 0f, 0f); } if (boundingBox) { Vector3 extents = (origJoint.BoundingBox.Max - origJoint.BoundingBox.Min) / 2; // Many bones have no extents, simply skip them to avoid adding them to the line renderer. if (extents.LengthSquared == 0f) { continue; } lineDrawer.DrawBox(curPos, extents, curRot, jointColor, 0f, 0f); } } }
public void DrawBones(IDebugLineDrawer lineDrawer) { IList <SkeletonJoint> boneList = (m_currentBoneAnimation != null) ? JNT1Tag.AnimatedJoints : JNT1Tag.BindJoints; Matrix4[] boneTransforms = new Matrix4[boneList.Count]; Vector3 lastPos = Vector3.Zero; for (int i = 0; i < boneList.Count; i++) { SkeletonJoint curJoint, origJoint; curJoint = origJoint = boneList[i]; Matrix4 cumulativeTransform = Matrix4.Identity; SkeletonJoint prevJoint = null; while (true) { Vector3 scale = curJoint.Scale; if (prevJoint != null && prevJoint.DoNotInheritParentScale) { scale = Vector3.One; } Matrix4 jointMatrix = Matrix4.CreateScale(scale) * Matrix4.CreateFromQuaternion(curJoint.Rotation) * Matrix4.CreateTranslation(curJoint.Translation); cumulativeTransform *= jointMatrix; if (curJoint.Parent == null) { break; } prevJoint = curJoint; curJoint = curJoint.Parent; } boneTransforms[i] = cumulativeTransform; Vector3 curPos = cumulativeTransform.ExtractTranslation(); WLinearColor jointColor = origJoint.Unknown1 == 0 ? WLinearColor.Yellow : WLinearColor.Blue; if (origJoint.DoNotInheritParentScale) { jointColor = WLinearColor.Red; } if (origJoint.Parent != null) { int parentIndex = boneList.IndexOf(origJoint.Parent); Vector3 parentPos = boneTransforms[parentIndex].ExtractTranslation(); lineDrawer.DrawLine(parentPos, curPos, jointColor, 0f, 0f); } lineDrawer.DrawSphere(curPos, 1f, 5, jointColor, 0f, 0f); lastPos = curPos; } }
public void DrawBoundsForShapes(bool boundingBox, bool boundingSphere, IDebugLineDrawer lineDrawer) { foreach (var shape in SHP1Tag.Shapes) { if (boundingSphere) { lineDrawer.DrawSphere(shape.BoundingBox.Center, shape.BoundingSphereDiameter / 2f, 12, WLinearColor.White, 0f, 0f); } if (boundingBox) { lineDrawer.DrawBox(shape.BoundingBox.Min, shape.BoundingBox.Max, WLinearColor.Green, 0f, 0f); } } }