From 51b0e39ceb5962ffd9b22f1b4722d2b243dba60f Mon Sep 17 00:00:00 2001 From: Treeki Date: Sun, 13 Mar 2011 23:28:22 +0100 Subject: added model bounding box calculation --- NW4RTools/NW4RTools.pidb | Bin 583215 -> 583263 bytes NW4RTools/ObjImporter.cs | 36 ++++++++++++++++++++++++---------- NW4RTools/bin/Debug/NW4RTools.dll | Bin 236544 -> 236544 bytes NW4RTools/bin/Debug/NW4RTools.dll.mdb | Bin 114260 -> 114305 bytes 4 files changed, 26 insertions(+), 10 deletions(-) (limited to 'NW4RTools') diff --git a/NW4RTools/NW4RTools.pidb b/NW4RTools/NW4RTools.pidb index fb7e2a9..ccf0cfb 100644 Binary files a/NW4RTools/NW4RTools.pidb and b/NW4RTools/NW4RTools.pidb differ 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 Normals; List 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 index b6af23d..6f24c8e 100755 Binary files a/NW4RTools/bin/Debug/NW4RTools.dll and b/NW4RTools/bin/Debug/NW4RTools.dll differ diff --git a/NW4RTools/bin/Debug/NW4RTools.dll.mdb b/NW4RTools/bin/Debug/NW4RTools.dll.mdb index dea185a..0dab4c1 100644 Binary files a/NW4RTools/bin/Debug/NW4RTools.dll.mdb and b/NW4RTools/bin/Debug/NW4RTools.dll.mdb differ -- cgit v1.2.3