diff options
Diffstat (limited to 'NW4RTools/ObjImporter.cs')
-rwxr-xr-x | NW4RTools/ObjImporter.cs | 309 |
1 files changed, 218 insertions, 91 deletions
diff --git a/NW4RTools/ObjImporter.cs b/NW4RTools/ObjImporter.cs index 81fcf81..1606028 100755 --- a/NW4RTools/ObjImporter.cs +++ b/NW4RTools/ObjImporter.cs @@ -239,86 +239,165 @@ namespace NW4RTools { // Create a new material and initialise everything
// Default settings taken from Test_Lift material
currentMaterial = new Material();
-
- currentMaterial.TexCoordGenCount = 1;
- currentMaterial.ChanCount = 1;
- currentMaterial.TevStageCount = 2;
- currentMaterial.IndStageCount = 0;
-
- // This might need changing
- currentMaterial.CullMode = 2;
-
- currentMaterial.SRTSettings[0] = new SRTSettingInfo();
-
- currentMaterial.ChanCtrls[0] = new ChanCtrl();
- currentMaterial.ChanCtrls[0].Flags = 0x3F;
- currentMaterial.ChanCtrls[0].MatColor.Rgba = 0xFFFFFFFF;
- currentMaterial.ChanCtrls[0].AmbColor.Rgba = 0xFFFFFFFF;
- currentMaterial.ChanCtrls[0].FlagC = 0x702;
- currentMaterial.ChanCtrls[0].FlagA = 0x700;
-
- currentMaterial.ChanCtrls[1] = new ChanCtrl();
- currentMaterial.ChanCtrls[1].Flags = 0xF;
- currentMaterial.ChanCtrls[1].MatColor.Rgba = 0x000000FF;
- currentMaterial.ChanCtrls[1].AmbColor.Rgba = 0x00000000;
- currentMaterial.ChanCtrls[1].FlagC = 0;
+ + currentMaterial.ChanCtrls[0] = new ChanCtrl(); + currentMaterial.ChanCtrls[0].Flags = 0x3F; + currentMaterial.ChanCtrls[0].MatColor.Rgba = 0xFFFFFFFF; + currentMaterial.ChanCtrls[0].AmbColor.Rgba = 0xFFFFFFFF; + currentMaterial.ChanCtrls[0].FlagC = Lightmaps ? (uint)0x701 : (uint)0x702; + currentMaterial.ChanCtrls[0].FlagA = 0x700; + + currentMaterial.ChanCtrls[1] = new ChanCtrl(); + currentMaterial.ChanCtrls[1].Flags = 0xF; + currentMaterial.ChanCtrls[1].MatColor.Rgba = 0x000000FF; + currentMaterial.ChanCtrls[1].AmbColor.Rgba = 0x00000000; + currentMaterial.ChanCtrls[1].FlagC = 0; currentMaterial.ChanCtrls[1].FlagA = 0; - currentMaterial.LightSetID = 1;
+ if (!Lightmaps) {
+ currentMaterial.TexCoordGenCount = 1;
+ currentMaterial.ChanCount = 1;
+ currentMaterial.TevStageCount = 2;
+ currentMaterial.IndStageCount = 0;
+
+ // This might need changing
+ currentMaterial.CullMode = 2;
+ + currentMaterial.LightSetID = 1; + + currentMaterial.SRTSettings[0] = new SRTSettingInfo();
- // Default display lists, taken from test_lift
- var pixDL = new DisplayListWriter(); - pixDL.LoadBPReg(0xF31EFF80); - pixDL.LoadBPReg(0x40000017); - pixDL.LoadBPReg(0xFE00FFE3); - pixDL.LoadBPReg(0x410034A0); - pixDL.LoadBPReg(0x42000000); - pixDL.End(); - - currentMaterial.PixDL = pixDL.GetBuffer(); - - var tevColorDL = new DisplayListWriter(); - tevColorDL.LoadBPReg(0xE20000FF); - tevColorDL.LoadBPReg(0xE30FF0FF); - tevColorDL.LoadBPReg(0xE30FF0FF); - tevColorDL.LoadBPReg(0xE30FF0FF); - tevColorDL.LoadBPReg(0xE4000000); - tevColorDL.LoadBPReg(0xE5000000); - tevColorDL.LoadBPReg(0xE5000000); - tevColorDL.LoadBPReg(0xE5000000); - tevColorDL.LoadBPReg(0xE6000000); - tevColorDL.LoadBPReg(0xE7000000); - tevColorDL.LoadBPReg(0xE7000000); - tevColorDL.LoadBPReg(0xE7000000); - tevColorDL.AddPadding(4); - tevColorDL.LoadBPReg(0xE0800000); - tevColorDL.LoadBPReg(0xE1800000); - tevColorDL.LoadBPReg(0xE2800000); - tevColorDL.LoadBPReg(0xE3800000); - tevColorDL.LoadBPReg(0xE4800000); - tevColorDL.LoadBPReg(0xE5800000); - tevColorDL.LoadBPReg(0xE6800000); - tevColorDL.LoadBPReg(0xE7800000); - tevColorDL.AddPadding(24); - tevColorDL.End(); - - currentMaterial.TevColorDL = tevColorDL.GetBuffer(); - - var indMtxAndScaleDL = new DisplayListWriter(); - indMtxAndScaleDL.LoadBPReg(0x25000000); - indMtxAndScaleDL.LoadBPReg(0x26000000); - indMtxAndScaleDL.AddPadding(54); - indMtxAndScaleDL.End(); - - currentMaterial.IndMtxAndScaleDL = indMtxAndScaleDL.GetBuffer(); - - var texCoordGenDL = new DisplayListWriter(); - texCoordGenDL.LoadXFReg(0x1040, new byte[] { 0x00, 0x00, 0x52, 0x80 }); - texCoordGenDL.LoadXFReg(0x1050, new byte[] { 0x00, 0x00, 0x00, 0x00 }); - texCoordGenDL.AddPadding(110); - texCoordGenDL.End(); - - currentMaterial.TexCoordGenDL = texCoordGenDL.GetBuffer(); + // Default display lists, taken from test_lift
+ var pixDL = new DisplayListWriter(); + pixDL.LoadBPReg(0xF31EFF80); + pixDL.LoadBPReg(0x40000017); + pixDL.LoadBPReg(0xFE00FFE3); + pixDL.LoadBPReg(0x410034A0); + pixDL.LoadBPReg(0x42000000); + pixDL.End(); + + currentMaterial.PixDL = pixDL.GetBuffer(); + + var tevColorDL = new DisplayListWriter(); + tevColorDL.LoadBPReg(0xE20000FF); + tevColorDL.LoadBPReg(0xE30FF0FF); + tevColorDL.LoadBPReg(0xE30FF0FF); + tevColorDL.LoadBPReg(0xE30FF0FF); + tevColorDL.LoadBPReg(0xE4000000); + tevColorDL.LoadBPReg(0xE5000000); + tevColorDL.LoadBPReg(0xE5000000); + tevColorDL.LoadBPReg(0xE5000000); + tevColorDL.LoadBPReg(0xE6000000); + tevColorDL.LoadBPReg(0xE7000000); + tevColorDL.LoadBPReg(0xE7000000); + tevColorDL.LoadBPReg(0xE7000000); + tevColorDL.AddPadding(4); + tevColorDL.LoadBPReg(0xE0800000); + tevColorDL.LoadBPReg(0xE1800000); + tevColorDL.LoadBPReg(0xE2800000); + tevColorDL.LoadBPReg(0xE3800000); + tevColorDL.LoadBPReg(0xE4800000); + tevColorDL.LoadBPReg(0xE5800000); + tevColorDL.LoadBPReg(0xE6800000); + tevColorDL.LoadBPReg(0xE7800000); + tevColorDL.AddPadding(24); + tevColorDL.End(); + + currentMaterial.TevColorDL = tevColorDL.GetBuffer(); + + var indMtxAndScaleDL = new DisplayListWriter(); + indMtxAndScaleDL.LoadBPReg(0x25000000); + indMtxAndScaleDL.LoadBPReg(0x26000000); + indMtxAndScaleDL.AddPadding(54); + indMtxAndScaleDL.End(); + + currentMaterial.IndMtxAndScaleDL = indMtxAndScaleDL.GetBuffer(); + + var texCoordGenDL = new DisplayListWriter(); + texCoordGenDL.LoadXFReg(0x1040, new byte[] { 0x00, 0x00, 0x52, 0x80 }); + texCoordGenDL.LoadXFReg(0x1050, new byte[] { 0x00, 0x00, 0x00, 0x00 }); + texCoordGenDL.AddPadding(110); + texCoordGenDL.End(); + + currentMaterial.TexCoordGenDL = texCoordGenDL.GetBuffer(); + + } else { + // These are taken from mtSand on CS_W1 + currentMaterial.TexCoordGenCount = 3; + currentMaterial.ChanCount = 1; + currentMaterial.TevStageCount = 3; + currentMaterial.IndStageCount = 0; + + currentMaterial.CullMode = 2; + + currentMaterial.ZCompLoc = 1; + currentMaterial.LightSetID = 0xFF; + currentMaterial.FogID = 1; + + currentMaterial.SRTSettings[0] = new SRTSettingInfo(); + currentMaterial.SRTSettings[1] = new SRTSettingInfo(); + currentMaterial.SRTSettings[2] = new SRTSettingInfo(); + + currentMaterial.SRTSettings[1].MapType = 1; + currentMaterial.SRTSettings[2].MapType = 1; + + var pixDL = new DisplayListWriter(); + pixDL.LoadBPReg(0xF33F0000); + pixDL.LoadBPReg(0x40000017); + pixDL.LoadBPReg(0xFE00FFE3); + pixDL.LoadBPReg(0x410034A0); + pixDL.LoadBPReg(0x42000000); + pixDL.End(); + + currentMaterial.PixDL = pixDL.GetBuffer(); + + var tevColorDL = new DisplayListWriter(); + tevColorDL.LoadBPReg(0xE2000000); + tevColorDL.LoadBPReg(0xE3000000); + tevColorDL.LoadBPReg(0xE3000000); + tevColorDL.LoadBPReg(0xE3000000); + tevColorDL.LoadBPReg(0xE4000000); + tevColorDL.LoadBPReg(0xE5000000); + tevColorDL.LoadBPReg(0xE5000000); + tevColorDL.LoadBPReg(0xE5000000); + tevColorDL.LoadBPReg(0xE6000000); + tevColorDL.LoadBPReg(0xE7000000); + tevColorDL.LoadBPReg(0xE7000000); + tevColorDL.LoadBPReg(0xE7000000); + tevColorDL.AddPadding(4); + tevColorDL.LoadBPReg(0xE0800000); + tevColorDL.LoadBPReg(0xE1800000); + tevColorDL.LoadBPReg(0xE2800000); + tevColorDL.LoadBPReg(0xE3800000); + tevColorDL.LoadBPReg(0xE4800000); + tevColorDL.LoadBPReg(0xE5800000); + tevColorDL.LoadBPReg(0xE68FF000); + tevColorDL.LoadBPReg(0xE7800000); + tevColorDL.AddPadding(24); + tevColorDL.End(); + + currentMaterial.TevColorDL = tevColorDL.GetBuffer(); + + var indMtxAndScaleDL = new DisplayListWriter(); + indMtxAndScaleDL.LoadBPReg(0x25000000); + indMtxAndScaleDL.LoadBPReg(0x26000000); + indMtxAndScaleDL.AddPadding(54); + indMtxAndScaleDL.End(); + + currentMaterial.IndMtxAndScaleDL = indMtxAndScaleDL.GetBuffer(); + + var texCoordGenDL = new DisplayListWriter(); + texCoordGenDL.LoadXFReg(0x1040, new byte[] { 0x00, 0x00, 0x52, 0x80 }); + texCoordGenDL.LoadXFReg(0x1050, new byte[] { 0x00, 0x00, 0x00, 0x00 }); + texCoordGenDL.LoadXFReg(0x1041, new byte[] { 0x00, 0x00, 0x50, 0x86 }); + texCoordGenDL.LoadXFReg(0x1051, new byte[] { 0x00, 0x00, 0x01, 0x03 }); + texCoordGenDL.LoadXFReg(0x1042, new byte[] { 0x00, 0x00, 0x50, 0x86 }); + texCoordGenDL.LoadXFReg(0x1052, new byte[] { 0x00, 0x00, 0x01, 0x06 }); + texCoordGenDL.PadToSize(0xA0); + texCoordGenDL.End(); + + currentMaterial.TexCoordGenDL = texCoordGenDL.GetBuffer(); + } CurrentModel.Materials.Add(parsed[1], currentMaterial); @@ -348,6 +427,26 @@ namespace NW4RTools { texInfo.MagFilt = 1; currentMaterial.TextureInfos.Add(texInfo); + + // Now add the lm_01m and lm_02m + var lm01m = new TextureInfo(); + lm01m.TextureName = "lm_01m"; + lm01m.TexMapID = 1; + lm01m.TlutID = 1; + + lm01m.MinFilt = 1; + lm01m.MagFilt = 1; + + var lm02m = new TextureInfo(); + lm02m.TextureName = "lm_02m"; + lm02m.TexMapID = 2; + lm02m.TlutID = 2; + + lm02m.MinFilt = 1; + lm02m.MagFilt = 1; + + currentMaterial.TextureInfos.Add(lm01m); + currentMaterial.TextureInfos.Add(lm02m); break;
@@ -373,12 +472,8 @@ namespace NW4RTools { private Shader CreateShader() { var shader = new Shader(); - - shader.TevStageCount = 2; - shader.Unk1 = 0x00FFFFFF; - shader.Unk2 = 0xFFFFFFFF; - var dl = new DisplayListWriter(); + dl.LoadBPReg(0xFE00000F); dl.LoadBPReg(0xF6000004); dl.LoadBPReg(0xFE00000F); @@ -397,15 +492,47 @@ namespace NW4RTools { dl.LoadBPReg(0xFD00000E); dl.LoadBPReg(0x27FFFFFF); dl.AddPadding(11); - dl.LoadBPReg(0xFEFFFFF0); - dl.LoadBPReg(0xF6E338C0); - dl.LoadBPReg(0x2803F040); - dl.LoadBPReg(0xC008F8AF); - dl.LoadBPReg(0xC208F20F); - dl.LoadBPReg(0xC108F2F0); - dl.LoadBPReg(0xC3081FF0); - dl.LoadBPReg(0x10000000); - dl.LoadBPReg(0x11000000); + + if (!Lightmaps) { + shader.TevStageCount = 2; + shader.Unk1 = 0x00FFFFFF; + shader.Unk2 = 0xFFFFFFFF; + + dl.LoadBPReg(0xFEFFFFF0); + dl.LoadBPReg(0xF6E338C0); + dl.LoadBPReg(0x2803F040); + dl.LoadBPReg(0xC008F8AF); + dl.LoadBPReg(0xC208F20F); + dl.LoadBPReg(0xC108F2F0); + dl.LoadBPReg(0xC3081FF0); + dl.LoadBPReg(0x10000000); + dl.LoadBPReg(0x11000000); + + } else { + shader.TevStageCount = 3; + shader.Unk1 = 0x000102FF; + shader.Unk2 = 0xFFFFFFFF; + + dl.LoadBPReg(0xFEFFFFF0); + dl.LoadBPReg(0xF6E338C0); + dl.LoadBPReg(0x283C0049); + dl.LoadBPReg(0xC008F8AF); + dl.LoadBPReg(0xC208F80F); + dl.LoadBPReg(0xC108FFD0); + dl.LoadBPReg(0xC308E270); + dl.LoadBPReg(0x10000000); + dl.LoadBPReg(0x11000000); + dl.AddPadding(3); + dl.LoadBPReg(0xFEFFFFF0); + dl.LoadBPReg(0xF7003EF0); + dl.LoadBPReg(0x293BF052); + dl.LoadBPReg(0xC4080A8E); + dl.AddPadding(5); + dl.LoadBPReg(0xC508E370); + dl.AddPadding(5); + dl.LoadBPReg(0x12000000); + } + dl.PadToSize(0x1E0); dl.End(); |