CMB model previewing and parsing

This commit is contained in:
KillzXGaming 2019-08-02 17:27:44 -04:00
parent 894e53ea07
commit f06cfbd053
12 changed files with 1161 additions and 26 deletions

Binary file not shown.

View file

@ -254,10 +254,16 @@ namespace FirstPlugin
node.Nodes.Insert(index, NewNode);
}
public static byte[] GetASSTData(FileEntry entry)
{
return entry.CompressedData;
if (entry.IsCompressed)
{
return STLibraryCompression.ZSTD.Decompress(entry.CompressedData);
}
else
return entry.CompressedData;
}

View file

@ -18,10 +18,8 @@ using OpenTK;
namespace FirstPlugin
{
public class BMD : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureContainer, ITextureIconLoader
public class BMD : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureContainer
{
public List<STGenericTexture> IconTextureList { get; set; }
public FileType FileType { get; set; } = FileType.Layout;
public bool CanSave { get; set; }
@ -117,7 +115,6 @@ namespace FirstPlugin
DrawableContainer.Drawables.Add(Skeleton);
Textures = new Dictionary<string, STGenericTexture>();
IconTextureList = new List<STGenericTexture>();
BMD_Renderer.TextureContainers.Add(this);
@ -278,7 +275,6 @@ namespace FirstPlugin
var texWrapper = new BMDTextureWrapper(BMDFile.Textures.Textures[i]);
TextureFolder.Nodes.Add(texWrapper);
Renderer.TextureList.Add(texWrapper);
IconTextureList.Add(texWrapper);
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,116 @@
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
{
FRONT_AND_BACK,
BACK,
FRONT,
NONE,
}
public enum SkinningMode : ushort
{
SINGLE_BONE = 0x00,
RIGID_SKINNING = 0x01,
SMOOTH_SKINNING = 0x02,
}
public enum TextureWrapMode
{
CLAMP = 0x2900,
REPEAT = 0x2901,
CLAMP_TO_EDGE = 0x812F,
MIRRORED_REPEAT = 0x8370,
}
public enum CombineResultOpDMP
{
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
{
_1 = 0x01,
_2 = 0x02,
_4 = 0x04,
};
public enum CombineBufferInputDMP
{
PREVIOUS = 0x8578,
PREVIOUS_BUFFER = 0x8579,
};
public enum CombineSourceDMP
{
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
{
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,
};
}

View file

@ -206,6 +206,7 @@
<Compile Include="FileFormats\Archives\ARC.cs" />
<Compile Include="FileFormats\Archives\GFA.cs" />
<Compile Include="FileFormats\Archives\LM2\LM2_Material.cs" />
<Compile Include="FileFormats\Grezzo\CMB_Enums.cs" />
<Compile Include="FileFormats\HyruleWarriors\G1T.cs" />
<Compile Include="FileFormats\HyruleWarriors\HWBinGzResource.cs" />
<Compile Include="FileFormats\Archives\IGA_PAK.cs" />
@ -278,6 +279,7 @@
<Compile Include="FileFormats\Texture\TPL.cs" />
<Compile Include="FileFormats\Rom\GCDisk.cs" />
<Compile Include="GL\BMD_Renderer.cs" />
<Compile Include="GL\CMB_Renderer.cs" />
<Compile Include="GL\GXToOpenGL.cs" />
<Compile Include="GL\LM2_Render.cs" />
<Compile Include="GUI\BFFNT\BffntEditor.cs">

View file

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Toolbox.Library.Rendering;
using GL_EditorFramework.GL_Core;
using GL_EditorFramework.Interfaces;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using Toolbox.Library;
namespace FirstPlugin
{
public class CMB_Renderer : GenericModelRenderer
{
public override float PreviewScale { get; set; } = 0.01f;
public List<CTXB.TextureWrapper> TextureList = new List<CTXB.TextureWrapper>();
public override void OnRender(GLControl control)
{
}
public override int BindTexture(STGenericMatTexture tex, ShaderProgram shader)
{
GL.ActiveTexture(TextureUnit.Texture0 + tex.textureUnit + 1);
GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID);
string activeTex = tex.Name;
foreach (var texture in TextureList)
{
if (TextureList.IndexOf(texture) == ((CMB.CMBTextureMapWrapper)tex).TextureIndex)
{
BindGLTexture(tex, shader, TextureList[((CMB.CMBTextureMapWrapper)tex).TextureIndex]);
return tex.textureUnit + 1;
}
}
return tex.textureUnit + 1;
}
}
}

View file

@ -272,7 +272,7 @@ namespace Toolbox.Library
imgList.Images.Add("vec3", Properties.Resources.IconVec3);
imgList.Images.Add("vec4", Properties.Resources.IconVec4);
Bitmap bmp = new Bitmap(32, 32);
Bitmap bmp = new Bitmap(Width, Height);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.Transparent);

View file

@ -19,6 +19,8 @@ namespace Toolbox.Library
{
public class STSkeleton : EditableObject
{
public virtual float PreviewScale { get; set; } = 1.0f;
public Vector3 position = new Vector3(0, 0, 0);
protected bool Selected = false;
@ -200,7 +202,7 @@ namespace Toolbox.Library
DrawBoundingBoxes();
control.UpdateModelMatrix(
Matrix4.CreateScale(Runtime.previewScale) *
Matrix4.CreateScale(Runtime.previewScale * PreviewScale) *
Matrix4.CreateTranslation(Selected ? editorScene.CurrentAction.NewPos(position) : position));

View file

@ -14,6 +14,8 @@ namespace Toolbox.Library.Rendering
{
public class GenericModelRenderer : AbstractGlDrawable
{
public virtual float PreviewScale { get; set; } = 1.0f;
public static List<ITextureContainer> TextureContainers = new List<ITextureContainer>();
public List<GenericRenderedObject> Meshes = new List<GenericRenderedObject>();
@ -170,7 +172,7 @@ namespace Toolbox.Library.Rendering
ShaderProgram shader = defaultShaderProgram;
control.CurrentShader = shader;
control.UpdateModelMatrix(Matrix4.CreateScale(Runtime.previewScale) * ModelTransform);
control.UpdateModelMatrix(Matrix4.CreateScale(Runtime.previewScale * PreviewScale) * ModelTransform);
OnRender(control);