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

Fix more bugs. Additional probe stuff

This commit is contained in:
KillzXGaming 2019-04-10 15:36:10 -04:00
parent 6414744c28
commit 76ca51d20a
21 changed files with 397 additions and 18 deletions

Binary file not shown.

View File

@ -680,9 +680,9 @@ namespace FirstPlugin
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(Min.X, vertex.pos.X);
Max.Y = Math.Max(Min.Y, vertex.pos.Y);
Max.Z = Math.Max(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);
}
}

View File

@ -183,6 +183,15 @@ namespace FirstPlugin
private void DrawBoundingBoxes()
{
var boundings = GetSelectionBox();
DrawableBoundingBox.DrawBoundingBox(
new Vector3(boundings.minX, boundings.minY, boundings.minZ),
new Vector3(boundings.maxX, boundings.maxY, boundings.maxZ)
);
return;
foreach (FMDL mdl in models)
{
foreach (FSHP m in mdl.shapes)
@ -1097,9 +1106,9 @@ namespace FirstPlugin
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(Min.X, vertex.pos.X);
Max.Y = Math.Max(Min.Y, vertex.pos.Y);
Max.Z = Math.Max(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);
}
}
}

View File

@ -157,15 +157,18 @@ namespace FirstPlugin.Forms
{
probeLightingConfig = new ProbeLighting();
viewport.AddDrawable(probeLightingConfig);
treeView1.Nodes.Add(new ProbeLightingWrapper(probeLightingConfig));
var probeRoot = new ProbeLightingWrapper(probeLightingConfig);
treeView1.Nodes.Add(probeRoot);
uint index = 0;
foreach (var val in aamp.RootNode.childParams)
{
var entry = new ProbeLighting.Entry();
entry.Index = index;
entry.Index = index++;
probeLightingConfig.Entries.Add(entry);
probeRoot.Nodes.Add(new ProbeLightingEntryWrapper(entry));
foreach (var param in val.paramObjects)
{
switch (param.HashString)
@ -189,6 +192,8 @@ namespace FirstPlugin.Forms
}
}
aamp.Save("DEBUG_PROBE.aamp");
foreach (var entry in probeLightingConfig.Entries)
{
Console.WriteLine(entry.Name);
@ -251,12 +256,21 @@ namespace FirstPlugin.Forms
{
ProbeLighting.Grid grid = new ProbeLighting.Grid();
var mainBfres = scene.BfresObjects[0];
var boundings = mainBfres.BFRESRender.GetSelectionBox();
foreach (var entry in paramEntries)
{
if (entry.HashString == "aabb_min_pos")
if (entry.HashString == "aabb_min_pos") {
grid.AABB_Max_Position = Utils.ToVec3((Syroot.Maths.Vector3F)entry.Value);
if (entry.HashString == "aabb_max_pos")
entry.Value = new Syroot.Maths.Vector3F(boundings.minX, boundings.minY, boundings.minZ);
}
if (entry.HashString == "aabb_max_pos") {
grid.AABB_Min_Position = Utils.ToVec3((Syroot.Maths.Vector3F)entry.Value);
entry.Value = new Syroot.Maths.Vector3F(boundings.maxX, boundings.maxY, boundings.maxZ);
}
if (entry.HashString == "voxel_step_pos")
grid.Voxel_Step_Position = Utils.ToVec3((Syroot.Maths.Vector3F)entry.Value);
}
@ -382,6 +396,23 @@ namespace FirstPlugin.Forms
{
stPropertyGrid1.LoadProperty(scene, OnPropertyChanged);
}
else if (node is ProbeLightingWrapper)
{
}
else if (node is ProbeLightingEntryWrapper)
{
var parent = (ProbeLightingWrapper)node.Parent;
foreach (var child in parent.Nodes)
{
( (ProbeLightingEntryWrapper)child).entry.Grid.GridColor = new Vector3(9, 0, 0);
}
var probeEntry = (ProbeLightingEntryWrapper)node;
probeEntry.entry.Grid.GridColor = new Vector3(1,0,0);
stPropertyGrid1.LoadProperty(probeEntry.entry, OnPropertyChanged);
}
else if (node is PathCollectionNode)
{
foreach (var group in ((PathCollectionNode)node).Nodes)
@ -441,6 +472,8 @@ namespace FirstPlugin.Forms
{
if (node is PathPointNode)
((PathPointNode)node).OnChecked(IsChecked);
if (node is ProbeLightingEntryWrapper)
((ProbeLightingEntryWrapper)node).OnChecked(IsChecked);
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Switch_Toolbox.Library;
using Switch_Toolbox.Library.Rendering;
namespace FirstPlugin.Turbo.CourseMuuntStructs
{
public class ProbeLightingEntryWrapper : TreeNodeCustom
{
public ProbeLighting.Entry entry;
public void OnChecked(bool IsChecked)
{
entry.IsVisable = IsChecked;
}
public ProbeLightingEntryWrapper(ProbeLighting.Entry config) {
Text = config.Name;
Checked = true;
entry = config;
}
}
}

View File

@ -10,11 +10,12 @@ namespace FirstPlugin.Turbo.CourseMuuntStructs
{
public class ProbeLightingWrapper : TreeNodeCustom
{
ProbeLighting ProbeLightingConfig;
public ProbeLighting ProbeLightingConfig;
public ProbeLightingWrapper(ProbeLighting config) {
Text = "course.bglpbd (Probe Lighting)";
ProbeLightingConfig = config;
Checked = true;
}
}
}

View File

@ -362,6 +362,7 @@
<Compile Include="GUI\Byaml\CourseMuunt\Wrappers\PathCollectionNode.cs" />
<Compile Include="GUI\Byaml\CourseMuunt\Wrappers\PathGroupNode.cs" />
<Compile Include="GUI\Byaml\CourseMuunt\Wrappers\PathPointNode.cs" />
<Compile Include="GUI\Byaml\CourseMuunt\Wrappers\ProbeLightingEntryWrapper.cs" />
<Compile Include="GUI\Byaml\CourseMuunt\Wrappers\ProbeLightingWrapper.cs" />
<Compile Include="MarioCostumeEditor.cs" />
<Compile Include="GUI\AAMP\AampV1Editor.cs">

View File

@ -1 +1 @@
7798e93b603f2ef483cd6e7dc6584588e301ec40
fb185deacd6b91f90d3d81f0920e25025a615d0b

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK.Graphics.OpenGL;
using OpenTK;
namespace Switch_Toolbox.Library.Rendering
{
public class DrawableBoundingBox
{
public static List<Vector3> GetBoundingVertices(Vector3 Min, Vector3 Max)
{
var vertices = new List<Vector3>();
vertices.Add(new Vector3(Min.X, Min.Y, Min.Z));
vertices.Add(new Vector3(Min.X, Min.Y, Max.Z));
vertices.Add(new Vector3(Min.X, Max.Y, Min.Z));
vertices.Add(new Vector3(Min.X, Max.Y, Max.Z));
vertices.Add(new Vector3(Max.X, Min.Y, Min.Z));
vertices.Add(new Vector3(Max.X, Min.Y, Max.Z));
vertices.Add(new Vector3(Max.X, Max.Y, Min.Z));
vertices.Add(new Vector3(Max.X, Max.Y, Max.Z));
return vertices;
}
public static void DrawBoundingBox(Vector3 Min, Vector3 Max)
{
var vertices = GetBoundingVertices(Min, Max);
GL.Begin(PrimitiveType.LineLoop);
GL.Vertex3(vertices[0]);
GL.Vertex3(vertices[1]);
GL.Vertex3(vertices[3]);
GL.Vertex3(vertices[2]);
GL.End();
GL.Begin(PrimitiveType.LineLoop);
GL.Vertex3(vertices[4]);
GL.Vertex3(vertices[5]);
GL.Vertex3(vertices[7]);
GL.Vertex3(vertices[6]);
GL.End();
GL.Begin(PrimitiveType.Lines);
GL.Vertex3(vertices[0]);
GL.Vertex3(vertices[4]);
GL.Vertex3(vertices[1]);
GL.Vertex3(vertices[5]);
GL.Vertex3(vertices[3]);
GL.Vertex3(vertices[7]);
GL.Vertex3(vertices[2]);
GL.Vertex3(vertices[6]);
GL.End();
}
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using System.Text;
using System.Threading.Tasks;
using GL_EditorFramework.GL_Core;
@ -16,6 +17,8 @@ namespace Switch_Toolbox.Library.Rendering
public class Entry
{
public bool IsVisable = true;
public string Name { get { return $"b_{Index}"; } }
public uint Index = 0;
@ -29,24 +32,254 @@ namespace Switch_Toolbox.Library.Rendering
public uint MaxIndexNum;
public uint[] IndexBuffer = new uint[0];
public ushort[] GetUint16BufferIndices()
{
if (!IsUint16Buffer())
throw new Exception("Buffer not a ushort buffer!");
List<ushort> Indices = new List<ushort>();
//Read the buffer data back as ushort
for (int i = 0; i < IndexBuffer.Length; i++)
{
byte[] bytes = BitConverter.GetBytes(IndexBuffer[i]);
Indices.Add(BitConverter.ToUInt16(bytes, 0));
Indices.Add(BitConverter.ToUInt16(bytes, 2));
}
return Indices.ToArray();
}
public bool IsUint16Buffer()
{
if (IndexBuffer.Length / 2 == UsedIndexNum)
return true;
else return false;
}
public bool IsUint32Buffer()
{
if (IndexBuffer.Length == UsedIndexNum)
return true;
else return false;
}
//Data Buffer
public uint DataType = 0;
public uint UsedShDataNum;
public uint MaxShDataNum;
public uint PerProbeNum = 27;
public float[] DataBuffer = new float[0];
public bool IsHalfFloatBuffer()
{
if ((DataBuffer.Length * PerProbeNum) / 2 == UsedShDataNum)
return true;
else return false;
}
public bool IsFloatBuffer()
{
if ((DataBuffer.Length * PerProbeNum) == UsedShDataNum)
return true;
else return false;
}
//Color data in the data buffer
public class ShereHermonic
{
//Usually 27
public Vector3[] Coefficents;
public ShereHermonic(int PerProbeNum) {
Coefficents = new Vector3[PerProbeNum];
}
}
}
public class Grid
{
public Vector3 GridColor;
public Vector3 AABB_Max_Position;
public Vector3 AABB_Min_Position;
public Vector3 Voxel_Step_Position;
}
protected static ShaderProgram ProbeSHShaderProgram;
int vbo_position;
public void Destroy()
{
bool buffersWereInitialized = vbo_position != 0;
if (!buffersWereInitialized)
return;
GL.DeleteBuffer(vbo_position);
}
public List<Vector3> GetProbeVertices(int index)
{
var entry = Entries[index];
var vertices = new List<Vector3>();
Vector3 Max = entry.Grid.AABB_Max_Position;
Vector3 Min = entry.Grid.AABB_Min_Position;
Vector3 Step = entry.Grid.AABB_Min_Position;
float GridWidth = Min.X + Max.X;
float GirdHeight = Min.Y + Max.Y;
/* //Draw Z plane
for (int x = 0; x < GridWidth; x++)
{
for (int y = 0; y < GirdHeight; y++)
{
Vector3 position = new Vector3(Min.X + (x / Step.X) * (Max.X - Min.X),
Min.Y + (y / Step.Y) * (Max.Y - Min.Y),
Max.Z);
vertices.Add(position);
}
}*/
return vertices;
}
public List<Vector3> GetBoundingVertices(int index)
{
var entry = Entries[index];
var vertices = new List<Vector3>();
Vector3 Max = entry.Grid.AABB_Max_Position;
Vector3 Min = entry.Grid.AABB_Min_Position;
vertices.Add(new Vector3(Min.X, Min.Y, Min.Z));
vertices.Add(new Vector3(Min.X, Min.Y, Max.Z));
vertices.Add(new Vector3(Min.X, Max.Y, Min.Z));
vertices.Add(new Vector3(Min.X, Max.Y, Max.Z));
vertices.Add(new Vector3(Max.X, Min.Y, Min.Z));
vertices.Add(new Vector3(Max.X, Min.Y, Max.Z));
vertices.Add(new Vector3(Max.X, Max.Y, Min.Z));
vertices.Add(new Vector3(Max.X, Max.Y, Max.Z));
return vertices;
}
public static int CellAmount;
public static int CellSize;
int CurrentIndex = 0;
Vector3[] Vertices
{
get
{
return GetProbeVertices(CurrentIndex).ToArray();
}
}
public void UpdateVertexData()
{
Vector3[] vertices = Vertices;
GL.GenBuffers(1, out vbo_position);
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_position);
GL.BufferData<Vector3>(BufferTarget.ArrayBuffer,
new IntPtr(vertices.Length * Vector3.SizeInBytes),
vertices, BufferUsageHint.StaticDraw);
}
public override void Draw(GL_ControlModern control, Pass pass)
{
if (pass == Pass.TRANSPARENT)
return;
bool buffersWereInitialized = vbo_position != 0;
if (!buffersWereInitialized)
UpdateVertexData();
if (!Runtime.OpenTKInitialized)
return;
control.CurrentShader = ProbeSHShaderProgram;
control.UpdateModelMatrix(Matrix4.Identity);
Matrix4 previewScale = Utils.TransformValues(Vector3.Zero, Vector3.Zero, Runtime.previewScale);
ProbeSHShaderProgram.SetMatrix4x4("previewScale", ref previewScale);
foreach (var entry in Entries)
{
if (!entry.IsVisable)
continue;
Vector3[] vertices = GetBoundingVertices((int)entry.Index).ToArray();
Vector3 Max = entry.Grid.AABB_Max_Position;
Vector3 Min = entry.Grid.AABB_Min_Position;
Vector3 Step = entry.Grid.Voxel_Step_Position;
float gridHeight = Min.Y + Max.Y;
float gridWidth = Min.X + Max.X;
float gridDepth = Min.Z + Max.Z;
//Draw bounding box
GL.Color3(entry.Grid.GridColor);
GL.Begin(PrimitiveType.LineLoop);
GL.Vertex3(vertices[0]);
GL.Vertex3(vertices[1]);
GL.Vertex3(vertices[3]);
GL.Vertex3(vertices[2]);
GL.End();
GL.Begin(PrimitiveType.LineLoop);
GL.Vertex3(vertices[4]);
GL.Vertex3(vertices[5]);
GL.Vertex3(vertices[7]);
GL.Vertex3(vertices[6]);
GL.End();
GL.Begin(PrimitiveType.Lines);
GL.Vertex3(vertices[0]);
GL.Vertex3(vertices[4]);
GL.Vertex3(vertices[1]);
GL.Vertex3(vertices[5]);
GL.Vertex3(vertices[3]);
GL.Vertex3(vertices[7]);
GL.Vertex3(vertices[2]);
GL.Vertex3(vertices[6]);
GL.End();
ProbeSHShaderProgram.EnableVertexAttributes();
Draw(ProbeSHShaderProgram);
ProbeSHShaderProgram.DisableVertexAttributes();
}
GL.UseProgram(0);
}
private void Attributes(ShaderProgram shader)
{
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_position);
GL.VertexAttribPointer(shader.GetAttribute("vPosition"), 3, VertexAttribPointerType.Float, false, 12, 0);
}
private void Uniforms(ShaderProgram shader)
{
shader.SetVector3("gridColor", ColorUtility.ToVector3(System.Drawing.Color.Black));
}
private void Draw(ShaderProgram shader)
{
Uniforms(shader);
Attributes(shader);
GL.DrawArrays(PrimitiveType.Points, 0, Vertices.Length);
}
public override void Draw(GL_ControlLegacy control, Pass pass)
@ -56,7 +289,24 @@ namespace Switch_Toolbox.Library.Rendering
public override void Prepare(GL_ControlModern control)
{
var Frag = new FragmentShader(
@"#version 330
uniform vec3 gridColor;
void main(){
gl_FragColor = vec4(gridColor, 1);
}");
var Vert = new VertexShader(
@"#version 330
in vec3 vPosition;
uniform mat4 mtxMdl;
uniform mat4 mtxCam;
void main(){
gl_Position = mtxMdl * mtxCam * vec4(vPosition.xyz, 1);
}");
ProbeSHShaderProgram = new ShaderProgram(Frag, Vert);
}
public override void Prepare(GL_ControlLegacy control)

View File

@ -570,6 +570,7 @@
</Compile>
<Compile Include="PublicEnums.cs" />
<Compile Include="Rendering\DrawableBackground.cs" />
<Compile Include="Rendering\DrawableBoundingBox.cs" />
<Compile Include="Rendering\DrawableCube.cs" />
<Compile Include="Rendering\DrawableSkybox.cs" />
<Compile Include="Rendering\DrawableFloor.cs" />

View File

@ -754,7 +754,7 @@ namespace Switch_Toolbox.Library
return swizzleSurf(width, height, depth, format_, tileMode, swizzle_, pitch, bpp, data, depthLevel, 1);
}
private static byte[] swizzleSurf(uint width, uint height,uint depth, uint format, uint tileMode, uint swizzle_,
private static byte[] swizzleSurf(uint width, uint height, uint depth, uint format, uint tileMode, uint swizzle_,
uint pitch, uint bitsPerPixel, byte[] data, int depthLevel, int swizzle)
{
uint bytesPerPixel = bitsPerPixel / 8;
@ -1910,9 +1910,9 @@ namespace Switch_Toolbox.Library
tileMode,
padDims,
(flags.value >> 4) & 1,
(flags.value >> 7) & 1,
pitchAlign,
heightAlign);
heightAlign,
microTileThickness);
expPitch = padDimens.Item1;
expHeight = padDimens.Item2;
@ -1995,9 +1995,9 @@ namespace Switch_Toolbox.Library
tileMode,
padDims,
(flags.value >> 4) & 1,
(flags.value >> 7) & 1,
pitchAlign,
heightAlign);
heightAlign,
microTileThickness);
expPitch = padDimens.Item1;
expHeight = padDimens.Item2;
@ -2485,4 +2485,4 @@ namespace Switch_Toolbox.Library
return pSurfOut;
}
}
}
}