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); }
// <AnimTrack name="RootNode" count="61" has_scale="true"> /// <summary> /// Tracks a bone's states of all frames in one pose. /// </summary> /// <param name="xAnimTrack"></param> /// <returns></returns> public static EZMAnimTrack Parse(System.Xml.Linq.XElement xElement) { EZMAnimTrack result = null; if (xElement.Name == "AnimTrack") { result = new EZMAnimTrack(); { var name = xElement.Attribute("name"); if (name != null) { result.BoneName = name.Value; } } int count = 0; bool hasScale = false; { var c = xElement.Attribute("count"); if (c != null) { count = int.Parse(c.Value); } var h = xElement.Attribute("has_scale"); if (h != null) { hasScale = bool.Parse(h.Value); } } { string[] parts = xElement.Value.Split(Separator.separators, StringSplitOptions.RemoveEmptyEntries); if (parts.Length % 10 != 0) { throw new Exception("Parsing failed."); } var values = new float[parts.Length]; var states = new EZMBoneState[parts.Length / 10]; int index = 0; vec3 p = new vec3(); Quaternion o = new Quaternion(); vec3 s = new vec3(); while (index < parts.Length) { { var x = float.Parse(parts[index++]); var y = float.Parse(parts[index++]); var z = float.Parse(parts[index++]); p = new vec3(x, y, z); } { var x = float.Parse(parts[index++]); var y = float.Parse(parts[index++]); var z = float.Parse(parts[index++]); var w = float.Parse(parts[index++]); o = new Quaternion(x, y, z, w); } { var x = float.Parse(parts[index++]); var y = float.Parse(parts[index++]); var z = float.Parse(parts[index++]); s = new vec3(x, y, z); } states[index / 10 - 1] = new EZMBoneState(p, o, s); } result.States = states; } } return(result); }