public TextureListObject(UInt32 imageHeaderOffset, TextureNode node) { name = "Texture " + (DatFile.textureList.Items.Count + 1) + " (" + imageHeaderOffset.ToString("x8") + ")"; this.node = node; imageHeader = node.imageHeader; paletteHeader = node.paletteHeader; imageBitmap = TPL.ConvertFromTextureMelee(imageHeader, paletteHeader, out imageSize); }
/// <summary> /// Creates a <see cref="Bitmap"/> of this texture /// </summary> /// <returns></returns> public Bitmap ToBitmap() { if (ImageData != null && Tlut != null) { return(TPL.ConvertFromTextureMelee(ImageData.Data, ImageData.Width, ImageData.Height, (int)ImageData.Format, Tlut.Data, Tlut.ColorCount, (int)Tlut.Format)); } if (ImageData != null) { return(TPL.ConvertFromTextureMelee(ImageData.Data, ImageData.Width, ImageData.Height, (int)ImageData.Format, null, 0, 0)); } return(null); }
private void ParseDOBJs(IHSDNode node, HSD_JOBJ parent, List <HSD_JOBJ> BoneList) { if (node is HSD_JOBJ jobj) { if (jobj.DOBJ != null) { foreach (var child in jobj.DOBJ.List) { ParseDOBJs(child, jobj, BoneList); } } foreach (var child in jobj.Children) { ParseDOBJs(child, child, BoneList); } } if (node is HSD_DOBJ dobj) { Console.WriteLine("DOBJ found"); GenericMesh mesh = new GenericMesh(); mesh.Name = "Mesh_" + outModel.Meshes.Count; GenericMaterial mat = new GenericMaterial(); mesh.MaterialName = "material_" + outModel.MaterialBank.Count; outModel.MaterialBank.Add(mesh.MaterialName, mat); var Xscale = 1; var Yscale = 1; if (dobj.MOBJ != null) { if (dobj.MOBJ.Textures != null) { var tobj = dobj.MOBJ.Textures; mat.SWrap = GXTranslator.toWrapMode(tobj.WrapS); mat.TWrap = GXTranslator.toWrapMode(tobj.WrapT); Xscale = tobj.WScale; Yscale = tobj.HScale; if (!tobjToIndex.ContainsKey(tobj.ImageData.Data)) { Bitmap B = null; if (tobj.ImageData != null) { if (tobj.Tlut != null) { B = TPL.ConvertFromTextureMelee(tobj.ImageData.Data, tobj.ImageData.Width, tobj.ImageData.Height, (int)tobj.ImageData.Format, tobj.Tlut.Data, tobj.Tlut.ColorCount, (int)tobj.Tlut.Format); } else { B = TPL.ConvertFromTextureMelee(tobj.ImageData.Data, tobj.ImageData.Width, tobj.ImageData.Height, (int)tobj.ImageData.Format, null, 0, 0); } } GenericTexture t = new GenericTexture(); t.FromBitmap(B); B.Dispose(); tobjToIndex.Add(tobj.ImageData.Data, outModel.TextureBank.Count); outModel.TextureBank.Add("texture_" + outModel.TextureBank.Count, t); } mat.TextureDiffuse = outModel.TextureBank.Keys.ToArray()[tobjToIndex[tobj.ImageData.Data]]; } } outModel.Meshes.Add(mesh); if (dobj.POBJ != null) { foreach (HSD_POBJ pobj in dobj.POBJ.List) { // Decode the Display List Data GXDisplayList DisplayList = new GXDisplayList(pobj.DisplayListBuffer, pobj.VertexAttributes); var Vertices = ToGenericVertex(VertexAccessor.GetDecodedVertices(pobj), BoneList, pobj.BindGroups != null ? new List <HSD_JOBJWeight>(pobj.BindGroups.Elements) : null, parent); int bufferOffset = 0; foreach (GXPrimitiveGroup g in DisplayList.Primitives) { var primitiveType = GXTranslator.toPrimitiveType(g.PrimitiveType); var strip = new List <GenericVertex>(); for (int i = bufferOffset; i < bufferOffset + g.Count; i++) { strip.Add(Vertices[i]); } bufferOffset += g.Count; switch (primitiveType) { case OpenTK.Graphics.OpenGL.PrimitiveType.TriangleStrip: Tools.TriangleConverter.StripToList(strip, out strip); break; case OpenTK.Graphics.OpenGL.PrimitiveType.Quads: Tools.TriangleConverter.QuadToList(strip, out strip); break; case OpenTK.Graphics.OpenGL.PrimitiveType.Triangles: break; default: Debug.WriteLine("Error converting primitive type " + primitiveType); break; } mesh.Vertices.AddRange(strip); } } } for (int i = 0; i < mesh.Vertices.Count; i++) { var vert = mesh.Vertices[i]; vert.UV0 = new Vector2(vert.UV0.X * Xscale, vert.UV0.Y * Yscale); mesh.Vertices[i] = vert; } mesh.Optimize(); Tools.TriangleConverter.ReverseFaces(mesh.Triangles, out mesh.Triangles); } }