private void SaveBones(Node parentBone, STBone bone, STSkeleton skeleton) { Node boneNode = new Node(bone.Text); parentBone.Children.Add(boneNode); boneNode.Transform = AssimpHelper.GetBoneMatrix(bone); foreach (STBone child in bone.GetChildren()) { SaveBones(boneNode, child, skeleton); } }
public void update(bool reset = false) { Updated = true; List <STBone> nodesToProcess = new List <STBone>(); // Add all root nodes from the VBN foreach (STBone b in bones) { if (b.Parent == null) { nodesToProcess.Add(b); } } // some special processing for the root bones before we start foreach (STBone b in nodesToProcess) { b.transform = Matrix4.CreateScale(b.sca) * Matrix4.CreateFromQuaternion(b.rot) * Matrix4.CreateTranslation(b.pos); // scale down the model in its entirety only when mid-animation (i.e. reset == false) if (!reset) { b.transform *= Matrix4.CreateScale(1); } } // Process as a tree from the root node's children and beyond. These // all use the same processing, unlike the root nodes. int numRootNodes = nodesToProcess.Count; for (int i = 0; i < numRootNodes; i++) { nodesToProcess.AddRange(nodesToProcess[0].GetChildren()); nodesToProcess.RemoveAt(0); } while (nodesToProcess.Count > 0) { // DFS STBone currentBone = nodesToProcess[0]; nodesToProcess.RemoveAt(0); nodesToProcess.AddRange(currentBone.GetChildren()); // Process this node currentBone.transform = Matrix4.CreateScale(currentBone.sca) * Matrix4.CreateFromQuaternion(currentBone.rot) * Matrix4.CreateTranslation(currentBone.pos); if (currentBone.Parent != null) { currentBone.transform = currentBone.transform * ((STBone)currentBone.Parent).transform; } } }
public List <STBone> getBoneTreeOrder() { List <STBone> bone = new List <STBone>(); Queue <STBone> q = new Queue <STBone>(); q.Enqueue(bones[0]); while (q.Count > 0) { STBone b = q.Dequeue(); foreach (STBone bo in b.GetChildren()) { q.Enqueue(bo); } bone.Add(b); } return(bone); }