From 5926616de2bd346f1a1c69c93ff2aaa3c453a2b3 Mon Sep 17 00:00:00 2001 From: Treeki Date: Thu, 10 Mar 2011 03:00:09 +0100 Subject: kinda hackish, but mostly working NSMBW lightmap support --- NW4RTools/ColladaExporter.cs | 72 +++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 35 deletions(-) (limited to 'NW4RTools/ColladaExporter.cs') diff --git a/NW4RTools/ColladaExporter.cs b/NW4RTools/ColladaExporter.cs index f18bfed..cd5aaf1 100644 --- a/NW4RTools/ColladaExporter.cs +++ b/NW4RTools/ColladaExporter.cs @@ -264,50 +264,52 @@ namespace NW4RTools { } drawID = 0; - - foreach (var insn in CurrentModel.Bytecode["DrawXlu"].Instructions) { - if (insn is ByteCode.DrawShapeInstruction) { - var dsInsn = insn as ByteCode.DrawShapeInstruction; + + if (CurrentModel.Bytecode.ContainsKey("DrawXlu")) { + foreach (var insn in CurrentModel.Bytecode["DrawXlu"].Instructions) { + if (insn is ByteCode.DrawShapeInstruction) { + var dsInsn = insn as ByteCode.DrawShapeInstruction; - Shape shape = CurrentModel.Shapes[dsInsn.ShapeID]; - string shapeName = CurrentModel.Shapes.GetKeyForIndex(dsInsn.ShapeID); + Shape shape = CurrentModel.Shapes[dsInsn.ShapeID]; + string shapeName = CurrentModel.Shapes.GetKeyForIndex(dsInsn.ShapeID); - Node origNode = CurrentModel.Nodes[dsInsn.NodeID]; - node cNode = NodeDefs[origNode]; + Node origNode = CurrentModel.Nodes[dsInsn.NodeID]; + node cNode = NodeDefs[origNode]; - Material mat = CurrentModel.Materials[dsInsn.MaterialID]; - string matName = CurrentModel.Materials.GetKeyForIndex(dsInsn.MaterialID); + Material mat = CurrentModel.Materials[dsInsn.MaterialID]; + string matName = CurrentModel.Materials.GetKeyForIndex(dsInsn.MaterialID); - var newGeoEntry = new instance_geometry(); - newGeoEntry.name = String.Format("DrawXlu{0}-{1}", drawID, shapeName); - newGeoEntry.url = String.Format("#{0}-lib", shapeName); + var newGeoEntry = new instance_geometry(); + newGeoEntry.name = String.Format("DrawXlu{0}-{1}", drawID, shapeName); + newGeoEntry.url = String.Format("#{0}-lib", shapeName); - // now add the material - var bindMaterial = newGeoEntry.bind_material = new bind_material(); - bindMaterial.technique_common = new instance_material[1]; - var matTechnique = bindMaterial.technique_common[0] = new instance_material(); + // now add the material + var bindMaterial = newGeoEntry.bind_material = new bind_material(); + bindMaterial.technique_common = new instance_material[1]; + var matTechnique = bindMaterial.technique_common[0] = new instance_material(); - // constant marker so that I don't have to set a unique material name in each primitive - // it doesn't matter, since each geometry instance only uses one material anyway - matTechnique.symbol = "NW4R_MATERIAL"; - matTechnique.target = "#Material-" + matName; + // constant marker so that I don't have to set a unique material name in each primitive + // it doesn't matter, since each geometry instance only uses one material anyway + matTechnique.symbol = "NW4R_MATERIAL"; + matTechnique.target = "#Material-" + matName; - matTechnique.bind_vertex_input = new instance_materialBind_vertex_input[1]; - matTechnique.bind_vertex_input[0] = new instance_materialBind_vertex_input(); - matTechnique.bind_vertex_input[0].semantic = "CHANNEL1"; - matTechnique.bind_vertex_input[0].input_semantic = "TEXCOORD"; - matTechnique.bind_vertex_input[0].input_set = 0; + matTechnique.bind_vertex_input = new instance_materialBind_vertex_input[1]; + matTechnique.bind_vertex_input[0] = new instance_materialBind_vertex_input(); + matTechnique.bind_vertex_input[0].semantic = "CHANNEL1"; + matTechnique.bind_vertex_input[0].input_semantic = "TEXCOORD"; + matTechnique.bind_vertex_input[0].input_set = 0; - // ok, now add the instance_geometry into the node - 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; + // ok, now add the instance_geometry into the node + 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; - drawID++; + drawID++; + } } } -- cgit v1.2.3