diff options
author | Treeki <treeki@gmail.com> | 2011-03-13 23:28:22 +0100 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2011-03-13 23:28:22 +0100 |
commit | 51b0e39ceb5962ffd9b22f1b4722d2b243dba60f (patch) | |
tree | 7443441619577bbfee76322ffe622adcdbd09121 | |
parent | a9ef5367e5696602837900934df9b27ca15d944c (diff) | |
download | nw4rtools-51b0e39ceb5962ffd9b22f1b4722d2b243dba60f.tar.gz nw4rtools-51b0e39ceb5962ffd9b22f1b4722d2b243dba60f.zip |
added model bounding box calculation
-rw-r--r-- | NW4RTools.userprefs | 6 | ||||
-rw-r--r-- | NW4RTools/NW4RTools.pidb | bin | 583215 -> 583263 bytes | |||
-rwxr-xr-x | NW4RTools/ObjImporter.cs | 36 | ||||
-rwxr-xr-x | NW4RTools/bin/Debug/NW4RTools.dll | bin | 236544 -> 236544 bytes | |||
-rw-r--r-- | NW4RTools/bin/Debug/NW4RTools.dll.mdb | bin | 114260 -> 114305 bytes | |||
-rw-r--r-- | TestApp/Main.cs | 9 | ||||
-rw-r--r-- | TestApp/TestApp.pidb | bin | 4427 -> 4427 bytes | |||
-rwxr-xr-x | TestApp/bin/Debug/NW4RTools.dll | bin | 236544 -> 236544 bytes | |||
-rw-r--r-- | TestApp/bin/Debug/NW4RTools.dll.mdb | bin | 114260 -> 114305 bytes | |||
-rwxr-xr-x | TestApp/bin/Debug/TestApp.exe | bin | 7680 -> 7680 bytes | |||
-rw-r--r-- | TestApp/bin/Debug/TestApp.exe.mdb | bin | 1257 -> 1246 bytes |
11 files changed, 34 insertions, 17 deletions
diff --git a/NW4RTools.userprefs b/NW4RTools.userprefs index cbe4527..eef25ca 100644 --- a/NW4RTools.userprefs +++ b/NW4RTools.userprefs @@ -2,13 +2,13 @@ <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" /> <MonoDevelop.Ide.Workbench ActiveDocument="NW4RTools/ObjImporter.cs"> <Files> - <File FileName="NW4RTools/ObjImporter.cs" Line="60" Column="17" /> + <File FileName="NW4RTools/ObjImporter.cs" Line="97" Column="13" /> <File FileName="NW4RTools/ObjExporter.cs" Line="105" Column="25" /> - <File FileName="NW4RTools/BrresReader.cs" Line="619" Column="1" /> + <File FileName="NW4RTools/BrresReader.cs" Line="182" Column="1" /> <File FileName="NW4RTools/BrresWriter.cs" Line="1327" Column="9" /> <File FileName="NW4RTools/Models/Model.cs" Line="1" Column="1" /> <File FileName="NW4RTools/Models/ByteCode.cs" Line="1" Column="1" /> - <File FileName="TestApp/Main.cs" Line="14" Column="22" /> + <File FileName="TestApp/Main.cs" Line="25" Column="13" /> <File FileName="NW4RTools/Types.cs" Line="1" Column="1" /> <File FileName="NW4RTools/Models/Material.cs" Line="70" Column="1" /> <File FileName="NW4RTools/VertexSettings.cs" Line="184" Column="46" /> diff --git a/NW4RTools/NW4RTools.pidb b/NW4RTools/NW4RTools.pidb Binary files differindex fb7e2a9..ccf0cfb 100644 --- a/NW4RTools/NW4RTools.pidb +++ b/NW4RTools/NW4RTools.pidb diff --git a/NW4RTools/ObjImporter.cs b/NW4RTools/ObjImporter.cs index 78294bd..a1f04b7 100755 --- a/NW4RTools/ObjImporter.cs +++ b/NW4RTools/ObjImporter.cs @@ -35,9 +35,6 @@ namespace NW4RTools { List<float[]> Normals; List<float[]> TexCoords; - Vec3 CurrentMinimum; - Vec3 CurrentMaximum; - private ObjImporter(string basePath, ResFile file, TextReader tr) { BasePath = basePath; CurrentFile = file; @@ -79,7 +76,7 @@ namespace NW4RTools { // Set current material (usemtl): // -- A different material will be assigned for the current shape. - if (Lightmap != LightmapType.None) { + if (Lightmap != LightmapType.None && !texGroup.ContainsKey(LightmapName1)) { var lm01 = new Texture(); var lm02 = new Texture(); @@ -93,8 +90,8 @@ namespace NW4RTools { lm02.Format = TextureFormat.I8; - CurrentFile.GetTextureGroup().Add(LightmapName1, lm01); - CurrentFile.GetTextureGroup().Add(LightmapName2, lm02); + texGroup.Add(LightmapName1, lm01); + texGroup.Add(LightmapName2, lm02); } @@ -110,8 +107,8 @@ namespace NW4RTools { // Todo: vertex count, triangle count // Minimum, Maximum will be calc'd later - CurrentMinimum = new Vec3(0, 0, 0); - CurrentMaximum = new Vec3(0, 0, 0); + var minimum = new Vec3(0, 0, 0); + var maximum = new Vec3(0, 0, 0); // Create one node // Default settings from test_lift.brres @@ -183,14 +180,30 @@ namespace NW4RTools { if (line.Length == 0 || line[0] == '#') continue; - var parsed = line.Split(new char[] { ' '}, StringSplitOptions.RemoveEmptyEntries); + var parsed = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); switch (parsed[0]) { case "mtllib": LoadMaterialLibrary(string.Join(" ", parsed, 1, parsed.Length - 1)); break; case "v": - Positions.Add(ParseFloatArray(parsed, 1, 3)); + var vEntry = ParseFloatArray(parsed, 1, 3); + Positions.Add(vEntry); + + if (vEntry[0] < minimum.x) + minimum.x = vEntry[0]; + if (vEntry[1] < minimum.y) + minimum.y = vEntry[1]; + if (vEntry[2] < minimum.z) + minimum.z = vEntry[2]; + + if (vEntry[0] > maximum.x) + maximum.x = vEntry[0]; + if (vEntry[1] > maximum.y) + maximum.y = vEntry[1]; + if (vEntry[2] > maximum.z) + maximum.z = vEntry[2]; + break; case "vn": Normals.Add(ParseFloatArray(parsed, 1, 3)); @@ -221,6 +234,9 @@ namespace NW4RTools { // Parsing is finished. Let's finish up DrawOpa drawOpa.Instructions.Add(new ByteCode.DoneInstruction()); + + CurrentModel.Minimum = minimum; + CurrentModel.Maximum = maximum; } diff --git a/NW4RTools/bin/Debug/NW4RTools.dll b/NW4RTools/bin/Debug/NW4RTools.dll Binary files differindex b6af23d..6f24c8e 100755 --- a/NW4RTools/bin/Debug/NW4RTools.dll +++ b/NW4RTools/bin/Debug/NW4RTools.dll diff --git a/NW4RTools/bin/Debug/NW4RTools.dll.mdb b/NW4RTools/bin/Debug/NW4RTools.dll.mdb Binary files differindex dea185a..0dab4c1 100644 --- a/NW4RTools/bin/Debug/NW4RTools.dll.mdb +++ b/NW4RTools/bin/Debug/NW4RTools.dll.mdb diff --git a/TestApp/Main.cs b/TestApp/Main.cs index eb3bcc8..56991bd 100644 --- a/TestApp/Main.cs +++ b/TestApp/Main.cs @@ -17,14 +17,15 @@ namespace TestApp { // Going to create a model! //string filename = "crapmap", resmdlname = "CrapMap"; - string filename = "GoldwoodBase", resmdlname = "GoldwoodBase"; - + string filename = "SMGoldwood"; ResFile rf = new ResFile(); - ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + filename + ".obj"), rf, resmdlname, ObjImporter.LightmapType.MapObj); + ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + "GoldwoodBase.obj"), rf, "GoldwoodBase", ObjImporter.LightmapType.Map); + ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + "BrownTree.obj"), rf, "BrownTree", ObjImporter.LightmapType.MapObj); + ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + "RedTree.obj"), rf, "RedTree", ObjImporter.LightmapType.MapObj); - File.WriteAllBytes(mdlPath + filename + ".brres", BrresWriter.WriteFile(rf)); + File.WriteAllBytes(mdlPath + "SMGoldwood.brres", BrresWriter.WriteFile(rf)); /*ResFile rf2 = BrresReader.LoadFile(File.ReadAllBytes(mdlPath + filename + ".brres")); diff --git a/TestApp/TestApp.pidb b/TestApp/TestApp.pidb Binary files differindex ceb7cc4..4763179 100644 --- a/TestApp/TestApp.pidb +++ b/TestApp/TestApp.pidb diff --git a/TestApp/bin/Debug/NW4RTools.dll b/TestApp/bin/Debug/NW4RTools.dll Binary files differindex b6af23d..6f24c8e 100755 --- a/TestApp/bin/Debug/NW4RTools.dll +++ b/TestApp/bin/Debug/NW4RTools.dll diff --git a/TestApp/bin/Debug/NW4RTools.dll.mdb b/TestApp/bin/Debug/NW4RTools.dll.mdb Binary files differindex dea185a..0dab4c1 100644 --- a/TestApp/bin/Debug/NW4RTools.dll.mdb +++ b/TestApp/bin/Debug/NW4RTools.dll.mdb diff --git a/TestApp/bin/Debug/TestApp.exe b/TestApp/bin/Debug/TestApp.exe Binary files differindex 07e8e26..48903c9 100755 --- a/TestApp/bin/Debug/TestApp.exe +++ b/TestApp/bin/Debug/TestApp.exe diff --git a/TestApp/bin/Debug/TestApp.exe.mdb b/TestApp/bin/Debug/TestApp.exe.mdb Binary files differindex 08b9311..f2f707d 100644 --- a/TestApp/bin/Debug/TestApp.exe.mdb +++ b/TestApp/bin/Debug/TestApp.exe.mdb |