private void ProcessAnimations() { if (!scene.HasAnimations) { return; } foreach (var animation in scene.Animations) { if (!animation.HasNodeAnimations) { continue; } var ticksPerSecond = animation.TicksPerSecond > 0 ? animation.TicksPerSecond : 25.0; // Is this format dependent? At least some .x files behave strangely. var animationData = new ModelData.Animation { Name = animation.Name, Duration = (float)(animation.DurationInTicks / ticksPerSecond) }; model.Animations.Add(animationData); foreach (var channel in animation.NodeAnimationChannels) { var keyFrames = new LinkedList <ModelData.KeyFrame>(); if (channel.HasScalingKeys) { foreach (var key in channel.ScalingKeys) { var keyFrame = GetKeyFrame((float)(key.Time / ticksPerSecond), keyFrames); keyFrame.Value = new CompositeTransform(ConvertVector(key.Value), Quaternion.Identity, Vector3.Zero); } } if (channel.HasRotationKeys) { foreach (var key in channel.RotationKeys) { var keyFrame = GetKeyFrame((float)(key.Time / ticksPerSecond), keyFrames); keyFrame.Value = new CompositeTransform(keyFrame.Value.Scale, ConvertQuaternion(key.Value), Vector3.Zero); } } if (channel.HasPositionKeys) { foreach (var key in channel.PositionKeys) { var keyFrame = GetKeyFrame((float)(key.Time / ticksPerSecond), keyFrames); keyFrame.Value = new CompositeTransform(keyFrame.Value.Scale, keyFrame.Value.Rotation, ConvertVector(key.Value)); } } LinearKeyFrameReduction(keyFrames); var channelData = new ModelData.AnimationChannel { BoneName = channel.NodeName }; channelData.KeyFrames.AddRange(keyFrames); animationData.Channels.Add(channelData); } } }
private void ProcessAnimations() { if (!scene.HasAnimations) return; foreach (var animation in scene.Animations) { if (!animation.HasNodeAnimations) continue; var ticksPerSecond = animation.TicksPerSecond > 0 ? animation.TicksPerSecond : 25.0; // Is this format dependent? At least some .x files behave strangely. var animationData = new ModelData.Animation { Name = animation.Name, Duration = (float)(animation.DurationInTicks / ticksPerSecond) }; model.Animations.Add(animationData); foreach (var channel in animation.NodeAnimationChannels) { var keyFrames = new LinkedList<ModelData.KeyFrame>(); if (channel.HasScalingKeys) { foreach (var key in channel.ScalingKeys) { var keyFrame = GetKeyFrame((float)(key.Time / ticksPerSecond), keyFrames); keyFrame.Value = new CompositeTransform(ConvertVector(key.Value), Quaternion.Identity, Vector3.Zero); } } if (channel.HasRotationKeys) { foreach (var key in channel.RotationKeys) { var keyFrame = GetKeyFrame((float)(key.Time / ticksPerSecond), keyFrames); keyFrame.Value = new CompositeTransform(keyFrame.Value.Scale, ConvertQuaternion(key.Value), Vector3.Zero); } } if (channel.HasPositionKeys) { foreach (var key in channel.PositionKeys) { var keyFrame = GetKeyFrame((float)(key.Time / ticksPerSecond), keyFrames); keyFrame.Value = new CompositeTransform(keyFrame.Value.Scale, keyFrame.Value.Rotation, ConvertVector(key.Value)); } } LinearKeyFrameReduction(keyFrames); var channelData = new ModelData.AnimationChannel { BoneName = channel.NodeName }; channelData.KeyFrames.AddRange(keyFrames); animationData.Channels.Add(channelData); } } }