예제 #1
0
        public Matrix4[] GetAnimatedOffsetedMatrices(ParentBone rootBone)
        {
            List <Matrix4> animatePoseMatrices        = GetAnimatedNotOffsetedPoseMatricesList();
            List <Matrix4> offsetMatrices             = rootBone.GetOffsetMatricesList();
            List <Matrix4> animateToBoneSpaceMatrices = new List <Matrix4>();

            Matrix4 parentOfRootBone = Matrix4.Identity;

            TransformFromLocalSpaceToBoneSpace(rootBone, ref parentOfRootBone, animatePoseMatrices, ref animateToBoneSpaceMatrices);

            Int32 countOfAnimatedBones = animatePoseMatrices.Count;

            Matrix4[] skinningMatrices = new Matrix4[countOfAnimatedBones];

            for (Int32 i = 0; i < countOfAnimatedBones; i++)
            {
                Matrix4 animateMatrix = animateToBoneSpaceMatrices[i];
                Matrix4 offsetMatrix  = offsetMatrices[i];
                skinningMatrices[i] = offsetMatrix * animateMatrix;
            }

            animatePoseMatrices.Clear();
            animateToBoneSpaceMatrices.Clear();
            animatePoseMatrices = animateToBoneSpaceMatrices = null;

            return(skinningMatrices);
        }
예제 #2
0
 private void TransformFromLocalSpaceToBoneSpace(ParentBone parentBone, ref Matrix4 parentMatrix, List <Matrix4> srcTransformation, ref List <Matrix4> dstMatrices)
 {
     foreach (Bone child in parentBone.GetChildren())
     {
         Matrix4 currentBoneMatrix = srcTransformation[child.GetId()] * parentMatrix;
         dstMatrices.Add(currentBoneMatrix);
         GoThroughBoneHierarchy(child, ref currentBoneMatrix, srcTransformation, ref dstMatrices);
     }
 }
예제 #3
0
        public static EngineParentBone ConvertAssimpBoneToEngineBone(CParser.Assimp.LoaderSkeletonParentBone rootBone)
        {
            EngineParentBone resultBone = new EngineParentBone();

            foreach (var bone in rootBone.GetChildren())
            {
                EngineBone root = new EngineBone(bone.GetBoneId(), bone.GetBoneInfo().Name, null);
                root.SetOffsetMatrix(ConvertAssimpMatrix4x4ToOpenTKMatrix4(bone.GetBoneInfo().OffsetMatrix));
                IterateBoneTree(root, bone);
                resultBone.AddChildBone(root);
            }

            return(resultBone);
        }