From f809b701c4116fc993d449a8b36e395b55984f42 Mon Sep 17 00:00:00 2001 From: Treeki Date: Sat, 12 Feb 2011 13:53:39 +0100 Subject: half-assed node support --- NW4RTools.userprefs | 14 +++-- NW4RTools/BrresReader.cs | 2 + NW4RTools/ColladaWriter.cs | 104 +++++++++++++++++++++++++++++++--- NW4RTools/NW4RTools.pidb | Bin 525316 -> 525525 bytes NW4RTools/bin/Debug/NW4RTools.dll | Bin 157696 -> 158720 bytes NW4RTools/bin/Debug/NW4RTools.dll.mdb | Bin 87412 -> 87798 bytes TestApp/Main.cs | 8 ++- TestApp/TestApp.pidb | Bin 3039 -> 3039 bytes TestApp/bin/Debug/NW4RTools.dll | Bin 157696 -> 158720 bytes TestApp/bin/Debug/NW4RTools.dll.mdb | Bin 87412 -> 87798 bytes TestApp/bin/Debug/TestApp.exe | Bin 4096 -> 4096 bytes 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 @@  - + - - - - + + + + @@ -13,6 +13,10 @@ + + + + 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(); - - // 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(); + + 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(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(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 index d136108..c5ab445 100644 Binary files a/NW4RTools/NW4RTools.pidb and b/NW4RTools/NW4RTools.pidb differ diff --git a/NW4RTools/bin/Debug/NW4RTools.dll b/NW4RTools/bin/Debug/NW4RTools.dll index 85d9abd..1b431d2 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 f87c22c..d635b92 100644 Binary files a/NW4RTools/bin/Debug/NW4RTools.dll.mdb and b/NW4RTools/bin/Debug/NW4RTools.dll.mdb differ 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 index e277998..d59d1d6 100644 Binary files a/TestApp/TestApp.pidb and b/TestApp/TestApp.pidb differ diff --git a/TestApp/bin/Debug/NW4RTools.dll b/TestApp/bin/Debug/NW4RTools.dll index 85d9abd..1b431d2 100755 Binary files a/TestApp/bin/Debug/NW4RTools.dll and b/TestApp/bin/Debug/NW4RTools.dll differ diff --git a/TestApp/bin/Debug/NW4RTools.dll.mdb b/TestApp/bin/Debug/NW4RTools.dll.mdb index f87c22c..d635b92 100644 Binary files a/TestApp/bin/Debug/NW4RTools.dll.mdb and b/TestApp/bin/Debug/NW4RTools.dll.mdb differ diff --git a/TestApp/bin/Debug/TestApp.exe b/TestApp/bin/Debug/TestApp.exe index c53c4cf..7dc9d18 100755 Binary files a/TestApp/bin/Debug/TestApp.exe and b/TestApp/bin/Debug/TestApp.exe differ diff --git a/TestApp/bin/Debug/TestApp.exe.mdb b/TestApp/bin/Debug/TestApp.exe.mdb index 6f4ba2c..1e26877 100644 Binary files a/TestApp/bin/Debug/TestApp.exe.mdb and b/TestApp/bin/Debug/TestApp.exe.mdb differ -- cgit v1.2.3