Esempio n. 1
0
        public BoneAnimation LoadBoneAnimation(Assimp.Scene aScene, Assimp.Node aNode, BoneAnimation parent)
        {
            var boneAnimation = new BoneAnimation()
            {
                Parent    = parent,
                Children  = new List <BoneAnimation>(),
                Positions = new List <Vector3>(),
                Rotations = new List <Quaternion>(),
                Scales    = new List <Vector3>()
            };

            boneAnimation.Name = aNode.Name;

            var animationChanel = aScene.Animations[0].NodeAnimationChannels.Where(n => n.NodeName == boneAnimation.Name).FirstOrDefault();

            if (animationChanel != null)
            {
                boneAnimation.IsAnimate = true;

                foreach (var aScale in animationChanel.ScalingKeys)
                {
                    var scale = new Vector3(aScale.Value.X, aScale.Value.Y, aScale.Value.Z);
                    boneAnimation.Scales.Add(scale);
                }

                foreach (var aRotation in animationChanel.RotationKeys)
                {
                    var rotation = new Quaternion(aRotation.Value.X, aRotation.Value.Y, aRotation.Value.Z, aRotation.Value.W);
                    boneAnimation.Rotations.Add(rotation);
                }

                foreach (var aTranslate in animationChanel.PositionKeys)
                {
                    var translate = new Vector3(aTranslate.Value.X, aTranslate.Value.Y, aTranslate.Value.Z);
                    boneAnimation.Positions.Add(translate);
                }
            }
            else
            {
                boneAnimation.IsAnimate      = false;
                boneAnimation.Transformation = Matrix.Transpose(AssimpHelper.MatrixAssimpToXna(aNode.Transform));
            }

            foreach (var child in aNode.Children)
            {
                boneAnimation.Children.Add(LoadBoneAnimation(aScene, child, boneAnimation));
            }
            BoneAnimations.Add(boneAnimation);
            return(boneAnimation);
        }
Esempio n. 2
0
        Bone GetBone(Mesh mesh, Assimp.Bone aBone)
        {
            var bone = mesh.Bones.FirstOrDefault(b => b.Name == aBone.Name);

            if (bone == null)
            {
                var offsetMatrix = aBone.OffsetMatrix;
                offsetMatrix.Transpose();

                bone               = new Bone();
                bone.Name          = aBone.Name;
                bone.Index         = mesh.Bones.Count;
                bone.Offset        = AssimpHelper.MatrixAssimpToXna(offsetMatrix);
                bone.OffsetInverse = Matrix.Invert(AssimpHelper.MatrixAssimpToXna(offsetMatrix));
                mesh.Bones.Add(bone);
            }
            return(bone);
        }