public MDL0VertexNode NewVertex() { MDL0Node model = (MDL0Node)_resource; MDL0GroupNode g = model._vertGroup; if (g == null) { model.AddChild(g = new MDL0GroupNode(MDLResourceType.Vertices), true); model._vertGroup = g; model._vertList = g.Children; } MDL0VertexNode node = new MDL0VertexNode() { Name = "VertexSet" + ((MDL0Node)_resource)._vertList.Count }; node.Vertices = new Vector3[] { new Vector3(0) }; g.AddChild(node, true); node.ForceRebuild = true; node.Rebuild(true); node.SignalPropertyChange(); FindResource(node, true).EnsureVisible(); return(node); }
public void NewShader() { MDL0Node model = ((MDL0Node)_resource); if (model._shadGroup == null) { MDL0GroupNode g = model._shadGroup; if (g == null) { model.AddChild(g = new MDL0GroupNode(MDLResourceType.Shaders), true); model._shadGroup = g; model._shadList = g.Children; } } if (model._shadList != null && model._matList != null && model._shadList.Count < model._matList.Count) { MDL0ShaderNode shader = new MDL0ShaderNode(); model._shadGroup.AddChild(shader); shader.Default(); shader.Rebuild(true); BaseWrapper b = FindResource(shader, true); if (b != null) { b.EnsureVisible(); } } }
public MDL0ColorNode NewColor() { MDL0Node model = ((MDL0Node)_resource); MDL0GroupNode g = model._colorGroup; if (g == null) { model.AddChild(g = new MDL0GroupNode(MDLResourceType.Colors), true); model._colorGroup = g; model._colorList = g.Children; } MDL0ColorNode node = new MDL0ColorNode() { Name = "ColorSet" + ((MDL0Node)_resource)._colorList.Count }; node.Colors = new RGBAPixel[] { new RGBAPixel() { A = 255, R = 128, G = 128, B = 128 } }; g.AddChild(node, true); node.Rebuild(true); node.SignalPropertyChange(); FindResource(node, true).EnsureVisible(); return(node); }
//~ModelLinker() //{ // Dispose(); //} //public void Dispose() //{ // if (_vertices != null) // { // foreach (VertexCodec c in _vertices) // c.Dispose(); // _vertices = null; // } // if (_normals != null) // { // foreach (VertexCodec c in _normals) // c.Dispose(); // _normals = null; // } // if (_colors != null) // { // //foreach (ColorCodec c in _colors) // // c.Dispose(); // _colors = null; // } // if (_uvs != null) // { // foreach (VertexCodec c in _uvs) // c.Dispose(); // _uvs = null; // } // GC.SuppressFinalize(this); //} public static ModelLinker Prepare(MDL0Node model) { ModelLinker linker = new ModelLinker(); linker.Model = model; linker.Version = model._version; MDLResourceType resType; int index; List <MDLResourceType> iList = IndexBank[model._version]; foreach (MDL0GroupNode group in model.Children) { resType = (MDLResourceType)Enum.Parse(typeof(MDLResourceType), group.Name); //Get flattened bone list and assign it to bone cache if (resType == MDLResourceType.Bones) { linker.BoneCache = group.FindChildrenByType(null, ResourceType.MDL0Bone); } //If version contains resource type, add it to group list if ((index = iList.IndexOf(resType)) >= 0) { linker.Groups[(int)resType] = group; } } return(linker); }
private void CreateNode() { TreeView.BeginUpdate(); int id = 1; string name = "NewBone0"; MDL0Node model = ((MDL0BoneNode)_resource).Model; Top: foreach (MDL0BoneNode b in model._linker.BoneCache) { if (b.Name == name) { name = "NewBone" + id++; goto Top; } } MDL0BoneNode bone = new MDL0BoneNode { Name = name, _entryIndex = model._linker.BoneCache.Length }; bone.FrameState = bone.BindState = FrameState.Neutral; _resource.AddChild(bone, true); bone.RecalcFrameState(); bone.RecalcBindState(false, false, false); model._linker.RegenerateBoneCache(); TreeView.EndUpdate(); Nodes[Nodes.Count - 1].EnsureVisible(); //TreeView.SelectedNode = Nodes[Nodes.Count - 1]; }
public void NameColor() { MDL0Node model = ((MDL0Node)_resource); MDL0GroupNode g = model._colorGroup; if (g != null) { foreach (MDL0ColorNode v in g.Children) { string name = model.Name + "_"; if (v._objects.Count > 0) { MDL0ObjectNode o = v._objects[0]; name += o.Name; if (o._drawCalls.Count > 0) { DrawCall c = o._drawCalls[0]; if (c.MaterialNode != null && c.VisibilityBoneNode != null) { name += "_" + c.Material + "_" + c.VisibilityBone; } } } else { name += "ColorArray"; } v.Name = g.FindName(name); } } }
public MDL0NormalNode NewNormal() { MDL0Node model = ((MDL0Node)_resource); MDL0GroupNode g = model._normGroup; if (g == null) { model.AddChild(g = new MDL0GroupNode(MDLResourceType.Normals), true); model._normGroup = g; model._normList = g.Children; } MDL0NormalNode node = new MDL0NormalNode() { Name = "NormalSet" + ((MDL0Node)_resource)._normList.Count }; node.Normals = new Vector3[] { new Vector3(0) }; g.AddChild(node, true); node._forceRebuild = true; node.Rebuild(true); node.SignalPropertyChange(); FindResource(node, true).EnsureVisible(); return(node); }
public MDL0ShaderNode NewShader() { MDL0Node model = (MDL0Node)_resource; if (model._shadGroup == null) { MDL0GroupNode g = model._shadGroup; if (g == null) { model.AddChild(g = new MDL0GroupNode(MDLResourceType.Shaders), true); model._shadGroup = g; model._shadList = g.Children; } } if (model._shadList != null && model._matList != null && model._shadList.Count < model._matList.Count) { MDL0ShaderNode shader = new MDL0ShaderNode(); model._shadGroup.AddChild(shader); shader.Default(); shader.Rebuild(true); BaseWrapper b = FindResource(shader, true); b?.EnsureVisible(); return(shader); } MessageBox.Show("Shader could not be added. Make sure that you do not have more shaders than materials", "Error"); return(null); }
public MDL0UVNode NewUV() { MDL0Node model = ((MDL0Node)_resource); MDL0GroupNode g = model._uvGroup; if (g == null) { model.AddChild(g = new MDL0GroupNode(MDLResourceType.UVs), true); model._uvGroup = g; model._uvList = g.Children; } MDL0UVNode node = new MDL0UVNode() { Name = "#" + ((MDL0Node)_resource)._uvList.Count }; node.Points = new Vector2[] { new Vector2(0) }; g.AddChild(node, true); node._forceRebuild = true; node.Rebuild(true); node.SignalPropertyChange(); FindResource(node, true).EnsureVisible(); return(node); }
private void ModelChanged(MDL0Node model) { //if (_externalNode != null) //{ // _externalNode.Dispose(); // _externalNode = null; //} if (_targetModel != null) { modelPanel1.RemoveTarget(_targetModel); } if ((_targetModel = model) != null) { modelPanel1.AddTarget(_targetModel); } modelPanel1.ResetCamera(); //modelPanel1.TargetModel = _targetModel; pnlOptions.TargetModel = _targetModel; pnlAnim.TargetModel = _targetModel; pnlAssets.Attach(_targetModel); //UpdateReferences(); //_animFrame = -1; SetFrame(0); }
public DialogResult ShowDialog(IWin32Window owner, MDL0Node model) { this.Text = String.Format("Advanced Model Editor - {0}", model.Name); _model = model; try { return(ShowDialog(owner)); } finally { _model = null; } }
public static ModelLinker Prepare(MDL0Node model) { ModelLinker linker = new ModelLinker() { Model = model, Version = model._version }; //Get flattened bone list and assign it to bone cache linker.RegenerateBoneCache(); MR resType; int index; List <MR> iList = IndexBank[model._version]; foreach (MDL0GroupNode group in model.Children) { //If version contains resource type, add it to group list resType = (MR)Enum.Parse(typeof(MR), group.Name); if ((index = iList.IndexOf(resType)) >= 0) { linker.Groups[(int)resType] = group; } } return(linker); }
public void ImportModel() { string path; if (Program.OpenFile(FileFilters.MDL0Import, out path) > 0) { MDL0Node node = MDL0Node.FromFile(path); if (node != null) { ((BRESNode)_resource).GetOrCreateFolder <MDL0Node>().AddChild(node); BaseWrapper w = this.FindResource(node, true); w.EnsureVisible(); w.TreeView.SelectedNode = w; if ((node as MDL0Node)._reopen == true) { string tempPath = Path.GetTempFileName(); node.Export(tempPath); node.Replace(tempPath, FileMapProtect.ReadWrite, FileOptions.SequentialScan | FileOptions.DeleteOnClose); node.SignalPropertyChange(); } } } }
private static void WriteImages(MDL0Node model, string path, XmlWriter writer) { if (model._texList == null) { return; } writer.WriteStartElement("library_images"); foreach (MDL0TextureNode tex in model._texList) { writer.WriteStartElement("image"); writer.WriteAttributeString("id", tex.Name + "-image"); writer.WriteAttributeString("name", tex.Name); writer.WriteStartElement("init_from"); string outPath = String.Format("{0}/{1}.png", path.Replace('\\', '/'), tex.Name); //Export image and set full path. Or, cheat... writer.WriteString(String.Format("file://{0}", outPath)); writer.WriteEndElement(); //init_from writer.WriteEndElement(); //image } writer.WriteEndElement(); //library_images }
protected override void OnShown(EventArgs e) { modelEditControl1._openedFiles.Add(Program.RootNode); MainForm.Instance.Visible = !Properties.Settings.Default.ViewerSettings.HideMainWindow; if (_models.Count != 0) { for (int i = 0; i < _models.Count; i++) { if (_models[i] != null) { modelEditControl1.AppendTarget(_models[i]); } } modelEditControl1.TargetModel = _models[0]; modelEditControl1.EditingAll = _models.Count > 1; modelEditControl1.ResetBoneColors(); } else { modelEditControl1.TargetModel = null; } if (_collisions.Count != 0) { foreach (CollisionNode node in _collisions) { modelEditControl1.AppendTarget(node); // Link bones foreach (CollisionObject obj in node.Children) { if (obj._modelName == "" || obj._boneName == "") { continue; } MDL0Node model = _models .FirstOrDefault(m => m is MDL0Node && ((ResourceNode)m).Name == obj._modelName) as MDL0Node; MDL0BoneNode bone = model?._linker?.BoneCache? .FirstOrDefault(b => b.Name == obj._boneName); if (bone != null) { obj._linkedBone = bone; } } } } modelEditControl1.ModelPanel.Capture(); ReadSettings(); base.OnShown(e); }
private void ModelChanged(MDL0Node model) { if (model != null && !_targetModels.Contains(model)) { _targetModels.Add(model); } if (_targetModel != null) { _targetModel._isTargetModel = false; } if (model == null) { ModelPanel.RemoveTarget(_targetModel); } if ((_targetModel = model) != null) { ModelPanel.AddTarget(_targetModel); leftPanel.VIS0Indices = _targetModel.VIS0Indices; _targetModel._isTargetModel = true; ResetVertexColors(); } else { models.SelectedIndex = 0; } if (_resetCamera) { ModelPanel.ResetCamera(); SetFrame(0); } else { _resetCamera = true; } leftPanel.Reset(); rightPanel.Reset(); if (TargetModelChanged != null) { TargetModelChanged(this, null); } _updating = true; if (_targetModel != null && !_editingAll) { models.SelectedItem = _targetModel; } _updating = false; if (_targetModel != null) { RenderBones = _targetModel._renderBones; } }
public static void Serialize(MDL0Node model, string outFile) { using (FileStream stream = new FileStream(outFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 0x1000, FileOptions.SequentialScan)) using (XmlWriter writer = XmlWriter.Create(stream, _writerSettings)) { writer.WriteStartDocument(); writer.WriteStartElement("COLLADA", "http://www.collada.org/2008/03/COLLADASchema"); writer.WriteAttributeString("version", "1.4.0"); writer.WriteStartElement("asset"); writer.WriteElementString("up_axis", "Y_UP"); writer.WriteEndElement(); //Define images WriteImages(model, Path.GetDirectoryName(outFile), writer); //Define materials WriteMaterials(model, writer); //Define effects WriteEffects(model, writer); //Define geometry //Create a geometry object for each polygon WriteGeometry(model, writer); //Define controllers //Each weighted polygon needs a controller, which assigns weights to each vertex. WriteControllers(model, writer); //Define scenes writer.WriteStartElement("library_visual_scenes"); writer.WriteStartElement("visual_scene"); //Attach nodes/bones to scene, starting with TopN //Specify transform for each node //Weighted polygons must use instance_controller //Standard geometry uses instance_geometry writer.WriteAttributeString("id", "VisualSceneNode"); //Define bones and geometry instances WriteNodes(model, writer); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteStartElement("scene"); writer.WriteStartElement("instance_visual_scene"); writer.WriteAttributeString("url", "#VisualSceneNode"); writer.WriteEndElement(); writer.WriteEndElement(); writer.Close(); } }
private void RecalcBoundingBoxes() { MDL0Node model = _resource as MDL0Node; if (model != null) { model.CalculateBoundingBoxes(); } }
public void RemoveTarget(MDL0Node model) { if (_targetModels.Contains(model)) { _targetModels.Remove(model); } modelPanel.RemoveTarget(model); }
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { MDL0Node model = (context.Instance as MDL0EntryNode).Model; return(new StandardValuesCollection(model != null && model._furVecList != null ? model._furVecList.Select(n => n.ToString()).ToList() : null)); }
public void SetObjectIndex(int index) { _uvSetIndices.Clear(); if ((_objIndex = _objNames.Count == 1 ? 0 : index >= 0 ? index.Clamp(0, _objNames.Count - 2) : -1) >= 0) { if (_targetMatRef.Material.Objects.Length != 0) { foreach (MDL0UVNode uv in _targetMatRef.Material.Objects[_objIndex]._uvSet) { if (uv != null) { _uvSetIndices.Add(uv.Index); } } } } else { foreach (MDL0ObjectNode obj in _targetMatRef.Material.Objects) { foreach (MDL0UVNode uv in obj._uvSet) { if (uv != null) { _uvSetIndices.Add(uv.Index); } } } } if (_targetMatRef != null) { MDL0Node model = _targetMatRef.Model; string name = null; if (_uvSetNames.Count > 0 && _uvIndex >= 0 && _uvIndex < _uvSetNames.Count) { name = _uvSetNames[_uvIndex]; } _uvSetNames.Clear(); _uvSetNames.Add(_uvSetIndices.Count == 1 ? model._uvList[_uvSetIndices[0]].Name : "All"); if (model != null && model._uvList != null && _uvSetIndices.Count != 1) { foreach (int i in _uvSetIndices) { _uvSetNames.Add(model._uvList[i].Name); } } SetUVIndex(String.IsNullOrEmpty(name) ? _uvSetNames.IndexOf(name) : -1); } if (ObjIndexChanged != null) { ObjIndexChanged(this, EventArgs.Empty); } }
public void NewModel() { MDL0Node node = ((BRRESNode)_resource).CreateResource <MDL0Node>("NewModel"); BaseWrapper res = this.FindResource(node, true); res = res.FindResource(node, false); res.EnsureVisible(); res.TreeView.SelectedNode = res; }
private void MergeChildren(MDL0BoneNode parent, MDL0BoneNode child, ResourceNode res) { bool found = false; MDL0BoneNode bone = null; foreach (MDL0BoneNode b1 in parent.Children) { if (b1.Name == child.Name) { found = true; bone = b1; foreach (MDL0BoneNode b in child.Children) { MergeChildren(b1, b, res); } break; } } if (!found) { MDL0BoneNode b = child.Clone(); parent.InsertChild(b, true, child.Index); bone = b; } else { found = false; } if (res is MDL0ObjectNode) { MDL0ObjectNode poly = res as MDL0ObjectNode; foreach (Vertex3 v in poly._manager._vertices) { if (v.MatrixNode == child) { v.MatrixNode = bone; } } } else if (res is MDL0Node) { MDL0Node mdl = res as MDL0Node; foreach (MDL0ObjectNode poly in mdl.FindChild("Objects", true).Children) { foreach (Vertex3 v in poly._manager._vertices) { if (v.MatrixNode == child) { v.MatrixNode = bone; } } } } }
private void UpdateModel(MDL0Node model) { int frame = CurrentFrame; if (_chr0 != null && !(TargetAnimType != AnimType.CHR && !playCHR0ToolStripMenuItem.Checked)) { model.ApplyCHR(_chr0, frame); } else { model.ApplyCHR(null, 0); } if (_srt0 != null && !(TargetAnimType != AnimType.SRT && !playSRT0ToolStripMenuItem.Checked)) { model.ApplySRT(_srt0, frame); } else { model.ApplySRT(null, 0); } if (_shp0 != null && !(TargetAnimType != AnimType.SHP && !playSHP0ToolStripMenuItem.Checked)) { model.ApplySHP(_shp0, frame); } else { model.ApplySHP(null, 0); } if (_pat0 != null && !(TargetAnimType != AnimType.PAT && !playPAT0ToolStripMenuItem.Checked)) { model.ApplyPAT(_pat0, frame); } else { model.ApplyPAT(null, 0); } if (_vis0 != null && !(TargetAnimType != AnimType.VIS && !playVIS0ToolStripMenuItem.Checked)) { if (model == TargetModel) { ReadVIS0(); } else { model.ApplyVIS(_vis0, frame); } } if (_clr0 != null && !(TargetAnimType != AnimType.CLR && !playCLR0ToolStripMenuItem.Checked)) { model.ApplyCLR(_clr0, frame); } else { model.ApplyCLR(null, 0); } }
private void TextureChanged(ResourceDefinition <TextureReference> tex) { MDL0Node model = Model; if (model != null) { //model.AttachTexture(tex.Text, (tex as TextureDefinition).Texture); MainForm.ActiveForm.Invalidate(true); } }
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { MDL0Node model = (context.Instance as MoveDefEntryNode).Model; if (model != null) { return(new StandardValuesCollection(model._linker.BoneCache)); } return(null); }
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { MDL0Node model = (context.Instance as MovesetEntryNode).Model; if (model != null) { return(new StandardValuesCollection(model._linker.BoneCache.Select(n => n.ToString()).ToList())); } return(null); }
public void AddTarget(MDL0Node model) { if (!_targetModels.Contains(model)) { _targetModels.Add(model); } modelPanel.AddTarget(model); model.ApplyCHR(null, 0); model._renderBones = true; }
private void MergeChildren(MDL0BoneNode main, MDL0BoneNode ext, ResourceNode res) { bool found = false; if (res is MDL0PolygonNode) { MDL0PolygonNode poly = res as MDL0PolygonNode; foreach (Vertex3 v in poly._manager._vertices) { if (v._influence == ext) { v._influence = main; main.ReferenceCount++; } } } else if (res is MDL0Node) { MDL0Node mdl = res as MDL0Node; foreach (MDL0PolygonNode poly in mdl.FindChild("Objects", true).Children) { foreach (Vertex3 v in poly._manager._vertices) { if (v._influence == ext) { v._influence = main; main.ReferenceCount++; } } } } foreach (MDL0BoneNode b2 in ext.Children) { foreach (MDL0BoneNode b1 in main.Children) { if (b1.Name == b2.Name) { found = true; MergeChildren(b1, b2, res); break; } } if (!found) { if (b2.ReferenceCount > 0) { main.InsertChild(b2, true, b2.Index); } } else { found = false; } } }
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { MDL0Node model = (context.Instance as DrawCall)._parentObject.Model; List <ResourceNode> mats = new List <ResourceNode>(); foreach (MDL0MaterialNode n in model._matList) { mats.Add(n); } return(new StandardValuesCollection(mats.Select(n => n.ToString()).ToList())); }