4 using System.Collections.Generic;
5 using SiliconStudio.Core;
6 using SiliconStudio.Core.Extensions;
7 using SiliconStudio.Paradox.DataModel;
11 namespace SiliconStudio.Paradox.Effects
20 private int currentSourceChannelCount;
21 private UpdateChannel[] updateChannels;
26 if (updateChannels == null
27 || currentSourceChannels != result.
Channels
28 || currentSourceChannels.Count != currentSourceChannelCount)
30 RegenerateUpdateChannels(hierarchy, result.
Channels);
31 currentSourceChannels = result.Channels;
32 currentSourceChannelCount = currentSourceChannels.Count;
36 fixed (byte* structures = result.Data)
38 foreach (var updateChannel
in updateChannels)
40 var structureData = (
float*)(structures + updateChannel.Offset);
41 var factor = *structureData++;
45 switch (updateChannel.Type)
47 case ChannelType.Translation:
50 case ChannelType.Rotation:
53 case ChannelType.Scaling:
57 throw new ArgumentOutOfRangeException();
63 private static bool NodeNameMatch(
string name1,
string name2)
71 name1 = name1.Substring(name1.LastIndexOf(
':') + 1);
72 name2 = name2.Substring(name2.LastIndexOf(
':') + 1);
74 return name1 == name2;
77 private void RegenerateUpdateChannels(ModelViewHierarchyUpdater hierarchy, List<AnimationBlender.Channel> channels)
79 var newUpdateChannels =
new List<UpdateChannel>();
82 foreach (var channel
in channels)
84 string nodeName = channel.NodeName;
88 var updateChannel =
new UpdateChannel();
89 updateChannel.Index = -1;
91 var hierarchyNodes = hierarchy.Nodes;
92 for (
int i = 0; i < hierarchyNodes.Length; ++i)
94 var node = hierarchyNodes[i];
95 if (node.Name == nodeName)
97 updateChannel.Index = i;
102 if (updateChannel.Index == -1)
109 updateChannel.Offset = channel.Offset;
110 updateChannel.Type = channel.Type;
112 newUpdateChannels.Add(updateChannel);
115 updateChannels = newUpdateChannels.ToArray();
118 internal static ChannelType GetType(
string propertyName)
120 if (propertyName.StartsWith(
"Transformation.Translation["))
122 return ChannelType.Translation;
124 if (propertyName.StartsWith(
"Transformation.Rotation["))
126 return ChannelType.Rotation;
128 if (propertyName.StartsWith(
"Transformation.Scaling["))
130 return ChannelType.Scaling;
133 return ChannelType.Unknown;
136 internal static string GetNodeName(
string propertyName)
138 int nodeNameFirstChar = propertyName.IndexOf(
'[');
139 if (nodeNameFirstChar == -1)
142 int nodeNameLastChar = propertyName.IndexOf(
']', nodeNameFirstChar);
144 return propertyName.Substring(nodeNameFirstChar + 1, nodeNameLastChar - nodeNameFirstChar - 1);
159 private struct UpdateChannel
161 public ChannelType Type;
Applies animation from a AnimationClip to a ModelViewHierarchyUpdater.
SiliconStudio.Core.Mathematics.Vector3 Vector3
ModelNodeTransformation[] NodeTransformations
List< AnimationBlender.Channel > Channels
Gets or sets the animation channel descriptions.
unsafe void Update(ModelViewHierarchyUpdater hierarchy, AnimationClipResult result)
SiliconStudio.Core.Mathematics.Quaternion Quaternion
SiliconStudio.Core.Mathematics.Quaternion Quaternion
Performs hierarchical updates for a given Model.
SiliconStudio.Core.Mathematics.Vector3 Vector3