1
0
mirror of synced 2025-01-19 01:14:08 +01:00

Add basic probe bounding box converter

This commit is contained in:
KillzXGaming 2019-06-06 17:57:55 -04:00
parent 28b231caaa
commit a520ff1dd9
12 changed files with 192 additions and 5 deletions

Binary file not shown.

View File

@ -17,7 +17,7 @@ namespace FirstPlugin
public bool CanSave { get; set; }
public string[] Description { get; set; } = new string[] { "AAMP" };
public string[] Extension { get; set; } = new string[] { "*.aamp" };
public string[] Extension { get; set; } = new string[] { "*.aamp", "*.bglpbd" };
public string FileName { get; set; }
public string FilePath { get; set; }
public IFileInfo IFileInfo { get; set; }
@ -53,6 +53,121 @@ namespace FirstPlugin
bool IsSaveDialog = false;
public static void GenerateProbeBoundings()
{
OpenFileDialog ofd1 = new OpenFileDialog();
ofd1.Filter = Utils.GetAllFilters(typeof(AAMP));
if (ofd1.ShowDialog() != DialogResult.OK)
return;
//Load the AAMP
var File = STFileLoader.OpenFileFormat(ofd1.FileName);
if (File == null || !(File is AAMP))
throw new Exception("File not a valid AAMP file!");
//Load bfres for generating the bounds
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = Utils.GetAllFilters(typeof(BFRES));
if (ofd.ShowDialog() == DialogResult.OK)
{
//Open and check bfres
var Bfres = STFileLoader.OpenFileFormat(ofd.FileName);
if (Bfres == null || !(Bfres is BFRES))
throw new Exception("File not a valid BFRES file!");
//Check version instance
if (((AAMP)File).aampFileV1 != null)
{
foreach (var val in ((AAMP)File).aampFileV1.RootNode.childParams)
{
foreach (var param in val.paramObjects)
{
switch (param.HashString)
{
case "grid":
GenerateGridData((BFRES)Bfres, param.paramEntries);
break;
}
}
}
foreach (var param in ((AAMP)File).aampFileV1.RootNode.paramObjects)
{
switch (param.HashString)
{
case "root_grid":
GenerateGridData((BFRES)Bfres, param.paramEntries);
break;
}
}
}
else
{
foreach (var val in ((AAMP)File).aampFileV2.RootNode.childParams)
{
foreach (var param in val.paramObjects)
{
switch (param.HashString)
{
case "grid":
GenerateGridData((BFRES)Bfres, param.paramEntries);
break;
}
}
}
foreach (var param in ((AAMP)File).aampFileV2.RootNode.paramObjects)
{
switch (param.HashString)
{
case "root_grid":
GenerateGridData((BFRES)Bfres, param.paramEntries);
break;
}
}
}
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = Utils.GetAllFilters(File);
if (sfd.ShowDialog() == DialogResult.OK)
{
//Save the aamp back
STFileSaver.SaveFileFormat(File, sfd.FileName);
}
File.Unload();
Bfres.Unload();
}
}
private static void GenerateGridData(BFRES bfres, aampv2.ParamEntry[] paramEntries)
{
//Load the grid min nad max and set them
var boundings = bfres.GetBoundingBox();
foreach (var entry in paramEntries)
{
if (entry.HashString == "aabb_min_pos")
entry.Value = new Syroot.Maths.Vector3F(boundings.Min.X, boundings.Min.Y, boundings.Min.Z);
if (entry.HashString == "aabb_max_pos")
entry.Value = new Syroot.Maths.Vector3F(boundings.Max.X, boundings.Max.Y, boundings.Max.Z);
}
}
private static void GenerateGridData(BFRES bfres, aampv1.ParamEntry[] paramEntries)
{
var boundings = bfres.GetBoundingBox();
foreach (var entry in paramEntries)
{
if (entry.HashString == "aabb_min_pos")
entry.Value = new Syroot.Maths.Vector3F(boundings.Min.X, boundings.Min.Y, boundings.Min.Z);
if (entry.HashString == "aabb_max_pos")
entry.Value = new Syroot.Maths.Vector3F(boundings.Max.X, boundings.Max.Y, boundings.Max.Z);
}
}
public AampEditorBase OpenForm()
{
if (aampFileV1 != null)

View File

@ -16,6 +16,7 @@ using Switch_Toolbox.Library.NodeWrappers;
using GL_EditorFramework.Interfaces;
using FirstPlugin.Forms;
using FirstPlugin.NodeWrappers;
using OpenTK;
namespace FirstPlugin
{
@ -159,7 +160,37 @@ namespace FirstPlugin
return data;
}
public BoundingBox GetBoundingBox()
{
Vector3 Min = new Vector3(0);
Vector3 Max = new Vector3(0);
var Models = GetModels();
if (Models == null)
return new BoundingBox();
foreach (FMDL model in Models)
{
foreach (var shape in model.shapes)
{
foreach (var vertex in shape.vertices)
{
Min.X = Math.Min(Min.X, vertex.pos.X);
Min.Y = Math.Min(Min.Y, vertex.pos.Y);
Min.Z = Math.Min(Min.Z, vertex.pos.Z);
Max.X = Math.Max(Max.X, vertex.pos.X);
Max.Y = Math.Max(Max.Y, vertex.pos.Y);
Max.Z = Math.Max(Max.Z, vertex.pos.Z);
}
}
}
return new BoundingBox()
{
Max = Max,
Min = Min,
};
}
public void OnPropertyChanged()
{

View File

@ -273,6 +273,7 @@ namespace FirstPlugin
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
ofd.Filter = Utils.GetAllFilters(typeof(NUTEXB));
if (ofd.ShowDialog() == DialogResult.OK)
{
@ -374,11 +375,8 @@ namespace FirstPlugin
}
private void Save(object sender, EventArgs args)
{
List<IFileFormat> formats = new List<IFileFormat>();
formats.Add(this);
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = Utils.GetAllFilters(formats);
sfd.Filter = Utils.GetAllFilters(this);
sfd.FileName = FileName;
if (sfd.ShowDialog() == DialogResult.OK)

View File

@ -83,6 +83,24 @@ namespace FirstPlugin
PluginRuntime.bntxContainers.Clear();
}
class ProbeBoundingConverter : IMenuExtension
{
public STToolStripItem[] FileMenuExtensions => null;
public STToolStripItem[] ToolsMenuExtensions => toolsExt;
public STToolStripItem[] TitleBarExtensions => null;
readonly STToolStripItem[] toolsExt = new STToolStripItem[1];
public ProbeBoundingConverter()
{
toolsExt[0] = new STToolStripItem("Mario Kart 8 Probe Light Converter");
toolsExt[0].Click += GenerateProbeLightBounds;
}
private void GenerateProbeLightBounds(object sender, EventArgs args) {
AAMP.GenerateProbeBoundings();
}
}
class OdysseyCostumeSelectorMenu : IMenuExtension
{
public STToolStripItem[] FileMenuExtensions => null;
@ -237,6 +255,7 @@ namespace FirstPlugin
{
List<Type> MenuItems = new List<Type>();
MenuItems.Add(typeof(OdysseyCostumeSelectorMenu));
MenuItems.Add(typeof(ProbeBoundingConverter));
return MenuItems.ToArray();
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK;
namespace Switch_Toolbox.Library
{
public class BoundingBox
{
public Vector3 Min;
public Vector3 Max;
}
}

View File

@ -507,6 +507,7 @@
<Compile Include="Forms\ViewportDivider.Designer.cs">
<DependentUpon>ViewportDivider.cs</DependentUpon>
</Compile>
<Compile Include="Generics\BoundingBox.cs" />
<Compile Include="Generics\GenericBitmapTexture.cs" />
<Compile Include="Generics\GenericMaterial.cs" />
<Compile Include="Generics\GenericMatTexture.cs" />

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Drawing;
using OpenTK;
using System.Reflection;
namespace Switch_Toolbox.Library
{
@ -181,6 +182,13 @@ namespace Switch_Toolbox.Library
{
return Guid.NewGuid().ToString();
}
public static string GetAllFilters(Type type)
{
Object instance = Activator.CreateInstance(type);
return GetAllFilters((IFileFormat)instance);
}
public static string GetAllFilters(IFileFormat format)
{
List<IFileFormat> f = new List<IFileFormat>();