diff --git a/3DS/3DS.csproj b/3DS/3DS.csproj
index 13d2b2f..de5bf80 100644
--- a/3DS/3DS.csproj
+++ b/3DS/3DS.csproj
@@ -106,12 +106,6 @@
CFNTViewer.cs
-
- Form
-
-
- CGFXViewer.cs
-
Form
@@ -136,6 +130,18 @@
DARCViewer.cs
+
+ Form
+
+
+ CGFXViewer.cs
+
+
+ UserControl
+
+
+ CMDLViewer.cs
+
Form
@@ -166,6 +172,12 @@
ThemeViewer.cs
+
+ UserControl
+
+
+ TXOBViewer.cs
+
@@ -185,9 +197,6 @@
CFNTViewer.cs
-
- CGFXViewer.cs
-
CLIMViewer.cs
@@ -200,6 +209,12 @@
DARCViewer.cs
+
+ CGFXViewer.cs
+
+
+ CMDLViewer.cs
+
SAHTViewer.cs
@@ -215,9 +230,23 @@
ThemeViewer.cs
+
+ TXOBViewer.cs
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/3DS/NintendoWare/GFX/CGFX.cs b/3DS/NintendoWare/GFX/CGFX.cs
index d0fe49a..595c225 100644
--- a/3DS/NintendoWare/GFX/CGFX.cs
+++ b/3DS/NintendoWare/GFX/CGFX.cs
@@ -14,7 +14,7 @@ using LibEveryFileExplorer.Collections;
namespace _3DS.NintendoWare.GFX
{
- public class CGFX : FileFormat, IConvertable, IViewable, IWriteable
+ public class CGFX : FileFormat, IViewable, IWriteable
{
public CGFX(byte[] Data)
{
@@ -35,56 +35,6 @@ namespace _3DS.NintendoWare.GFX
return new UI.CGFXViewer(this);
}
- public string GetConversionFileFilters()
- {
- return "COLLADA DAE File (*.dae)|*.dae|Wavefront OBJ File (*.obj)|*.obj";
- }
-
- public bool Convert(int FilterIndex, String Path)
- {
- switch (FilterIndex)
- {
- case 0:
- {
- DAE o = ToDAE(0);
- File.Create(Path).Close();
- File.WriteAllBytes(Path, o.Write());
- Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Path) + "\\Tex");
- foreach (var v in Data.Textures)
- {
- if (!(v is ImageTextureCtr)) continue;
- ((ImageTextureCtr)v).GetBitmap().Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
- }
- return true;
- }
- case 1:
- {
- if (Data.Models.Length == 0) return false;
- OBJ o = ToOBJ(0);
- o.MTLPath = System.IO.Path.GetFileNameWithoutExtension(Path) + ".mtl";
- MTL m = ToMTL(0);
- byte[] d = o.Write();
- byte[] d2 = m.Write();
- File.Create(Path).Close();
- File.WriteAllBytes(Path, d);
- File.Create(System.IO.Path.ChangeExtension(Path, "mtl")).Close();
- File.WriteAllBytes(System.IO.Path.ChangeExtension(Path, "mtl"), d2);
- Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Path) + "\\Tex");
- foreach (var v in Data.Textures)
- {
- //if (v.NrLevels > 2) v.GetBitmap(2).Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
- //else if (v.NrLevels > 1) v.GetBitmap(1).Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
- //else v.GetBitmap(0).Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
- if (!(v is ImageTextureCtr)) continue;
- ((ImageTextureCtr)v).GetBitmap().Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
- }
- return true;
- }
- default:
- return false;
- }
- }
-
public string GetSaveDefaultFileFilter()
{
return "CTR Graphics Resource (*.bcres)|*.bcres";
@@ -326,331 +276,6 @@ namespace _3DS.NintendoWare.GFX
public CANM[] VisibilityAnimations;
}
- public OBJ ToOBJ(int Model)
- {
- if (Data.Models.Length == 0 || Data.Models.Length <= Model) return null;
- var o = new OBJ();
- int v = 0;
- int vn = 0;
- int vt = 0;
- //int vc = 0;
- int ff = 0;
- var m = Data.Models[Model];
- //foreach (CMDL m in Models)
- {
- foreach (var vv in m.Shapes)
- {
- Polygon p = vv.GetVertexData(m);
- var mat = m.Materials[m.Meshes[ff].MaterialIndex];
-
- int TexCoord = -1;
- if (mat.NrActiveTextureCoordiators > 0 && mat.TextureCoordiators[0].MappingMethod == 0)// && mat.TextureCoordiators[0].SourceCoordinate == 0)
- {
- if (mat.TextureCoordiators[0].SourceCoordinate == 0) TexCoord = 0;
- else if (mat.TextureCoordiators[0].SourceCoordinate == 1) TexCoord = 1;
- else TexCoord = 2;
- }
-
- foreach (var q in vv.PrimitiveSets[0].Primitives[0].IndexStreams)
- {
- Vector3[] defs = q.GetFaceData();
- foreach (Vector3 d in defs)
- {
- OBJ.OBJFace f = new OBJ.OBJFace();
- f.Material = mat.Name;
- o.Vertices.Add(p.Vertex[(int)d.X]);
- o.Vertices.Add(p.Vertex[(int)d.Y]);
- o.Vertices.Add(p.Vertex[(int)d.Z]);
- f.VertexIndieces.Add(v);
- f.VertexIndieces.Add(v + 1);
- f.VertexIndieces.Add(v + 2);
- v += 3;
- if (p.Normals != null)
- {
- o.Normals.Add(p.Normals[(int)d.X]);
- o.Normals.Add(p.Normals[(int)d.Y]);
- o.Normals.Add(p.Normals[(int)d.Z]);
- f.NormalIndieces.Add(vn);
- f.NormalIndieces.Add(vn + 1);
- f.NormalIndieces.Add(vn + 2);
- vn += 3;
- }
- if (TexCoord == 0)
- {
- o.TexCoords.Add(p.TexCoords[(int)d.X] * new Matrix34(mat.TextureCoordiators[0].Matrix));
- o.TexCoords.Add(p.TexCoords[(int)d.Y] * new Matrix34(mat.TextureCoordiators[0].Matrix));
- o.TexCoords.Add(p.TexCoords[(int)d.Z] * new Matrix34(mat.TextureCoordiators[0].Matrix));
- }
- else if (TexCoord == 1)
- {
- o.TexCoords.Add(p.TexCoords2[(int)d.X] * new Matrix34(mat.TextureCoordiators[0].Matrix));
- o.TexCoords.Add(p.TexCoords2[(int)d.Y] * new Matrix34(mat.TextureCoordiators[0].Matrix));
- o.TexCoords.Add(p.TexCoords2[(int)d.Z] * new Matrix34(mat.TextureCoordiators[0].Matrix));
- }
- else if (TexCoord == 2)
- {
- o.TexCoords.Add(p.TexCoords3[(int)d.X] * new Matrix34(mat.TextureCoordiators[0].Matrix));
- o.TexCoords.Add(p.TexCoords3[(int)d.Y] * new Matrix34(mat.TextureCoordiators[0].Matrix));
- o.TexCoords.Add(p.TexCoords3[(int)d.Z] * new Matrix34(mat.TextureCoordiators[0].Matrix));
- }
- else goto cont;
- f.TexCoordIndieces.Add(vt);
- f.TexCoordIndieces.Add(vt + 1);
- f.TexCoordIndieces.Add(vt + 2);
- vt += 3;
- cont:
- /*if (p.Colors != null)
- {
- o.VertexColors.Add(p.Colors[(int)d.X]);
- o.VertexColors.Add(p.Colors[(int)d.Y]);
- o.VertexColors.Add(p.Colors[(int)d.Z]);
- f.VertexColorIndieces.Add(vc);
- f.VertexColorIndieces.Add(vc + 1);
- f.VertexColorIndieces.Add(vc + 2);
- vc += 3;
- }*/
- o.Faces.Add(f);
- }
- }
- ff++;
- }
- }
- return o;
- }
-
- public DAE ToDAE(int Model)
- {
- if (Data.Models.Length == 0 || Data.Models.Length <= Model) return null;
- var m = Data.Models[Model];
- var o = new DAE();
- o.Content.scene = new DAE.COLLADA._scene();
- o.Content.scene.instance_visual_scene = new DAE.InstanceWithExtra();
- o.Content.scene.instance_visual_scene.url = "#ID1";
- o.Content.library_visual_scenes = new DAE.library_visual_scenes();
- var scene = new DAE.visual_scene("ID1");
- var rootnode = new DAE.node(m.Name);
- scene.node.Add(rootnode);
- o.Content.library_visual_scenes.visual_scene.Add(scene);
- o.Content.library_geometries = new DAE.library_geometries();
- o.Content.library_materials = new DAE.library_materials();
- o.Content.library_effects = new DAE.library_effects();
- if (Data.Textures != null && Data.Textures.Length > 0) o.Content.library_images = new DAE.library_images();
- int id = 2;
- int i = 0;
- foreach (var matt in m.Materials)
- {
- var mat2 = new DAE.material();
- mat2.id = "ID" + id++;
- mat2.name = matt.Name;
- var eff = new DAE.effect();
- eff.id = "ID" + id++;
- mat2.instance_effect = new DAE.instance_effect();
- mat2.instance_effect.url = "#" + eff.id;
- eff.profile_COMMON = new DAE.profile_COMMON();
- eff.profile_COMMON.technique = new DAE.profile_COMMON._technique();
- eff.profile_COMMON.technique.sid = "COMMON";
- eff.profile_COMMON.technique.lambert = new DAE.profile_COMMON._technique._lambert();
- eff.profile_COMMON.technique.lambert.diffuse = new DAE.common_color_or_texture_type();
- if (matt.Tex0 != null && matt.Tex0.TextureObject is ReferenceTexture)
- {
- string texid = "ID" + id++;
- o.Content.library_images.image.Add(new DAE.image() { id = texid, init_from = "Tex/" + ((ReferenceTexture)matt.Tex0.TextureObject).LinkedTextureName + ".png" });
-
- var param1 = new DAE.common_newparam_type() { sid = "ID" + id++, choice = new DAE.fx_surface_common() { type = DAE.fx_surface_type_enum._2D } };
- ((DAE.fx_surface_common)param1.choice).init_from.Add(new DAE.fx_surface_init_from_common() { content = texid });
- eff.profile_COMMON.newparam = new List();
- eff.profile_COMMON.newparam.Add(param1);
- eff.profile_COMMON.newparam.Add(new DAE.common_newparam_type() { sid = "ID" + id++, choice = new DAE.fx_sampler2D_common() { source = param1.sid } });
- eff.profile_COMMON.technique.lambert.diffuse.texture = new DAE.common_color_or_texture_type._texture() { texture = eff.profile_COMMON.newparam[1].sid, texcoord = "UVSET0" };
- }
- else
- {
- eff.profile_COMMON.technique.lambert.diffuse.color = new DAE.common_color_or_texture_type._color();
- eff.profile_COMMON.technique.lambert.diffuse.color.content = Color.White;
- }
- o.Content.library_materials.material.Add(mat2);
- o.Content.library_effects.effect.Add(eff);
- }
-
- int ff = 0;
- //foreach (CMDL m in Models)
- {
- foreach (var vv in m.Shapes)
- {
- var geometry = new DAE.geometry();
- geometry.id = "ID" + id++;
-
- Polygon p = vv.GetVertexData(m);
- var mat = m.Materials[m.Meshes[ff].MaterialIndex];
-
- geometry.mesh = new DAE.mesh();
- geometry.mesh.vertices = new DAE.vertices() { id = "ID" + id++ };
- if (p.Vertex != null)
- {
- var src = new DAE.source() { id = "ID" + id++ };
- src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)p.Vertex.Length * 3 };
- foreach (var v in p.Vertex)
- {
- src.float_array.content.Add(v.X);
- src.float_array.content.Add(v.Y);
- src.float_array.content.Add(v.Z);
- }
- src.technique_common = new DAE.source._technique_common();
- src.technique_common.accessor = new DAE.accessor();
- src.technique_common.accessor.count = (uint)p.Vertex.Length;
- src.technique_common.accessor.source = "#" + src.float_array.id;
- src.technique_common.accessor.stride = 3;
- src.technique_common.accessor.param.Add(new DAE.param() { name = "X", type = "float" });
- src.technique_common.accessor.param.Add(new DAE.param() { name = "Y", type = "float" });
- src.technique_common.accessor.param.Add(new DAE.param() { name = "Z", type = "float" });
- geometry.mesh.source.Add(src);
- geometry.mesh.vertices.input.Add(new DAE.InputLocal() { semantic = "POSITION", source = "#" + src.id });
- }
- if (p.Normals != null)
- {
- var src = new DAE.source() { id = "ID" + id++ };
- src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)p.Normals.Length * 3 };
- foreach (var v in p.Normals)
- {
- src.float_array.content.Add(v.X);
- src.float_array.content.Add(v.Y);
- src.float_array.content.Add(v.Z);
- }
- src.technique_common = new DAE.source._technique_common();
- src.technique_common.accessor = new DAE.accessor();
- src.technique_common.accessor.count = (uint)p.Normals.Length;
- src.technique_common.accessor.source = "#" + src.float_array.id;
- src.technique_common.accessor.stride = 3;
- src.technique_common.accessor.param.Add(new DAE.param() { name = "X", type = "float" });
- src.technique_common.accessor.param.Add(new DAE.param() { name = "Y", type = "float" });
- src.technique_common.accessor.param.Add(new DAE.param() { name = "Z", type = "float" });
- geometry.mesh.source.Add(src);
- geometry.mesh.vertices.input.Add(new DAE.InputLocal() { semantic = "NORMAL", source = "#" + src.id });
- }
- DAE.source texcoordsrc = null;
- if (p.TexCoords != null)
- {
- if (mat.NrActiveTextureCoordiators > 0 && mat.TextureCoordiators[0].MappingMethod == 0)
- {
- Vector2[] texc;
- if (mat.TextureCoordiators[0].SourceCoordinate == 0)
- {
- texc = p.TexCoords.ToArray();
- }
- else if (mat.TextureCoordiators[0].SourceCoordinate == 1)
- {
- texc = p.TexCoords2.ToArray();
- }
- else
- {
- texc = p.TexCoords3.ToArray();
- }
-
- var src = texcoordsrc = new DAE.source() { id = "ID" + id++ };
- src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)texc.Length * 2 };
- foreach (var v in texc)
- {
- Vector2 result = v * new Matrix34(mat.TextureCoordiators[0].Matrix);
- src.float_array.content.Add(result.X);
- src.float_array.content.Add(result.Y);
- }
- src.technique_common = new DAE.source._technique_common();
- src.technique_common.accessor = new DAE.accessor();
- src.technique_common.accessor.count = (uint)p.TexCoords.Length;
- src.technique_common.accessor.source = "#" + src.float_array.id;
- src.technique_common.accessor.stride = 2;
- src.technique_common.accessor.param.Add(new DAE.param() { name = "S", type = "float" });
- src.technique_common.accessor.param.Add(new DAE.param() { name = "T", type = "float" });
- geometry.mesh.source.Add(src);
- }
- }
- DAE.source colorsrc = null;
- if (p.Colors != null)
- {
- var src = colorsrc = new DAE.source() { id = "ID" + id++ };
- src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)p.Colors.Length * 4 };
- foreach (var v in p.Colors)
- {
- src.float_array.content.Add(v.R / 255f);
- src.float_array.content.Add(v.G / 255f);
- src.float_array.content.Add(v.B / 255f);
- src.float_array.content.Add(v.A / 255f);
- }
- src.technique_common = new DAE.source._technique_common();
- src.technique_common.accessor = new DAE.accessor();
- src.technique_common.accessor.count = (uint)p.Colors.Length;
- src.technique_common.accessor.source = "#" + src.float_array.id;
- src.technique_common.accessor.stride = 4;
- src.technique_common.accessor.param.Add(new DAE.param() { name = "R", type = "float" });
- src.technique_common.accessor.param.Add(new DAE.param() { name = "G", type = "float" });
- src.technique_common.accessor.param.Add(new DAE.param() { name = "B", type = "float" });
- src.technique_common.accessor.param.Add(new DAE.param() { name = "A", type = "float" });
- geometry.mesh.source.Add(src);
- }
-
- foreach (var q in vv.PrimitiveSets[0].Primitives[0].IndexStreams)
- {
- Vector3[] defs = q.GetFaceData();
-
- var tri = new DAE.triangles() { count = (uint)defs.Length, material = mat.Name };
- uint offs = 0;
- tri.input.Add(new DAE.InputLocalOffset() { offset = offs++, semantic = "VERTEX", source = "#" + geometry.mesh.vertices.id });
- if (texcoordsrc != null) tri.input.Add(new DAE.InputLocalOffset() { offset = offs++, semantic = "TEXCOORD", source = "#" + texcoordsrc.id });
- if (colorsrc != null) tri.input.Add(new DAE.InputLocalOffset() { offset = offs++, semantic = "COLOR", source = "#" + colorsrc.id, set = 0 });
- tri.p.Add(new DAE.p());
- foreach (Vector3 d in defs)
- {
- tri.p[0].content.Add((ulong)d.X);
- if (texcoordsrc != null) tri.p[0].content.Add((ulong)d.X);
- if (colorsrc != null) tri.p[0].content.Add((ulong)d.X);
- tri.p[0].content.Add((ulong)d.Y);
- if (texcoordsrc != null) tri.p[0].content.Add((ulong)d.Y);
- if (colorsrc != null) tri.p[0].content.Add((ulong)d.Y);
- tri.p[0].content.Add((ulong)d.Z);
- if (texcoordsrc != null) tri.p[0].content.Add((ulong)d.Z);
- if (colorsrc != null) tri.p[0].content.Add((ulong)d.Z);
- }
- geometry.mesh.triangles.Add(tri);
- }
- o.Content.library_geometries.geometry.Add(geometry);
- var instgem = new DAE.instance_geometry() { url = "#" + geometry.id };
- instgem.bind_material = new DAE.bind_material();
- instgem.bind_material.technique_common = new DAE.bind_material._technique_common();
- var instmat = new DAE.instance_material();
- instmat.symbol = mat.Name;
- instmat.target = "#" + o.Content.library_materials.material[(int)m.Meshes[ff].MaterialIndex].id;
- instmat.bind_vertex_input.Add(new DAE.instance_material._bind_vertex_input() { semantic = "UVSET0", input_semantic = "TEXCOORD", input_set = 0 });
- instgem.bind_material.technique_common.instance_material.Add(instmat);
- rootnode.instance_geometry.Add(instgem);
- ff++;
- }
- }
- return o;
- }
-
- public MTL ToMTL(int Model)
- {
- if (Data.Models.Length == 0 || Data.Models.Length <= Model) return null;
- var o = new MTL();
- var m = Data.Models[Model];
- //foreach (CMDL m in Models)
- {
- foreach (var vv in m.Materials)
- {
- MTL.MTLMaterial mm = new MTL.MTLMaterial(vv.Name);
- mm.DiffuseColor = vv.MaterialColor.DiffuseU32;
- mm.AmbientColor = vv.MaterialColor.AmbientU32;
- mm.Alpha = vv.MaterialColor.Diffuse.W;
- mm.SpecularColor = vv.MaterialColor.Specular0U32;
- if (vv.Tex0 != null && vv.Tex0.TextureObject is ReferenceTexture/* && vv.TextureCoordiators[0].SourceCoordinate == 0*/) mm.DiffuseMapPath = "Tex/" + ((ReferenceTexture)vv.Tex0.TextureObject).LinkedTextureName + ".png";
- //else if (vv.Tex1 != null && vv.Tex1.TextureObject is ReferenceTexture && vv.TextureCoordiators[1].SourceCoordinate == 0) mm.DiffuseMapPath = "Tex/" + ((ReferenceTexture)vv.Tex1.TextureObject).LinkedTextureName + ".png";
- //else if (vv.Tex2 != null && vv.Tex2.TextureObject is ReferenceTexture && vv.TextureCoordiators[2].SourceCoordinate == 0) mm.DiffuseMapPath = "Tex/" + ((ReferenceTexture)vv.Tex2.TextureObject).LinkedTextureName + ".png";
- o.Materials.Add(mm);
- }
- }
- return o;
- }
-
public class CGFXIdentifier : FileFormatIdentifier
{
public override string GetCategory()
diff --git a/3DS/NintendoWare/GFX/CMDL.cs b/3DS/NintendoWare/GFX/CMDL.cs
index 3dd4e6d..02ac6a8 100644
--- a/3DS/NintendoWare/GFX/CMDL.cs
+++ b/3DS/NintendoWare/GFX/CMDL.cs
@@ -9,6 +9,7 @@ using Tao.OpenGl;
using LibEveryFileExplorer.IO;
using LibEveryFileExplorer._3D;
using LibEveryFileExplorer.Collections;
+using CommonFiles;
namespace _3DS.NintendoWare.GFX
{
@@ -3332,6 +3333,328 @@ namespace _3DS.NintendoWare.GFX
}
}
+ public OBJ ToOBJ()
+ {
+ var o = new OBJ();
+ int v = 0;
+ int vn = 0;
+ int vt = 0;
+ //int vc = 0;
+ int ff = 0;
+ var m = this;
+ //foreach (CMDL m in Models)
+ {
+ foreach (var vv in m.Shapes)
+ {
+ Polygon p = vv.GetVertexData(m);
+ var mat = m.Materials[m.Meshes[ff].MaterialIndex];
+
+ int TexCoord = -1;
+ if (mat.NrActiveTextureCoordiators > 0 && mat.TextureCoordiators[0].MappingMethod == 0)// && mat.TextureCoordiators[0].SourceCoordinate == 0)
+ {
+ if (mat.TextureCoordiators[0].SourceCoordinate == 0) TexCoord = 0;
+ else if (mat.TextureCoordiators[0].SourceCoordinate == 1) TexCoord = 1;
+ else TexCoord = 2;
+ }
+
+ foreach (var q in vv.PrimitiveSets[0].Primitives[0].IndexStreams)
+ {
+ Vector3[] defs = q.GetFaceData();
+ foreach (Vector3 d in defs)
+ {
+ OBJ.OBJFace f = new OBJ.OBJFace();
+ f.Material = mat.Name;
+ o.Vertices.Add(p.Vertex[(int)d.X]);
+ o.Vertices.Add(p.Vertex[(int)d.Y]);
+ o.Vertices.Add(p.Vertex[(int)d.Z]);
+ f.VertexIndieces.Add(v);
+ f.VertexIndieces.Add(v + 1);
+ f.VertexIndieces.Add(v + 2);
+ v += 3;
+ if (p.Normals != null)
+ {
+ o.Normals.Add(p.Normals[(int)d.X]);
+ o.Normals.Add(p.Normals[(int)d.Y]);
+ o.Normals.Add(p.Normals[(int)d.Z]);
+ f.NormalIndieces.Add(vn);
+ f.NormalIndieces.Add(vn + 1);
+ f.NormalIndieces.Add(vn + 2);
+ vn += 3;
+ }
+ if (TexCoord == 0)
+ {
+ o.TexCoords.Add(p.TexCoords[(int)d.X] * new Matrix34(mat.TextureCoordiators[0].Matrix));
+ o.TexCoords.Add(p.TexCoords[(int)d.Y] * new Matrix34(mat.TextureCoordiators[0].Matrix));
+ o.TexCoords.Add(p.TexCoords[(int)d.Z] * new Matrix34(mat.TextureCoordiators[0].Matrix));
+ }
+ else if (TexCoord == 1)
+ {
+ o.TexCoords.Add(p.TexCoords2[(int)d.X] * new Matrix34(mat.TextureCoordiators[0].Matrix));
+ o.TexCoords.Add(p.TexCoords2[(int)d.Y] * new Matrix34(mat.TextureCoordiators[0].Matrix));
+ o.TexCoords.Add(p.TexCoords2[(int)d.Z] * new Matrix34(mat.TextureCoordiators[0].Matrix));
+ }
+ else if (TexCoord == 2)
+ {
+ o.TexCoords.Add(p.TexCoords3[(int)d.X] * new Matrix34(mat.TextureCoordiators[0].Matrix));
+ o.TexCoords.Add(p.TexCoords3[(int)d.Y] * new Matrix34(mat.TextureCoordiators[0].Matrix));
+ o.TexCoords.Add(p.TexCoords3[(int)d.Z] * new Matrix34(mat.TextureCoordiators[0].Matrix));
+ }
+ else goto cont;
+ f.TexCoordIndieces.Add(vt);
+ f.TexCoordIndieces.Add(vt + 1);
+ f.TexCoordIndieces.Add(vt + 2);
+ vt += 3;
+ cont:
+ /*if (p.Colors != null)
+ {
+ o.VertexColors.Add(p.Colors[(int)d.X]);
+ o.VertexColors.Add(p.Colors[(int)d.Y]);
+ o.VertexColors.Add(p.Colors[(int)d.Z]);
+ f.VertexColorIndieces.Add(vc);
+ f.VertexColorIndieces.Add(vc + 1);
+ f.VertexColorIndieces.Add(vc + 2);
+ vc += 3;
+ }*/
+ o.Faces.Add(f);
+ }
+ }
+ ff++;
+ }
+ }
+ return o;
+ }
+
+ public DAE ToDAE(CGFX Resource)
+ {
+ var m = this;
+ var o = new DAE();
+ o.Content.scene = new DAE.COLLADA._scene();
+ o.Content.scene.instance_visual_scene = new DAE.InstanceWithExtra();
+ o.Content.scene.instance_visual_scene.url = "#ID1";
+ o.Content.library_visual_scenes = new DAE.library_visual_scenes();
+ var scene = new DAE.visual_scene("ID1");
+ var rootnode = new DAE.node(m.Name);
+ scene.node.Add(rootnode);
+ o.Content.library_visual_scenes.visual_scene.Add(scene);
+ o.Content.library_geometries = new DAE.library_geometries();
+ o.Content.library_materials = new DAE.library_materials();
+ o.Content.library_effects = new DAE.library_effects();
+ if (Resource.Data.Textures != null && Resource.Data.Textures.Length > 0) o.Content.library_images = new DAE.library_images();
+ int id = 2;
+ int i = 0;
+ foreach (var matt in m.Materials)
+ {
+ var mat2 = new DAE.material();
+ mat2.id = "ID" + id++;
+ mat2.name = matt.Name;
+ var eff = new DAE.effect();
+ eff.id = "ID" + id++;
+ mat2.instance_effect = new DAE.instance_effect();
+ mat2.instance_effect.url = "#" + eff.id;
+ eff.profile_COMMON = new DAE.profile_COMMON();
+ eff.profile_COMMON.technique = new DAE.profile_COMMON._technique();
+ eff.profile_COMMON.technique.sid = "COMMON";
+ eff.profile_COMMON.technique.lambert = new DAE.profile_COMMON._technique._lambert();
+ eff.profile_COMMON.technique.lambert.diffuse = new DAE.common_color_or_texture_type();
+ if (matt.Tex0 != null && matt.Tex0.TextureObject is ReferenceTexture)
+ {
+ string texid = "ID" + id++;
+ o.Content.library_images.image.Add(new DAE.image() { id = texid, init_from = "Tex/" + ((ReferenceTexture)matt.Tex0.TextureObject).LinkedTextureName + ".png" });
+
+ var param1 = new DAE.common_newparam_type() { sid = "ID" + id++, choice = new DAE.fx_surface_common() { type = DAE.fx_surface_type_enum._2D } };
+ ((DAE.fx_surface_common)param1.choice).init_from.Add(new DAE.fx_surface_init_from_common() { content = texid });
+ eff.profile_COMMON.newparam = new List();
+ eff.profile_COMMON.newparam.Add(param1);
+ eff.profile_COMMON.newparam.Add(new DAE.common_newparam_type() { sid = "ID" + id++, choice = new DAE.fx_sampler2D_common() { source = param1.sid } });
+ eff.profile_COMMON.technique.lambert.diffuse.texture = new DAE.common_color_or_texture_type._texture() { texture = eff.profile_COMMON.newparam[1].sid, texcoord = "UVSET0" };
+ }
+ else
+ {
+ eff.profile_COMMON.technique.lambert.diffuse.color = new DAE.common_color_or_texture_type._color();
+ eff.profile_COMMON.technique.lambert.diffuse.color.content = Color.White;
+ }
+ o.Content.library_materials.material.Add(mat2);
+ o.Content.library_effects.effect.Add(eff);
+ }
+
+ int ff = 0;
+ //foreach (CMDL m in Models)
+ {
+ foreach (var vv in m.Shapes)
+ {
+ var geometry = new DAE.geometry();
+ geometry.id = "ID" + id++;
+
+ Polygon p = vv.GetVertexData(m);
+ var mat = m.Materials[m.Meshes[ff].MaterialIndex];
+
+ geometry.mesh = new DAE.mesh();
+ geometry.mesh.vertices = new DAE.vertices() { id = "ID" + id++ };
+ if (p.Vertex != null)
+ {
+ var src = new DAE.source() { id = "ID" + id++ };
+ src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)p.Vertex.Length * 3 };
+ foreach (var v in p.Vertex)
+ {
+ src.float_array.content.Add(v.X);
+ src.float_array.content.Add(v.Y);
+ src.float_array.content.Add(v.Z);
+ }
+ src.technique_common = new DAE.source._technique_common();
+ src.technique_common.accessor = new DAE.accessor();
+ src.technique_common.accessor.count = (uint)p.Vertex.Length;
+ src.technique_common.accessor.source = "#" + src.float_array.id;
+ src.technique_common.accessor.stride = 3;
+ src.technique_common.accessor.param.Add(new DAE.param() { name = "X", type = "float" });
+ src.technique_common.accessor.param.Add(new DAE.param() { name = "Y", type = "float" });
+ src.technique_common.accessor.param.Add(new DAE.param() { name = "Z", type = "float" });
+ geometry.mesh.source.Add(src);
+ geometry.mesh.vertices.input.Add(new DAE.InputLocal() { semantic = "POSITION", source = "#" + src.id });
+ }
+ if (p.Normals != null)
+ {
+ var src = new DAE.source() { id = "ID" + id++ };
+ src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)p.Normals.Length * 3 };
+ foreach (var v in p.Normals)
+ {
+ src.float_array.content.Add(v.X);
+ src.float_array.content.Add(v.Y);
+ src.float_array.content.Add(v.Z);
+ }
+ src.technique_common = new DAE.source._technique_common();
+ src.technique_common.accessor = new DAE.accessor();
+ src.technique_common.accessor.count = (uint)p.Normals.Length;
+ src.technique_common.accessor.source = "#" + src.float_array.id;
+ src.technique_common.accessor.stride = 3;
+ src.technique_common.accessor.param.Add(new DAE.param() { name = "X", type = "float" });
+ src.technique_common.accessor.param.Add(new DAE.param() { name = "Y", type = "float" });
+ src.technique_common.accessor.param.Add(new DAE.param() { name = "Z", type = "float" });
+ geometry.mesh.source.Add(src);
+ geometry.mesh.vertices.input.Add(new DAE.InputLocal() { semantic = "NORMAL", source = "#" + src.id });
+ }
+ DAE.source texcoordsrc = null;
+ if (p.TexCoords != null)
+ {
+ if (mat.NrActiveTextureCoordiators > 0 && mat.TextureCoordiators[0].MappingMethod == 0)
+ {
+ Vector2[] texc;
+ if (mat.TextureCoordiators[0].SourceCoordinate == 0)
+ {
+ texc = p.TexCoords.ToArray();
+ }
+ else if (mat.TextureCoordiators[0].SourceCoordinate == 1)
+ {
+ texc = p.TexCoords2.ToArray();
+ }
+ else
+ {
+ texc = p.TexCoords3.ToArray();
+ }
+
+ var src = texcoordsrc = new DAE.source() { id = "ID" + id++ };
+ src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)texc.Length * 2 };
+ foreach (var v in texc)
+ {
+ Vector2 result = v * new Matrix34(mat.TextureCoordiators[0].Matrix);
+ src.float_array.content.Add(result.X);
+ src.float_array.content.Add(result.Y);
+ }
+ src.technique_common = new DAE.source._technique_common();
+ src.technique_common.accessor = new DAE.accessor();
+ src.technique_common.accessor.count = (uint)p.TexCoords.Length;
+ src.technique_common.accessor.source = "#" + src.float_array.id;
+ src.technique_common.accessor.stride = 2;
+ src.technique_common.accessor.param.Add(new DAE.param() { name = "S", type = "float" });
+ src.technique_common.accessor.param.Add(new DAE.param() { name = "T", type = "float" });
+ geometry.mesh.source.Add(src);
+ }
+ }
+ DAE.source colorsrc = null;
+ if (p.Colors != null)
+ {
+ var src = colorsrc = new DAE.source() { id = "ID" + id++ };
+ src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)p.Colors.Length * 4 };
+ foreach (var v in p.Colors)
+ {
+ src.float_array.content.Add(v.R / 255f);
+ src.float_array.content.Add(v.G / 255f);
+ src.float_array.content.Add(v.B / 255f);
+ src.float_array.content.Add(v.A / 255f);
+ }
+ src.technique_common = new DAE.source._technique_common();
+ src.technique_common.accessor = new DAE.accessor();
+ src.technique_common.accessor.count = (uint)p.Colors.Length;
+ src.technique_common.accessor.source = "#" + src.float_array.id;
+ src.technique_common.accessor.stride = 4;
+ src.technique_common.accessor.param.Add(new DAE.param() { name = "R", type = "float" });
+ src.technique_common.accessor.param.Add(new DAE.param() { name = "G", type = "float" });
+ src.technique_common.accessor.param.Add(new DAE.param() { name = "B", type = "float" });
+ src.technique_common.accessor.param.Add(new DAE.param() { name = "A", type = "float" });
+ geometry.mesh.source.Add(src);
+ }
+
+ foreach (var q in vv.PrimitiveSets[0].Primitives[0].IndexStreams)
+ {
+ Vector3[] defs = q.GetFaceData();
+
+ var tri = new DAE.triangles() { count = (uint)defs.Length, material = mat.Name };
+ uint offs = 0;
+ tri.input.Add(new DAE.InputLocalOffset() { offset = offs++, semantic = "VERTEX", source = "#" + geometry.mesh.vertices.id });
+ if (texcoordsrc != null) tri.input.Add(new DAE.InputLocalOffset() { offset = offs++, semantic = "TEXCOORD", source = "#" + texcoordsrc.id });
+ if (colorsrc != null) tri.input.Add(new DAE.InputLocalOffset() { offset = offs++, semantic = "COLOR", source = "#" + colorsrc.id, set = 0 });
+ tri.p.Add(new DAE.p());
+ foreach (Vector3 d in defs)
+ {
+ tri.p[0].content.Add((ulong)d.X);
+ if (texcoordsrc != null) tri.p[0].content.Add((ulong)d.X);
+ if (colorsrc != null) tri.p[0].content.Add((ulong)d.X);
+ tri.p[0].content.Add((ulong)d.Y);
+ if (texcoordsrc != null) tri.p[0].content.Add((ulong)d.Y);
+ if (colorsrc != null) tri.p[0].content.Add((ulong)d.Y);
+ tri.p[0].content.Add((ulong)d.Z);
+ if (texcoordsrc != null) tri.p[0].content.Add((ulong)d.Z);
+ if (colorsrc != null) tri.p[0].content.Add((ulong)d.Z);
+ }
+ geometry.mesh.triangles.Add(tri);
+ }
+ o.Content.library_geometries.geometry.Add(geometry);
+ var instgem = new DAE.instance_geometry() { url = "#" + geometry.id };
+ instgem.bind_material = new DAE.bind_material();
+ instgem.bind_material.technique_common = new DAE.bind_material._technique_common();
+ var instmat = new DAE.instance_material();
+ instmat.symbol = mat.Name;
+ instmat.target = "#" + o.Content.library_materials.material[(int)m.Meshes[ff].MaterialIndex].id;
+ instmat.bind_vertex_input.Add(new DAE.instance_material._bind_vertex_input() { semantic = "UVSET0", input_semantic = "TEXCOORD", input_set = 0 });
+ instgem.bind_material.technique_common.instance_material.Add(instmat);
+ rootnode.instance_geometry.Add(instgem);
+ ff++;
+ }
+ }
+ return o;
+ }
+
+ public MTL ToMTL()
+ {
+ var o = new MTL();
+ var m = this;//Data.Models[Model];
+ //foreach (CMDL m in Models)
+ {
+ foreach (var vv in m.Materials)
+ {
+ MTL.MTLMaterial mm = new MTL.MTLMaterial(vv.Name);
+ mm.DiffuseColor = vv.MaterialColor.DiffuseU32;
+ mm.AmbientColor = vv.MaterialColor.AmbientU32;
+ mm.Alpha = vv.MaterialColor.Diffuse.W;
+ mm.SpecularColor = vv.MaterialColor.Specular0U32;
+ if (vv.Tex0 != null && vv.Tex0.TextureObject is ReferenceTexture/* && vv.TextureCoordiators[0].SourceCoordinate == 0*/) mm.DiffuseMapPath = "Tex/" + ((ReferenceTexture)vv.Tex0.TextureObject).LinkedTextureName + ".png";
+ //else if (vv.Tex1 != null && vv.Tex1.TextureObject is ReferenceTexture && vv.TextureCoordiators[1].SourceCoordinate == 0) mm.DiffuseMapPath = "Tex/" + ((ReferenceTexture)vv.Tex1.TextureObject).LinkedTextureName + ".png";
+ //else if (vv.Tex2 != null && vv.Tex2.TextureObject is ReferenceTexture && vv.TextureCoordiators[2].SourceCoordinate == 0) mm.DiffuseMapPath = "Tex/" + ((ReferenceTexture)vv.Tex2.TextureObject).LinkedTextureName + ".png";
+ o.Materials.Add(mm);
+ }
+ }
+ return o;
+ }
+
public override string ToString()
{
return Name;
diff --git a/3DS/NintendoWare/GFX/TXOB.cs b/3DS/NintendoWare/GFX/TXOB.cs
index 1b4e52c..f74b4c9 100644
--- a/3DS/NintendoWare/GFX/TXOB.cs
+++ b/3DS/NintendoWare/GFX/TXOB.cs
@@ -9,98 +9,6 @@ using _3DS.GPU;
namespace _3DS.NintendoWare.GFX
{
- /*public class TXOB
- {
- public TXOB() { }
- public TXOB(EndianBinaryReader er)
- {
- Flags = er.ReadUInt32();
- Signature = er.ReadString(Encoding.ASCII, 4);
- if (Signature != "TXOB") throw new SignatureNotCorrectException(Signature, "TXOB", er.BaseStream.Position);
- Unknown1 = er.ReadUInt32();
- NameOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
- Unknown2 = er.ReadUInt32();
- Unknown3 = er.ReadUInt32();
- Height = er.ReadUInt32();
- Width = er.ReadUInt32();
- GlFormat = er.ReadUInt32();
- Type = er.ReadUInt32();
- NrLevels = er.ReadUInt32();
- Unknown7 = er.ReadUInt32();
- Unknown8 = er.ReadUInt32();
- Format = (GPU.Textures.ImageFormat)er.ReadUInt32();
- Unknown9 = er.ReadUInt32();
- Height2 = er.ReadUInt32();
- Width2 = er.ReadUInt32();
- DataSize = er.ReadUInt32();
- DataOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
- Unknown10 = er.ReadUInt32();
- BitsPerPixel = er.ReadUInt32();
- Unknown12 = er.ReadUInt32();
-
- long curpos = er.BaseStream.Position;
- er.BaseStream.Position = NameOffset;
- Name = er.ReadStringNT(Encoding.ASCII);
- er.BaseStream.Position = DataOffset;
- Data = er.ReadBytes((int)DataSize);
- er.BaseStream.Position = curpos;
- }
- public UInt32 Flags;//?
- public String Signature;
- public UInt32 Unknown1;
- public UInt32 NameOffset;
- public UInt32 Unknown2;
- public UInt32 Unknown3;
- public UInt32 Height;
- public UInt32 Width;
- public UInt32 GlFormat;
- public UInt32 Type;
- public UInt32 NrLevels;
- public UInt32 Unknown7;
- public UInt32 Unknown8;
- public GPU.Textures.ImageFormat Format;
- public UInt32 Unknown9;
- public UInt32 Height2;
- public UInt32 Width2;
- public UInt32 DataSize;
- public UInt32 DataOffset;
- public UInt32 Unknown10;
- public UInt32 BitsPerPixel;
- public UInt32 Unknown12;
-
- public String Name;
- public byte[] Data;
-
- //The flags are like this:
- //Image Texture = 0x20000011 (this structure)
- //Cube Texture = 0x20000009
- //Reference Texture = 0x20000004
- //Procedural Texture = 0x20000002
- //Shadow Texture = 0x20000021
-
- public Bitmap GetBitmap(int Level = 0)
- {
- int l = Level;
- uint w = Width;
- uint h = Height;
- int bpp = GPU.Textures.GetBpp(Format);
- int offset = 0;
- while (l > 0)
- {
- offset += (int)(w * h * bpp / 8);
- w /= 2;
- h /= 2;
- l--;
- }
- return GPU.Textures.ToBitmap(Data, offset, (int)w, (int)h, Format);
- }
-
- public override string ToString()
- {
- return Name;
- }
- }*/
-
public class TXOB
{
public TXOB(EndianBinaryReader er)
diff --git a/3DS/Resource.Designer.cs b/3DS/Resource.Designer.cs
index 541b2b0..242fd0f 100644
--- a/3DS/Resource.Designer.cs
+++ b/3DS/Resource.Designer.cs
@@ -116,6 +116,26 @@ namespace _3DS {
}
}
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap film {
+ get {
+ object obj = ResourceManager.GetObject("film", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap films {
+ get {
+ object obj = ResourceManager.GetObject("films", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
///
/// Looks up a localized resource of type System.Drawing.Bitmap.
///
@@ -146,6 +166,26 @@ namespace _3DS {
}
}
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap images_stack {
+ get {
+ object obj = ResourceManager.GetObject("images_stack", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap jar {
+ get {
+ object obj = ResourceManager.GetObject("jar", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
///
/// Looks up a localized resource of type System.Drawing.Bitmap.
///
@@ -156,6 +196,36 @@ namespace _3DS {
}
}
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap light_bulb {
+ get {
+ object obj = ResourceManager.GetObject("light_bulb", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap lighthouse_shine {
+ get {
+ object obj = ResourceManager.GetObject("lighthouse_shine", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap point {
+ get {
+ object obj = ResourceManager.GetObject("point", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
///
/// Looks up a localized resource of type System.Drawing.Bitmap.
///
@@ -186,6 +256,46 @@ namespace _3DS {
}
}
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap table {
+ get {
+ object obj = ResourceManager.GetObject("table", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap tables_stacks {
+ get {
+ object obj = ResourceManager.GetObject("tables_stacks", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap weather_cloud {
+ get {
+ object obj = ResourceManager.GetObject("weather_cloud", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap weather_clouds {
+ get {
+ object obj = ResourceManager.GetObject("weather_clouds", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
///
/// Looks up a localized resource of type System.Drawing.Bitmap.
///
diff --git a/3DS/Resource.resx b/3DS/Resource.resx
index 6e674be..581a625 100644
--- a/3DS/Resource.resx
+++ b/3DS/Resource.resx
@@ -133,12 +133,21 @@
Resources\image16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+ Resources\images-stack.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
Resources\image-sunset.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+ Resources\jar.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
Resources\leaf.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+ Resources\point.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
Resources\preview_background.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
@@ -157,4 +166,28 @@
Resources\zones-stack.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+ Resources\films.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ Resources\film.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ Resources\table.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ Resources\tables-stacks.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ Resources\weather-cloud.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ Resources\weather-clouds.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ Resources\light-bulb.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ Resources\lighthouse-shine.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
\ No newline at end of file
diff --git a/3DS/Resources/film.png b/3DS/Resources/film.png
new file mode 100644
index 0000000..c8bd259
Binary files /dev/null and b/3DS/Resources/film.png differ
diff --git a/3DS/Resources/films.png b/3DS/Resources/films.png
new file mode 100644
index 0000000..d1270dd
Binary files /dev/null and b/3DS/Resources/films.png differ
diff --git a/3DS/Resources/images-stack.png b/3DS/Resources/images-stack.png
new file mode 100644
index 0000000..ef098a8
Binary files /dev/null and b/3DS/Resources/images-stack.png differ
diff --git a/3DS/Resources/jar.png b/3DS/Resources/jar.png
new file mode 100644
index 0000000..8711832
Binary files /dev/null and b/3DS/Resources/jar.png differ
diff --git a/3DS/Resources/light-bulb.png b/3DS/Resources/light-bulb.png
new file mode 100644
index 0000000..845e110
Binary files /dev/null and b/3DS/Resources/light-bulb.png differ
diff --git a/3DS/Resources/lighthouse-shine.png b/3DS/Resources/lighthouse-shine.png
new file mode 100644
index 0000000..4e88e4e
Binary files /dev/null and b/3DS/Resources/lighthouse-shine.png differ
diff --git a/3DS/Resources/point.png b/3DS/Resources/point.png
new file mode 100644
index 0000000..1776e06
Binary files /dev/null and b/3DS/Resources/point.png differ
diff --git a/3DS/Resources/table.png b/3DS/Resources/table.png
new file mode 100644
index 0000000..b0cd69f
Binary files /dev/null and b/3DS/Resources/table.png differ
diff --git a/3DS/Resources/tables-stacks.png b/3DS/Resources/tables-stacks.png
new file mode 100644
index 0000000..79c8e80
Binary files /dev/null and b/3DS/Resources/tables-stacks.png differ
diff --git a/3DS/Resources/weather-cloud.png b/3DS/Resources/weather-cloud.png
new file mode 100644
index 0000000..49afdad
Binary files /dev/null and b/3DS/Resources/weather-cloud.png differ
diff --git a/3DS/Resources/weather-clouds.png b/3DS/Resources/weather-clouds.png
new file mode 100644
index 0000000..732c635
Binary files /dev/null and b/3DS/Resources/weather-clouds.png differ
diff --git a/3DS/UI/CGFXViewer.cs b/3DS/UI/CGFXViewer.cs
index 57eca0a..5159243 100644
--- a/3DS/UI/CGFXViewer.cs
+++ b/3DS/UI/CGFXViewer.cs
@@ -9,446 +9,250 @@ using System.Windows.Forms;
using Tao.OpenGl;
using LibEveryFileExplorer._3D;
using System.Drawing.Imaging;
+using LibEveryFileExplorer.Files;
+using LibEveryFileExplorer;
+using System.Runtime.InteropServices;
using _3DS.NintendoWare.GFX;
-using LibEveryFileExplorer.Collections;
namespace _3DS.UI
{
public partial class CGFXViewer : Form
{
- bool init = false;
- CGFX cgfx;
- public CGFXViewer(CGFX cgfx)
+ ImageList ImageL;
+ CMDLViewer ModViewer = null;
+
+ CGFX mod;
+
+ public CGFXViewer(CGFX mod)
{
- this.cgfx = cgfx;
+ this.mod = mod;
InitializeComponent();
- simpleOpenGlControl1.MouseWheel += new MouseEventHandler(simpleOpenGlControl1_MouseWheel);
- }
- void simpleOpenGlControl1_MouseWheel(object sender, MouseEventArgs e)
- {
- if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { dist += ((float)e.Delta / 10); }
- else { dist += ((float)e.Delta / 100); }
- Render();
+ Win32Util.SetWindowTheme(treeView1.Handle, "explorer", null);
+ ImageL = new ImageList();
+ ImageL.ColorDepth = ColorDepth.Depth32Bit;
+ ImageL.ImageSize = new Size(16, 16);
+ ImageL.Images.Add(Resource.jar);
+ ImageL.Images.Add(Resource.point);
+ ImageL.Images.Add(Resource.images_stack);
+ ImageL.Images.Add(Resource.image_sunset);
+ ImageL.Images.Add(Resource.films);
+ ImageL.Images.Add(Resource.film);
+ ImageL.Images.Add(Resource.tables_stacks);
+ ImageL.Images.Add(Resource.table);
+ ImageL.Images.Add(Resource.weather_clouds);
+ ImageL.Images.Add(Resource.weather_cloud);
+ ImageL.Images.Add(Resource.lighthouse_shine);
+ ImageL.Images.Add(Resource.light_bulb);
+ treeView1.ImageList = ImageL;
}
- String glversion = null;
- float X = 0.0f;
- float Y = 0.0f;
- float ang = 0.0f;
- float dist = 0.0f;
- float elev = 0.0f;
private void CGFX_Load(object sender, EventArgs e)
{
- simpleOpenGlControl1.InitializeContexts();
- Gl.ReloadFunctions();
- //Gl.glEnable(Gl.GL_LIGHTING);
- Gl.glEnable(Gl.GL_RESCALE_NORMAL);
- Gl.glEnable(Gl.GL_COLOR_MATERIAL);
- Gl.glEnable(Gl.GL_DEPTH_TEST);
- Gl.glEnable(Gl.GL_NORMALIZE);
- Gl.glDisable(Gl.GL_CULL_FACE);
- Gl.glFrontFace(Gl.GL_CCW);
- Gl.glEnable(Gl.GL_TEXTURE_2D);
- Gl.glClearDepth(1);
- Gl.glEnable(Gl.GL_ALPHA_TEST);
- Gl.glAlphaFunc(Gl.GL_GREATER, 0f);
- Gl.glEnable(Gl.GL_BLEND);
- Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
-
- //Gl.glTexEnvf(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_BLEND);
-
- Gl.glShadeModel(Gl.GL_SMOOTH);
-
- Gl.glDepthFunc(Gl.GL_LEQUAL);
-
-
-
- Gl.glClearColor(51f / 255f, 51f / 255f, 51f / 255f, 0f);
-
- if (cgfx.Data.Textures != null && cgfx.Data.Models != null)
+ bool sel = false;
+ treeView1.BeginUpdate();
+ treeView1.Nodes.Clear();
+ if (mod.Data.Models != null)
{
- int i = 0;
- foreach (var v in cgfx.Data.Models[0].Materials)
+ TreeNode section = new TreeNode("Models", 0, 0);
+ treeView1.Nodes.Add(section);
+ for (int i = 0; i < mod.Data.Models.Length; i++)
{
- if (v.Tex0 != null) UploadTex(v.Tex0, i * 4 + 0 + 1);
- if (v.Tex1 != null) UploadTex(v.Tex1, i * 4 + 1 + 1);
- if (v.Tex2 != null) UploadTex(v.Tex2, i * 4 + 2 + 1);
- //if (v.Tex3 != null) UploadTex(v.Tex3, i * 4 + 3 + 1);
- i++;
- }
- }
- if (cgfx.Data.Models != null) Shaders = new CGFXShader[cgfx.Data.Models[0].Materials.Length];
- //GlNitro.glNitroBindTextures(file, 1);
-
- glversion = Gl.glGetString(Gl.GL_VERSION);
-
- init = true;
- Render();
- }
-
- private void UploadTex(CMDL.MTOB.TexInfo TextureMapper, int Id)
- {
- if (!(TextureMapper.TextureObject is ReferenceTexture))
- return;
- var tex = cgfx.Data.Textures[cgfx.Data.Dictionaries[1].IndexOf(((ReferenceTexture)TextureMapper.TextureObject).LinkedTextureName)] as ImageTextureCtr;
- if (tex == null)
- return;
- Gl.glBindTexture(Gl.GL_TEXTURE_2D, Id);
- Gl.glColor3f(1, 1, 1);
- Bitmap b = tex.GetBitmap();
- b.RotateFlip(RotateFlipType.RotateNoneFlipY);
- BitmapData d = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
- Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, b.Width, b.Height, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, d.Scan0);
- b.UnlockBits(d);
-
- if (((TextureMapper.Unknown12 >> 1) & 1) == 1) Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
- else Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_NEAREST);
- //if (((TextureMapper.Unknown12 >> 2) & 1) == 1) Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
- //else Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_NEAREST);
- //A bit confusing, so using this for now:
- Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
-
- switch ((TextureMapper.Unknown12 >> 12) & 0xF)
- {
- case 0:
- Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE);
- break;
- case 1:
- Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_BORDER);
- break;
- case 2:
- Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
- break;
- case 3:
- Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_MIRRORED_REPEAT);
- break;
- default:
- Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
- break;
- }
-
- switch ((TextureMapper.Unknown12 >> 8) & 0xF)
- {
- case 0:
- Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE);
- break;
- case 1:
- Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_BORDER);
- break;
- case 2:
- Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
- break;
- case 3:
- Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_MIRRORED_REPEAT);
- break;
- default:
- Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
- break;
- }
- }
-
- CGFXShader[] Shaders;
- public void Render()
- {
- if (!init) return;
- if (cgfx.Data.Models == null) return;
- //G3D_Binary_File_Format.Shaders.Shader s = new G3D_Binary_File_Format.Shaders.Shader();
- //s.Compile();
- //s.Enable();
- //Gl.glViewport(0, 0, simpleOpenGlControl1.Width, simpleOpenGlControl1.Height);
- float aspect = (float)simpleOpenGlControl1.Width / (float)simpleOpenGlControl1.Height;
- //float fov = 60.0f; // in degrees
- //float znear = 0.02f;
- //float zfar = 1000.0f * file.modelSet.models[SelMdl].info.posScale;
- //Gl.glMatrixMode(Gl.GL_PROJECTION);
- //Gl.glLoadMatrixf(BuildPerspProjMat(fov, aspect, znear, zfar));
- Gl.glMatrixMode(Gl.GL_PROJECTION);
- Gl.glLoadIdentity();
- Gl.glViewport(0, 0, simpleOpenGlControl1.Width, simpleOpenGlControl1.Height);
- //Gl.glOrtho(-simpleOpenGlControl1.Width / 2.0f, simpleOpenGlControl1.Width / 2.0f, -simpleOpenGlControl1.Height / 2.0f, simpleOpenGlControl1.Height / 2.0f, 0.02f, 1000f * file.modelSet.models[SelMdl].info.posScale);
- //Gl.glMatrixMode(Gl.GL_PROJECTION);
- //Gl.glLoadIdentity();
- //Gl.glFrustum(-simpleOpenGlControl1.Width / 2f, simpleOpenGlControl1.Width / 2f, -simpleOpenGlControl1.Height / 2f, simpleOpenGlControl1.Height / 2f, 1000, -1000);
- Glu.gluPerspective(30, aspect, 0.1f, 20480000f);//0.02f, 32.0f);
-
- Gl.glMatrixMode(Gl.GL_MODELVIEW);
- Gl.glLoadIdentity();
- Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
- Gl.glColor3f(1.0f, 1.0f, 1.0f);
- //Gl.glEnable(Gl.GL_DEPTH_TEST);
- Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
-
- /*Gl.glRotatef(elev, 1, 0, 0);
- Gl.glFogfv(Gl.GL_FOG_COLOR, new float[] { 0, 0, 0, 1 });
- Gl.glFogf(Gl.GL_FOG_DENSITY, 1);
- Gl.glRotatef(-elev, 1, 0, 0);*/
-
- Gl.glTranslatef(X, Y, -dist);
- Gl.glRotatef(elev, 1, 0, 0);
- Gl.glRotatef(ang, 0, 1, 0);
-
- Gl.glPushMatrix();
- RenderModel();
- Gl.glPopMatrix();
- simpleOpenGlControl1.Refresh();
- }
-
- void RenderModel()
- {
- CMDL m = cgfx.Data.Models[0];
- //foreach (_3DS.CGFX.DATA.CMDL m in cgfx.Data.Models)
- //{
- //int i = 0;
- foreach (var mm in m.Meshes)
- {
- var vv = m.Shapes[mm.ShapeIndex];
- Polygon p = vv.GetVertexData(m);
-
- var mat = m.Materials[mm.MaterialIndex];
- mat.FragShader.AlphaTest.GlApply();
- mat.FragmentOperation.BlendOperation.GlApply();
-
- Gl.glMatrixMode(Gl.GL_TEXTURE);
- if (mat.Tex0 != null)
- {
- Gl.glActiveTexture(Gl.GL_TEXTURE0);
- Gl.glBindTexture(Gl.GL_TEXTURE_2D, mm.MaterialIndex * 4 + 0 + 1);
- Gl.glEnable(Gl.GL_TEXTURE_2D);
- Gl.glLoadIdentity();
- float[] mtx = new float[16];
- Array.Copy(mat.TextureCoordiators[0].Matrix, mtx, 4 * 3);
- mtx[15] = 1;
- mtx[12] = mtx[3];
- mtx[13] = mtx[7];
- mtx[14] = mtx[11];
- mtx[3] = 0;
- mtx[7] = 0;
- mtx[11] = 0;
- Gl.glLoadMatrixf(mtx);
- //if (mat.TextureCoordiators[0].MappingMethod == 2)
- //{
- // Gl.glTexGeni(Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
- // Gl.glTexGeni(Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
- //}
- //Gl.glTranslatef(mat.TextureCoordiators[0].Scale.X / mat.TextureCoordiators[0].Translate.X, mat.TextureCoordiators[0].Translate.Y * mat.TextureCoordiators[0].Scale.Y, 0);
- //Gl.glRotatef(mat.TextureCoordiators[0].Rotate, 0, 1, 0);
- //Gl.glScalef(mat.TextureCoordiators[0].Scale.X, mat.TextureCoordiators[0].Scale.Y, 1);
- }
- if (mat.Tex1 != null)
- {
- Gl.glActiveTexture(Gl.GL_TEXTURE1);
- Gl.glBindTexture(Gl.GL_TEXTURE_2D, mm.MaterialIndex * 4 + 1 + 1);
- Gl.glEnable(Gl.GL_TEXTURE_2D);
- Gl.glLoadIdentity();
- float[] mtx = new float[16];
- Array.Copy(mat.TextureCoordiators[1].Matrix, mtx, 4 * 3);
- mtx[15] = 1;
- mtx[12] = mtx[3];
- mtx[13] = mtx[7];
- mtx[14] = mtx[11];
- mtx[3] = 0;
- mtx[7] = 0;
- mtx[11] = 0;
- Gl.glLoadMatrixf(mtx);
- //if (mat.TextureCoordiators[1].MappingMethod == 2)
- //{
- // Gl.glTexGeni(Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
- // Gl.glTexGeni(Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
- //}
- }
- if (mat.Tex2 != null)
- {
- Gl.glActiveTexture(Gl.GL_TEXTURE2);
- Gl.glBindTexture(Gl.GL_TEXTURE_2D, mm.MaterialIndex * 4 + 2 + 1);
- Gl.glEnable(Gl.GL_TEXTURE_2D);
- Gl.glLoadIdentity();
- float[] mtx = new float[16];
- Array.Copy(mat.TextureCoordiators[2].Matrix, mtx, 4 * 3);
- mtx[15] = 1;
- mtx[12] = mtx[3];
- mtx[13] = mtx[7];
- mtx[14] = mtx[11];
- mtx[3] = 0;
- mtx[7] = 0;
- mtx[11] = 0;
- Gl.glLoadMatrixf(mtx);
- //if (mat.TextureCoordiators[2].MappingMethod == 2)
- //{
- // Gl.glTexGeni(Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
- // Gl.glTexGeni(Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
- //}
- }
- /*if (mat.Tex3 != null)
- {
- MessageBox.Show("Tex3!!!!!!!!!!!");
- Gl.glActiveTexture(Gl.GL_TEXTURE3);
- Gl.glBindTexture(Gl.GL_TEXTURE_2D, mm.MaterialIndex * 4 + 3 + 1);
- Gl.glEnable(Gl.GL_TEXTURE_2D);
- Gl.glLoadIdentity();
- }*/
- Gl.glMatrixMode(Gl.GL_MODELVIEW);
- Gl.glPushMatrix();
- Gl.glTranslatef(vv.PositionOffset.X, vv.PositionOffset.Y, vv.PositionOffset.Z);
-
- if (glversion.StartsWith("2.") && Shaders[mm.MaterialIndex] == null)
- {
- List tex = new List();
- if (mat.Tex0 != null) tex.Add((int)mm.MaterialIndex * 4 + 0 + 1);
- else tex.Add(0);
- if (mat.Tex1 != null) tex.Add((int)mm.MaterialIndex * 4 + 1 + 1);
- else tex.Add(0);
- if (mat.Tex2 != null) tex.Add((int)mm.MaterialIndex * 4 + 2 + 1);
- else tex.Add(0);
- //if (mat.Tex3 != null) tex.Add((int)mm.MaterialIndex * 4 + 3 + 1);
- /*else */
- tex.Add(0);
-
- Shaders[mm.MaterialIndex] = new CGFXShader(mat, tex.ToArray());
- Shaders[mm.MaterialIndex].Compile();
- }
- if (glversion.StartsWith("2.")) Shaders[mm.MaterialIndex].Enable();
-
- //Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_EMISSION, new float[] { mat.Emission_2.R / 255f, mat.Emission_2.G / 255f, mat.Emission_2.B / 255f, mat.Emission_2.A / 255f });
- //Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_AMBIENT, new float[] { mat.Ambient_1.R / 255f, mat.Ambient_1.G / 255f, mat.Ambient_1.B / 255f, mat.Ambient_1.A / 255f });
- //Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE, new float[] { mat.Diffuse_2.R / 255f, mat.Diffuse_2.G / 255f, mat.Diffuse_2.B / 255f, mat.Diffuse_2.A / 255f });
- //Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE);
- //Gl.glEnable(Gl.GL_COLOR_MATERIAL);
-
- foreach (var q in vv.PrimitiveSets[0].Primitives[0].IndexStreams)
- {
- Vector3[] defs = q.GetFaceData();
-
- Gl.glBegin(Gl.GL_TRIANGLES);
- foreach (Vector3 d in defs)
+ TreeNode entry = new TreeNode(mod.Data.Models[i].Name, 1, 1) { Tag = mod.Data.Models[i] };
+ section.Nodes.Add(entry);
+ if (i == 0 && !sel)
{
- if (p.Normals != null) Gl.glNormal3f(p.Normals[(int)d.X].X, p.Normals[(int)d.X].Y, p.Normals[(int)d.X].Z);
- if (p.Colors != null) Gl.glColor4f(p.Colors[(int)d.X].R / 255f, p.Colors[(int)d.X].G / 255f, p.Colors[(int)d.X].B / 255f, p.Colors[(int)d.X].A / 255f);
- else Gl.glColor4f(1, 1, 1, 1);
- if (p.TexCoords != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, p.TexCoords[(int)d.X].X, p.TexCoords[(int)d.X].Y);
- if (p.TexCoords2 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE1, p.TexCoords2[(int)d.X].X, p.TexCoords2[(int)d.X].Y);
- if (p.TexCoords3 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE2, p.TexCoords3[(int)d.X].X, p.TexCoords3[(int)d.X].Y);
- Gl.glVertex3f(p.Vertex[(int)d.X].X, p.Vertex[(int)d.X].Y, p.Vertex[(int)d.X].Z);
-
- if (p.Normals != null) Gl.glNormal3f(p.Normals[(int)d.Y].X, p.Normals[(int)d.Y].Y, p.Normals[(int)d.Y].Z);
- if (p.Colors != null) Gl.glColor4f(p.Colors[(int)d.Y].R / 255f, p.Colors[(int)d.Y].G / 255f, p.Colors[(int)d.Y].B / 255f, p.Colors[(int)d.Y].A / 255f);
- else Gl.glColor4f(1, 1, 1, 1);
- if (p.TexCoords != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, p.TexCoords[(int)d.Y].X, p.TexCoords[(int)d.Y].Y);
- if (p.TexCoords2 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE1, p.TexCoords2[(int)d.Y].X, p.TexCoords2[(int)d.Y].Y);
- if (p.TexCoords3 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE2, p.TexCoords3[(int)d.Y].X, p.TexCoords3[(int)d.Y].Y);
- Gl.glVertex3f(p.Vertex[(int)d.Y].X, p.Vertex[(int)d.Y].Y, p.Vertex[(int)d.Y].Z);
-
- if (p.Normals != null) Gl.glNormal3f(p.Normals[(int)d.Z].X, p.Normals[(int)d.Z].Y, p.Normals[(int)d.Z].Z);
- if (p.Colors != null) Gl.glColor4f(p.Colors[(int)d.Z].R / 255f, p.Colors[(int)d.Z].G / 255f, p.Colors[(int)d.Z].B / 255f, p.Colors[(int)d.Z].A / 255f);
- else Gl.glColor4f(1, 1, 1, 1);
- if (p.TexCoords != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, p.TexCoords[(int)d.Z].X, p.TexCoords[(int)d.Z].Y);
- if (p.TexCoords2 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE1, p.TexCoords2[(int)d.Z].X, p.TexCoords2[(int)d.Z].Y);
- if (p.TexCoords3 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE2, p.TexCoords3[(int)d.Z].X, p.TexCoords3[(int)d.Z].Y);
- Gl.glVertex3f(p.Vertex[(int)d.Z].X, p.Vertex[(int)d.Z].Y, p.Vertex[(int)d.Z].Z);
+ section.Expand();
+ treeView1.SelectedNode = entry;
+ sel = true;
}
- Gl.glEnd();
+ //TODO: Content of CMDL
}
- Gl.glPopMatrix();
}
- }
-
- bool wire = false;
- bool licht = true;
- protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
- {
- switch (keyData)
+ if (mod.Data.Textures != null)
{
- case Keys.Right:
- ang += 1;
- Render();
- return true;
- case Keys.Left:
- ang -= 1;
- Render();
- return true;
- case Keys.Up:
- elev += 1;
- Render();
- return true;
- case Keys.Down:
- elev -= 1;
- Render();
- return true;
- case Keys.Z:
- X -= 5f;
- Render();
- return true;
- case Keys.X:
- X += 5f;
- Render();
- return true;
- case Keys.A:
- Y -= 5f;
- Render();
- return true;
- case Keys.S:
- Y += 5f;
- Render();
- return true;
- case Keys.W:
- wire = !wire;
- if (wire) { Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_LINE); Render(); }
- else { Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_FILL); Render(); }
- return true;
- case Keys.Escape:
- X = 0.0f;
- Y = 0.0f;
- ang = 0.0f;
- dist = 0.0f;
- elev = 0.0f;
- Render();
- return true;
- case Keys.T:
- elev = 90;
- ang = 0;
- Render();
- return true;
- case Keys.L:
- licht = !licht;
- Render();
- return true;
- case Keys.OemMinus:
- case Keys.OemMinus | Keys.Shift:
- if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) dist += 12f;
- else dist += 1.2f;
- Render();
- return true;
- case Keys.Oemplus:
- case Keys.Oemplus | Keys.Shift:
- if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) dist -= 12f;
- else dist -= 1.2f;
- Render();
- return true;
- default:
- return base.ProcessCmdKey(ref msg, keyData);
+ TreeNode section = new TreeNode("Textures", 2, 2);
+ treeView1.Nodes.Add(section);
+ for (int i = 0; i < mod.Data.Textures.Length; i++)
+ {
+ TreeNode entry = new TreeNode(mod.Data.Textures[i].Name, 3, 3) { Tag = mod.Data.Textures[i] };
+ section.Nodes.Add(entry);
+ if (i == 0 && !sel)
+ {
+ section.Expand();
+ treeView1.SelectedNode = entry;
+ sel = true;
+ }
+ }
}
+ if (mod.Data.Dictionaries[2] != null)
+ {
+ TreeNode section = new TreeNode("Lookup Tables", 6, 6);
+ treeView1.Nodes.Add(section);
+ for (int i = 0; i < mod.Data.Dictionaries[2].Count; i++)
+ {
+ TreeNode entry = new TreeNode(mod.Data.Dictionaries[2][i].Name, 7, 7);// { Tag = mod.Data.Textures[i] };
+ section.Nodes.Add(entry);
+ }
+ }
+ if (mod.Data.Dictionaries[6] != null)
+ {
+ TreeNode section = new TreeNode("Lights", 10, 10);
+ treeView1.Nodes.Add(section);
+ for (int i = 0; i < mod.Data.Dictionaries[6].Count; i++)
+ {
+ TreeNode entry = new TreeNode(mod.Data.Dictionaries[6][i].Name, 11, 11);// { Tag = mod.Data.Textures[i] };
+ section.Nodes.Add(entry);
+ if (i == 0 && !sel)
+ {
+ section.Expand();
+ treeView1.SelectedNode = entry;
+ sel = true;
+ }
+ }
+ }
+ if (mod.Data.Dictionaries[7] != null)
+ {
+ TreeNode section = new TreeNode("Fog", 8, 8);
+ treeView1.Nodes.Add(section);
+ for (int i = 0; i < mod.Data.Dictionaries[7].Count; i++)
+ {
+ TreeNode entry = new TreeNode(mod.Data.Dictionaries[7][i].Name, 9, 9);// { Tag = mod.Data.Textures[i] };
+ section.Nodes.Add(entry);
+ if (i == 0 && !sel)
+ {
+ section.Expand();
+ treeView1.SelectedNode = entry;
+ sel = true;
+ }
+ }
+ }
+ if (mod.Data.SkeletonAnimations != null)
+ {
+ TreeNode section = new TreeNode("Skeleton Animations", 4, 4);
+ treeView1.Nodes.Add(section);
+ for (int i = 0; i < mod.Data.SkeletonAnimations.Length; i++)
+ {
+ TreeNode entry = new TreeNode(mod.Data.SkeletonAnimations[i].Name, 5, 5) { Tag = mod.Data.SkeletonAnimations[i] };
+ section.Nodes.Add(entry);
+ if (i == 0 && !sel)
+ {
+ section.Expand();
+ treeView1.SelectedNode = entry;
+ sel = true;
+ }
+ }
+ }
+ if (mod.Data.MaterialAnimations != null)
+ {
+ TreeNode section = new TreeNode("Material Animations", 4, 4);
+ treeView1.Nodes.Add(section);
+ for (int i = 0; i < mod.Data.MaterialAnimations.Length; i++)
+ {
+ TreeNode entry = new TreeNode(mod.Data.MaterialAnimations[i].Name, 5, 5) { Tag = mod.Data.MaterialAnimations[i] };
+ section.Nodes.Add(entry);
+ if (i == 0 && !sel)
+ {
+ section.Expand();
+ treeView1.SelectedNode = entry;
+ sel = true;
+ }
+ }
+ }
+ if (mod.Data.VisibilityAnimations != null)
+ {
+ TreeNode section = new TreeNode("Visibility Animations", 4, 4);
+ treeView1.Nodes.Add(section);
+ for (int i = 0; i < mod.Data.VisibilityAnimations.Length; i++)
+ {
+ TreeNode entry = new TreeNode(mod.Data.VisibilityAnimations[i].Name, 5, 5) { Tag = mod.Data.VisibilityAnimations[i] };
+ section.Nodes.Add(entry);
+ if (i == 0 && !sel)
+ {
+ section.Expand();
+ treeView1.SelectedNode = entry;
+ sel = true;
+ }
+ }
+ }
+ treeView1.EndUpdate();
}
private void CGFX_Resize(object sender, EventArgs e)
{
- Render();
- Render();
+ if (ModViewer != null)
+ {
+ ModViewer.Render();
+ ModViewer.Render();
+ }
}
private void CGFX_Layout(object sender, LayoutEventArgs e)
{
- Render();
+ if (ModViewer != null)
+ {
+ ModViewer.Render();
+ }
}
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
- Render();
+ if (ModViewer != null)
+ {
+ ModViewer.Render();
+ }
}
- private void CGFXViewer_Activated(object sender, EventArgs e)
+ private void NSBMDViewer_Activated(object sender, EventArgs e)
{
- for (int i = 0; i < 8; i++) Render();
+ //render it multiple times to avoid glitches!
+ if (ModViewer != null)
+ {
+ for (int i = 0; i < 8; i++) ModViewer.Render();
+ }
}
+ private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
+ {
+ switch (e.Node.ImageIndex)
+ {
+ case 1:
+ ModViewer = new CMDLViewer(mod, (CMDL)e.Node.Tag) { Dock = DockStyle.Fill };
+ ModViewer.Width = panel1.Width;
+ ModViewer.Height = panel1.Height;
+ panel1.SuspendLayout();
+ panel1.Controls.Add(ModViewer);
+ if (panel1.Controls.Count > 1) panel1.Controls.RemoveAt(0);
+ panel1.Invalidate();
+ panel1.ResumeLayout();
+ ModViewer.Invalidate();
+ ModViewer.Render();
+ ModViewer.Render();
+ break;
+ case 3:
+ ModViewer = null;
+ panel1.SuspendLayout();
+ panel1.Controls.Add(new TXOBViewer((ImageTextureCtr)e.Node.Tag) { Dock = DockStyle.Fill, Width = panel1.Width, Height = panel1.Height });
+ if (panel1.Controls.Count > 1) panel1.Controls.RemoveAt(0);
+ panel1.Invalidate();
+ panel1.ResumeLayout();
+ break;
+ default:
+ ModViewer = null;
+ panel1.SuspendLayout();
+ panel1.Controls.Clear();
+ panel1.Invalidate();
+ panel1.ResumeLayout();
+ break;
+ }
+ }
+
+ private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
+ {
+ if (ModViewer != null)
+ {
+ ModViewer.Render();
+ }
+ }
}
}
diff --git a/3DS/UI/CGFXViewer.designer.cs b/3DS/UI/CGFXViewer.designer.cs
index ed3d17d..74dbc64 100644
--- a/3DS/UI/CGFXViewer.designer.cs
+++ b/3DS/UI/CGFXViewer.designer.cs
@@ -28,109 +28,70 @@
///
private void InitializeComponent()
{
- this.simpleOpenGlControl1 = new Tao.Platform.Windows.SimpleOpenGlControl();
- this.tabControl1 = new System.Windows.Forms.TabControl();
- this.tabPage1 = new System.Windows.Forms.TabPage();
- this.tabPage2 = new System.Windows.Forms.TabPage();
+ this.components = new System.ComponentModel.Container();
+ this.mainMenu1 = new LibEveryFileExplorer.UI.MainMenu(this.components);
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.treeView1 = new System.Windows.Forms.TreeView();
- this.tabControl1.SuspendLayout();
- this.tabPage1.SuspendLayout();
- this.tabPage2.SuspendLayout();
+ this.panel1 = new System.Windows.Forms.Panel();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
+ this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
- // simpleOpenGlControl1
- //
- this.simpleOpenGlControl1.AccumBits = ((byte)(0));
- this.simpleOpenGlControl1.AutoCheckErrors = false;
- this.simpleOpenGlControl1.AutoFinish = false;
- this.simpleOpenGlControl1.AutoMakeCurrent = true;
- this.simpleOpenGlControl1.AutoSwapBuffers = true;
- this.simpleOpenGlControl1.BackColor = System.Drawing.Color.Black;
- this.simpleOpenGlControl1.ColorBits = ((byte)(32));
- this.simpleOpenGlControl1.DepthBits = ((byte)(32));
- this.simpleOpenGlControl1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.simpleOpenGlControl1.Location = new System.Drawing.Point(3, 3);
- this.simpleOpenGlControl1.Name = "simpleOpenGlControl1";
- this.simpleOpenGlControl1.Size = new System.Drawing.Size(575, 353);
- this.simpleOpenGlControl1.StencilBits = ((byte)(8));
- this.simpleOpenGlControl1.TabIndex = 0;
- //
- // tabControl1
- //
- this.tabControl1.Controls.Add(this.tabPage1);
- this.tabControl1.Controls.Add(this.tabPage2);
- this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.tabControl1.Location = new System.Drawing.Point(0, 0);
- this.tabControl1.Name = "tabControl1";
- this.tabControl1.SelectedIndex = 0;
- this.tabControl1.Size = new System.Drawing.Size(589, 385);
- this.tabControl1.TabIndex = 1;
- this.tabControl1.Selecting += new System.Windows.Forms.TabControlCancelEventHandler(this.tabControl1_Selecting);
- //
- // tabPage1
- //
- this.tabPage1.Controls.Add(this.simpleOpenGlControl1);
- this.tabPage1.Location = new System.Drawing.Point(4, 22);
- this.tabPage1.Name = "tabPage1";
- this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
- this.tabPage1.Size = new System.Drawing.Size(581, 359);
- this.tabPage1.TabIndex = 0;
- this.tabPage1.Text = "Render";
- this.tabPage1.UseVisualStyleBackColor = true;
- this.tabPage1.Layout += new System.Windows.Forms.LayoutEventHandler(this.CGFX_Layout);
- //
- // tabPage2
- //
- this.tabPage2.Controls.Add(this.splitContainer1);
- this.tabPage2.Location = new System.Drawing.Point(4, 22);
- this.tabPage2.Name = "tabPage2";
- this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
- this.tabPage2.Size = new System.Drawing.Size(581, 359);
- this.tabPage2.TabIndex = 1;
- this.tabPage2.Text = "Content";
- this.tabPage2.UseVisualStyleBackColor = true;
- //
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.splitContainer1.Location = new System.Drawing.Point(3, 3);
+ this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
+ this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.treeView1);
- this.splitContainer1.Size = new System.Drawing.Size(575, 353);
- this.splitContainer1.SplitterDistance = 191;
- this.splitContainer1.TabIndex = 0;
+ //
+ // splitContainer1.Panel2
+ //
+ this.splitContainer1.Panel2.Controls.Add(this.panel1);
+ this.splitContainer1.Size = new System.Drawing.Size(589, 385);
+ this.splitContainer1.SplitterDistance = 176;
+ this.splitContainer1.TabIndex = 1;
+ this.splitContainer1.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(this.splitContainer1_SplitterMoved);
//
// treeView1
//
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.treeView1.HideSelection = false;
+ this.treeView1.HotTracking = true;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Name = "treeView1";
- this.treeView1.Size = new System.Drawing.Size(191, 353);
+ this.treeView1.Size = new System.Drawing.Size(176, 385);
this.treeView1.TabIndex = 0;
+ this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
//
- // CGFXViewer
+ // panel1
+ //
+ this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.panel1.Location = new System.Drawing.Point(0, 0);
+ this.panel1.Name = "panel1";
+ this.panel1.Size = new System.Drawing.Size(409, 385);
+ this.panel1.TabIndex = 0;
+ //
+ // CGFXViewer2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(589, 385);
- this.Controls.Add(this.tabControl1);
- this.Name = "CGFXViewer";
+ this.Controls.Add(this.splitContainer1);
+ this.Menu = this.mainMenu1;
+ this.Name = "CGFXViewer2";
this.Text = "CGFX";
- this.Activated += new System.EventHandler(this.CGFXViewer_Activated);
+ this.Activated += new System.EventHandler(this.NSBMDViewer_Activated);
this.Load += new System.EventHandler(this.CGFX_Load);
this.Layout += new System.Windows.Forms.LayoutEventHandler(this.CGFX_Layout);
this.Resize += new System.EventHandler(this.CGFX_Resize);
- this.tabControl1.ResumeLayout(false);
- this.tabPage1.ResumeLayout(false);
- this.tabPage2.ResumeLayout(false);
this.splitContainer1.Panel1.ResumeLayout(false);
+ this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
@@ -139,11 +100,9 @@
#endregion
- private Tao.Platform.Windows.SimpleOpenGlControl simpleOpenGlControl1;
- private System.Windows.Forms.TabControl tabControl1;
- private System.Windows.Forms.TabPage tabPage1;
- private System.Windows.Forms.TabPage tabPage2;
+ private LibEveryFileExplorer.UI.MainMenu mainMenu1;
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.TreeView treeView1;
+ private System.Windows.Forms.Panel panel1;
}
}
\ No newline at end of file
diff --git a/3DS/UI/CGFXViewer.resx b/3DS/UI/CGFXViewer.resx
index 1af7de1..65410b6 100644
--- a/3DS/UI/CGFXViewer.resx
+++ b/3DS/UI/CGFXViewer.resx
@@ -117,4 +117,7 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
\ No newline at end of file
diff --git a/3DS/UI/CMDLViewer.Designer.cs b/3DS/UI/CMDLViewer.Designer.cs
new file mode 100644
index 0000000..b8c84f8
--- /dev/null
+++ b/3DS/UI/CMDLViewer.Designer.cs
@@ -0,0 +1,105 @@
+namespace _3DS.UI
+{
+ partial class CMDLViewer
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Component Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CMDLViewer));
+ this.simpleOpenGlControl1 = new Tao.Platform.Windows.SimpleOpenGlControl();
+ this.toolStrip1 = new System.Windows.Forms.ToolStrip();
+ this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
+ this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
+ this.toolStrip1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // simpleOpenGlControl1
+ //
+ this.simpleOpenGlControl1.AccumBits = ((byte)(0));
+ this.simpleOpenGlControl1.AutoCheckErrors = false;
+ this.simpleOpenGlControl1.AutoFinish = false;
+ this.simpleOpenGlControl1.AutoMakeCurrent = true;
+ this.simpleOpenGlControl1.AutoSwapBuffers = true;
+ this.simpleOpenGlControl1.BackColor = System.Drawing.Color.Black;
+ this.simpleOpenGlControl1.ColorBits = ((byte)(32));
+ this.simpleOpenGlControl1.DepthBits = ((byte)(32));
+ this.simpleOpenGlControl1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.simpleOpenGlControl1.Location = new System.Drawing.Point(0, 25);
+ this.simpleOpenGlControl1.Name = "simpleOpenGlControl1";
+ this.simpleOpenGlControl1.Size = new System.Drawing.Size(462, 332);
+ this.simpleOpenGlControl1.StencilBits = ((byte)(8));
+ this.simpleOpenGlControl1.TabIndex = 1;
+ //
+ // toolStrip1
+ //
+ this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripButton1});
+ this.toolStrip1.Location = new System.Drawing.Point(0, 0);
+ this.toolStrip1.Name = "toolStrip1";
+ this.toolStrip1.Size = new System.Drawing.Size(462, 25);
+ this.toolStrip1.TabIndex = 2;
+ this.toolStrip1.Text = "toolStrip1";
+ //
+ // toolStripButton1
+ //
+ this.toolStripButton1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
+ this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+ this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image")));
+ this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.toolStripButton1.Name = "toolStripButton1";
+ this.toolStripButton1.Size = new System.Drawing.Size(23, 22);
+ this.toolStripButton1.Text = "Export";
+ this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click);
+ //
+ // saveFileDialog1
+ //
+ this.saveFileDialog1.Filter = "COLLADA DAE File (*.dae)|*.dae|Wavefront OBJ File (*.obj)|*.obj";
+ //
+ // CMDLViewer
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.simpleOpenGlControl1);
+ this.Controls.Add(this.toolStrip1);
+ this.DoubleBuffered = true;
+ this.Name = "CMDLViewer";
+ this.Size = new System.Drawing.Size(462, 357);
+ this.Load += new System.EventHandler(this.MDL0Viewer_Load);
+ this.toolStrip1.ResumeLayout(false);
+ this.toolStrip1.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Tao.Platform.Windows.SimpleOpenGlControl simpleOpenGlControl1;
+ private System.Windows.Forms.ToolStrip toolStrip1;
+ private System.Windows.Forms.ToolStripButton toolStripButton1;
+ private System.Windows.Forms.SaveFileDialog saveFileDialog1;
+ }
+}
diff --git a/3DS/UI/CMDLViewer.cs b/3DS/UI/CMDLViewer.cs
new file mode 100644
index 0000000..12b8588
--- /dev/null
+++ b/3DS/UI/CMDLViewer.cs
@@ -0,0 +1,464 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using Tao.OpenGl;
+using _3DS.NintendoWare.GFX;
+using System.Drawing.Imaging;
+using LibEveryFileExplorer._3D;
+using LibEveryFileExplorer.Collections;
+using CommonFiles;
+using System.IO;
+
+namespace _3DS.UI
+{
+ public partial class CMDLViewer : UserControl
+ {
+ CGFX Resource;
+ CMDL Model;
+
+ public CMDLViewer(CGFX Resource, CMDL Model)
+ {
+ this.Resource = Resource;
+ this.Model = Model;
+ InitializeComponent();
+ simpleOpenGlControl1.MouseWheel += new MouseEventHandler(simpleOpenGlControl1_MouseWheel);
+ }
+ void simpleOpenGlControl1_MouseWheel(object sender, MouseEventArgs e)
+ {
+ if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { dist += ((float)e.Delta / 10); }
+ else { dist += ((float)e.Delta / 100); }
+ Render();
+ }
+
+ bool init = false;
+ String glversion = null;
+
+ float X = 0.0f;
+ float Y = 0.0f;
+ float ang = 0.0f;
+ float dist = 0.0f;
+ float elev = 0.0f;
+ private void MDL0Viewer_Load(object sender, EventArgs e)
+ {
+ simpleOpenGlControl1.InitializeContexts();
+ Gl.ReloadFunctions();
+ //Gl.glEnable(Gl.GL_LIGHTING);
+ Gl.glEnable(Gl.GL_RESCALE_NORMAL);
+ Gl.glEnable(Gl.GL_COLOR_MATERIAL);
+ Gl.glEnable(Gl.GL_DEPTH_TEST);
+ Gl.glEnable(Gl.GL_NORMALIZE);
+ Gl.glDisable(Gl.GL_CULL_FACE);
+ Gl.glFrontFace(Gl.GL_CCW);
+ Gl.glEnable(Gl.GL_TEXTURE_2D);
+ Gl.glClearDepth(1);
+ Gl.glEnable(Gl.GL_ALPHA_TEST);
+ Gl.glAlphaFunc(Gl.GL_GREATER, 0f);
+ Gl.glEnable(Gl.GL_BLEND);
+ Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
+
+ //Gl.glTexEnvf(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_BLEND);
+
+ Gl.glShadeModel(Gl.GL_SMOOTH);
+
+ Gl.glDepthFunc(Gl.GL_LEQUAL);
+
+
+
+ Gl.glClearColor(51f / 255f, 51f / 255f, 51f / 255f, 0f);
+
+ if (Resource.Data.Textures != null && Model != null)
+ {
+ int i = 0;
+ foreach (var v in Model.Materials)
+ {
+ if (v.Tex0 != null) UploadTex(v.Tex0, i * 4 + 0 + 1);
+ if (v.Tex1 != null) UploadTex(v.Tex1, i * 4 + 1 + 1);
+ if (v.Tex2 != null) UploadTex(v.Tex2, i * 4 + 2 + 1);
+ //if (v.Tex3 != null) UploadTex(v.Tex3, i * 4 + 3 + 1);
+ i++;
+ }
+ }
+ if (Model != null) Shaders = new CGFXShader[Model.Materials.Length];
+ //GlNitro.glNitroBindTextures(file, 1);
+
+ glversion = Gl.glGetString(Gl.GL_VERSION);
+
+ init = true;
+ Render();
+ }
+
+ private void UploadTex(CMDL.MTOB.TexInfo TextureMapper, int Id)
+ {
+ if (!(TextureMapper.TextureObject is ReferenceTexture))
+ return;
+ var tex = Resource.Data.Textures[Resource.Data.Dictionaries[1].IndexOf(((ReferenceTexture)TextureMapper.TextureObject).LinkedTextureName)] as ImageTextureCtr;
+ if (tex == null)
+ return;
+ Gl.glBindTexture(Gl.GL_TEXTURE_2D, Id);
+ Gl.glColor3f(1, 1, 1);
+ Bitmap b = tex.GetBitmap();
+ b.RotateFlip(RotateFlipType.RotateNoneFlipY);
+ BitmapData d = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
+ Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, b.Width, b.Height, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, d.Scan0);
+ b.UnlockBits(d);
+
+ if (((TextureMapper.Unknown12 >> 1) & 1) == 1) Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
+ else Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_NEAREST);
+ //if (((TextureMapper.Unknown12 >> 2) & 1) == 1) Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
+ //else Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_NEAREST);
+ //A bit confusing, so using this for now:
+ Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
+
+ switch ((TextureMapper.Unknown12 >> 12) & 0xF)
+ {
+ case 0: Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE); break;
+ case 1: Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_BORDER); break;
+ case 2: Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT); break;
+ case 3: Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_MIRRORED_REPEAT); break;
+ default: Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT); break;
+ }
+
+ switch ((TextureMapper.Unknown12 >> 8) & 0xF)
+ {
+ case 0: Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE); break;
+ case 1: Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_BORDER); break;
+ case 2: Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT); break;
+ case 3: Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_MIRRORED_REPEAT); break;
+ default: Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT); break;
+ }
+ }
+
+ CGFXShader[] Shaders;
+ public void Render()
+ {
+ if (!init) return;
+ if (Model == null) return;
+ //G3D_Binary_File_Format.Shaders.Shader s = new G3D_Binary_File_Format.Shaders.Shader();
+ //s.Compile();
+ //s.Enable();
+ //Gl.glViewport(0, 0, simpleOpenGlControl1.Width, simpleOpenGlControl1.Height);
+ float aspect = (float)simpleOpenGlControl1.Width / (float)simpleOpenGlControl1.Height;
+ //float fov = 60.0f; // in degrees
+ //float znear = 0.02f;
+ //float zfar = 1000.0f * file.modelSet.models[SelMdl].info.posScale;
+ //Gl.glMatrixMode(Gl.GL_PROJECTION);
+ //Gl.glLoadMatrixf(BuildPerspProjMat(fov, aspect, znear, zfar));
+ Gl.glMatrixMode(Gl.GL_PROJECTION);
+ Gl.glLoadIdentity();
+ Gl.glViewport(0, 0, simpleOpenGlControl1.Width, simpleOpenGlControl1.Height);
+ //Gl.glOrtho(-simpleOpenGlControl1.Width / 2.0f, simpleOpenGlControl1.Width / 2.0f, -simpleOpenGlControl1.Height / 2.0f, simpleOpenGlControl1.Height / 2.0f, 0.02f, 1000f * file.modelSet.models[SelMdl].info.posScale);
+ //Gl.glMatrixMode(Gl.GL_PROJECTION);
+ //Gl.glLoadIdentity();
+ //Gl.glFrustum(-simpleOpenGlControl1.Width / 2f, simpleOpenGlControl1.Width / 2f, -simpleOpenGlControl1.Height / 2f, simpleOpenGlControl1.Height / 2f, 1000, -1000);
+ Glu.gluPerspective(30, aspect, 0.1f, 20480000f);//0.02f, 32.0f);
+
+ Gl.glMatrixMode(Gl.GL_MODELVIEW);
+ Gl.glLoadIdentity();
+ Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
+ Gl.glColor3f(1.0f, 1.0f, 1.0f);
+ //Gl.glEnable(Gl.GL_DEPTH_TEST);
+ Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
+
+ /*Gl.glRotatef(elev, 1, 0, 0);
+ Gl.glFogfv(Gl.GL_FOG_COLOR, new float[] { 0, 0, 0, 1 });
+ Gl.glFogf(Gl.GL_FOG_DENSITY, 1);
+ Gl.glRotatef(-elev, 1, 0, 0);*/
+
+ Gl.glTranslatef(X, Y, -dist);
+ Gl.glRotatef(elev, 1, 0, 0);
+ Gl.glRotatef(ang, 0, 1, 0);
+
+ Gl.glPushMatrix();
+ RenderModel();
+ Gl.glPopMatrix();
+ simpleOpenGlControl1.Refresh();
+ }
+
+ void RenderModel()
+ {
+ CMDL m = Model;
+ //foreach (_3DS.CGFX.DATA.CMDL m in cgfx.Data.Models)
+ //{
+ //int i = 0;
+ foreach (var mm in m.Meshes)
+ {
+ var vv = m.Shapes[mm.ShapeIndex];
+ Polygon p = vv.GetVertexData(m);
+
+ var mat = m.Materials[mm.MaterialIndex];
+ mat.FragShader.AlphaTest.GlApply();
+ mat.FragmentOperation.BlendOperation.GlApply();
+
+ Gl.glMatrixMode(Gl.GL_TEXTURE);
+ if (mat.Tex0 != null)
+ {
+ Gl.glActiveTexture(Gl.GL_TEXTURE0);
+ Gl.glBindTexture(Gl.GL_TEXTURE_2D, mm.MaterialIndex * 4 + 0 + 1);
+ Gl.glEnable(Gl.GL_TEXTURE_2D);
+ Gl.glLoadIdentity();
+ float[] mtx = new float[16];
+ Array.Copy(mat.TextureCoordiators[0].Matrix, mtx, 4 * 3);
+ mtx[15] = 1;
+ mtx[12] = mtx[3];
+ mtx[13] = mtx[7];
+ mtx[14] = mtx[11];
+ mtx[3] = 0;
+ mtx[7] = 0;
+ mtx[11] = 0;
+ Gl.glLoadMatrixf(mtx);
+ //if (mat.TextureCoordiators[0].MappingMethod == 2)
+ //{
+ // Gl.glTexGeni(Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
+ // Gl.glTexGeni(Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
+ //}
+ //Gl.glTranslatef(mat.TextureCoordiators[0].Scale.X / mat.TextureCoordiators[0].Translate.X, mat.TextureCoordiators[0].Translate.Y * mat.TextureCoordiators[0].Scale.Y, 0);
+ //Gl.glRotatef(mat.TextureCoordiators[0].Rotate, 0, 1, 0);
+ //Gl.glScalef(mat.TextureCoordiators[0].Scale.X, mat.TextureCoordiators[0].Scale.Y, 1);
+ }
+ if (mat.Tex1 != null)
+ {
+ Gl.glActiveTexture(Gl.GL_TEXTURE1);
+ Gl.glBindTexture(Gl.GL_TEXTURE_2D, mm.MaterialIndex * 4 + 1 + 1);
+ Gl.glEnable(Gl.GL_TEXTURE_2D);
+ Gl.glLoadIdentity();
+ float[] mtx = new float[16];
+ Array.Copy(mat.TextureCoordiators[1].Matrix, mtx, 4 * 3);
+ mtx[15] = 1;
+ mtx[12] = mtx[3];
+ mtx[13] = mtx[7];
+ mtx[14] = mtx[11];
+ mtx[3] = 0;
+ mtx[7] = 0;
+ mtx[11] = 0;
+ Gl.glLoadMatrixf(mtx);
+ //if (mat.TextureCoordiators[1].MappingMethod == 2)
+ //{
+ // Gl.glTexGeni(Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
+ // Gl.glTexGeni(Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
+ //}
+ }
+ if (mat.Tex2 != null)
+ {
+ Gl.glActiveTexture(Gl.GL_TEXTURE2);
+ Gl.glBindTexture(Gl.GL_TEXTURE_2D, mm.MaterialIndex * 4 + 2 + 1);
+ Gl.glEnable(Gl.GL_TEXTURE_2D);
+ Gl.glLoadIdentity();
+ float[] mtx = new float[16];
+ Array.Copy(mat.TextureCoordiators[2].Matrix, mtx, 4 * 3);
+ mtx[15] = 1;
+ mtx[12] = mtx[3];
+ mtx[13] = mtx[7];
+ mtx[14] = mtx[11];
+ mtx[3] = 0;
+ mtx[7] = 0;
+ mtx[11] = 0;
+ Gl.glLoadMatrixf(mtx);
+ //if (mat.TextureCoordiators[2].MappingMethod == 2)
+ //{
+ // Gl.glTexGeni(Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
+ // Gl.glTexGeni(Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
+ //}
+ }
+ /*if (mat.Tex3 != null)
+ {
+ MessageBox.Show("Tex3!!!!!!!!!!!");
+ Gl.glActiveTexture(Gl.GL_TEXTURE3);
+ Gl.glBindTexture(Gl.GL_TEXTURE_2D, mm.MaterialIndex * 4 + 3 + 1);
+ Gl.glEnable(Gl.GL_TEXTURE_2D);
+ Gl.glLoadIdentity();
+ }*/
+ Gl.glMatrixMode(Gl.GL_MODELVIEW);
+ Gl.glPushMatrix();
+ Gl.glTranslatef(vv.PositionOffset.X, vv.PositionOffset.Y, vv.PositionOffset.Z);
+
+ if (glversion.StartsWith("2.") && Shaders[mm.MaterialIndex] == null)
+ {
+ List tex = new List();
+ if (mat.Tex0 != null) tex.Add((int)mm.MaterialIndex * 4 + 0 + 1);
+ else tex.Add(0);
+ if (mat.Tex1 != null) tex.Add((int)mm.MaterialIndex * 4 + 1 + 1);
+ else tex.Add(0);
+ if (mat.Tex2 != null) tex.Add((int)mm.MaterialIndex * 4 + 2 + 1);
+ else tex.Add(0);
+ //if (mat.Tex3 != null) tex.Add((int)mm.MaterialIndex * 4 + 3 + 1);
+ /*else */
+ tex.Add(0);
+
+ Shaders[mm.MaterialIndex] = new CGFXShader(mat, tex.ToArray());
+ Shaders[mm.MaterialIndex].Compile();
+ }
+ if (glversion.StartsWith("2.")) Shaders[mm.MaterialIndex].Enable();
+
+ //Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_EMISSION, new float[] { mat.Emission_2.R / 255f, mat.Emission_2.G / 255f, mat.Emission_2.B / 255f, mat.Emission_2.A / 255f });
+ //Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_AMBIENT, new float[] { mat.Ambient_1.R / 255f, mat.Ambient_1.G / 255f, mat.Ambient_1.B / 255f, mat.Ambient_1.A / 255f });
+ //Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE, new float[] { mat.Diffuse_2.R / 255f, mat.Diffuse_2.G / 255f, mat.Diffuse_2.B / 255f, mat.Diffuse_2.A / 255f });
+ //Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE);
+ //Gl.glEnable(Gl.GL_COLOR_MATERIAL);
+
+ foreach (var q in vv.PrimitiveSets[0].Primitives[0].IndexStreams)
+ {
+ Vector3[] defs = q.GetFaceData();
+
+ Gl.glBegin(Gl.GL_TRIANGLES);
+ foreach (Vector3 d in defs)
+ {
+ if (p.Normals != null) Gl.glNormal3f(p.Normals[(int)d.X].X, p.Normals[(int)d.X].Y, p.Normals[(int)d.X].Z);
+ if (p.Colors != null) Gl.glColor4f(p.Colors[(int)d.X].R / 255f, p.Colors[(int)d.X].G / 255f, p.Colors[(int)d.X].B / 255f, p.Colors[(int)d.X].A / 255f);
+ else Gl.glColor4f(1, 1, 1, 1);
+ if (p.TexCoords != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, p.TexCoords[(int)d.X].X, p.TexCoords[(int)d.X].Y);
+ if (p.TexCoords2 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE1, p.TexCoords2[(int)d.X].X, p.TexCoords2[(int)d.X].Y);
+ if (p.TexCoords3 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE2, p.TexCoords3[(int)d.X].X, p.TexCoords3[(int)d.X].Y);
+ Gl.glVertex3f(p.Vertex[(int)d.X].X, p.Vertex[(int)d.X].Y, p.Vertex[(int)d.X].Z);
+
+ if (p.Normals != null) Gl.glNormal3f(p.Normals[(int)d.Y].X, p.Normals[(int)d.Y].Y, p.Normals[(int)d.Y].Z);
+ if (p.Colors != null) Gl.glColor4f(p.Colors[(int)d.Y].R / 255f, p.Colors[(int)d.Y].G / 255f, p.Colors[(int)d.Y].B / 255f, p.Colors[(int)d.Y].A / 255f);
+ else Gl.glColor4f(1, 1, 1, 1);
+ if (p.TexCoords != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, p.TexCoords[(int)d.Y].X, p.TexCoords[(int)d.Y].Y);
+ if (p.TexCoords2 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE1, p.TexCoords2[(int)d.Y].X, p.TexCoords2[(int)d.Y].Y);
+ if (p.TexCoords3 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE2, p.TexCoords3[(int)d.Y].X, p.TexCoords3[(int)d.Y].Y);
+ Gl.glVertex3f(p.Vertex[(int)d.Y].X, p.Vertex[(int)d.Y].Y, p.Vertex[(int)d.Y].Z);
+
+ if (p.Normals != null) Gl.glNormal3f(p.Normals[(int)d.Z].X, p.Normals[(int)d.Z].Y, p.Normals[(int)d.Z].Z);
+ if (p.Colors != null) Gl.glColor4f(p.Colors[(int)d.Z].R / 255f, p.Colors[(int)d.Z].G / 255f, p.Colors[(int)d.Z].B / 255f, p.Colors[(int)d.Z].A / 255f);
+ else Gl.glColor4f(1, 1, 1, 1);
+ if (p.TexCoords != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, p.TexCoords[(int)d.Z].X, p.TexCoords[(int)d.Z].Y);
+ if (p.TexCoords2 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE1, p.TexCoords2[(int)d.Z].X, p.TexCoords2[(int)d.Z].Y);
+ if (p.TexCoords3 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE2, p.TexCoords3[(int)d.Z].X, p.TexCoords3[(int)d.Z].Y);
+ Gl.glVertex3f(p.Vertex[(int)d.Z].X, p.Vertex[(int)d.Z].Y, p.Vertex[(int)d.Z].Z);
+ }
+ Gl.glEnd();
+ }
+ Gl.glPopMatrix();
+ }
+ }
+
+ bool wire = false;
+ bool licht = true;
+ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
+ {
+ switch (keyData)
+ {
+ case Keys.Right:
+ ang += 1;
+ Render();
+ return true;
+ case Keys.Left:
+ ang -= 1;
+ Render();
+ return true;
+ case Keys.Up:
+ elev += 1;
+ Render();
+ return true;
+ case Keys.Down:
+ elev -= 1;
+ Render();
+ return true;
+ case Keys.Z:
+ X -= 5f;
+ Render();
+ return true;
+ case Keys.X:
+ X += 5f;
+ Render();
+ return true;
+ case Keys.A:
+ Y -= 5f;
+ Render();
+ return true;
+ case Keys.S:
+ Y += 5f;
+ Render();
+ return true;
+ case Keys.W:
+ wire = !wire;
+ if (wire) { Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_LINE); Render(); }
+ else { Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_FILL); Render(); }
+ return true;
+ case Keys.Escape:
+ X = 0.0f;
+ Y = 0.0f;
+ ang = 0.0f;
+ dist = 0.0f;
+ elev = 0.0f;
+ Render();
+ return true;
+ case Keys.T:
+ elev = 90;
+ ang = 0;
+ Render();
+ return true;
+ case Keys.L:
+ licht = !licht;
+ Render();
+ return true;
+ case Keys.OemMinus:
+ case Keys.OemMinus | Keys.Shift:
+ if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) dist += 12f;
+ else dist += 1.2f;
+ Render();
+ return true;
+ case Keys.Oemplus:
+ case Keys.Oemplus | Keys.Shift:
+ if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) dist -= 12f;
+ else dist -= 1.2f;
+ Render();
+ return true;
+ default:
+ return base.ProcessCmdKey(ref msg, keyData);
+ }
+ }
+
+ private void toolStripButton1_Click(object sender, EventArgs e)
+ {
+ saveFileDialog1.FileName = Model.Name;
+ if (saveFileDialog1.ShowDialog() == DialogResult.OK
+ && saveFileDialog1.FileName.Length > 0)
+ {
+ switch (saveFileDialog1.FilterIndex)
+ {
+ case 0:
+ {
+ DAE o = Model.ToDAE(Resource);
+ File.Create(saveFileDialog1.FileName).Close();
+ File.WriteAllBytes(saveFileDialog1.FileName, o.Write());
+ Directory.CreateDirectory(Path.GetDirectoryName(saveFileDialog1.FileName) + "\\Tex");
+ foreach (var v in Resource.Data.Textures)
+ {
+ if (!(v is ImageTextureCtr)) continue;
+ ((ImageTextureCtr)v).GetBitmap().Save(Path.GetDirectoryName(saveFileDialog1.FileName) + "\\Tex\\" + v.Name + ".png");
+ }
+ break;
+ }
+ case 1:
+ {
+ OBJ o = Model.ToOBJ();
+ o.MTLPath = Path.GetFileNameWithoutExtension(saveFileDialog1.FileName) + ".mtl";
+ MTL m = Model.ToMTL();
+ byte[] d = o.Write();
+ byte[] d2 = m.Write();
+ File.Create(saveFileDialog1.FileName).Close();
+ File.WriteAllBytes(saveFileDialog1.FileName, d);
+ File.Create(Path.ChangeExtension(saveFileDialog1.FileName, "mtl")).Close();
+ File.WriteAllBytes(Path.ChangeExtension(saveFileDialog1.FileName, "mtl"), d2);
+ Directory.CreateDirectory(Path.GetDirectoryName(saveFileDialog1.FileName) + "\\Tex");
+ foreach (var v in Resource.Data.Textures)
+ {
+ //if (v.NrLevels > 2) v.GetBitmap(2).Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
+ //else if (v.NrLevels > 1) v.GetBitmap(1).Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
+ //else v.GetBitmap(0).Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
+ if (!(v is ImageTextureCtr)) continue;
+ ((ImageTextureCtr)v).GetBitmap().Save(Path.GetDirectoryName(saveFileDialog1.FileName) + "\\Tex\\" + v.Name + ".png");
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/3DS/UI/CMDLViewer.resx b/3DS/UI/CMDLViewer.resx
new file mode 100644
index 0000000..5f52d69
--- /dev/null
+++ b/3DS/UI/CMDLViewer.resx
@@ -0,0 +1,143 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 17, 17
+
+
+
+
+ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
+ YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAI3SURBVDhPYxi6gLmM2R3KxALqGTiYS5hdmEuZO5lKmFYD
+ 8R6mUqa96BiqGg0UM8gzFzLPVOtROh+xNeh11uHkHyUnc/6Xnsr9X3U+/3/zjZL/HXfL/zMVMO2D6kAC
+ WQzyXCUc6z2Xuj7N2JvyP3FbIhgnbY//n3c49X/Nxbz/DVcL/zffLPnPlIfugnigszOZZznNt38atznm
+ f9T6qP+R6yKAdAhQc9L/irPZcFx6JuMnUybTOqhOCGBOZnaVrZG5GL4m9H/Q8qD/3gu8gLTX/+wDCUAD
+ kpFwyv/YrUFvGVMYe6BaIYAxnrHXborNW58FPv8dpjr895jr/D95R8z/lJ2oGGSIWqPyJeYEZleoVghg
+ jGbc4DTD8af1BOv/Vv3mYKej4/gtEf+9l67/LVuRvUemsJATqhUCmEKZDtlOsvmvXqP232+x9/+Apb5w
+ HLjMF2yA6yy75wY9Bz6YT7552XzS3RioVghgCmA6ql6j/t95hiPYAP8lPmCNVhNm/TPq3P5Hu2nzN/X6
+ rW90Ws5cnv70/3+99ktndFrPQw2xZ+BhdGY8joFdGI/JFiz9MOnx//9ZV///j72IwMU3/v9Xrjx8BmKA
+ OUMRowVjB4MsgxREAAGE/DtmimdtPYOMLY7+/w+iJXK2QV2gz7CbgZ/BEcjSAmJVIJYHYgkgFgJiHiBm
+ B2ImIGbgiVl+BoR541aihAHIZpAGUSAWBmIBIAZpBIU0GxCzADEjEDOwBc6ZyRowG6qZgQEAZbYdbqlW
+ taMAAAAASUVORK5CYII=
+
+
+
+ 122, 17
+
+
\ No newline at end of file
diff --git a/3DS/UI/TXOBViewer.Designer.cs b/3DS/UI/TXOBViewer.Designer.cs
new file mode 100644
index 0000000..e7f1494
--- /dev/null
+++ b/3DS/UI/TXOBViewer.Designer.cs
@@ -0,0 +1,134 @@
+namespace _3DS.UI
+{
+ partial class TXOBViewer
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TXOBViewer));
+ this.toolStrip1 = new System.Windows.Forms.ToolStrip();
+ this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
+ this.toolStripButton2 = new System.Windows.Forms.ToolStripButton();
+ this.toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox();
+ this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel();
+ this.pictureBox1 = new System.Windows.Forms.PictureBox();
+ this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
+ this.toolStrip1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
+ this.SuspendLayout();
+ //
+ // toolStrip1
+ //
+ this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripButton1,
+ this.toolStripButton2,
+ this.toolStripComboBox1,
+ this.toolStripLabel1});
+ this.toolStrip1.Location = new System.Drawing.Point(0, 0);
+ this.toolStrip1.Name = "toolStrip1";
+ this.toolStrip1.Size = new System.Drawing.Size(464, 25);
+ this.toolStrip1.TabIndex = 0;
+ this.toolStrip1.Text = "toolStrip1";
+ //
+ // toolStripButton1
+ //
+ this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+ this.toolStripButton1.Enabled = false;
+ this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image")));
+ this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.toolStripButton1.Name = "toolStripButton1";
+ this.toolStripButton1.Size = new System.Drawing.Size(23, 22);
+ this.toolStripButton1.Text = "Import";
+ //
+ // toolStripButton2
+ //
+ this.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+ this.toolStripButton2.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton2.Image")));
+ this.toolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.toolStripButton2.Name = "toolStripButton2";
+ this.toolStripButton2.Size = new System.Drawing.Size(23, 22);
+ this.toolStripButton2.Text = "Export";
+ this.toolStripButton2.Click += new System.EventHandler(this.toolStripButton2_Click);
+ //
+ // toolStripComboBox1
+ //
+ this.toolStripComboBox1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
+ this.toolStripComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.toolStripComboBox1.FlatStyle = System.Windows.Forms.FlatStyle.Standard;
+ this.toolStripComboBox1.Name = "toolStripComboBox1";
+ this.toolStripComboBox1.Size = new System.Drawing.Size(121, 25);
+ this.toolStripComboBox1.SelectedIndexChanged += new System.EventHandler(this.toolStripComboBox1_SelectedIndexChanged);
+ //
+ // toolStripLabel1
+ //
+ this.toolStripLabel1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
+ this.toolStripLabel1.Name = "toolStripLabel1";
+ this.toolStripLabel1.Size = new System.Drawing.Size(40, 22);
+ this.toolStripLabel1.Text = "Level: ";
+ //
+ // pictureBox1
+ //
+ this.pictureBox1.BackgroundImage = global::_3DS.Resource.preview_background;
+ this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBox1.Location = new System.Drawing.Point(0, 25);
+ this.pictureBox1.Name = "pictureBox1";
+ this.pictureBox1.Size = new System.Drawing.Size(464, 308);
+ this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
+ this.pictureBox1.TabIndex = 1;
+ this.pictureBox1.TabStop = false;
+ //
+ // saveFileDialog1
+ //
+ this.saveFileDialog1.Filter = "PNG Images (*.png)|*.png";
+ //
+ // TXOBViewer
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.pictureBox1);
+ this.Controls.Add(this.toolStrip1);
+ this.Name = "TXOBViewer";
+ this.Size = new System.Drawing.Size(464, 333);
+ this.Load += new System.EventHandler(this.TXOBViewer_Load);
+ this.toolStrip1.ResumeLayout(false);
+ this.toolStrip1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.ToolStrip toolStrip1;
+ private System.Windows.Forms.PictureBox pictureBox1;
+ private System.Windows.Forms.ToolStripButton toolStripButton1;
+ private System.Windows.Forms.ToolStripButton toolStripButton2;
+ private System.Windows.Forms.ToolStripComboBox toolStripComboBox1;
+ private System.Windows.Forms.ToolStripLabel toolStripLabel1;
+ private System.Windows.Forms.SaveFileDialog saveFileDialog1;
+ }
+}
\ No newline at end of file
diff --git a/3DS/UI/TXOBViewer.cs b/3DS/UI/TXOBViewer.cs
new file mode 100644
index 0000000..de4dec0
--- /dev/null
+++ b/3DS/UI/TXOBViewer.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using _3DS.NintendoWare.GFX;
+using System.Drawing.Imaging;
+
+namespace _3DS.UI
+{
+ public partial class TXOBViewer : UserControl
+ {
+ public ImageTextureCtr Texture;
+ public TXOBViewer(ImageTextureCtr Texture)
+ {
+ this.Texture = Texture;
+ InitializeComponent();
+ }
+
+ private void TXOBViewer_Load(object sender, EventArgs e)
+ {
+ for (int i = 0; i < Texture.NrLevels; i++)
+ {
+ toolStripComboBox1.Items.Add(i.ToString());
+ }
+ toolStripComboBox1.SelectedIndex = 0;
+ }
+
+ private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ pictureBox1.Image = Texture.GetBitmap(toolStripComboBox1.SelectedIndex);
+ }
+
+ private void toolStripButton2_Click(object sender, EventArgs e)
+ {
+ saveFileDialog1.FileName = Texture.Name + ".png";
+ if (saveFileDialog1.ShowDialog() == DialogResult.OK
+ && saveFileDialog1.FileName.Length > 0)
+ {
+ pictureBox1.Image.Save(saveFileDialog1.FileName, ImageFormat.Png);
+ }
+ }
+ }
+}
diff --git a/3DS/UI/TXOBViewer.resx b/3DS/UI/TXOBViewer.resx
new file mode 100644
index 0000000..5114548
--- /dev/null
+++ b/3DS/UI/TXOBViewer.resx
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 17, 17
+
+
+
+
+ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
+ YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHFSURBVDhPzZBfKOthHMa/t26mbOqsmHKjxcXq7FAuWLkS
+ F/6cG8s57YoT0lIzdjEhfxpaHc5KJ7JThrFdkC0Zyp9FkuICpSUUWfw4HdqMPed95+fUuTM3PPWp9316
+ P8/FS+8nn83m6tcg6kQlJtO3aDSKFwOAO6JOVGww1Nw/PMDh9WJ8dhLeMQ0W7NJ/+Owy+EakmOfYP+CR
+ DXBH1IkK9fra23AYQ243IqFLOF2tWJxUY82ZCv+UAn53GvwuBVbYfXkiHRE2wB3KKCoyPfPD4QDnPiRA
+ OJuHx6XFxowKuytqHB2VYX+nAJuzSqxPZyLMBgrq6upJodG0sPN/uREEnB4u4Xi3DXurpQgEtDi5qImx
+ s6TGlkeFO/Yuv6pKT9Ls7PZnOmw2cG6EK+xtL6LdpEW3/hM8U5U4DQ7g4PA7fvaUYu5XDv6wgVydrkH8
+ ASJ1RYUhEAzCbLUidHcJS181Ri0SOHolcPYnwueWYXo4CePWxFj/mw1wR9SJssrLjQfn52i2WNDc1YrG
+ L7IYxq/J6GyQY3QwDSP9iljXpJPjmg1wR9SJUvLyWgRWxgN3RJ0oQansihemSZ7sp8gZH+Mgi/HmIfoL
+ mcCdW7XvzrgAAAAASUVORK5CYII=
+
+
+
+
+ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
+ YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAINSURBVDhPYxh4EFZb6xtSV5dODgbpZQiorc34TyYA6WUI
+ KCvL/Pvv3/9za4RJwiA9IL0MniUl2b/+/v1/ZZMkFiz1/+pmqf/XtkrDMYgPEgfpAellcMvNzf3+58//
+ ZW2G/w8v0v5/d7cSHN/bo/z/wX7V/0+Oa/1/dlYPTIP4IHGQHpBeBqfMzPzPv379j7S0/B9rZ/d/SYvJ
+ /yeHNMG4KFHsv6+z4P/th1L/7zqdB6bXrQv8v3qF7/+AoKD/wnJyOxhsUlML3//8+d9aUvK/l4bG/0hz
+ 0/9Ti43+r+s1/u9gJvi/paXl/z9ggIH8DMMgPkicg4/vEoNlfHzxm+/f/+f7coJxUQDP/7oYif8NcVL/
+ NeU5/9fU1PwHufDd169wDOKDxDn5+a8ymERGlr749u3/oQUCGNhcj/V/eXn5/zPXrv1/CVQDwyA+SBxo
+ wA0GvdDQimdfvvzvymDDwKqyzP/DwsL+Gxsbo2ATE5P/4eHh/zm4uO4wyDk51b0EhsHjz58xsIWNzf/g
+ 4OD/x44d/3/o0GEwBrEtLCz+R0RE/Gfh4nrAwKmiksGrq9uGDTOzsDwJDAz8v3373v9KSkrAGNgCZtva
+ 2v6Pior6z8TMfA+UHdiAWAyIpdAxIyPjOiC+snbtbrDTV67c9h/EdnJy+h8bG/sfKHcBqA4v4AbirczM
+ zF3IGCj2GIIZVgIAhmv0Ys3vGOAAAAAASUVORK5CYII=
+
+
+
+ 122, 17
+
+
\ No newline at end of file
diff --git a/NDS/UI/NSBMDViewer.cs b/NDS/UI/NSBMDViewer.cs
index 33e293e..b50c7e9 100644
--- a/NDS/UI/NSBMDViewer.cs
+++ b/NDS/UI/NSBMDViewer.cs
@@ -276,7 +276,10 @@ namespace NDS.UI
mainMenu1.MenuItems.Clear();
mainMenu1.MenuItems.Add(menuItem1);
//render it multiple times to avoid glitches!
- for (int i = 0; i < 8; i++) ModViewer.Render();
+ if (ModViewer != null)
+ {
+ for (int i = 0; i < 8; i++) ModViewer.Render();
+ }
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
@@ -322,5 +325,13 @@ namespace NDS.UI
break;
}
}
+
+ private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
+ {
+ if (ModViewer != null)
+ {
+ ModViewer.Render();
+ }
+ }
}
}
diff --git a/NDS/UI/NSBMDViewer.designer.cs b/NDS/UI/NSBMDViewer.designer.cs
index e331643..8f8ddaa 100644
--- a/NDS/UI/NSBMDViewer.designer.cs
+++ b/NDS/UI/NSBMDViewer.designer.cs
@@ -68,6 +68,7 @@
this.splitContainer1.Size = new System.Drawing.Size(589, 385);
this.splitContainer1.SplitterDistance = 176;
this.splitContainer1.TabIndex = 1;
+ this.splitContainer1.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(this.splitContainer1_SplitterMoved);
//
// treeView1
//