diff options
author | Treeki <treeki@gmail.com> | 2011-03-10 03:00:09 +0100 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2011-03-10 03:00:09 +0100 |
commit | 5926616de2bd346f1a1c69c93ff2aaa3c453a2b3 (patch) | |
tree | f282b05ae5616a05fb4db167fad20ec242775c27 /NW4RTools/ColladaExporter.cs | |
parent | 7d391e33a0b3d9793c95fce832abb2c6d9002186 (diff) | |
download | nw4rtools-5926616de2bd346f1a1c69c93ff2aaa3c453a2b3.tar.gz nw4rtools-5926616de2bd346f1a1c69c93ff2aaa3c453a2b3.zip |
kinda hackish, but mostly working NSMBW lightmap support
Diffstat (limited to '')
-rw-r--r-- | NW4RTools/ColladaExporter.cs | 72 |
1 files changed, 37 insertions, 35 deletions
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<instance_geometry>(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<instance_geometry>(ref geoArrayCopy, geoArrayCopy.Length + 1); + geoArrayCopy[geoArrayCopy.Length - 1] = newGeoEntry; + cNode.instance_geometry = geoArrayCopy; - drawID++; + drawID++; + } } } |