Exemplo n.º 1
0
        private static AiAnimation Parse(EZMAnimation ezmAnimation)
        {
            var aiAnimation = new AiAnimation();

            aiAnimation.Name = ezmAnimation.Name;

            /*
             * double ticksPerSecond = aiScene.Animations[0].TicksPerSecond;
             * if (ticksPerSecond == 0) { ticksPerSecond = 25.0; }
             * double timeInTicks = TimeInSeconds * ticksPerSecond;
             * float animationTime = (float)(timeInTicks % aiScene.Animations[0].DurationInTicks);
             */
            /*
             * DateTime now = DateTime.Now;
             *  var deltaTime = now.Subtract(this.lastTime).TotalSeconds;
             *  float frameDuration = animation.duration / animation.FrameCount;
             *  if (deltaTime + passedTime > frameDuration)
             *  {
             *      this.currentFrame = (this.currentFrame + 1) % animation.FrameCount;
             *      passedTime = deltaTime - frameDuration;
             *  }
             *  this.lastTime = now;*/
            float durationInSeconds = ezmAnimation.duration;

            aiAnimation.TicksPerSecond  = 1;
            aiAnimation.DurationInTicks = ezmAnimation.duration;
            // nothing to do with ezmAnimation.dtime...
            int trackCount = ezmAnimation.TrackCount;
            var channels   = new AiNodeAnimationChannel[trackCount];

            for (int i = 0; i < trackCount; i++)
            {
                var            channel     = new AiNodeAnimationChannel();
                EZMAnimTrack   track       = ezmAnimation.AnimTracks[i];
                EZMBoneState[] states      = track.States;
                int            stateCount  = states.Length;
                var            positions   = new VectorKey[stateCount];
                var            quaternions = new QuaternionKey[stateCount];
                var            scalings    = new VectorKey[stateCount];
                for (int t = 0; t < stateCount; t++)
                {
                    EZMBoneState state = states[t];
                    positions[i]   = new VectorKey(0, state.position);
                    quaternions[i] = new QuaternionKey(0, state.orientation);
                    scalings[i]    = new VectorKey(0, state.scale);
                }
                channel.PositionKeys   = positions;
                channel.QuaternionKeys = quaternions;
                channel.ScalingKeys    = scalings;
                channels[i]            = channel;
            }
            aiAnimation.NodeAnimationChannels = channels;

            return(aiAnimation);
        }
Exemplo n.º 2
0
        public static AiScene Parse(this EZMFile ezmFile)
        {
            if (ezmFile == null)
            {
                throw new ArgumentNullException();
            }

            var aiScene = new AiScene();

            aiScene.Fullname = ezmFile.Fullname;
            // root node.
            {
                EZMSkeleton skeleton = ezmFile.MeshSystem.Skeletons[0];
                EZMBone[]   bones    = skeleton.Bones;
                aiScene.RootNode = Parse(bones[0]);
                Match(aiScene.RootNode, bones[0]);
            }
            // meshes.
            {
                EZMMesh[] ezmMeshes = ezmFile.MeshSystem.Meshes;
                var       lstAiMesh = new List <AiMesh>();
                for (int i = 0; i < ezmMeshes.Length; i++)
                {
                    AiMesh[] aiMeshes = Parse(ezmMeshes[i]);
                    lstAiMesh.AddRange(aiMeshes);
                }
                aiScene.Meshes = lstAiMesh.ToArray();
            }
            // materials.
            {
                EZMMaterial[] ezmMaterials = ezmFile.MeshSystem.Materials;
                var           aiMaterials  = new AiMaterial[ezmMaterials.Length];
                for (int i = 0; i < aiMaterials.Length; i++)
                {
                    aiMaterials[i] = Parse(ezmMaterials[i]);
                }
                aiScene.Materials = aiMaterials;
            }
            // animations.
            {
                EZMAnimation[] ezmAnimations = ezmFile.MeshSystem.Animations;
                var            aiAnimations  = new AiAnimation[ezmAnimations.Length];
                for (int i = 0; i < ezmAnimations.Length; i++)
                {
                    aiAnimations[i] = Parse(ezmAnimations[i]);
                }
                aiScene.Animations = aiAnimations;
            }
            {
                // init material indexes in mesh.
                foreach (AiMesh aiMesh in aiScene.Meshes)
                {
                    string name = aiMesh.materialName;
                    for (int i = 0; i < aiScene.Materials.Length; i++)
                    {
                        if (aiScene.Materials[i].Name == name)
                        {
                            aiMesh.MaterialIndex = i;
                            break;
                        }
                    }
                }
            }
            {
                // bones.
                EZMSkeleton skeleton = ezmFile.MeshSystem.Skeletons[0];
                EZMBone[]   bones    = skeleton.Bones;
                var         aiBones  = new AiBone[bones.Length];
                for (int i = 0; i < bones.Length; i++)
                {
                    var aiBone = new AiBone();
                    var bone   = bones[i];
                    //bone.
                    aiBones[i] = aiBone;
                }
                aiScene.RootNode = Parse(bones[0]);
                Match(aiScene.RootNode, bones[0]);
            }
            return(aiScene);
        }