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); }
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 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); }
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 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 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 void NewMaterial() { if (_modelViewerOpen) { return; } MDL0Node model = ((MDL0Node)_resource); if (model._matGroup == null) { MDL0GroupNode g = model._matGroup; if (g == null) { model.AddChild(g = new MDL0GroupNode(MDLResourceType.Materials), true); model._matGroup = g; model._matList = g.Children; } } MDL0MaterialNode mat = new MDL0MaterialNode(); model._matGroup.AddChild(mat); mat.Name = "Material" + mat.Index; mat.New = true; 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.Count == 0) { NewShader(); } mat.ShaderNode = (MDL0ShaderNode)model._shadList[0]; mat.AddChild(new MDL0MaterialRefNode() { Name = "MatRef0" }); mat.Rebuild(true); BaseWrapper b = FindResource(mat, true); if (b != null) { b.EnsureVisible(); } }
public void NameUV() { MDL0Node model = (MDL0Node) _resource; MDL0GroupNode g = model._uvGroup; int i = 0; if (g != null) { foreach (MDL0UVNode v in g.Children) { v.Name = "#" + i++; } } }
public void NameObject() { MDL0Node model = (MDL0Node) _resource; MDL0GroupNode g = model._objGroup; int i = 0; if (g != null) { foreach (MDL0ObjectNode o in g.Children) { o.Name = "polygon" + i++; } } }
public void NameMaterial() { MDL0Node model = (MDL0Node) _resource; MDL0GroupNode g = model._matGroup; int i = 0; if (g != null) { foreach (MDL0MaterialNode m in g.Children) { m.Name = "Material_" + i++; } } }
public MDL0MaterialNode NewMaterial() { MDL0Node model = (MDL0Node)_resource; if (model._matGroup == null) { MDL0GroupNode g = model._matGroup; if (g == null) { model.AddChild(g = new MDL0GroupNode(MDLResourceType.Materials), true); model._matGroup = g; model._matList = g.Children; } } MDL0MaterialNode mat = new MDL0MaterialNode(); model._matGroup.AddChild(mat); mat.Name = "Material" + mat.Index; 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.Count == 0) { NewShader(); } mat.ShaderNode = (MDL0ShaderNode)model._shadList[0]; MDL0MaterialRefNode mr = new MDL0MaterialRefNode(); mat.AddChild(mr); mr.Name = "MatRef0"; mat.Rebuild(true); BaseWrapper b = FindResource(mat, true); b?.EnsureVisible(); return(mat); }
private void CreateNode() { MDL0GroupNode group = _resource as MDL0GroupNode; MDL0Node model = group.Parent as MDL0Node; switch (group._type.ToString("g")) { case "Bones": MDL0BoneNode bone = new MDL0BoneNode { Name = "NewBone" }; model._boneGroup.InsertChild(bone, false, 0); bone._boneFlags = (BoneFlags)284; bone.Scale = new Vector3(1, 1, 1); bone._bindMatrix = Matrix.Identity; bone._inverseBindMatrix = Matrix.Identity; bone.OnMoved(); break; } }
public void Write(ref byte *pGroup, ref byte *pData, bool force) { MDL0GroupNode group; ResourceGroup *pGrp; ResourceEntry *pEntry; int len; fixed(ResourceGroup **pOut = &Defs) foreach (MDLResourceType resType in OrderBank) { if (((group = Groups[(int)resType]) == null) || (TypeBank[(int)resType] == null)) { continue; } pOut[(int)resType] = pGrp = (ResourceGroup *)pGroup; pEntry = &pGrp->_first + 1; if (resType == MDLResourceType.Bones) { *pGrp = new ResourceGroup(BoneCache.Length); foreach (ResourceNode e in BoneCache) { (pEntry++)->_dataOffset = (int)(pData - pGroup); len = e._calcSize; e.Rebuild(pData, len, true); pData += len; } } else if (resType == MDLResourceType.Shaders) { MDL0GroupNode mats = Groups[(int)MDLResourceType.Materials]; MDL0Material *mHeader; *pGrp = new ResourceGroup(mats._children.Count); //Write data without headers foreach (ResourceNode e in group._children) { len = e._calcSize; e.Rebuild(pData, len, force); pData += len; } //Write one header for each material, using same order. foreach (MDL0MaterialNode mat in mats._children) { mHeader = mat.Header; len = (int)mat._shader.Header; mHeader->_shaderOffset = len - (int)mHeader; (pEntry++)->_dataOffset = len - (int)pGrp; } } else { *pGrp = new ResourceGroup(group._children.Count); foreach (ResourceNode e in group._children) { (pEntry++)->_dataOffset = (int)(pData - pGroup); len = e._calcSize; e.Rebuild(pData, len, force); pData += len; } } pGroup += pGrp->_totalSize; } }
public void Write(Collada form, ref byte *pGroup, ref byte *pData, bool force) { MDL0GroupNode group; ResourceGroup *pGrp; ResourceEntry *pEntry; int len; //Write data in the order it appears foreach (MDLResourceType resType in OrderBank) { if (((group = Groups[(int)resType]) == null) || SpecialRebuildData((int)resType)) { continue; } if (resType == MDLResourceType.Bones) { if (form != null) { form.Say("Writing Bones"); } MDL0Bone *pBone = (MDL0Bone *)pData; foreach (MDL0BoneNode e in BoneCache) { len = e._calcSize; e.Rebuild(pData, len, true); pData += len; } //Loop through after all bones are written //and set header offsets to related bones foreach (MDL0BoneNode e in BoneCache) { e.CalculateOffsets(); } } else if (resType == MDLResourceType.Shaders) { MDL0GroupNode mats = Groups[(int)MDLResourceType.Materials]; MDL0Material *mHeader; if (form != null) { form.Say("Writing Shaders"); } //Write data without headers foreach (ResourceNode e in group.Children) { if (((MDL0ShaderNode)e)._materials.Count > 0) { len = e._calcSize; e.Rebuild(pData, len, force); pData += len; } } //Write one header for each material, using same order. if (mats != null) { foreach (MDL0MaterialNode mat in mats.Children) { mHeader = mat.Header; if (mat._shader != null) { len = (int)mat._shader.Header; mHeader->_shaderOffset = len - (int)mHeader; } else { mHeader->_shaderOffset = 0; } } } } else if (resType == MDLResourceType.Objects || resType == MDLResourceType.Materials) { foreach (ResourceNode r in group.Children) { if (form != null) { form.Say("Writing " + resType.ToString() + " - " + r.Name); } len = r._calcSize; r.Rebuild(pData, len, true); //Forced to fix object node ids and align materials pData += len; } } else { bool rebuild = true; if (Model._isImport) { if (group._name == "Vertices" || group._name == "Normals" || group._name == "UVs" || group._name == "Colors") { rebuild = false; //The data has already been written! } } if (rebuild) { foreach (ResourceNode e in group.Children) { //Console.WriteLine("Rebuilding the " + group.Name); if (form != null) { form.Say("Writing the " + resType.ToString() + " - " + e.Name); } len = e._calcSize; e.Rebuild(pData, len, true); //Forced just in case we need to convert to float. pData += len; } } } } //Write relocation offsets in the order of the header fixed(ResourceGroup **pOut = &Defs) foreach (MDLResourceType resType in IndexBank[Version]) { if (((group = Groups[(int)resType]) == null) || SpecialRebuildData((int)resType)) { continue; } pOut[(int)resType] = pGrp = (ResourceGroup *)pGroup; pEntry = &pGrp->_first + 1; if (resType == MDLResourceType.Bones) { *pGrp = new ResourceGroup(BoneCache.Length); foreach (ResourceNode e in BoneCache) { (pEntry++)->_dataOffset = (int)((byte *)(e.WorkingUncompressed.Address) - pGroup); } } else if (resType == MDLResourceType.Shaders) { MDL0GroupNode mats = Groups[(int)MDLResourceType.Materials]; if (mats != null) { //Create a material group with the amount of entries *pGrp = new ResourceGroup(mats.Children.Count); foreach (MDL0MaterialNode mat in mats.Children) { (pEntry++)->_dataOffset = (int)mat._shader.Header - (int)pGrp; } } } else { *pGrp = new ResourceGroup(group.Children.Count); foreach (ResourceNode e in group.Children) { (pEntry++)->_dataOffset = (int)((byte *)(e.WorkingUncompressed.Address) - pGroup); } } pGroup += pGrp->_totalSize; } }
//Materials must already be written. Do this last! private static void WriteTextures(ModelLinker linker, ref byte *pGroup) { MDL0GroupNode texGrp = linker.Groups[(int)MDLResourceType.Textures]; MDL0GroupNode palGrp = linker.Groups[(int)MDLResourceType.Palettes]; if (texGrp == null) { return; } ResourceGroup *pTexGroup = null; ResourceEntry *pTexEntry = null; if (linker._texCount > 0) { linker.Textures = pTexGroup = (ResourceGroup *)pGroup; *pTexGroup = new ResourceGroup(linker._texCount); pTexEntry = &pTexGroup->_first + 1; pGroup += pTexGroup->_totalSize; } ResourceGroup *pDecGroup = null; ResourceEntry *pDecEntry = null; if (linker._palCount > 0) { linker.Palettes = pDecGroup = (ResourceGroup *)pGroup; *pDecGroup = new ResourceGroup(linker._palCount); pDecEntry = &pDecGroup->_first + 1; pGroup += pDecGroup->_totalSize; } bint *pData = (bint *)pGroup; int offset; //Textures if (pTexGroup != null) { foreach (MDL0TextureNode t in texGrp._children) { if (t._references.Count > 0) { offset = (int)pData; (pTexEntry++)->_dataOffset = offset - (int)pTexGroup; *pData++ = t._references.Count; foreach (MDL0MaterialRefNode mat in t._references) { *pData++ = (int)mat.Material.WorkingUncompressed.Address - offset; *pData++ = (int)mat.WorkingUncompressed.Address - offset; } } } } //Palettes if (pDecGroup != null) { foreach (MDL0TextureNode t in palGrp._children) { if (t._references.Count > 0) { offset = (int)pData; (pDecEntry++)->_dataOffset = offset - (int)pDecGroup; *pData++ = t._references.Count; foreach (MDL0MaterialRefNode mat in t._references) { *pData++ = (int)mat.Material.WorkingUncompressed.Address - offset; *pData++ = (int)mat.WorkingUncompressed.Address - offset; } } } } }