diff options
author | Treeki <treeki@gmail.com> | 2012-09-24 21:55:47 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2012-09-24 21:55:47 +0200 |
commit | 57459fda5c237873f287a0a600dd0daee666fe4d (patch) | |
tree | eeaecdbf31657b5aefaf79d058c20bdc61a44655 | |
parent | c9bfbf84244c8aa4e26ece994ef6b93386c708e3 (diff) | |
download | nw4rtools-57459fda5c237873f287a0a600dd0daee666fe4d.tar.gz nw4rtools-57459fda5c237873f287a0a600dd0daee666fe4d.zip |
a cat
Diffstat (limited to '')
-rwxr-xr-x | TestApp/Main.cs | 260 |
1 files changed, 247 insertions, 13 deletions
diff --git a/TestApp/Main.cs b/TestApp/Main.cs index 76329b7..e9d0663 100755 --- a/TestApp/Main.cs +++ b/TestApp/Main.cs @@ -11,19 +11,19 @@ using OpenTK.Graphics.OpenGL; namespace TestApp { class MainClass { public static void Main(string[] args) { - ResFile shits = BrresReader.LoadFile(File.ReadAllBytes("Z:/stuff/Games/Newer/bros.brres")); - ColladaExporter.WriteModel(File.OpenWrite("Z:/stuff/Games/Newer/bros.dae"), shits, "bros"); - //ResFile shits = BrresReader.LoadFile(File.ReadAllBytes("/home/me/Games/Newer/bros.brres")); - //ColladaExporter.WriteModel(File.OpenWrite("/home/me/Games/Newer/bros.dae"), shits, "bros");
- return; - - striphammer(); - return; - - fuckskawo(); - return; - - ewater(); +// ResFile shits = BrresReader.LoadFile(File.ReadAllBytes("Z:/stuff/Games/Newer/bros.brres")); +// ColladaExporter.WriteModel(File.OpenWrite("Z:/stuff/Games/Newer/bros.dae"), shits, "bros"); +// //ResFile shits = BrresReader.LoadFile(File.ReadAllBytes("/home/me/Games/Newer/bros.brres")); +// //ColladaExporter.WriteModel(File.OpenWrite("/home/me/Games/Newer/bros.dae"), shits, "bros");
+// return; +// +// striphammer(); +// return; +// +// fuckskawo(); +// return; +// + elava(); return; blah(args); @@ -420,6 +420,240 @@ namespace TestApp { } + private static void elava() { + string mdlPath = getPath(); + + ResFile rf = BrresReader.LoadFile(File.ReadAllBytes(mdlPath + "CS_W8.brres")); + Model m = rf.GetModelGroup()["CS_W8"]; + + foreach (var kv in m.Shapes) { + var s = kv.Value; + Console.WriteLine("{0} : {1}", + kv.Key, + m.VtxPosData.GetKeyForValue(s.PosData)); + } + + var tgrp = rf.GetTextureGroup(); + var texremove = new List<string>(); + var texkeep = new Dictionary<string, bool>(); + texkeep.Add("W3a_water01", true); + texkeep.Add("wmy_objmagma03", true); + texkeep.Add("W8_cap128", true); + texkeep.Add("id02", true); + //texkeep.Add("texMask", true); + foreach (var k in tgrp.Keys) + if (!texkeep.ContainsKey(k)) + texremove.Add(k); + foreach (var k in texremove) + tgrp.Remove(k); + + rf.Remove("AnmClr(NW4R)"); + rf.Remove("AnmChr(NW4R)"); + + var tsanmg = rf.GetGroup<TextureSRTAnim>("AnmTexSrt(NW4R)"); + var tsanm = tsanmg["CS_W8"]; + tsanmg.RemoveAt(0); + tsanmg.Add("KpBG", tsanm); + + var anmnoderemove = new List<string>(); + foreach (var k in tsanm.Nodes.Keys) + if (k != "mtYogan_neo") + anmnoderemove.Add(k); + foreach (var k in anmnoderemove) + tsanm.Nodes.Remove(k); + + rf.GetModelGroup().RemoveAt(0); + rf.GetModelGroup()["KpBG"] = m; + + // Make bytecode + m.MatrixIDtoNodeID = new int[1]; + m.MatrixIDtoNodeID[0] = 0; + + // Now put together the NodeTree + var nodeTreeInsn = new ByteCode.AssignNodeToParentMtxInstruction(); + nodeTreeInsn.NodeID = 0; + nodeTreeInsn.ParentMatrixID = 0; + + var done = new ByteCode.DoneInstruction(); + + var nodeTree = new ByteCode(); + nodeTree.Instructions.Add(nodeTreeInsn); + nodeTree.Instructions.Add(done); + + m.Bytecode["NodeTree"] = nodeTree; + + // Also, DrawOpa + var drawOpa = new ByteCode(); + var shapeInsn = new ByteCode.DrawShapeInstruction(); + shapeInsn.ShapeID = 0; + shapeInsn.NodeID = 0; + shapeInsn.MaterialID = 0; + drawOpa.Instructions.Add(shapeInsn); + drawOpa.Instructions.Add(done); + m.Bytecode["DrawOpa"] = drawOpa; + + var drawXlu = new ByteCode(); + drawXlu.Instructions.Add(done); + m.Bytecode["DrawXlu"] = drawXlu; + + + // Clean up other shit + var seashape = m.Shapes["polygon215"]; + var posd = seashape.PosData; + var nrmd = seashape.NrmData; + var clrd = seashape.ClrData; + var tcd = seashape.TexCoordData; + + var nnod = new ResDict<Node>(); + var nshp = new ResDict<Shape>(); + var nshd = new ResDict<Shader>(); + var nmat = new ResDict<Material>(); + var npos = new ResDict<VertexPosData>(); + var nnrm = new ResDict<VertexNrmData>(); + var nclr = new ResDict<VertexClrData>(); + var ntc = new ResDict<VertexTexCoordData>(); + + Node rn = m.Nodes["CS_W8"]; + rn.FirstChild = null; + nnod["RootNode"] = rn; + nshp["lavapoly"] = seashape; + nshd["mtYogan_neo"] = m.Shaders["mtYogan_neo"]; + nmat["mtYogan_neo"] = m.Materials["mtYogan_neo"]; + + if (posd != null) { + npos[m.VtxPosData.GetKeyForValue(posd)] = posd; + } + + if (nrmd != null) { + nnrm[m.VtxNrmData.GetKeyForValue(nrmd)] = nrmd; + } + + foreach (var t in clrd) { + if (t != null) { + nclr[m.VtxClrData.GetKeyForValue(t)] = t; + } + } + + foreach (var t in tcd) { + if (t != null) { + ntc[m.VtxTexCoordData.GetKeyForValue(t)] = t; + } + } + + m.Nodes = nnod; + m.Shapes = nshp; + m.Shaders = nshd; + m.Materials = nmat; + m.VtxPosData = npos; + m.VtxNrmData = nnrm; + m.VtxClrData = nclr; + m.VtxTexCoordData = ntc; + + m.PairingLookupByTexture = new ResDict<List<TexMatPairing>>(); + m.PairingLookupByPalette = new ResDict<List<TexMatPairing>>(); + + // NEW + var dl = new DisplayListWriter(); + dl.BeginPrimitives(PrimitiveType.Quads, 0, 4); + dl.WriteByte(0); + dl.WriteByte(0); + dl.WriteByte(1); + dl.WriteByte(1); + dl.WriteByte(2); + dl.WriteByte(2); + dl.WriteByte(3); + dl.WriteByte(3); + dl.End(); + seashape.DisplayList2 = dl.GetBuffer(); + seashape.DLBufferSize2 = (uint)seashape.DisplayList2.Length; + var shape = seashape; + + float w = 200000, h = 100000; + float sw = 600, sh = 600; + float ow = -480, oh = 480; + + posd.EntryCount = 4; + posd.Data = new float[][] { + new float[] { ow, (-h) + oh, -40 }, + new float[] { ow, oh, -40 }, + new float[] { ow + w, oh, -40 }, + new float[] { ow + w, (-h) + oh, -40 } + }; + posd.EntrySize = 12; + posd.Fraction = 0; + posd.ComponentType = VertexSettings.CompType.Float32; + posd.Save(); + + tcd[0].EntryCount = 4; + tcd[0].Fraction = 0; + tcd[0].Data = new float[][] { + new float[] { 0, 0 }, + new float[] { sw, 0 }, + new float[] { sw, sh }, + new float[] { 0, sh } + }; + tcd[0].Save(); + /* posd.Data = new float[][] { + new float[] { 0, -40, h }, + new float[] { 0, -40, 0 }, + new float[] { w, -40, 0 }, + new float[] { w, -40, h } + };*/ + + var vs = new VertexSettings(); + vs.PositionDesc = VertexSettings.DescType.Index8; + vs.PositionFormat = VertexSettings.CompType.Float32; + vs.PositionCount = VertexSettings.CompCount.Position3; + + vs.TexCoordDesc[0] = VertexSettings.DescType.Index8; + vs.TexCoordFormat[0] = VertexSettings.CompType.Int16; + vs.TexCoordCount[0] = VertexSettings.CompCount.TexCoord2; + vs.TexCoordFrac[0] = 0; + + uint vd1, vd2, vat1, vat2, vat3; + vs.GetDesc(out vd1, out vd2); + vs.GetAttrFmt(out vat1, out vat2, out vat3); + + byte vtxSpecs = 1 << 4; + // setting up Unk in the hopes it will work, I think this is what it's for.. + var unkStream = new OutputStream(); + unkStream.WriteUInt32(vd1); + unkStream.WriteUInt32(vd2); + unkStream.WriteUInt32(vtxSpecs); + shape.Unk = unkStream.GetBuffer(); + + // now make the display list + var dl1 = new DisplayListWriter(); + dl1.AddPadding(10); + dl1.LoadCPReg(0x50, vd1); + dl1.LoadCPReg(0x60, vd2); + dl1.LoadXFReg(0x1008, new byte[] { 0x00, 0x00, 0x00, vtxSpecs }); + dl1.Nop(); + dl1.LoadCPReg(0x70, vat1); + dl1.LoadCPReg(0x80, vat2); + dl1.LoadCPReg(0x90, vat3); + + // extend it + // should it be bigger if more texcoords are used? maybe... + dl1.PadToSize(0x80); + dl1.End(); + + shape.DLBufferSize1 = 0xE0; + shape.DisplayList1 = dl1.GetBuffer(); + + + +// var texmask = tgrp["texMask"].Images[0]; +// var g = System.Drawing.Graphics.FromImage(texmask); +// g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.White), 0, 0, texmask.Width, texmask.Height); +// g.Dispose(); + + + // END NEW + + File.WriteAllBytes(mdlPath + "Lava.brres", BrresWriter.WriteFile(rf)); + } + private static string getPath() { if (Directory.Exists("/home/me")) return "/home/me/Games/Newer/WaterL/"; |