示例#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);
        }
示例#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();
        }
示例#3
0
文件: ModelBone.cs 项目: q4a/Flummery
        protected void GetChildren(ModelBone parent, ref ModelBoneCollection list)
        {
            foreach (ModelBone child in parent.Children)
            {
                list.Add(child);

                child.GetChildren(child, ref list);
            }
        }
示例#4
0
文件: ModelMesh.cs 项目: q4a/Flummery
        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();
        }
示例#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);
        }
示例#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];
                }
            }
        }
示例#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);
        }
示例#8
0
文件: ModelBone.cs 项目: q4a/Flummery
        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);
        }
示例#9
0
 public SelectEventArgs(ModelBone item)
 {
     Item = item;
 }