diff options
Diffstat (limited to '')
-rw-r--r-- | NW4RTools.userprefs | 20 | ||||
-rw-r--r-- | NW4RTools/ColladaWriter.cs | 122 | ||||
-rw-r--r-- | NW4RTools/NW4RTools.pidb | bin | 530650 -> 531637 bytes | |||
-rw-r--r-- | NW4RTools/Texture.cs | 18 | ||||
-rw-r--r-- | NW4RTools/Util/IOrderedDictionary.cs | 3 | ||||
-rw-r--r-- | NW4RTools/Util/OrderedDictionary.cs | 6 | ||||
-rwxr-xr-x | NW4RTools/bin/Debug/NW4RTools.dll | bin | 164864 -> 166400 bytes | |||
-rw-r--r-- | NW4RTools/bin/Debug/NW4RTools.dll.mdb | bin | 90336 -> 90788 bytes |
8 files changed, 151 insertions, 18 deletions
diff --git a/NW4RTools.userprefs b/NW4RTools.userprefs index 895a11a..843535e 100644 --- a/NW4RTools.userprefs +++ b/NW4RTools.userprefs @@ -1,22 +1,14 @@ <Properties> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" /> - <MonoDevelop.Ide.Workbench ActiveDocument="NW4RTools/BrresReader.cs"> + <MonoDevelop.Ide.Workbench ActiveDocument="TestApp/Main.cs"> <Files> - <File FileName="NW4RTools/ObjWriter.cs" Line="164" Column="3" /> - <File FileName="TestApp/Main.cs" Line="10" Column="30" /> - <File FileName="NW4RTools/BrresReader.cs" Line="652" Column="66" /> - <File FileName="NW4RTools/Models/Shape.cs" Line="30" Column="1" /> - <File FileName="NW4RTools/Models/Model.cs" Line="33" Column="39" /> - <File FileName="NW4RTools/InputStream.cs" Line="1" Column="1" /> - <File FileName="NW4RTools/Models/ByteCode.cs" Line="1" Column="1" /> - <File FileName="NW4RTools/VertexSettings.cs" Line="102" Column="1" /> - <File FileName="NW4RTools/Logger.cs" Line="1" Column="1" /> - <File FileName="NW4RTools/Enums.cs" Line="1" Column="1" /> - <File FileName="NW4RTools/Models/VertexData.cs" Line="23" Column="6" /> + <File FileName="TestApp/Main.cs" Line="11" Column="27" /> + <File FileName="NW4RTools/BrresReader.cs" Line="266" Column="1" /> + <File FileName="NW4RTools/Enums.cs" Line="13" Column="1" /> <File FileName="NW4RTools/Models/Node.cs" Line="27" Column="1" /> <File FileName="NW4RTools/Models/Material.cs" Line="1" Column="1" /> - <File FileName="NW4RTools/ColladaWriter.cs" Line="184" Column="15" /> - <File FileName="NW4RTools/ResDict.cs" Line="1" Column="1" /> + <File FileName="NW4RTools/ColladaWriter.cs" Line="376" Column="37" /> + <File FileName="NW4RTools/Texture.cs" Line="263" Column="102" /> </Files> </MonoDevelop.Ide.Workbench> <MonoDevelop.Ide.DebuggingService.Breakpoints> diff --git a/NW4RTools/ColladaWriter.cs b/NW4RTools/ColladaWriter.cs index b7c039a..f0f5b19 100644 --- a/NW4RTools/ColladaWriter.cs +++ b/NW4RTools/ColladaWriter.cs @@ -69,7 +69,7 @@ namespace NW4RTools { img.name = "Texture-" + texName; img.id = img.name; - img.Item = texName + ".png"; + img.Item = "./images/" + texName + ".png"; ImageList.Add(img); } @@ -193,7 +193,7 @@ namespace NW4RTools { } // Apply shapes to nodes - foreach (var kv in CurrentModel.Shapes) { + /*foreach (var kv in CurrentModel.Shapes) { Shape shape = kv.Value; Node origNode = CurrentModel.Nodes[CurrentModel.MatrixIDtoNodeID[shape.MatrixID]]; node cNode = NodeDefs[origNode]; @@ -211,8 +211,107 @@ namespace NW4RTools { cNode.instance_geometry = geoArrayCopy; // TODO: Add material handling, I'll probably have to parse DrawOpa/DrawXlu for this... + }*/ + + // WARNING: THIS NEEDS REFACTORING + + int drawID = 0; + + foreach (var insn in CurrentModel.Bytecode["DrawOpa"].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); + + Node origNode = CurrentModel.Nodes[dsInsn.NodeID]; + node cNode = NodeDefs[origNode]; + + Material mat = CurrentModel.Materials[dsInsn.MaterialID]; + string matName = CurrentModel.Materials.GetKeyForIndex(dsInsn.MaterialID); + + var newGeoEntry = new instance_geometry(); + newGeoEntry.name = String.Format("DrawOpa{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(); + + // 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; + + // 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 = 0; + + 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); + + Node origNode = CurrentModel.Nodes[dsInsn.NodeID]; + node cNode = NodeDefs[origNode]; + + 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); + + // 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; + + 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; + + drawID++; + } } + /*foreach (var kv in CurrentModel.Shapes) { var thisNode = new node(); @@ -277,10 +376,27 @@ namespace NW4RTools { sampler2d.source = "Surface-" + mat.TextureInfos[0].TextureName; + samplerParam.sid = "Sampler-" + mat.TextureInfos[0].TextureName; samplerParam.ItemElementName = ItemChoiceType.sampler2D; samplerParam.Item = sampler2d; profile.Items[1] = samplerParam; + // now make a technique + // should I really use blinn...? + profile.technique = new effectFx_profile_abstractProfile_COMMONTechnique(); + profile.technique.sid = "common"; + + var pShader = new effectFx_profile_abstractProfile_COMMONTechniquePhong(); + pShader.diffuse = new common_color_or_texture_type(); + + var diffuseTex = new common_color_or_texture_typeTexture(); + diffuseTex.texture = "Sampler-" + mat.TextureInfos[0].TextureName; + diffuseTex.texcoord = "CHANNEL1"; + + pShader.diffuse.Item = diffuseTex; + + profile.technique.Item = pShader; + return eff; } @@ -529,6 +645,7 @@ namespace NW4RTools { switch (prim) { case PrimitiveType.Triangles: var pTri = new triangles(); + pTri.material = "NW4R_MATERIAL"; pTri.count = (ulong)(vtxCount / 3); // should be 1? dunno pTri.input = inputArray; @@ -567,6 +684,7 @@ namespace NW4RTools { // If any tristrips were found, add them! if (triStrips.Count > 0) { var pTriStrips = new tristrips(); + pTriStrips.material = "NW4R_MATERIAL"; pTriStrips.input = inputArray; pTriStrips.count = (ulong)triStrips.Count; pTriStrips.p = triStrips.ToArray(); diff --git a/NW4RTools/NW4RTools.pidb b/NW4RTools/NW4RTools.pidb Binary files differindex 5cd6dc3..ff53d24 100644 --- a/NW4RTools/NW4RTools.pidb +++ b/NW4RTools/NW4RTools.pidb diff --git a/NW4RTools/Texture.cs b/NW4RTools/Texture.cs index 954852d..2de9ad8 100644 --- a/NW4RTools/Texture.cs +++ b/NW4RTools/Texture.cs @@ -137,6 +137,8 @@ namespace NW4RTools { case TextureFormat.RGB5A3: case TextureFormat.I4: case TextureFormat.I8: + case TextureFormat.IA4: + case TextureFormat.IA8: // I4 is stupid and breaks my parser. I'll keep some state here bool alreadyHaveI4Nybble = false; byte currentI4Byte = 0; @@ -194,6 +196,18 @@ namespace NW4RTools { } else if (format == TextureFormat.I8) { byte val = data.ReadByte(); *pPixel = 0xFF000000 | (uint)(val << 16) | (uint)(val << 8) | val; + + } else if (format == TextureFormat.IA4) { + byte val = data.ReadByte(); + uint i = (uint)(val >> 4); + uint a = (uint)((val & 0xF0) << 4); + *pPixel = (a << 24) | (i << 16) | (i << 8) | i; + + } else if (format == TextureFormat.IA8) { + byte i = data.ReadByte(); + byte a = data.ReadByte(); + *pPixel = (uint)(a << 24) | (uint)(i << 16) | (uint)(i << 8) | i; + } } } @@ -259,7 +273,9 @@ namespace NW4RTools { image.UnlockBits(bits); - + + image.RotateFlip(RotateFlipType.RotateNoneFlipY); // TODO: remove this, and fix texcoords properly + BaseImage = image; Format = format; } diff --git a/NW4RTools/Util/IOrderedDictionary.cs b/NW4RTools/Util/IOrderedDictionary.cs index a574c7c..6cf9b85 100644 --- a/NW4RTools/Util/IOrderedDictionary.cs +++ b/NW4RTools/Util/IOrderedDictionary.cs @@ -55,5 +55,8 @@ namespace NW4RTools.Util get;
set;
}
+
+
+ TKey GetKeyForIndex(int index);
}
}
diff --git a/NW4RTools/Util/OrderedDictionary.cs b/NW4RTools/Util/OrderedDictionary.cs index 3dd4fb4..98e523a 100644 --- a/NW4RTools/Util/OrderedDictionary.cs +++ b/NW4RTools/Util/OrderedDictionary.cs @@ -162,11 +162,15 @@ namespace NW4RTools.Util return List.GetEnumerator();
}
- IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey,TValue>>.GetEnumerator()
+ IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator()
{
return List.GetEnumerator();
}
+ public TKey GetKeyForIndex(int index) {
+ return List[index].Key;
+ }
+
/// <summary>
/// Inserts a new entry into the <see cref="OrderedDictionary{TKey,TValue}">OrderedDictionary<TKey,TValue></see> collection with the specified key and value at the specified index.
/// </summary>
diff --git a/NW4RTools/bin/Debug/NW4RTools.dll b/NW4RTools/bin/Debug/NW4RTools.dll Binary files differindex a87dfa6..91a4b75 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 4b18386..127ef0f 100644 --- a/NW4RTools/bin/Debug/NW4RTools.dll.mdb +++ b/NW4RTools/bin/Debug/NW4RTools.dll.mdb |