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); }
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(); }
protected void GetChildren(ModelBone parent, ref ModelBoneCollection list) { foreach (ModelBone child in parent.Children) { list.Add(child); child.GetChildren(child, ref list); } }
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(); }
//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); }
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]; } } }
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); }
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); }
public SelectEventArgs(ModelBone item) { Item = item; }