summaryrefslogtreecommitdiff
path: root/NW4RTools/ColladaWriter.cs
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-02-12 13:53:39 +0100
committerTreeki <treeki@gmail.com>2011-02-12 13:53:39 +0100
commitf809b701c4116fc993d449a8b36e395b55984f42 (patch)
tree5ee4417571b97dfcee4b17a8230ef16737a7382e /NW4RTools/ColladaWriter.cs
parent3b5195f442b263807dda1675b05e0301c902c58f (diff)
downloadnw4rtools-f809b701c4116fc993d449a8b36e395b55984f42.tar.gz
nw4rtools-f809b701c4116fc993d449a8b36e395b55984f42.zip
half-assed node support
Diffstat (limited to 'NW4RTools/ColladaWriter.cs')
-rw-r--r--NW4RTools/ColladaWriter.cs104
1 files changed, 95 insertions, 9 deletions
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;
}
}