public void GenerateDefaultBoneTransformsList()
        {
            _boneTransforms.Clear();
            CompositeBone root = this.Parent.Parent.RootBone;

            if (root != null)
            {
                AddBoneTransformFromBone(root);
            }
        }
Beispiel #2
0
 public CompositeEntity()
     : base()
 {
     _sceneItemBank     = new Dictionary <String, SceneItem>();
     _animations        = new List <CompositeAnimation>();
     _rootBone          = new CompositeBone();
     _rootBone.Name     = "Root";
     this.AutoPlay      = true;
     _queuedAnimationID = null;
 }
Beispiel #3
0
 public CompositeEntity()
     : base()
 {
     _sceneItemBank = new Dictionary<String, SceneItem>();
     _animations = new List<CompositeAnimation>();
     _rootBone = new CompositeBone();
     _rootBone.Name = "Root";
     this.AutoPlay = true;
     _queuedAnimationID = null;
 }
        private void AddBoneTransformFromBone(CompositeBone bone)
        {
            CompositeBoneTransform newBoneTrans = new CompositeBoneTransform("");

            newBoneTrans.Parent        = this;
            newBoneTrans.BoneReference = bone.Name;
            _boneTransforms.Add(newBoneTrans);
            for (int i = 0; i < bone.ChildBones.Count; i++)
            {
                AddBoneTransformFromBone(bone.ChildBones[i]);
            }
        }
Beispiel #5
0
 public CompositeBone(String sceneItemBankEntry, String name)
 {
     _name                  = name;
     _parentBone            = null;
     _sceneItem             = sceneItemBankEntry;
     _subItem               = String.Empty;
     _childBones            = new List <CompositeBone>();
     this.MasterVisibility  = null;
     this.Interpolate       = true;
     this.InheritPosition   = true;
     this.InheritRotation   = true;
     this.InheritScale      = true;
     this.InheritVisibility = true;
 }
Beispiel #6
0
 /// <summary>
 /// Removes a children from this bone
 /// </summary>
 public void RemoveChildBone(CompositeBone childBone)
 {
     // sync transforms
     for (int i = 0; i < Parent.Animations.Count; i++)
     {
         // loop through every keyframe to sync them
         for (int j = 0; j < Parent.Animations[i].KeyFrames.Count; j++)
         {
             CompositeKeyFrame keyframe = Parent.Animations[i].KeyFrames[j];
             // remove the entry AND its children entries
             RemoveBoneTransformEntry(keyframe.BoneTransforms, childBone);
         }
     }
     // remove the bone
     this.ChildBones.Remove(childBone);
 }
Beispiel #7
0
 /// <summary>
 /// Recurisvely search the bone and its children for this name, and return null if didn't find any match
 /// </summary>
 internal CompositeBone FindBone(String boneName)
 {
     if (this.Name == boneName)
     {
         return(this);
     }
     foreach (CompositeBone childBone in this.ChildBones)
     {
         CompositeBone testBone = childBone.FindBone(boneName);
         if (testBone != null)
         {
             return(testBone);
         }
     }
     return(null);
 }
Beispiel #8
0
 private CompositeBone FindBone(String name, CompositeBone bone)
 {
     if (bone.Name == name)
     {
         return(bone);
     }
     for (int i = 0; i < bone.ChildBones.Count; i++)
     {
         CompositeBone returnBone = FindBone(name, bone.ChildBones[i]);
         if (returnBone != null)
         {
             return(returnBone);
         }
     }
     return(null);
 }
