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/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 5 files changed, 97 insertions(+), 9 deletions(-) (limited to 'NW4RTools') 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 -- cgit v1.2.3