Merge pull request #218 from M-1-RLG/master
CMB: Redo cmb reading/writing using ZeldaLib (WIP)
This commit is contained in:
commit
38c9011fd4
File diff suppressed because it is too large
Load Diff
@ -1,164 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Grezzo.CmbEnums
|
|
||||||
{
|
|
||||||
//All enums from
|
|
||||||
//https://github.com/magcius/noclip.website/blob/master/src/oot3d/cmb.ts
|
|
||||||
public enum TextureFilter
|
|
||||||
{
|
|
||||||
NEAREST = 0x2600,
|
|
||||||
LINEAR = 0x2601,
|
|
||||||
NEAREST_MIPMAP_NEAREST = 0x2700,
|
|
||||||
LINEAR_MIPMAP_NEAREST = 0x2701,
|
|
||||||
NEAREST_MIPMAP_LINEAR = 0x2702,
|
|
||||||
LINEAR_MIPMAP_LINEAR = 0x2703,
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum SepdVertexAttribMode : ushort
|
|
||||||
{
|
|
||||||
ARRAY = 0,
|
|
||||||
CONSTANT = 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum CmbDataType : ushort
|
|
||||||
{
|
|
||||||
Byte = 0x1400,
|
|
||||||
UByte = 0x1401,
|
|
||||||
Short = 0x1402,
|
|
||||||
UShort = 0x1403,
|
|
||||||
Int = 0x1404,
|
|
||||||
UInt = 0x1405,
|
|
||||||
Float = 0x1406,
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum CullMode : byte
|
|
||||||
{
|
|
||||||
NONE,
|
|
||||||
BACK,
|
|
||||||
FRONT,
|
|
||||||
FRONT_AND_BACK,
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum SkinningMode : ushort
|
|
||||||
{
|
|
||||||
SINGLE_BONE = 0x00,
|
|
||||||
RIGID_SKINNING = 0x01,
|
|
||||||
SMOOTH_SKINNING = 0x02,
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum CMBTextureWrapMode
|
|
||||||
{
|
|
||||||
CLAMP = 0x2900,
|
|
||||||
REPEAT = 0x2901,
|
|
||||||
CLAMP_TO_EDGE = 0x812F,
|
|
||||||
MIRRORED_REPEAT = 0x8370,
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum CombineResultOpDMP : ushort
|
|
||||||
{
|
|
||||||
REPLACE = 0x1E01,
|
|
||||||
MODULATE = 0x2100,
|
|
||||||
ADD = 0x0104,
|
|
||||||
ADD_SIGNED = 0x8574,
|
|
||||||
INTERPOLATE = 0x8575,
|
|
||||||
SUBTRACT = 0x84E7,
|
|
||||||
DOT3_RGB = 0x86AE,
|
|
||||||
DOT3_RGBA = 0x86AF,
|
|
||||||
MULT_ADD = 0x6401,
|
|
||||||
ADD_MULT = 0x6402,
|
|
||||||
};
|
|
||||||
|
|
||||||
public enum CombineScaleDMP : ushort
|
|
||||||
{
|
|
||||||
_1 = 0x01,
|
|
||||||
_2 = 0x02,
|
|
||||||
_4 = 0x04,
|
|
||||||
};
|
|
||||||
|
|
||||||
public enum CombineBufferInputDMP : ushort
|
|
||||||
{
|
|
||||||
PREVIOUS = 0x8578,
|
|
||||||
PREVIOUS_BUFFER = 0x8579,
|
|
||||||
};
|
|
||||||
|
|
||||||
public enum CombineSourceDMP : ushort
|
|
||||||
{
|
|
||||||
TEXTURE0 = 0x84C0,
|
|
||||||
TEXTURE1 = 0x84C1,
|
|
||||||
TEXTURE2 = 0x84C2,
|
|
||||||
TEXTURE3 = 0x84C3,
|
|
||||||
CONSTANT = 0x8576,
|
|
||||||
PRIMARY_COLOR = 0x8577,
|
|
||||||
PREVIOUS = 0x8578,
|
|
||||||
PREVIOUS_BUFFER = 0x8579,
|
|
||||||
FRAGMENT_PRIMARY_COLOR = 0x6210,
|
|
||||||
FRAGMENT_SECONDARY_COLOR = 0x6211,
|
|
||||||
};
|
|
||||||
|
|
||||||
public enum CombineOpDMP : ushort
|
|
||||||
{
|
|
||||||
SRC_COLOR = 0x0300,
|
|
||||||
ONE_MINUS_SRC_COLOR = 0x0301,
|
|
||||||
SRC_ALPHA = 0x0302,
|
|
||||||
ONE_MINUS_SRC_ALPHA = 0x0303,
|
|
||||||
SRC_R = 0x8580,
|
|
||||||
SRC_G = 0x8581,
|
|
||||||
SRC_B = 0x8582,
|
|
||||||
ONE_MINUS_SRC_R = 0x8583,
|
|
||||||
ONE_MINUS_SRC_G = 0x8584,
|
|
||||||
ONE_MINUS_SRC_B = 0x8585,
|
|
||||||
};
|
|
||||||
|
|
||||||
public enum FresnelSelector : ushort
|
|
||||||
{
|
|
||||||
No = 25280,
|
|
||||||
Pri = 25281,
|
|
||||||
Sec = 25282,
|
|
||||||
PriSec = 25283
|
|
||||||
};
|
|
||||||
|
|
||||||
public enum LayerConfig
|
|
||||||
{
|
|
||||||
LayerConfig0 = 25264,
|
|
||||||
LayerConfig1 = 25265,
|
|
||||||
LayerConfig2 = 25266,
|
|
||||||
LayerConfig3 = 25267,
|
|
||||||
LayerConfig4 = 25268,
|
|
||||||
LayerConfig5 = 25269,
|
|
||||||
LayerConfig6 = 25270,
|
|
||||||
LayerConfig7 = 25271,
|
|
||||||
};
|
|
||||||
|
|
||||||
public enum LUTInput : ushort
|
|
||||||
{
|
|
||||||
CosNormalHalf = 25248,
|
|
||||||
CosViewHalf = 25249,
|
|
||||||
CosNormalView = 25250,
|
|
||||||
CosLightNormal = 25251,
|
|
||||||
CosLightSpot = 25252,
|
|
||||||
CosPhi = 25253
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum StencilOp
|
|
||||||
{
|
|
||||||
Keep = 7680,
|
|
||||||
Zero = 0,
|
|
||||||
Replace = 7681,
|
|
||||||
Increment = 7682,
|
|
||||||
Decrement = 7683,
|
|
||||||
Invert = 5386,
|
|
||||||
IncrementWrap = 34055,
|
|
||||||
DecrementWrap = 34055
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum BumpMode
|
|
||||||
{
|
|
||||||
NotUsed = 25288,
|
|
||||||
AsBump = 25289,
|
|
||||||
AsTangent = 25290//Doesn't exist in OoT3D
|
|
||||||
}
|
|
||||||
}
|
|
@ -299,7 +299,7 @@ namespace FirstPlugin
|
|||||||
writer.WriteString(Name, 16);
|
writer.WriteString(Name, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Dictionary<TextureFormat, CTR_3DS.PICASurfaceFormat> FormatList =
|
public static Dictionary<TextureFormat, CTR_3DS.PICASurfaceFormat> FormatList =
|
||||||
new Dictionary<TextureFormat, CTR_3DS.PICASurfaceFormat>()
|
new Dictionary<TextureFormat, CTR_3DS.PICASurfaceFormat>()
|
||||||
{
|
{
|
||||||
{ TextureFormat.A8, CTR_3DS.PICASurfaceFormat.A8 },
|
{ TextureFormat.A8, CTR_3DS.PICASurfaceFormat.A8 },
|
||||||
|
@ -209,7 +209,7 @@ namespace HyruleWarriors.G1M
|
|||||||
{
|
{
|
||||||
foreach (var mesh in Model.GenericMeshes)
|
foreach (var mesh in Model.GenericMeshes)
|
||||||
{
|
{
|
||||||
bool isSingleBind = false;;
|
bool isSingleBind = false;
|
||||||
|
|
||||||
if (isSingleBind)
|
if (isSingleBind)
|
||||||
{
|
{
|
||||||
|
@ -218,6 +218,7 @@
|
|||||||
<Compile Include="FileFormats\Archives\QuickAccess\QuickAccessFile.cs" />
|
<Compile Include="FileFormats\Archives\QuickAccess\QuickAccessFile.cs" />
|
||||||
<Compile Include="FileFormats\Archives\QuickAccess\QuickAccessFolder.cs" />
|
<Compile Include="FileFormats\Archives\QuickAccess\QuickAccessFolder.cs" />
|
||||||
<Compile Include="FileFormats\Archives\WTA.cs" />
|
<Compile Include="FileFormats\Archives\WTA.cs" />
|
||||||
|
<Compile Include="FileFormats\Audio\BARS\BarsFile.cs" />
|
||||||
<Compile Include="FileFormats\BCH\BCH.cs" />
|
<Compile Include="FileFormats\BCH\BCH.cs" />
|
||||||
<Compile Include="FileFormats\BCH\MBN.cs" />
|
<Compile Include="FileFormats\BCH\MBN.cs" />
|
||||||
<Compile Include="FileFormats\BCH\Wrappers\BCHGroupNode.cs" />
|
<Compile Include="FileFormats\BCH\Wrappers\BCHGroupNode.cs" />
|
||||||
@ -334,7 +335,6 @@
|
|||||||
<Compile Include="FileFormats\HedgehogEngine\HedgeModel.cs" />
|
<Compile Include="FileFormats\HedgehogEngine\HedgeModel.cs" />
|
||||||
<Compile Include="FileFormats\HedgehogEngine\PACx.cs" />
|
<Compile Include="FileFormats\HedgehogEngine\PACx.cs" />
|
||||||
<Compile Include="FileFormats\CrashBandicoot\IGZ_Structure.cs" />
|
<Compile Include="FileFormats\CrashBandicoot\IGZ_Structure.cs" />
|
||||||
<Compile Include="FileFormats\Grezzo\CMB_Enums.cs" />
|
|
||||||
<Compile Include="FileFormats\Grezzo\CSAB.cs" />
|
<Compile Include="FileFormats\Grezzo\CSAB.cs" />
|
||||||
<Compile Include="FileFormats\HyruleWarriors\G1M\G1MChunkCommon.cs" />
|
<Compile Include="FileFormats\HyruleWarriors\G1M\G1MChunkCommon.cs" />
|
||||||
<Compile Include="FileFormats\HyruleWarriors\G1M\G1MEnums.cs" />
|
<Compile Include="FileFormats\HyruleWarriors\G1M\G1MEnums.cs" />
|
||||||
@ -363,7 +363,7 @@
|
|||||||
<Compile Include="FileFormats\Grezzo\CMB.cs" />
|
<Compile Include="FileFormats\Grezzo\CMB.cs" />
|
||||||
<Compile Include="FileFormats\Grezzo\GAR.cs" />
|
<Compile Include="FileFormats\Grezzo\GAR.cs" />
|
||||||
<Compile Include="FileFormats\Grezzo\ZSI.cs" />
|
<Compile Include="FileFormats\Grezzo\ZSI.cs" />
|
||||||
<Compile Include="FileFormats\Audio\Archives\BARS.cs" />
|
<Compile Include="FileFormats\Audio\BARS\BARS.cs" />
|
||||||
<Compile Include="FileFormats\Audio\BARSLIST.cs" />
|
<Compile Include="FileFormats\Audio\BARSLIST.cs" />
|
||||||
<Compile Include="FileFormats\Audio\BCSTM.cs" />
|
<Compile Include="FileFormats\Audio\BCSTM.cs" />
|
||||||
<Compile Include="FileFormats\Archives\BEA.cs" />
|
<Compile Include="FileFormats\Archives\BEA.cs" />
|
||||||
@ -2309,4 +2309,4 @@
|
|||||||
<Content Include="Resources\Hashes\Pkmn.txt" />
|
<Content Include="Resources\Hashes\Pkmn.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
@ -9,7 +9,6 @@ using GL_EditorFramework.Interfaces;
|
|||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics.OpenGL;
|
using OpenTK.Graphics.OpenGL;
|
||||||
using Toolbox.Library;
|
using Toolbox.Library;
|
||||||
using Grezzo.CmbEnums;
|
|
||||||
|
|
||||||
namespace FirstPlugin
|
namespace FirstPlugin
|
||||||
{
|
{
|
||||||
@ -67,7 +66,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
for (int m = 0; m < Meshes.Count; m++)
|
for (int m = 0; m < Meshes.Count; m++)
|
||||||
{
|
{
|
||||||
if (((CMB.CMBMaterialWrapper)Meshes[m].GetMaterial()).CMBMaterial.IsTransparent)
|
if (((CMB.CMBMaterialWrapper)Meshes[m].GetMaterial()).CMBMaterial.AlphaTest.Enabled)
|
||||||
transparent.Add(Meshes[m]);
|
transparent.Add(Meshes[m]);
|
||||||
else
|
else
|
||||||
opaque.Add(Meshes[m]);
|
opaque.Add(Meshes[m]);
|
||||||
@ -91,35 +90,81 @@ namespace FirstPlugin
|
|||||||
var cmbMaterial = ((CMB.CMBMaterialWrapper)mat).CMBMaterial;
|
var cmbMaterial = ((CMB.CMBMaterialWrapper)mat).CMBMaterial;
|
||||||
var cmbMesh = ((CMB.CmbMeshWrapper)m);
|
var cmbMesh = ((CMB.CmbMeshWrapper)m);
|
||||||
|
|
||||||
bool HasNoNormals = cmbMesh.Shape.Normal.VertexData == null || cmbMesh.Shape.Normal.VertexData.Length == 0;
|
bool HasNoNormals = cmbMesh.Mesh.HasNormal == false;
|
||||||
|
|
||||||
shader.SetBoolToInt("HasNoNormals", HasNoNormals);
|
shader.SetBoolToInt("HasNoNormals", HasNoNormals);
|
||||||
shader.SetBoolToInt("isTransparent", cmbMaterial.BlendEnaled);
|
shader.SetBoolToInt("isTransparent", cmbMaterial.BlendEnabled);
|
||||||
|
|
||||||
SetGLCullMode(cmbMaterial.CullMode);
|
SetGLCullMode(cmbMaterial.CullMode);
|
||||||
|
|
||||||
GL.Enable(EnableCap.Blend);
|
if (cmbMaterial.BlendEnabled)
|
||||||
GL.BlendFunc(cmbMaterial.BlendingFactorSrcAlpha, cmbMaterial.BlendingFactorDestAlpha);
|
{
|
||||||
GL.BlendColor(1.0f, 1.0f, 1.0f, cmbMaterial.BlendColorA);
|
GL.Enable(EnableCap.Blend);
|
||||||
if (cmbMaterial.AlphaTestEnable)
|
GL.BlendColor(cmbMaterial.BlendColor.R / 255, cmbMaterial.BlendColor.G / 255, cmbMaterial.BlendColor.B / 255, cmbMaterial.BlendColor.A / 255);
|
||||||
|
GL.BlendFunc(ConvertBlendFunc(cmbMaterial.BlendFunction.AlphaSrcFunc), ConvertBlendFunc(cmbMaterial.BlendFunction.AlphaDstFunc));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
GL.Disable(EnableCap.Blend);
|
||||||
|
|
||||||
|
if (cmbMaterial.AlphaTest.Enabled)
|
||||||
|
{
|
||||||
GL.Enable(EnableCap.AlphaTest);
|
GL.Enable(EnableCap.AlphaTest);
|
||||||
|
GL.AlphaFunc(ConvertTestFunction(cmbMaterial.AlphaTest.Function), cmbMaterial.AlphaTest.Reference / 255f);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
GL.Disable(EnableCap.AlphaTest);
|
GL.Disable(EnableCap.AlphaTest);
|
||||||
|
|
||||||
GL.AlphaFunc(cmbMaterial.AlphaTestFunction, cmbMaterial.AlphaTestReference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetGLCullMode(CullMode CullMode)
|
private AlphaFunction ConvertTestFunction(ZeldaLib.CtrModelBinary.Types.TestFunc func)
|
||||||
|
{
|
||||||
|
switch (func)
|
||||||
|
{
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.TestFunc.Always: return AlphaFunction.Always;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.TestFunc.Equal: return AlphaFunction.Equal;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.TestFunc.Gequal: return AlphaFunction.Gequal;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.TestFunc.Greater: return AlphaFunction.Greater;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.TestFunc.Lequal: return AlphaFunction.Lequal;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.TestFunc.Less: return AlphaFunction.Less;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.TestFunc.Never: return AlphaFunction.Never;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.TestFunc.Notequal: return AlphaFunction.Notequal;
|
||||||
|
default: return AlphaFunction.Always;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BlendingFactor ConvertBlendFunc(ZeldaLib.CtrModelBinary.Types.BlendFunc factor)
|
||||||
|
{
|
||||||
|
switch (factor)
|
||||||
|
{
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.ConstantAlpha: return BlendingFactor.ConstantAlpha;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.ConstantColor: return BlendingFactor.ConstantColor;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.DestinationAlpha: return BlendingFactor.DstAlpha;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.DestinationColor: return BlendingFactor.DstColor;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.One: return BlendingFactor.One;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.OneMinusConstantAlpha: return BlendingFactor.OneMinusConstantAlpha;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.OneMinusConstantColor: return BlendingFactor.OneMinusConstantColor;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.OneMinusDestinationAlpha: return BlendingFactor.OneMinusDstAlpha;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.OneMinusDestinationColor: return BlendingFactor.OneMinusDstColor;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.OneMinusSourceAlpha: return BlendingFactor.OneMinusSrcAlpha;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.OneMinusSourceColor: return BlendingFactor.OneMinusSrcColor;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.SourceAlpha: return BlendingFactor.SrcAlpha;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.SourceColor: return BlendingFactor.SrcColor;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.SourceAlphaSaturate: return BlendingFactor.SrcAlphaSaturate;
|
||||||
|
case ZeldaLib.CtrModelBinary.Types.BlendFunc.Zero: return BlendingFactor.Zero;
|
||||||
|
default: return BlendingFactor.Zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetGLCullMode(ZeldaLib.CtrModelBinary.Types.CullMode CullMode)
|
||||||
{
|
{
|
||||||
GL.Enable(EnableCap.CullFace);
|
GL.Enable(EnableCap.CullFace);
|
||||||
|
|
||||||
if (CullMode == CullMode.BACK)
|
if (CullMode == ZeldaLib.CtrModelBinary.Types.CullMode.Back)
|
||||||
GL.CullFace(CullFaceMode.Back);
|
GL.CullFace(CullFaceMode.Back);
|
||||||
if (CullMode == CullMode.FRONT)
|
if (CullMode == ZeldaLib.CtrModelBinary.Types.CullMode.Front)
|
||||||
GL.CullFace(CullFaceMode.Front);
|
GL.CullFace(CullFaceMode.Front);
|
||||||
if (CullMode == CullMode.FRONT_AND_BACK)
|
if (CullMode == ZeldaLib.CtrModelBinary.Types.CullMode.Both)
|
||||||
GL.CullFace(CullFaceMode.FrontAndBack);
|
GL.CullFace(CullFaceMode.FrontAndBack);
|
||||||
if (CullMode == CullMode.NONE)
|
if (CullMode == ZeldaLib.CtrModelBinary.Types.CullMode.None)
|
||||||
GL.Disable(EnableCap.CullFace);
|
GL.Disable(EnableCap.CullFace);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user