Beispiel #9
0
 public void CopyValuesTo(CompositeBone target, CompositeBone parentBone,
                          CompositeEntity newParentEntity)
 {
     target.Parent            = newParentEntity;
     target.ParentBone        = parentBone;
     target.Name              = this.Name;
     target.SceneItem         = this.SceneItem;
     target.SubItem           = this.SubItem;
     target.InheritPosition   = this.InheritPosition;
     target.InheritRotation   = this.InheritRotation;
     target.InheritScale      = this.InheritScale;
     target.InheritVisibility = this.InheritVisibility;
     target.MasterVisibility  = this.MasterVisibility;
     target.Interpolate       = this.Interpolate;
     // copy bones
     for (int i = 0; i < this.ChildBones.Count; i++)
     {
         CompositeBone targetCBone;
         bool          addToList = false;
         // if no child bone is available, create a new one
         if (target.ChildBones.Count <= i)
         {
             targetCBone = new CompositeBone();
             addToList   = true;
         }
         else
         {
             targetCBone = target.ChildBones[i];
         }
         this.ChildBones[i].CopyValuesTo(targetCBone, target, newParentEntity);
         if (addToList == true)
         {
             target.AddChildBone(targetCBone);
         }
     }
     // Remove remaining types (can cause garbage!)
     for (int i = target.ChildBones.Count; i > this.ChildBones.Count; i--)
     {
         target.ChildBones.RemoveAt(i - 1);
     }
 }
Beispiel #10
0
        /// <summary>
        /// Insert a children bone at specific index
        /// </summary>
        public void InsertChildBone(int index, CompositeBone childBone)
        {
            index = IceMath.Clamp(index, 0, _childBones.Count);
            _childBones.Insert(index, childBone);
            childBone.ParentBone = this;
            childBone.Parent     = this.Parent;
            CompositeBone precedingBone;

            if (index == 0)
            {
                precedingBone = this;
            }
            else
            {
                precedingBone = this.ChildBones[index - 1];
            }
            // sync transforms
            for (int i = 0; i < Parent.Animations.Count; i++)
            {
                // loop through every keyframe to sync them
                for (int j = 0; j < Parent.Animations[i].KeyFrames.Count; j++)
                {
                    CompositeKeyFrame keyframe = Parent.Animations[i].KeyFrames[j];
                    // loop to find the previous bone
                    for (int k = 0; k < keyframe.BoneTransforms.Count; k++)
                    {
                        CompositeBoneTransform transform = keyframe.BoneTransforms[k];
                        if (transform.Bone.Equals(precedingBone))
                        {
                            CompositeBoneTransform newTransform = new CompositeBoneTransform();
                            newTransform.Parent        = keyframe;
                            newTransform.BoneReference = childBone.Name;
                            // insert the new bone just after the preceding bone
                            keyframe.BoneTransforms.Insert(k + 1, newTransform);
                        }
                    }
                }
            }
        }
 private void AddBoneTransformFromBone(CompositeBone bone)
 {
     CompositeBoneTransform newBoneTrans = new CompositeBoneTransform("");
     newBoneTrans.Parent = this;
     newBoneTrans.BoneReference = bone.Name;
     _boneTransforms.Add(newBoneTrans);
     for (int i = 0; i < bone.ChildBones.Count; i++)
     {
         AddBoneTransformFromBone(bone.ChildBones[i]);
     }
 }
 private TreeNode InsertBoneNodeInNode(TreeNodeCollection parentNodes, CompositeBone bone, CompositeBone selectedBone)
 {
     String icon = (bone == CompositeEntity.RootBone) ? "anchor.png" : "link.png";
     TreeNode returnNode = null;
     TreeNode newNode = parentNodes.Add(
         "Node" + bone.Name, bone.Name, icon, icon);
     newNode.Tag = bone;
     if (bone.Equals(selectedBone))
     {                
         returnNode = newNode;
     }            
     foreach (CompositeBone childBone in bone.ChildBones)
     {
         TreeNode childNodeReturnValue = InsertBoneNodeInNode(newNode.Nodes, childBone, selectedBone);
         if (childNodeReturnValue != null)
         {
             returnNode = childNodeReturnValue;
         }
     }
     return returnNode;
 }
 private CompositeBone FindBone(String name, CompositeBone bone)
 {
     if (bone.Name == name)
     {
         return bone;
     }
     for (int i = 0; i < bone.ChildBones.Count; i++)
     {
         CompositeBone returnBone = FindBone(name, bone.ChildBones[i]);
         if (returnBone != null)
         {
             return returnBone;
         }
     }
     return null;
 }
 private void RefreshTreeViewBoneStructure(CompositeBone selectedBone)
 {
     treeViewBones.Nodes.Clear();
     if (CompositeEntity.RootBone != null)
     {
         TreeNode selectedNode = InsertBoneNodeInNode(treeViewBones.Nodes, CompositeEntity.RootBone, selectedBone);
         treeViewBones.ExpandAll();
         if (CompositeEntity.RootBone == selectedBone)
         {
             treeViewBones.SelectedNode = treeViewBones.Nodes[0];
         }
         else
         {
             treeViewBones.SelectedNode = selectedNode;
         }
     }            
     if (treeViewBones.SelectedNode == null)
     {
         treeViewBones_AfterSelect(treeViewBones, null);
         if (CompositeEntity.RootBone != null)
         {
             treeViewBones.SelectedNode = treeViewBones.Nodes[0];
         }
     }
 }
Beispiel #15
0
 /// <summary>
 /// Add a children to this bone
 /// </summary>
 public void AddChildBone(CompositeBone childBone)
 {
     // insert the children at the end
     InsertChildBone(_childBones.Count, childBone);
 }
Beispiel #16
0
 /// <summary>
 /// Insert a children bone at specific index
 /// </summary>
 public void InsertChildBone(int index, CompositeBone childBone)
 {
     index = IceMath.Clamp(index, 0, _childBones.Count);
     _childBones.Insert(index, childBone);
     childBone.ParentBone = this;
     childBone.Parent = this.Parent;
     CompositeBone precedingBone;
     if (index == 0)
     {
         precedingBone = this;
     }
     else
     {
         precedingBone = this.ChildBones[index - 1];
     }                        
     // sync transforms
     for (int i = 0; i < Parent.Animations.Count; i++)
     {
         // loop through every keyframe to sync them
         for (int j = 0; j < Parent.Animations[i].KeyFrames.Count; j++)
         {
             CompositeKeyFrame keyframe = Parent.Animations[i].KeyFrames[j];
             // loop to find the previous bone
             for (int k = 0; k < keyframe.BoneTransforms.Count; k++)
             {
                 CompositeBoneTransform transform = keyframe.BoneTransforms[k];                                               
                 if (transform.Bone.Equals(precedingBone))
                 {
                     CompositeBoneTransform newTransform = new CompositeBoneTransform();
                     newTransform.Parent = keyframe;
                     newTransform.BoneReference = childBone.Name;         
                     // insert the new bone just after the preceding bone
                     keyframe.BoneTransforms.Insert(k + 1, newTransform);
                 }
             }
         }
     }
 }
