diff options
-rw-r--r-- | NW4RTools.userprefs | 14 | ||||
-rw-r--r-- | NW4RTools/BrresReader.cs | 2 | ||||
-rw-r--r-- | NW4RTools/ColladaWriter.cs | 104 | ||||
-rw-r--r-- | NW4RTools/NW4RTools.pidb | bin | 525316 -> 525525 bytes | |||
-rwxr-xr-x | NW4RTools/bin/Debug/NW4RTools.dll | bin | 157696 -> 158720 bytes | |||
-rw-r--r-- | NW4RTools/bin/Debug/NW4RTools.dll.mdb | bin | 87412 -> 87798 bytes | |||
-rw-r--r-- | TestApp/Main.cs | 8 | ||||
-rw-r--r-- | TestApp/TestApp.pidb | bin | 3039 -> 3039 bytes | |||
-rwxr-xr-x | TestApp/bin/Debug/NW4RTools.dll | bin | 157696 -> 158720 bytes | |||
-rw-r--r-- | TestApp/bin/Debug/NW4RTools.dll.mdb | bin | 87412 -> 87798 bytes | |||
-rwxr-xr-x | TestApp/bin/Debug/TestApp.exe | bin | 4096 -> 4096 bytes | |||
-rw-r--r-- | TestApp/bin/Debug/TestApp.exe.mdb | bin | 464 -> 479 bytes |
12 files changed, 112 insertions, 16 deletions
diff --git a/NW4RTools.userprefs b/NW4RTools.userprefs index 5529d07..895a11a 100644 --- a/NW4RTools.userprefs +++ b/NW4RTools.userprefs @@ -1,11 +1,11 @@ <Properties> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" /> - <MonoDevelop.Ide.Workbench ActiveDocument="TestApp/Main.cs"> + <MonoDevelop.Ide.Workbench ActiveDocument="NW4RTools/BrresReader.cs"> <Files> - <File FileName="NW4RTools/ObjWriter.cs" Line="158" Column="7" /> - <File FileName="TestApp/Main.cs" Line="10" Column="27" /> - <File FileName="NW4RTools/BrresReader.cs" Line="657" Column="11" /> - <File FileName="NW4RTools/Models/Shape.cs" Line="18" Column="28" /> + <File FileName="NW4RTools/ObjWriter.cs" Line="164" Column="3" /> + <File FileName="TestApp/Main.cs" Line="10" Column="30" /> + <File FileName="NW4RTools/BrresReader.cs" Line="652" Column="66" /> + <File FileName="NW4RTools/Models/Shape.cs" Line="30" Column="1" /> <File FileName="NW4RTools/Models/Model.cs" Line="33" Column="39" /> <File FileName="NW4RTools/InputStream.cs" Line="1" Column="1" /> <File FileName="NW4RTools/Models/ByteCode.cs" Line="1" Column="1" /> @@ -13,6 +13,10 @@ <File FileName="NW4RTools/Logger.cs" Line="1" Column="1" /> <File FileName="NW4RTools/Enums.cs" Line="1" Column="1" /> <File FileName="NW4RTools/Models/VertexData.cs" Line="23" Column="6" /> + <File FileName="NW4RTools/Models/Node.cs" Line="27" Column="1" /> + <File FileName="NW4RTools/Models/Material.cs" Line="1" Column="1" /> + <File FileName="NW4RTools/ColladaWriter.cs" Line="184" Column="15" /> + <File FileName="NW4RTools/ResDict.cs" Line="1" Column="1" /> </Files> </MonoDevelop.Ide.Workbench> <MonoDevelop.Ide.DebuggingService.Breakpoints> diff --git a/NW4RTools/BrresReader.cs b/NW4RTools/BrresReader.cs index 288ff1e..fa3bf26 100644 --- a/NW4RTools/BrresReader.cs +++ b/NW4RTools/BrresReader.cs @@ -298,6 +298,8 @@ namespace NW4RTools { loadInfo.Name = ins.At(startPos + nameOffset - 4).ReadName(); NodeLoadData[startPos] = loadInfo; + Int32 extraDataOffset = ins.ReadInt32(); + n.NodeMatrix = ins.ReadMatrix(); n.NodeInvMatrix = ins.ReadMatrix(); diff --git a/NW4RTools/ColladaWriter.cs b/NW4RTools/ColladaWriter.cs index 794226f..c9412d3 100644 --- a/NW4RTools/ColladaWriter.cs +++ b/NW4RTools/ColladaWriter.cs @@ -51,7 +51,7 @@ namespace NW4RTools { } LibGeometries.geometry = GeometryList.ToArray(); - + // SHAPES ARE DONE. // Next up: Visual Scenes (I will just create one atm) @@ -65,22 +65,108 @@ namespace NW4RTools { mainScene.id = "RootNode"; mainScene.name = "RootNode"; var mainSceneNodeList = new List<node>(); - - // Right now: just make a node for each shape. + + // OK, so here's what's up: first off, we must create a definition for every node + var NodeDefs = new Dictionary<Node, node>(); + + foreach (var kv in CurrentModel.Nodes) { + string nodeName = kv.Key; + Node origNode = kv.Value; + var cNode = new node(); + + cNode.id = nodeName; + cNode.name = nodeName; + //cNode.type = NodeType.JOINT; + cNode.node1 = new node[0]; + + /*var origMatrix = origNode.NodeMatrix; + var nodeMatrix = new matrix(); + nodeMatrix.Values = new double[] { + origMatrix.v00, origMatrix.v01, origMatrix.v02, origMatrix.v03, + origMatrix.v10, origMatrix.v11, origMatrix.v12, origMatrix.v13, + origMatrix.v20, origMatrix.v21, origMatrix.v22, origMatrix.v23, + 0.0, 0.0, 0.0, 1.0 + }; + + cNode.Items = new object[] { nodeMatrix }; + cNode.ItemsElementName = new ItemsChoiceType2[] { ItemsChoiceType2.matrix };*/ + + var tScale = new TargetableFloat3(); + var tRotate = new rotate(); + var tTranslate = new TargetableFloat3(); + + tScale.Values = new double[] { + origNode.Scale.x, origNode.Scale.y, origNode.Scale.z + }; + + tRotate.Values = new double[] { + 0, 0, 0, 0 // TODO + }; + + tTranslate.Values = new double[] { + origNode.Translation.x, origNode.Translation.y, origNode.Translation.z + }; + + cNode.Items = new object[] { tScale, tRotate, tTranslate }; + cNode.ItemsElementName = new ItemsChoiceType2[] { + ItemsChoiceType2.scale, ItemsChoiceType2.rotate, + ItemsChoiceType2.translate + }; + + NodeDefs[origNode] = cNode; + } + + // Now add them to the hierarchy + foreach (var kv in NodeDefs) { + Node origNode = kv.Key; + node cNode = kv.Value; + + if (origNode.Parent == null) { + mainSceneNodeList.Add(cNode); + } else { + var parentNode = NodeDefs[origNode.Parent]; + + // this is stupid, thanks C# + node[] nodeArrayCopy = parentNode.node1; + Array.Resize<node>(ref nodeArrayCopy, nodeArrayCopy.Length + 1); + nodeArrayCopy[nodeArrayCopy.Length - 1] = cNode; + parentNode.node1 = nodeArrayCopy; + } + } + + // Apply shapes to nodes foreach (var kv in CurrentModel.Shapes) { + Shape shape = kv.Value; + Node origNode = CurrentModel.Nodes[CurrentModel.MatrixIDtoNodeID[shape.MatrixID]]; + node cNode = NodeDefs[origNode]; + + var newGeoEntry = new instance_geometry(); + newGeoEntry.name = kv.Key; + newGeoEntry.url = String.Format("#{0}-lib", kv.Key); + + instance_geometry[] geoArrayCopy = cNode.instance_geometry; + if (geoArrayCopy == null) + geoArrayCopy = new instance_geometry[1]; + else + Array.Resize<instance_geometry>(ref geoArrayCopy, geoArrayCopy.Length + 1); + geoArrayCopy[geoArrayCopy.Length - 1] = newGeoEntry; + cNode.instance_geometry = geoArrayCopy; + } + + /*foreach (var kv in CurrentModel.Shapes) { var thisNode = new node(); - + thisNode.id = kv.Key; thisNode.name = kv.Key; thisNode.instance_geometry = new instance_geometry[1]; thisNode.instance_geometry[0] = new instance_geometry(); thisNode.instance_geometry[0].url = String.Format("#{0}-lib", kv.Key); - + mainSceneNodeList.Add(thisNode); - } + }*/ mainScene.node = mainSceneNodeList.ToArray(); - + // Finally, create a scene Collada.scene = new COLLADAScene(); @@ -192,7 +278,7 @@ namespace NW4RTools { nrmArray.Values[dest++] = data[j]; } } - + nrmSource.Item = nrmArray; // Write normal technique @@ -368,7 +454,7 @@ namespace NW4RTools { Console.WriteLine("UNIMPLEMENTED PRIMITIVE TYPE"); - return; + return geo; } } diff --git a/NW4RTools/NW4RTools.pidb b/NW4RTools/NW4RTools.pidb Binary files differindex d136108..c5ab445 100644 --- a/NW4RTools/NW4RTools.pidb +++ b/NW4RTools/NW4RTools.pidb diff --git a/NW4RTools/bin/Debug/NW4RTools.dll b/NW4RTools/bin/Debug/NW4RTools.dll Binary files differindex 85d9abd..1b431d2 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 f87c22c..d635b92 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 a4d9545..1196f08 100644 --- a/TestApp/Main.cs +++ b/TestApp/Main.cs @@ -7,9 +7,13 @@ namespace TestApp { public static void Main(string[] args) { string mdlPath = "/home/me/Games/Newer/ModelRev/"; - string mdlName = "CS_W1"; + // NOTE: CS_W7 is broken!! + + string mdlName = "CS_W7"; //string mdlName = "bgB_4502"; + string whatever = (mdlName == "CS_W2" || mdlName == "CS_W3" || mdlName == "CS_W6") ? "a" : ""; + byte[] file = File.ReadAllBytes(mdlPath + mdlName + ".brres"); ResFile rf = BrresReader.LoadFile(file); @@ -17,7 +21,7 @@ namespace TestApp { var objFile = File.Open(mdlPath + mdlName + ".dae", FileMode.OpenOrCreate); //var sw = new StreamWriter(objFile); //ObjWriter.WriteModel(sw, rf, mdlName); - ColladaWriter.WriteModel(objFile, rf, mdlName); + ColladaWriter.WriteModel(objFile, rf, mdlName + whatever); objFile.Close(); } } diff --git a/TestApp/TestApp.pidb b/TestApp/TestApp.pidb Binary files differindex e277998..d59d1d6 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 85d9abd..1b431d2 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 f87c22c..d635b92 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 c53c4cf..7dc9d18 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 6f4ba2c..1e26877 100644 --- a/TestApp/bin/Debug/TestApp.exe.mdb +++ b/TestApp/bin/Debug/TestApp.exe.mdb |