public void ProcessTree(Model m, int index, bool bReset = false) { TreeNode ParentNode; if (bReset || tvNodes.Nodes.Count == 0) { Reset(); } ParentNode = tvNodes.Nodes[0]; for (int i = 0; i < m.Bones.Count; i++) { ModelBone bone = m.Bones[i]; int key = ModelBone.GetModelBoneKey(index, i); while (ParentNode != null && ParentNode.Tag != null && (int)ParentNode.Tag != ModelBone.GetModelBoneKey(index, bone.Parent.Index)) { ParentNode = ParentNode.Parent; } ParentNode = ParentNode.Nodes[ParentNode.Nodes.Add(CreateNode(bone, key))]; } tvNodes.Nodes[0].Expand(); if (tvNodes.Nodes[0].Nodes.Count > 0) { tvNodes.Nodes[0].Nodes[0].Expand(); } }
private void tvNodes_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (SceneManager.Current.Models.Count > 0) { if (e.Node.Parent == null) { SceneManager.Current.SetSelectedBone(-1, -1); } else if (e.Node.Tag != null) { int mI = ModelBone.GetModelIndexFromKey((int)e.Node.Tag); int bI = ModelBone.GetBoneIndexFromKey((int)e.Node.Tag); SceneManager.Current.SetSelectedBone(mI, bI); ModelBone bone = SceneManager.Current.Models[mI].Bones[bI]; if (bone.Type == BoneType.Mesh) { SceneManager.Current.Entities.Add(new Bounds { LinkedBox = bone.Mesh.BoundingBox }); } else { SceneManager.Current.Entities.Add(new Node { LinkedBone = bone }); } } } }
private void tvNodes_DragDrop(object sender, DragEventArgs e) { TreeNode NewNode; if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false)) { Point pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y)); TreeNode DestinationNode = ((TreeView)sender).GetNodeAt(pt); NewNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode"); int srcModel = ModelBone.GetModelIndexFromKey((int)NewNode.Tag); int srcBone = ModelBone.GetBoneIndexFromKey((int)NewNode.Tag); int dstModel = ModelBone.GetModelIndexFromKey((int)DestinationNode.Tag); int dstBone = ModelBone.GetBoneIndexFromKey((int)DestinationNode.Tag); DestinationNode.Nodes.Add((TreeNode)NewNode.Clone()); DestinationNode.Expand(); NewNode.Remove(); if (srcModel == dstModel) { if (SceneManager.Current.Models[srcModel].MoveBone(srcBone, dstBone)) { SceneManager.Current.Change(ChangeType.Move, ChangeContext.Model, srcBone, dstBone); } } else { SceneManager.Current.Models[dstModel].ImportBone(SceneManager.Current.Models[srcModel].Bones[srcBone], dstBone); SceneManager.Current.Models[srcModel].RemoveBone(srcBone); ReindexTree(); } } }
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]); var 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) { var cloneBone = bone.Clone(); var boneList = cloneBone.AllChildren(); var parent = bones[parentBoneIndex]; for (int i = 0; i < boneList.Count; i++) { bones.Insert(parentBoneIndex + i + 1, boneList[i]); if (boneList[i].Mesh != null) { var 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(); }
void scene_OnChange(object sender, ChangeEventArgs e) { if (e.Index == -1) { ProcessTree(SceneManager.Current.Models[0], 0, true); } TreeNode node; //if (node == null) { throw new IndexOutOfRangeException(string.Format("Can't find node with index {0}", e.Index)); } switch (e.Change) { case ChangeType.Add: FindNode((int)e.AdditionalInformation, tvNodes.Nodes[0], out node); node.Nodes.Add(CreateNode(SceneManager.Current.Models[0].Bones[e.Index], e.Index)); ReindexTree(); node.Expand(); break; case ChangeType.Delete: FindNode(e.Index, tvNodes.Nodes[0], out node); if ((bool)e.AdditionalInformation) { node.Remove(); ReindexTree(); } else { node.ImageIndex = 0; node.SelectedImageIndex = node.ImageIndex; } break; case ChangeType.Move: TreeNode dest; FindNode(e.Index, tvNodes.Nodes[0], out node); FindNode((int)e.AdditionalInformation, tvNodes.Nodes[0], out dest); node.Remove(); dest.Nodes.Add(node); ReindexTree(); break; case ChangeType.Rename: FindNode(e.Index, tvNodes.Nodes[0], out node); node.Text = getNodeText(SceneManager.Current.Models[0].Bones[e.Index]); break; case ChangeType.ChangeType: FindNode(e.Index, tvNodes.Nodes[0], out node); ModelBone bone = SceneManager.Current.Models[0].Bones[e.Index]; node.Text = getNodeText(bone); node.ImageIndex = (int)bone.Type; node.SelectedImageIndex = node.ImageIndex; break; } }
private void btnOK_Click(object sender, EventArgs e) { var model = (SceneManager.Current.Models.Count > 0 ? SceneManager.Current.Models[modelIndex] : (Model)SceneManager.Current.Add(new Model())); newBoneKey = model.AddMesh(null, boneIndex); model.SetName(txtName.Text, newBoneKey); newBoneKey = ModelBone.GetModelBoneKey(modelIndex, newBoneKey); this.Close(); }
protected void getChildren(ModelBone parent, ref ModelBoneCollection list) { foreach (var child in parent.children) { list.Add(child); child.getChildren(child, ref list); } }
protected TreeNode CreateNode(ModelBone bone, int index) { var node = new TreeNode(getNodeText(bone)); node.Tag = index; node.ImageIndex = (int)bone.Type; node.SelectedImageIndex = node.ImageIndex; return node; }
protected TreeNode CreateNode(ModelBone bone, int index) { var node = new TreeNode(getNodeText(bone)); node.Tag = index; node.ImageIndex = (int)bone.Type; node.SelectedImageIndex = node.ImageIndex; return(node); }
protected int ReindexHierarchy(int modelIndex, int boneIndex, TreeNode root) { root.Tag = ModelBone.GetModelBoneKey(modelIndex, boneIndex++); foreach (TreeNode child in root.Nodes) { boneIndex = ReindexHierarchy(modelIndex, boneIndex, child); } return(boneIndex); }
public void CopyAbsoluteBoneTransformsTo(Matrix4[] 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 int AddMesh(ModelMesh mesh, int ParentBoneIndex = 0) { bool bAddBone = true; ModelBone b = new ModelBone(); b.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; bAddBone = false; bones.Insert(index, b); b.Index = index; } } if (bAddBone) { 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 int AddMesh(ModelMesh mesh, int ParentBoneIndex = 0) { bool bAddBone = true; ModelBone b = new ModelBone(); b.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; bAddBone = false; bones.Insert(index, b); b.Index = index; } } if (bAddBone) { 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; }
private void btnOk_Click(object sender, EventArgs e) { ModelBone oldBone = SceneManager.Current.Models[modelIndex].Bones[boneIndex]; if (oldBone.Type == BoneType.Mesh && type != BoneType.Mesh) { SceneManager.Current.Models[modelIndex].ClearMesh(boneIndex); } switch (type) { case BoneType.Mesh: //SceneManager.Current.Models[modelIndex].SetMesh(SceneManager.Current.Content.Load<Model, MDLImporter>(Path.GetFileNameWithoutExtension(fileToAttach), Path.GetDirectoryName(fileToAttach)).Meshes[0], boneIndex); oldBone.AttachmentFile = null; break; case BoneType.Light: oldBone.Type = type; if (chkNewLight.Checked) { oldBone.Attachment = new ToxicRagers.CarmageddonReincarnation.Formats.LIGHT(); oldBone.AttachmentFile = null; } else { //oldBone.Attachment = SceneManager.Current.Content.Load<Model, LIGHTImporter>(Path.GetFileNameWithoutExtension(fileToAttach), Path.GetDirectoryName(fileToAttach)).Bones[0].Attachment; oldBone.AttachmentFile = Path.GetFileNameWithoutExtension(fileToAttach); } break; case BoneType.VFX: oldBone.Type = type; oldBone.Attachment = null; oldBone.AttachmentFile = Path.GetFileNameWithoutExtension(fileToAttach); break; case BoneType.Null: oldBone.Type = type; oldBone.Attachment = null; oldBone.AttachmentFile = null; break; } }
private void tvNodes_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Node.Tag != null && SceneManager.Current.Models.Count > 0) { int mI = ModelBone.GetModelIndexFromKey((int)e.Node.Tag); int bI = ModelBone.GetBoneIndexFromKey((int)e.Node.Tag); SceneManager.Current.SetSelectedBone(mI, bI); var bone = SceneManager.Current.Models[mI].Bones[bI]; if (bone.Type == BoneType.Mesh) { SceneManager.Current.SetBoundingBox(bone.Mesh.BoundingBox); } else { SceneManager.Current.SetNodePosition(bone); } } }
public ModelBone Clone() { var b = new ModelBone(); b.index = this.index; b.name = this.name; b.parent = this.parent; b.transform = this.transform; b.boneType = this.boneType; b.attachment = this.attachment; b.attachmentFile = this.attachmentFile; foreach (var child in this.children) { var cb = child.Clone(); cb.parent = b; b.children.Add(cb); } return(b); }
public void RemoveBone(int BoneIndex) { Console.WriteLine("Going to remove bone {0}", 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); Console.WriteLine("Removing bone at {0}, bones.Count = {1}", BoneIndex, bones.Count); }
private string getNodeText(ModelBone bone) { string name = bone.Name; switch (bone.Type) { case BoneType.Mesh: if (bone.Mesh != null) { name += " - " + bone.Mesh.Name; } break; case BoneType.Light: name += " - " + (bone.Attachment as ToxicRagers.CarmageddonReincarnation.Formats.LIGHT).Name; break; case BoneType.VFX: name += " - " + bone.AttachmentFile; break; } return(name); }
private void menuObjectClick(object sender, EventArgs e) { ToolStripMenuItem mi = (ToolStripMenuItem)sender; int boneIndex = SceneManager.Current.SelectedBoneIndex; int modelIndex = SceneManager.Current.SelectedModelIndex; int modelBoneKey = ModelBone.GetModelBoneKey(modelIndex, boneIndex); switch (mi.Text) { case "New...": var addNew = new frmNewObject(); addNew.SetParentNode(modelIndex, boneIndex); if (addNew.ShowDialog(this) == DialogResult.OK) { SceneManager.Current.Change(ChangeType.Add, addNew.NewBoneKey, modelBoneKey); } break; case "Remove...": var removeObject = new frmRemoveObject(); removeObject.SetParentNode(modelIndex, boneIndex); if (removeObject.ShowDialog(this) == DialogResult.OK) { SceneManager.Current.Change(ChangeType.Delete, modelBoneKey, removeObject.RemovedBone); } break; case "Modify geometry...": var geometry = new frmModifyModel(); geometry.SetParentNode(modelIndex, boneIndex); if (geometry.ShowDialog(this) == DialogResult.OK) { SceneManager.Current.Change(ChangeType.Transform, modelBoneKey); } break; case "Modify actor...": var transform = new frmModifyActor(); transform.SetParentNode(modelIndex, boneIndex); if (transform.ShowDialog(this) == DialogResult.OK) { SceneManager.Current.Change(ChangeType.Transform, modelBoneKey); } break; case "Rename": var rename = new frmRename(); rename.SetParentNode(modelIndex, boneIndex); if (rename.ShowDialog(this) == DialogResult.OK) { SceneManager.Current.Change(ChangeType.Rename, modelBoneKey, rename.NewName); } break; case "Add/Change Type...": var changeType = new frmChangeNodeType(); changeType.SetParentNode(modelIndex, boneIndex); if (changeType.ShowDialog(this) == DialogResult.OK) { SceneManager.Current.Change(ChangeType.ChangeType, modelBoneKey); } break; case "Remove": break; case "Optimise": foreach (ModelMesh mesh in SceneManager.Current.SelectedModel.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { part.Optimise(); } } break; case "Flatten hierarchy...": SceneManager.Current.UpdateProgress("TODO: Code \"Flatten hierarchy...\""); break; case "Invert texture 'v' coordinates": ModelManipulator.FlipUVs(SceneManager.Current.SelectedModel.Bones[SceneManager.Current.SelectedBoneIndex].Mesh); break; } }
public ModelMesh(ModelMesh from) { this.meshParts = new List<ModelMeshPart>(from.meshParts); this.name = from.name; this.parent = new ModelBone(); }
private string getNodeText(ModelBone bone) { string name = bone.Name; switch (bone.Type) { case BoneType.Mesh: if (bone.Mesh != null) { name += " - " + bone.Mesh.Name; } break; case BoneType.Light: name += " - " + (bone.Attachment as ToxicRagers.CarmageddonReincarnation.Formats.LIGHT).Name; break; case BoneType.VFX: name += " - " + bone.AttachmentFile; break; } return name; }
public ModelMesh(ModelMesh from) { this.meshParts = new List <ModelMeshPart>(from.meshParts); this.name = from.name; this.parent = new ModelBone(); }
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]); var 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 SelectEventArgs(ModelBone item) { Item = item; }
public void SetNodePosition(ModelBone bone) { this.node.LinkWith(bone, LinkType.Position | LinkType.Rotation); this.bb = null; }
private void setSelection(ModelBone bone) { this.Transform.Visible = (bone != null); this.Lighting.Visible = (bone.Type == BoneType.Light); }
public ModelBone Clone() { var b = new ModelBone(); b.index = this.index; b.name = this.name; b.parent = this.parent; b.transform = this.transform; b.boneType = this.boneType; b.attachment = this.attachment; b.attachmentFile = this.attachmentFile; foreach (var child in this.children) { var cb = child.Clone(); cb.parent = b; b.children.Add(cb); } return b; }
private void setSelection(ModelBone bone) { Transform.Visible = bone != null; Lighting.Visible = bone.Type == BoneType.Light; }