diff options
Diffstat (limited to 'NW4RTools')
-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 |
5 files changed, 97 insertions, 9 deletions
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 |