Beispiel #17
0
 private void RemoveBoneTransformEntry(List<CompositeBoneTransform> boneTransforms, CompositeBone bone)
 {
     String boneRefToRemove = bone.Name;
     // remove this bone's entry from the list
     for (int i = 0; i < boneTransforms.Count; i++)
     {
         if (boneTransforms[i].BoneReference == boneRefToRemove)
         {
             Console.WriteLine("Removing bone |" + boneRefToRemove + "| from transforms");
             boneTransforms.RemoveAt(i);
             break;
         }
     }
     // remove each child bone too
     for (int i = 0; i < bone.ChildBones.Count; i++)
     {
         RemoveBoneTransformEntry(boneTransforms, bone.ChildBones[i]);
     }
 }        
 private bool IsBoneNodeNameUnique(CompositeBone bone, String name)
 {
     if (bone != null)
     {
         if (bone.Name == name)
         {
             return false;
         }
         foreach (CompositeBone childBone in bone.ChildBones)
         {
             if (IsBoneNodeNameUnique(childBone, name) == false)
             {
                 return false;
             }
         }
     }
     return true;
 }
 private void toolStripButtonAddRootBone_Click(object sender, EventArgs e)
 {
     TreeNode selectedNode = treeViewBones.SelectedNode;
     CompositeBone selectedBone = null;
     CompositeBone parentBone = null;
     CompositeBone newBone = new CompositeBone("", GetNewBoneNodeName());
     newBone.Parent = CompositeEntity;
     if (selectedNode != null)
     {
         selectedBone = selectedNode.Tag as CompositeBone;
         if (selectedBone == CompositeEntity.RootBone)
         {
             parentBone = selectedBone;
         }
         else
         {
             parentBone = selectedBone.ParentBone;
         }
     }
     else
     {
         if (CompositeEntity.RootBone == null)
         {
             throw new Exception("CompositeEntity.RootBone is null");
         }
         else
         {
             parentBone = CompositeEntity.RootBone;
         }
     }
     parentBone.AddChildBone(newBone);
     RefreshTreeViewBoneStructure(null);
 }
 private void toolStripButtonAddChildBone_Click(object sender, EventArgs e)
 {
     TreeNode selectedNode = treeViewBones.SelectedNode;
     if (selectedNode != null)
     {
         CompositeBone selectedBone = null;
         CompositeBone newBone = new CompositeBone("", GetNewBoneNodeName());
         newBone.Parent = CompositeEntity;
         selectedBone = selectedNode.Tag as CompositeBone;
         selectedBone.AddChildBone(newBone);
         RefreshTreeViewBoneStructure(null);
     }
 }
Beispiel #21
0
 private static CompositeBone GetCompositeBone(XmlNode node)
 {
     CompositeBone newbone = new CompositeBone();
     SetProperty("Name", newbone, node);
     SetProperty("ChildBones", newbone, node);
     SetProperty("SceneItem", newbone, node);
     SetProperty("SubItem", newbone, node);
     SetProperty("MasterVisibility", newbone, node);
     SetProperty("InheritPosition", newbone, node);
     SetProperty("InheritScale", newbone, node);
     SetProperty("InheritRotation", newbone, node);
     SetProperty("InheritVisibility", newbone, node);
     SetProperty("Interpolate", newbone, node);
     return newbone;
 }
Beispiel #22
0
 private static void WriteCompositeBoneProperty(XmlNode _node, CompositeBone bone, XmlDocument doc)
 {
     _node.AppendChildIfNotNull(WriteProperty("Name", bone, doc));
     _node.AppendChildIfNotNull(WriteProperty("SceneItem", bone, doc));
     _node.AppendChildIfNotNull(WriteProperty("SubItem", bone, doc));
     _node.AppendChildIfNotNull(WriteProperty("MasterVisibility", bone, doc));
     _node.AppendChildIfNotNull(WriteProperty("InheritPosition", bone, doc));
     _node.AppendChildIfNotNull(WriteProperty("InheritScale", bone, doc));
     _node.AppendChildIfNotNull(WriteProperty("InheritRotation", bone, doc));
     _node.AppendChildIfNotNull(WriteProperty("InheritVisibility", bone, doc));
     _node.AppendChildIfNotNull(WriteProperty("Interpolate", bone, doc));
     XmlNode childBonesNode = _node.AppendChild(doc.CreateElement("ChildBones"));            
     foreach (var childBone in bone.ChildBones)
     {
         XmlNode childNode = childBonesNode.AppendChild(doc.CreateElement("Bone"));
         WriteCompositeBoneProperty(childNode, childBone, doc);
     }
 }
Beispiel #23
0
        private void RemoveBoneTransformEntry(List <CompositeBoneTransform> boneTransforms, CompositeBone bone)
        {
            String boneRefToRemove = bone.Name;

            // remove this bone's entry from the list
            for (int i = 0; i < boneTransforms.Count; i++)
            {
                if (boneTransforms[i].BoneReference == boneRefToRemove)
                {
                    Console.WriteLine("Removing bone |" + boneRefToRemove + "| from transforms");
                    boneTransforms.RemoveAt(i);
                    break;
                }
            }
            // remove each child bone too
            for (int i = 0; i < bone.ChildBones.Count; i++)
            {
                RemoveBoneTransformEntry(boneTransforms, bone.ChildBones[i]);
            }
        }
