mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-10 07:04:36 +00:00
CMB: Redo cmb reading/writing using ZeldaLib (WIP)
This commit is contained in:
parent
134b8e295c
commit
49a2d7e282
5 changed files with 464 additions and 2258 deletions
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);
|
||||
}
|
||||
|
||||
private static Dictionary<TextureFormat, CTR_3DS.PICASurfaceFormat> FormatList =
|
||||
public static Dictionary<TextureFormat, CTR_3DS.PICASurfaceFormat> FormatList =
|
||||
new Dictionary<TextureFormat, CTR_3DS.PICASurfaceFormat>()
|
||||
{
|
||||
{ TextureFormat.A8, CTR_3DS.PICASurfaceFormat.A8 },
|
||||
|
|
|
@ -209,7 +209,7 @@ namespace HyruleWarriors.G1M
|
|||
{
|
||||
foreach (var mesh in Model.GenericMeshes)
|
||||
{
|
||||
bool isSingleBind = false;;
|
||||
bool isSingleBind = false;
|
||||
|
||||
if (isSingleBind)
|
||||
{
|
||||
|
|
|
@ -9,7 +9,6 @@ using GL_EditorFramework.Interfaces;
|
|||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using Toolbox.Library;
|
||||
using Grezzo.CmbEnums;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
|
@ -67,7 +66,7 @@ namespace FirstPlugin
|
|||
|
||||
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]);
|
||||
else
|
||||
opaque.Add(Meshes[m]);
|
||||
|
@ -91,35 +90,81 @@ namespace FirstPlugin
|
|||
var cmbMaterial = ((CMB.CMBMaterialWrapper)mat).CMBMaterial;
|
||||
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("isTransparent", cmbMaterial.BlendEnaled);
|
||||
shader.SetBoolToInt("isTransparent", cmbMaterial.BlendEnabled);
|
||||
|
||||
SetGLCullMode(cmbMaterial.CullMode);
|
||||
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(cmbMaterial.BlendingFactorSrcAlpha, cmbMaterial.BlendingFactorDestAlpha);
|
||||
GL.BlendColor(1.0f, 1.0f, 1.0f, cmbMaterial.BlendColorA);
|
||||
if (cmbMaterial.AlphaTestEnable)
|
||||
if (cmbMaterial.BlendEnabled)
|
||||
{
|
||||
GL.Enable(EnableCap.Blend);
|
||||
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.AlphaFunc(ConvertTestFunction(cmbMaterial.AlphaTest.Function), cmbMaterial.AlphaTest.Reference / 255f);
|
||||
}
|
||||
else
|
||||
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);
|
||||
|
||||
if (CullMode == CullMode.BACK)
|
||||
if (CullMode == ZeldaLib.CtrModelBinary.Types.CullMode.Back)
|
||||
GL.CullFace(CullFaceMode.Back);
|
||||
if (CullMode == CullMode.FRONT)
|
||||
if (CullMode == ZeldaLib.CtrModelBinary.Types.CullMode.Front)
|
||||
GL.CullFace(CullFaceMode.Front);
|
||||
if (CullMode == CullMode.FRONT_AND_BACK)
|
||||
if (CullMode == ZeldaLib.CtrModelBinary.Types.CullMode.Both)
|
||||
GL.CullFace(CullFaceMode.FrontAndBack);
|
||||
if (CullMode == CullMode.NONE)
|
||||
if (CullMode == ZeldaLib.CtrModelBinary.Types.CullMode.None)
|
||||
GL.Disable(EnableCap.CullFace);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue