1
0
mirror of synced 2024-11-12 02:00:50 +01:00

Generate min and max value for FMDL for camera centering later

This commit is contained in:
KillzXGaming 2019-05-13 15:51:06 -04:00
parent 67d1b6920a
commit e3f720289b
10 changed files with 53 additions and 2 deletions

Binary file not shown.

View File

@ -12,11 +12,16 @@ using ResUGX2 = Syroot.NintenTools.Bfres.GX2;
using ResGFX = Syroot.NintenTools.NSW.Bfres.GFX;
using FirstPlugin;
using FirstPlugin.Forms;
using OpenTK;
namespace Bfres.Structs
{
public class FMDL : STGenericModel
{
//These get updated on UpdateVertexData()
public Vector3 MaxPosition = new Vector3(0);
public Vector3 MinPosition = new Vector3(0);
public bool IsEdited { get; set; }
public List<FSHP> shapes = new List<FSHP>();

View File

@ -1381,7 +1381,7 @@ namespace Bfres.Structs
}
}
public List<DisplayVertex> CreateDisplayVertices()
public List<DisplayVertex> CreateDisplayVertices(FMDL model)
{
// rearrange faces
display = lodMeshes[DisplayLODIndex].getDisplayFace().ToArray();
@ -1393,6 +1393,9 @@ namespace Bfres.Structs
foreach (Vertex v in vertices)
{
model.MaxPosition = OpenGLUtils.GetMax(model.MaxPosition, v.pos);
model.MinPosition = OpenGLUtils.GetMin(model.MinPosition, v.pos);
DisplayVertex displayVert = new DisplayVertex()
{
pos = v.pos,

View File

@ -235,6 +235,11 @@ namespace FirstPlugin
//Depth sort meshes
DepthSortMeshes(control.CameraTarget);
}
public void CenterCamera(GL_ControlModern control)
{
}
public static Vector4 GenerateBoundingSphere(IEnumerable<Vector4> boundingSpheres)
{
// The initial max/min should be the first point.
@ -286,6 +291,9 @@ namespace FirstPlugin
if (models.Count > 0)
{
if (models[0].Parent.Parent.IsSelected)
CenterCamera(control);
if (models[0].shapes.Count > 0)
{
if (models[0].shapes[0].GetMaterial().shaderassign.ShaderModel == "uking_mat")
@ -714,6 +722,10 @@ namespace FirstPlugin
foreach (FMDL mdl in models)
{
//Reset min/max
mdl.MaxPosition = new Vector3(0);
mdl.MinPosition = new Vector3(0);
foreach (FSHP m in mdl.shapes)
{
progressBar.Task = "Updating Shape... " + m.Text;
@ -722,7 +734,7 @@ namespace FirstPlugin
progressBar.Refresh();
m.Offset = poffset * 4;
List<DisplayVertex> pv = m.CreateDisplayVertices();
List<DisplayVertex> pv = m.CreateDisplayVertices(mdl);
Vs.AddRange(pv);
for (int i = 0; i < m.lodMeshes[m.DisplayLODIndex].displayFaceSize; i++)

View File

@ -642,6 +642,7 @@
<Compile Include="ThemeConfig.cs" />
<Compile Include="UpdateProgram.cs" />
<Compile Include="Util\ColorUtility.cs" />
<Compile Include="Util\OpenGLUtils.cs" />
<Compile Include="Util\Util.cs" />
<Compile Include="XML\XmlDoc.cs" />
</ItemGroup>

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK;
namespace Switch_Toolbox.Library
{
public class OpenGLUtils
{
public static Vector3 GetMax(Vector3 value1, Vector3 value2)
{
Vector3 val = new Vector3(0);
val.X = Math.Max(value1.X, value2.X);
val.Y = Math.Max(value1.Y, value2.Y);
val.Z = Math.Max(value1.Z, value2.Z);
return val;
}
public static Vector3 GetMin(Vector3 value1, Vector3 value2)
{
Vector3 val = new Vector3(0);
val.X = Math.Min(value1.X, value2.X);
val.Y = Math.Min(value1.Y, value2.Y);
val.Z = Math.Min(value1.Z, value2.Z);
return val;
}
}
}