コード例 #1
0
 public CompositeEntity()
     : base()
 {
     _sceneItemBank     = new Dictionary <String, SceneItem>();
     _animations        = new List <CompositeAnimation>();
     _rootBone          = new CompositeBone();
     _rootBone.Name     = "Root";
     this.AutoPlay      = true;
     _queuedAnimationID = null;
 }
コード例 #2
0
        public void GenerateDefaultBoneTransformsList()
        {
            _boneTransforms.Clear();
            CompositeBone root = this.Parent.Parent.RootBone;

            if (root != null)
            {
                AddBoneTransformFromBone(root);
            }
        }
コード例 #3
0
        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]);
            }
        }
コード例 #4
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;
 }
コード例 #5
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);
 }
コード例 #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);
 }
コード例 #7
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);
 }
コード例 #8
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);
     }
 }
コード例 #9
0
        /// <summary>
        /// Insert a children bone at specific index
        /// </summary>
        public void InsertChildBone(int index, CompositeBone childBone)
        {
            index = SquidMath.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);
                        }
                    }
                }
            }
        }
コード例 #10
0
 /// <summary>
 /// Add a children to this bone
 /// </summary>
 public void AddChildBone(CompositeBone childBone)
 {
     // insert the children at the end
     InsertChildBone(_childBones.Count, childBone);
 }
コード例 #11
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]);
            }
        }