Exemplo n.º 1
0
        public bool MoveBone(int boneIndex, int newParentBoneIndex)
        {
            int newBoneIndex;

            if (boneIndex == newParentBoneIndex)
            {
                return(false);
            }

            Bones[boneIndex].Parent.Children.Remove(Bones[boneIndex]);
            Bones[boneIndex].Parent = Bones[newParentBoneIndex];
            Bones[newParentBoneIndex].Children.Add(Bones[boneIndex]);

            ModelBone bone = Bones[boneIndex];

            Bones.RemoveAt(boneIndex);
            newBoneIndex = newParentBoneIndex + (boneIndex < newParentBoneIndex ? 0 : 1);
            Bones.Insert(newBoneIndex, bone);

            ModelBone[] children = new ModelBone[Bones[newBoneIndex].Children.Count];
            Bones[newBoneIndex].Children.CopyTo(children);

            for (int i = 0; i < children.Length; i++)
            {
                MoveBone(children[i].Index, newBoneIndex);
            }

            Bones.ReIndex();

            return(true);
        }
Exemplo n.º 2
0
        public void ImportBone(ModelBone bone, int parentBoneIndex)
        {
            ModelBone           cloneBone = bone.Clone();
            ModelBoneCollection boneList  = cloneBone.AllChildren();

            ModelBone parent = Bones[parentBoneIndex];

            for (int i = 0; i < boneList.Count; i++)
            {
                Bones.Insert(parentBoneIndex + i + 1, boneList[i]);

                if (boneList[i].Mesh != null)
                {
                    ModelMesh mesh = boneList[i].Mesh;
                    mesh.Parent = boneList[i];
                    Meshes.Add(mesh);
                }

                if (i == 0)
                {
                    boneList[i].Parent = parent;
                    parent.Children.Add(boneList[i]);
                }
            }

            Bones.ReIndex();
        }
Exemplo n.º 3
0
        protected void GetChildren(ModelBone parent, ref ModelBoneCollection list)
        {
            foreach (ModelBone child in parent.Children)
            {
                list.Add(child);

                child.GetChildren(child, ref list);
            }
        }
Exemplo n.º 4
0
        public ModelMesh(ModelMesh from)
        {
            MeshParts = new List <ModelMeshPart>(from.MeshParts.Count);

            foreach (ModelMeshPart part in from.MeshParts)
            {
                MeshParts.Add(part.Clone());
            }

            Name   = from.Name;
            Parent = new ModelBone();
        }
Exemplo n.º 5
0
        //public void CopyBoneTransformsFrom(Matrix4[] sourceBoneTransforms) { }
        //public void CopyBoneTransformsTo(Matrix4[] destinationBoneTransforms) { }

        public int AddMesh(ModelMesh mesh, int parentBoneIndex = 0)
        {
            bool      addBone = true;
            ModelBone b       = new ModelBone
            {
                Index = -1
            };

            if (Bones.Count > 0)
            {
                b.Parent = Bones[parentBoneIndex];
                Bones[parentBoneIndex].Children.Add(b);

                int childBoneCount = CountChildrenOf(parentBoneIndex);
                if (parentBoneIndex + childBoneCount < Bones.Count)
                {
                    int index = parentBoneIndex + childBoneCount;

                    addBone = false;
                    Bones.Insert(index, b);
                    b.Index = index;
                }
            }

            if (addBone)
            {
                Bones.Add(b);
                b.Index = Bones.Count - 1;
            }
            else
            {
                Bones.ReIndex();
            }

            if (mesh != null)
            {
                b.Type       = BoneType.Mesh;
                b.Attachment = mesh;
                mesh.Parent  = Bones[b.Index];
                Meshes.Add(mesh);
            }
            else
            {
                // Just a bone
            }

            return(b.Index);
        }
Exemplo n.º 6
0
        public void CopyAbsoluteBoneTransformsTo(Matrix4D[] destinationBoneTransforms)
        {
            for (int i = 0; i < Bones.Count; i++)
            {
                ModelBone bone = Bones[i];

                if (bone.Parent == null)
                {
                    destinationBoneTransforms[i] = bone.Transform;
                }
                else
                {
                    destinationBoneTransforms[i] = bone.Transform * destinationBoneTransforms[bone.Parent.Index];
                }
            }
        }
Exemplo n.º 7
0
        public void RemoveBone(int BoneIndex)
        {
            ModelBone[] children = new ModelBone[Bones[BoneIndex].Children.Count];
            Bones[BoneIndex].Children.CopyTo(children);
            for (int i = children.Length - 1; i > -1; i--)
            {
                RemoveBone(children[i].Index);
            }

            for (int i = BoneIndex + 1; i < Bones.Count; i++)
            {
                Bones[i].Index--;
            }
            if (Bones[BoneIndex].Parent != null)
            {
                Bones[BoneIndex].Parent.Children.Remove(Bones[BoneIndex]);
            }
            Meshes.Remove(Bones[BoneIndex].Mesh);

            Bones.RemoveAt(BoneIndex);
        }
Exemplo n.º 8
0
        public ModelBone Clone()
        {
            ModelBone b = new ModelBone()
            {
                Index     = Index,
                Name      = Name,
                Parent    = Parent,
                Transform = Transform,

                Type           = Type,
                Attachment     = Attachment,
                AttachmentFile = AttachmentFile
            };

            foreach (ModelBone child in Children)
            {
                ModelBone cb = child.Clone();
                cb.Parent = b;

                b.Children.Add(cb);
            }

            return(b);
        }
Exemplo n.º 9
0
 public SelectEventArgs(ModelBone item)
 {
     Item = item;
 }