Beispiel #24
0
 public CompositeBone(String sceneItemBankEntry, String name)
 {
     _name = name;
     _parentBone = null;
     _sceneItem = sceneItemBankEntry;
     _subItem = String.Empty;
     _childBones = new List<CompositeBone>();
     this.MasterVisibility = null;
     this.Interpolate = true;
     this.InheritPosition = true;
     this.InheritRotation = true;
     this.InheritScale = true;
     this.InheritVisibility = true;
 }
Beispiel #25
0
 /// <summary>
 /// Add a children to this bone
 /// </summary>
 public void AddChildBone(CompositeBone childBone)
 {
     // insert the children at the end
     InsertChildBone(_childBones.Count, childBone);
 }
Beispiel #26
0
 public void CopyValuesTo(CompositeBone target, CompositeBone parentBone,
     CompositeEntity newParentEntity)
 {
     target.Parent = newParentEntity;
     target.ParentBone = parentBone;
     target.Name = this.Name;
     target.SceneItem = this.SceneItem;
     target.SubItem = this.SubItem;
     target.InheritPosition = this.InheritPosition;
     target.InheritRotation = this.InheritRotation;
     target.InheritScale = this.InheritScale;
     target.InheritVisibility = this.InheritVisibility;
     target.MasterVisibility = this.MasterVisibility;
     target.Interpolate = this.Interpolate;
     // copy bones
     for (int i = 0; i < this.ChildBones.Count; i++)
     {
         CompositeBone targetCBone;
         bool addToList = false;
         // if no child bone is available, create a new one
         if (target.ChildBones.Count <= i)
         {
             targetCBone = new CompositeBone();
             addToList = true;
         }
         else
         {
             targetCBone = target.ChildBones[i];
         }
         this.ChildBones[i].CopyValuesTo(targetCBone, target, newParentEntity);
         if (addToList == true)
         {
             target.AddChildBone(targetCBone);
         }
     }
     // Remove remaining types (can cause garbage!)
     for (int i = target.ChildBones.Count; i > this.ChildBones.Count; i--)
     {                
         target.ChildBones.RemoveAt(i-1);
     }
 }
Beispiel #27
0
 /// <summary>
 /// Removes a children from this bone
 /// </summary>
 public void RemoveChildBone(CompositeBone childBone)
 {
     // sync transforms
     for (int i = 0; i < Parent.Animations.Count; i++)
     {
         // loop through every keyframe to sync them
         for (int j = 0; j < Parent.Animations[i].KeyFrames.Count; j++)
         {
             CompositeKeyFrame keyframe = Parent.Animations[i].KeyFrames[j];
             // remove the entry AND its children entries
             RemoveBoneTransformEntry(keyframe.BoneTransforms, childBone);
         }
     }
     // remove the bone
     this.ChildBones.Remove(childBone);
 }
 private void toolStripButtonNewBoneFromItem_Click(object sender, EventArgs e)
 {
     TreeNode selectedNode = treeViewBones.SelectedNode;
     if (selectedNode == null)
     {
         selectedNode = treeViewBones.Nodes[0];
     }
     SceneItem selectedItem = treeViewSceneItems.SelectedNode.Tag as SceneItem;       
     CompositeBone newBone = new CompositeBone(selectedItem.Name, 
         GetUniqueBoneNodeName(selectedItem.Name));
     newBone.Parent = CompositeEntity;
     CompositeBone selectedBone = selectedNode.Tag as CompositeBone;
     selectedBone.AddChildBone(newBone);
     RefreshTreeViewBoneStructure(null);            
 }