More BMD fixes and adjustments

This commit is contained in:
KillzXGaming 2019-07-11 20:23:47 -04:00
parent 9c5917cc6a
commit 134eff9401
11 changed files with 67 additions and 27 deletions

Binary file not shown.

View file

@ -96,6 +96,7 @@ namespace FirstPlugin
public Model BMDFile;
private TreeNode TextureFolder;
private TreeNode ShapeFolder;
private TreeNode MaterialFolder;
public void Load(System.IO.Stream stream)
{
@ -110,16 +111,22 @@ namespace FirstPlugin
BMD_Renderer.TextureContainers.Add(this);
ShapeFolder = new TreeNode("Shapes");
ShapeFolder = new TreeNode("Shapes");
MaterialFolder = new TreeNode("Materials");
TextureFolder = new TreeNode("Textures");
Nodes.Add(ShapeFolder);
Nodes.Add(MaterialFolder);
Nodes.Add(TextureFolder);
BMDFile = Model.Load(stream);
for (int i = 0; i < BMDFile.Shapes.Shapes.Count; i++)
{
var shpWrapper = new BMDShapeWrapper(BMDFile.Shapes.Shapes[i], BMDFile, i);
var mat = new BMDMaterialWrapper(BMDFile.Materials.m_Materials[i], BMDFile);
mat.Text = $"Material {i}";
MaterialFolder.Nodes.Add(mat);
var shpWrapper = new BMDShapeWrapper(BMDFile.Shapes.Shapes[i], BMDFile, mat);
shpWrapper.Text = $"Shape {i}";
ShapeFolder.Nodes.Add(shpWrapper);
Renderer.Meshes.Add(shpWrapper);
@ -186,7 +193,6 @@ namespace FirstPlugin
{
var texWrapper = new BMDTextureWrapper(BMDFile.Textures.Textures[i]);
TextureFolder.Nodes.Add(texWrapper);
Textures.Add(texWrapper.Text, texWrapper);
}
}

View file

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Switch_Toolbox.Library;
using SuperBMDLib.Materials;
namespace FirstPlugin
{
public class BMDMaterialWrapper : STGenericMaterial
{
Material Material;
SuperBMDLib.Model ParentModel;
public BMDMaterialWrapper(Material mat, SuperBMDLib.Model model)
{
Material = mat;
ParentModel = model;
int textureUnit = 1;
if (mat.TextureIndices[0] != -1)
{
int texIndex = mat.TextureIndices[0];
STGenericMatTexture matTexture = new STGenericMatTexture();
matTexture.Name = ParentModel.Textures[texIndex].Name;
matTexture.Type = STGenericMatTexture.TextureType.Diffuse;
matTexture.textureUnit = textureUnit++;
matTexture.wrapModeS = ConvertWrapMode(ParentModel.Textures[texIndex].WrapS);
matTexture.wrapModeT = ConvertWrapMode(ParentModel.Textures[texIndex].WrapT);
TextureMaps.Add(matTexture);
}
}
private int ConvertWrapMode(BinaryTextureImage.WrapModes WrapMode)
{
switch (WrapMode)
{
case BinaryTextureImage.WrapModes.Repeat:
return 0;
case BinaryTextureImage.WrapModes.MirroredRepeat:
return 1;
case BinaryTextureImage.WrapModes.ClampToEdge:
return 2;
default:
throw new Exception($"Unknown WrapMode {WrapMode}");
}
}
}
}

View file

@ -18,30 +18,11 @@ namespace FirstPlugin
Shape BMDShape;
private STGenericMaterial material;
public BMDShapeWrapper(Shape shape, SuperBMDLib.Model model, int Index)
public BMDShapeWrapper(Shape shape, SuperBMDLib.Model model, BMDMaterialWrapper mat)
{
BMDShape = shape;
ParentModel = model;
material = new STGenericMaterial();
// material.Text = $"Material {Index}";
var mat = model.Materials.m_Materials[Index];
int textureUnit = 1;
if (mat.TextureIndices[0] != -1)
{
int texIndex = mat.TextureIndices[0];
STGenericMatTexture matTexture = new STGenericMatTexture();
matTexture.Name = ParentModel.Textures[texIndex].Name;
matTexture.Type = STGenericMatTexture.TextureType.Diffuse;
matTexture.textureUnit = textureUnit++;
matTexture.wrapModeS = 0;
matTexture.wrapModeT = 0;
material.TextureMaps.Add(matTexture);
}
material = mat;
}
public override STGenericMaterial GetMaterial()

View file

@ -55,7 +55,7 @@ namespace FirstPlugin
editor.Text = Text;
editor.LoadProperties(TextureImage);
editor.LoadImage(this);
editor.LoadImage(this);
}
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)

View file

@ -243,6 +243,7 @@
<Compile Include="FileFormats\BFRES\GLEnumConverter.cs" />
<Compile Include="FileFormats\Bin\KartParts.cs" />
<Compile Include="FileFormats\BMD\BMD.cs" />
<Compile Include="FileFormats\BMD\BMDMaterialWrapper.cs" />
<Compile Include="FileFormats\BMD\BMDShapeWrapper.cs" />
<Compile Include="FileFormats\BMD\BMDTextureWrapper.cs" />
<Compile Include="FileFormats\Collision\KclFile.cs" />

View file

@ -119,9 +119,9 @@ namespace Switch_Toolbox.Library.Rendering
}
}
}
if (Surfaces.Count == 0 || Surfaces[0].mipmaps[0].Length == 0)
throw new Exception("Data is empty!");
return;
IsCubeMap = Surfaces.Count == 6;
ImageSize = Surfaces[0].mipmaps[0].Length;