static void ResolveParent(BoneTuple[] boneList, BoneTuple i, ref Matrix transform, ref Vector3 initialPosition) { if (i.Bone.ParentBoneID != -1) { var parentId = i.Bone.ParentBoneID; var parentBone = boneList.FirstOrDefault(_ => _.Bone.BoneID == parentId); if (parentBone != null) { initialPosition -= parentBone.Bone.InitialPosition; transform *= Matrix.Invert(parentBone.MmdBone.Transform); } } }
static void ResolveAffect(BoneTuple[] boneList, BoneTuple i, ref Matrix transform, ref Vector3 initialPosition) { if ((i.Bone.BoneFlags & BoneType.InhereRotate) != 0 || (i.Bone.BoneFlags & BoneType.InhereXYZ) != 0) { var affectId = i.Bone.InhereBoneID; var affectBone = boneList.FirstOrDefault(_ => _.Bone.BoneID == affectId); if (affectBone != null) { var affectInitialPosition = affectBone.Bone.InitialPosition; var affectTransform = affectBone.Transform; if (affectBone.Bone.ParentBoneID != -1) ResolveParent(boneList, affectBone, ref affectTransform, ref affectInitialPosition); Vector3 affectTranslation; Quaternion affectRotation; Vector3 affectScale; affectTransform.Decompose(out affectScale, out affectRotation, out affectTranslation); if ((i.Bone.BoneFlags & BoneType.InhereRotate) != 0) transform *= Matrix.Invert(Matrix.RotationAxis(affectRotation.Axis, affectRotation.Angle * i.Bone.InheraRate)); if ((i.Bone.BoneFlags & BoneType.InhereXYZ) != 0) initialPosition += (affectTranslation - affectInitialPosition) * i.Bone.InheraRate; } } }