private Matrix4 CalcInterpolatedRotation(float animationTime, NodeAnimation channel) { Matrix4x4 matrix; if (channel.ScalingKeysCount == 1) { matrix = channel.RotationKeys[0].Value.GetMatrix(); } var rotateIndex = FindRotation(animationTime, channel); var nextRotateIndex = rotateIndex + 1; if (nextRotateIndex < channel.RotationKeysCount) { var rotateKey = channel.RotationKeys[rotateIndex]; var nextRotateKey = channel.RotationKeys[nextRotateIndex]; var deltaTime = nextRotateKey.Time - rotateKey.Time; var factor = (animationTime - rotateKey.Time) / deltaTime; matrix = Assimp.Quaternion.Slerp(rotateKey.Value, nextRotateKey.Value, factor).GetMatrix(); } else { matrix = channel.RotationKeys[0].Value.GetMatrix(); } return(FromMatrix(matrix)); }
private void FillAnimationNode(Scene scene, Node node, int animationIndex) { var animation = scene.Animations[animationIndex]; NodeAnimationChannel channel = null; for (var i = 0; i < animation.NodeAnimationChannelCount; i++) { if (animation.NodeAnimationChannels[i].NodeName == node.Name) { channel = animation.NodeAnimationChannels[i]; } } if (channel != null && !СurrentAnimation.AnimationNodes.ContainsKey(node.Name)) { var nodeAnim = new NodeAnimation { PositionKeysCount = channel.PositionKeyCount, ScalingKeysCount = channel.ScalingKeyCount, RotationKeysCount = channel.RotationKeyCount }; nodeAnim.PositionKeys = new VectorInfo[nodeAnim.PositionKeysCount]; for (var i = 0; i < nodeAnim.PositionKeysCount; i++) { nodeAnim.PositionKeys[i] = new VectorInfo { Time = (float)channel.PositionKeys[i].Time, Value = FromVector(channel.PositionKeys[i].Value) } } ; nodeAnim.RotationKeys = new QuaternionInfo[nodeAnim.RotationKeysCount]; for (var i = 0; i < nodeAnim.RotationKeysCount; i++) { nodeAnim.RotationKeys[i] = new QuaternionInfo { Time = (float)channel.RotationKeys[i].Time, Value = channel.RotationKeys[i].Value } } ; nodeAnim.ScalingKeys = new VectorInfo[nodeAnim.ScalingKeysCount]; for (var i = 0; i < nodeAnim.ScalingKeysCount; i++) { nodeAnim.ScalingKeys[i] = new VectorInfo { Time = (float)channel.ScalingKeys[i].Time, Value = FromVector(channel.ScalingKeys[i].Value) } } ; СurrentAnimation.AnimationNodes.Add(node.Name, nodeAnim); } for (var i = 0; i < node.ChildCount; i++) { FillAnimationNode(scene, node.Children[i], animationIndex); } }
private int FindPosition(float animationTime, NodeAnimation channel) { for (var i = 0; i < channel.PositionKeysCount; i++) { if (animationTime < channel.PositionKeys[i].Time) { return(i); } } return(0); }
private Vector3 CalcInterpolatedScaling(float animationTime, NodeAnimation channel) { if (channel.ScalingKeysCount == 1) { return(channel.ScalingKeys[0].Value); } var scaleIndex = FindScaling(animationTime, channel); var nextScaleIndex = scaleIndex + 1; if (nextScaleIndex < channel.ScalingKeysCount) { var scaleKey = channel.ScalingKeys[scaleIndex]; var nextScaleKey = channel.ScalingKeys[nextScaleIndex]; var deltaTime = nextScaleKey.Time - scaleKey.Time; var factor = (animationTime - scaleKey.Time) / deltaTime; return(scaleKey.Value + (nextScaleKey.Value - scaleKey.Value) * factor); } return(channel.ScalingKeys[0].Value); }
private Vector3 CalcInterpolatedPosition(float animationTime, NodeAnimation channel) { if (channel.PositionKeysCount == 1) { return(channel.PositionKeys[0].Value); } var positionIndex = FindPosition(animationTime, channel); var nextPositionIndex = positionIndex + 1; if (nextPositionIndex < channel.PositionKeysCount) { var positionKey = channel.PositionKeys[positionIndex]; var nextPositionKey = channel.PositionKeys[nextPositionIndex]; var deltaTime = nextPositionKey.Time - positionKey.Time; var factor = (animationTime - positionKey.Time) / deltaTime; return(positionKey.Value + (nextPositionKey.Value - positionKey.Value) * factor); } return(channel.PositionKeys[0].Value); }
private static void AddAnimations(IEnumerable <Domain.Animations.Animation> animations, Document doc) { foreach (var animation in animations) { var anim = new Animation { Id = animation.Id, Name = animation.Name, BeginFrame = animation.BeginFrame, EndFrame = animation.EndFrame, FramesPerSecond = animation.FramesPerSecond, IsLoop = animation.IsLoop }; foreach (var nodeAnimation in animation.AnimationsPerNode.Values) { var nodeAnim = new NodeAnimation { NodeId = nodeAnimation.Node.Id }; foreach (var propertyAnimation in nodeAnimation.PropertyAnimations.Values) { var propAnim = new PropertyAnimation { Id = propertyAnimation.Id, Property = (uint)propertyAnimation.Property, Vertex = propertyAnimation.Vertex }; AddAnimationKeys(propertyAnimation.Keys, propAnim); nodeAnim.PropertyAnimations.Add(propAnim); } anim.NodeAnimations.Add(nodeAnim); } doc.Animations.Add(anim); } }
private int FindScaling(float animationTime, NodeAnimation channel) { for (var i = 0; i < channel.ScalingKeysCount; i++) if (animationTime < channel.ScalingKeys[i].Time) { return i; } return 0; }
private void FillAnimationNode(Scene scene, Node node, int animationIndex) { var animation = scene.Animations[animationIndex]; NodeAnimationChannel channel = null; for (var i = 0; i < animation.NodeAnimationChannelCount; i++) { if (animation.NodeAnimationChannels[i].NodeName == node.Name) channel = animation.NodeAnimationChannels[i]; } if (channel != null && !СurrentAnimation.AnimationNodes.ContainsKey(node.Name)) { var nodeAnim = new NodeAnimation { PositionKeysCount = channel.PositionKeyCount, ScalingKeysCount = channel.ScalingKeyCount, RotationKeysCount = channel.RotationKeyCount }; nodeAnim.PositionKeys = new VectorInfo[nodeAnim.PositionKeysCount]; for (var i = 0; i < nodeAnim.PositionKeysCount; i++) nodeAnim.PositionKeys[i] = new VectorInfo { Time = (float)channel.PositionKeys[i].Time, Value = FromVector(channel.PositionKeys[i].Value) }; nodeAnim.RotationKeys = new QuaternionInfo[nodeAnim.RotationKeysCount]; for (var i = 0; i < nodeAnim.RotationKeysCount; i++) nodeAnim.RotationKeys[i] = new QuaternionInfo { Time = (float)channel.RotationKeys[i].Time, Value = channel.RotationKeys[i].Value }; nodeAnim.ScalingKeys = new VectorInfo[nodeAnim.ScalingKeysCount]; for (var i = 0; i < nodeAnim.ScalingKeysCount; i++) nodeAnim.ScalingKeys[i] = new VectorInfo { Time = (float)channel.ScalingKeys[i].Time, Value = FromVector(channel.ScalingKeys[i].Value) }; СurrentAnimation.AnimationNodes.Add(node.Name, nodeAnim); } for (var i = 0; i < node.ChildCount; i++) FillAnimationNode(scene, node.Children[i], animationIndex); }
private Vector3 CalcInterpolatedScaling(float animationTime, NodeAnimation channel) { if (channel.ScalingKeysCount == 1) { return channel.ScalingKeys[0].Value; } var scaleIndex = FindScaling(animationTime, channel); var nextScaleIndex = scaleIndex + 1; if (nextScaleIndex < channel.ScalingKeysCount) { var scaleKey = channel.ScalingKeys[scaleIndex]; var nextScaleKey = channel.ScalingKeys[nextScaleIndex]; var deltaTime = nextScaleKey.Time - scaleKey.Time; var factor = (animationTime - scaleKey.Time) / deltaTime; return scaleKey.Value + (nextScaleKey.Value - scaleKey.Value) * factor; } return channel.ScalingKeys[0].Value; }
private Matrix4 CalcInterpolatedRotation(float animationTime, NodeAnimation channel) { Matrix4x4 matrix; if (channel.ScalingKeysCount == 1) { matrix = channel.RotationKeys[0].Value.GetMatrix(); } var rotateIndex = FindRotation(animationTime, channel); var nextRotateIndex = rotateIndex + 1; if (nextRotateIndex < channel.RotationKeysCount) { var rotateKey = channel.RotationKeys[rotateIndex]; var nextRotateKey = channel.RotationKeys[nextRotateIndex]; var deltaTime = nextRotateKey.Time - rotateKey.Time; var factor = (animationTime - rotateKey.Time) / deltaTime; matrix = Assimp.Quaternion.Slerp(rotateKey.Value, nextRotateKey.Value, factor).GetMatrix(); } else { matrix = channel.RotationKeys[0].Value.GetMatrix(); } return FromMatrix(matrix); }
private Vector3 CalcInterpolatedPosition(float animationTime, NodeAnimation channel) { if (channel.PositionKeysCount == 1) { return channel.PositionKeys[0].Value; } var positionIndex = FindPosition(animationTime, channel); var nextPositionIndex = positionIndex + 1; if (nextPositionIndex < channel.PositionKeysCount) { var positionKey = channel.PositionKeys[positionIndex]; var nextPositionKey = channel.PositionKeys[nextPositionIndex]; var deltaTime = nextPositionKey.Time - positionKey.Time; var factor = (animationTime - positionKey.Time) / deltaTime; return positionKey.Value + (nextPositionKey.Value - positionKey.Value) * factor; } return channel.PositionKeys[0].Value; }