Switch-Toolbox/Switch_FileFormatsMain/FileFormats/BMD/BMDMaterialWrapper.cs

77 lines
2.5 KiB
C#
Raw Normal View History

2019-07-12 00:23:47 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2019-07-12 00:46:45 +00:00
using System.Windows.Forms;
2019-07-12 00:23:47 +00:00
using Switch_Toolbox.Library;
2019-07-12 00:46:45 +00:00
using Switch_Toolbox.Library.Forms;
2019-07-12 00:23:47 +00:00
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;
2019-07-12 00:46:45 +00:00
Text = mat.Name;
2019-07-12 00:23:47 +00:00
int textureUnit = 1;
if (mat.TextureIndices[0] != -1)
{
int texIndex = mat.TextureIndices[0];
BMDTextureMap matTexture = new BMDTextureMap(this);
matTexture.TextureIndex = texIndex;
2019-07-12 00:23:47 +00:00
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);
2019-07-12 00:46:45 +00:00
foreach (var textureIndex in mat.TextureIndices)
{
if (textureIndex != -1)
Nodes.Add(ParentModel.Textures[textureIndex].Name);
}
2019-07-12 00:23:47 +00:00
}
}
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}");
}
}
2019-07-12 00:46:45 +00:00
public override void OnClick(TreeView treeView)
{
STPropertyGrid editor = (STPropertyGrid)LibraryGUI.GetActiveContent(typeof(STPropertyGrid));
if (editor == null)
{
editor = new STPropertyGrid();
LibraryGUI.LoadEditor(editor);
}
editor.Text = Text;
editor.Dock = DockStyle.Fill;
editor.LoadProperty(Material, null);
}
2019-07-12 00:23:47 +00:00
}
}