Merge pull request #2 from KillzXGaming/master

Merge updates
This commit is contained in:
AboodXD 2019-04-11 08:32:14 -07:00 committed by GitHub
commit f6d8e8196b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 835 additions and 82 deletions

Binary file not shown.

View file

@ -54,8 +54,8 @@ namespace FirstPlugin
}
}
aampv1.AampFile aampFileV1;
aampv2.AampFile aampFileV2;
public aampv1.AampFile aampFileV1;
public aampv2.AampFile aampFileV2;
AampV1Editor aampEditorV1;
AampV2Editor aampEditorV2;

View file

@ -452,32 +452,39 @@ namespace Bfres.Structs
else
Model.Export(FileName, GetResFile());
break;
case ".obj":
OBJ.ExportModel(FileName, this, GetTextures());
break;
default:
List<STGenericTexture> textures = new List<STGenericTexture>();
foreach (var mat in materials)
{
foreach (var texref in mat.Value.TextureMaps)
{
foreach (var bntx in PluginRuntime.bntxContainers)
{
if (bntx.Textures.ContainsKey(texref.Name))
textures.Add(bntx.Textures[texref.Name]);
}
foreach (var ftexCont in PluginRuntime.ftexContainers)
{
if (ftexCont.ResourceNodes.ContainsKey(texref.Name))
textures.Add((FTEX)ftexCont.ResourceNodes[texref.Name]);
}
}
}
AssimpSaver assimp = new AssimpSaver();
assimp.SaveFromModel(this, FileName, textures, Skeleton, Skeleton.Node_Array.ToList());
assimp.SaveFromModel(this, FileName, GetTextures(), Skeleton, Skeleton.Node_Array.ToList());
break;
}
}
private List<STGenericTexture> GetTextures()
{
List<STGenericTexture> textures = new List<STGenericTexture>();
foreach (var mat in materials)
{
foreach (var texref in mat.Value.TextureMaps)
{
foreach (var bntx in PluginRuntime.bntxContainers)
{
if (bntx.Textures.ContainsKey(texref.Name))
textures.Add(bntx.Textures[texref.Name]);
}
foreach (var ftexCont in PluginRuntime.ftexContainers)
{
if (ftexCont.ResourceNodes.ContainsKey(texref.Name))
textures.Add((FTEX)ftexCont.ResourceNodes[texref.Name]);
}
}
}
return textures;
}
public override void Replace(string FileName) {
AddOjects(FileName, GetResFile(), GetResFileU());
}

View file

@ -127,6 +127,9 @@ namespace Bfres.Structs
AnimDataOffset = keyGroup.AnimDataOffset,
Keys = keyGroup.Keys,
});
if (paramInfo.Text.Contains("Color") || paramInfo.Text.Contains("color"))
paramInfo.Type = AnimationType.Color;
}
}
}

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

@ -207,7 +207,7 @@ namespace FirstPlugin
variationSymbolData.Read(reader);
variationSymbolDataFull.Read(reader);
UniformBlocks.Read(reader, header.Version);
UniformBlocks.Read(reader, header.Version, true);
if (header.Version <= 12)
{

View file

@ -313,7 +313,6 @@ namespace FirstPlugin
public class VariationMacro
{
public string Name { get; set; }
public string[] Values { get; set; }
public string Value { get; set; }
public void Read(FileReader reader, uint Version)
@ -321,38 +320,16 @@ namespace FirstPlugin
var pos = reader.Position;
uint SectionSize = reader.ReadUInt32();
if (Version >= 13)
{
uint NameLength = reader.ReadUInt32();
uint ValueCount = reader.ReadUInt32();
Name = reader.ReadString((int)NameLength);
Value = reader.ReadString((int)ValueCount);
uint NameLength = reader.ReadUInt32();
uint ValueLength = reader.ReadUInt32();
Name = reader.ReadString((int)NameLength);
Value = reader.ReadString((int)ValueLength);
Values = new string[0];
Console.WriteLine("VariationMacro ------------------");
Console.WriteLine(Name);
Console.WriteLine(Value);
Console.WriteLine("------------------");
}
else
{
uint NameLength = reader.ReadUInt32();
uint ValueCount = reader.ReadUInt32();
uint Unk = reader.ReadUInt32();
Name = reader.ReadString((int)NameLength);
Values = reader.ReadStrings((int)ValueCount, Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
foreach (string vl in Values)
Value += $" {vl}";
Console.WriteLine("VariationMacro ------------------");
Console.WriteLine(Name);
Console.WriteLine(Value);
Console.WriteLine("------------------");
}
Console.WriteLine("VariationMacro ------------------");
Console.WriteLine(Name);
Console.WriteLine(Value);
Console.WriteLine("------------------");
reader.Seek(pos + SectionSize, System.IO.SeekOrigin.Begin);
@ -407,18 +384,22 @@ namespace FirstPlugin
public class ShaderSymbolData
{
public List<ShaderSymbol> symbols = new List<ShaderSymbol>();
public void Read(FileReader reader, uint Version = 12)
public void Read(FileReader reader, uint Version = 12, bool SkipReading = false)
{
var SectionPos = reader.Position;
uint SectionSize = reader.ReadUInt32();
uint SectionCount = reader.ReadUInt32();
for (int i = 0; i < SectionCount; i++)
if (!SkipReading)
{
ShaderSymbol symbol = new ShaderSymbol();
symbol.Read(reader, Version);
symbols.Add(symbol);
for (int i = 0; i < SectionCount; i++)
{
ShaderSymbol symbol = new ShaderSymbol();
symbol.Read(reader, Version);
symbols.Add(symbol);
}
}
reader.Seek(SectionPos + SectionSize, System.IO.SeekOrigin.Begin);
}
}

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

@ -297,6 +297,7 @@ namespace FirstPlugin.Turbo.CourseMuuntStructs
public List<BFRES> BfresObjects = new List<BFRES>();
public List<KCL> KclObjects = new List<KCL>();
public List<AAMP> ParameterArchives = new List<AAMP>();
public void AddRenderableKcl(string FilePath)
{
@ -319,5 +320,16 @@ namespace FirstPlugin.Turbo.CourseMuuntStructs
if (bfres != null)
BfresObjects.Add(bfres);
}
public void AddParameterArchive(string FilePath)
{
if (!System.IO.File.Exists(FilePath))
return;
AAMP aamp = (AAMP)Switch_Toolbox.Library.IO.STFileLoader.OpenFileFormat(FilePath);
if (aamp != null)
ParameterArchives.Add(aamp);
}
}
}

View file

@ -10,6 +10,9 @@ using FirstPlugin.Turbo.CourseMuuntStructs;
using GL_EditorFramework.EditorDrawables;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using aampv1 = AampV1Library;
using aampv2 = AampV2Library;
using Switch_Toolbox.Library.Rendering;
namespace FirstPlugin.Forms
{
@ -53,19 +56,41 @@ namespace FirstPlugin.Forms
CourseMuuntScene scene;
string CourseFolder;
public void LoadCourseInfo(System.Collections.IEnumerable by, string FilePath)
{
string CourseFolder = System.IO.Path.GetDirectoryName(FilePath);
CourseFolder = System.IO.Path.GetDirectoryName(FilePath);
scene = new CourseMuuntScene(by);
//Add collsion (switch)
if (File.Exists($"{CourseFolder}/course_kcl.szs"))
scene.AddRenderableKcl($"{CourseFolder}/course_kcl.szs");
//Add collsion (wii u)
if (File.Exists($"{CourseFolder}/course.kcl"))
scene.AddRenderableKcl($"{CourseFolder}/course.kcl");
//Add probe lighting config (wii u)
if (File.Exists($"{CourseFolder}/course.bglpbd"))
scene.AddParameterArchive($"{CourseFolder}/course.bglpbd");
//Add probe lighting config (switch)
if (File.Exists($"{CourseFolder}/course_bglpbd.szs"))
scene.AddParameterArchive($"{CourseFolder}/course_bglpbd.szs");
//Add course model
if (File.Exists($"{CourseFolder}/course_model.szs"))
{
scene.AddRenderableBfres($"{CourseFolder}/course_model.szs");
foreach (AAMP aamp in scene.ParameterArchives)
{
if (aamp.aampFileV1 != null)
LoadParameters(aamp.aampFileV1);
else if (aamp.aampFileV2 != null)
LoadParameters(aamp.aampFileV2);
else
throw new Exception("Failed to load parameter file " + aamp.FileName);
}
viewport.AddDrawable(new GL_EditorFramework.EditorDrawables.SingleObject(new OpenTK.Vector3(0)));
@ -110,21 +135,163 @@ namespace FirstPlugin.Forms
foreach (var kcl in scene.KclObjects)
{
viewport.AddDrawable(kcl.Renderer);
treeView1.Nodes.Add(kcl);
kcl.Checked = true;
// viewport.AddDrawable(kcl.Renderer);
// treeView1.Nodes.Add(kcl);
// kcl.Checked = true;
}
foreach (var bfres in scene.BfresObjects)
{
viewport.AddDrawable(bfres.BFRESRender);
treeView1.Nodes.Add(bfres);
bfres.Checked = true;
// viewport.AddDrawable(bfres.BFRESRender);
// treeView1.Nodes.Add(bfres);
// bfres.Checked = true;
}
IsLoaded = true;
}
ProbeLighting probeLightingConfig;
private void LoadParameters(aampv1.AampFile aamp)
{
if (aamp.EffectType == "Probe Data")
{
probeLightingConfig = new ProbeLighting();
viewport.AddDrawable(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++;
probeLightingConfig.Entries.Add(entry);
probeRoot.Nodes.Add(new ProbeLightingEntryWrapper(entry));
foreach (var param in val.paramObjects)
{
switch (param.HashString)
{
case "param_obj":
foreach (var data in param.paramEntries) {
if (data.HashString == "index") entry.Index = (uint)data.Value;
if (data.HashString == "type") entry.Type = (uint)data.Value;
}
break;
case "grid":
entry.Grid = LoadGridData(param.paramEntries);
break;
case "sh_index_buffer":
LoadIndexBuffer(param.paramEntries, entry);
break;
case "sh_data_buffer":
LoadDataBuffer(param.paramEntries, entry);
break;
}
}
}
aamp.Save($"{CourseFolder}/DEBUG_PROBE.aamp");
foreach (var entry in probeLightingConfig.Entries)
{
Console.WriteLine(entry.Name);
Console.WriteLine($"IndexType {entry.IndexType}");
Console.WriteLine($"DataType {entry.DataType}");
Console.WriteLine($"MaxIndexNum {entry.MaxIndexNum}");
Console.WriteLine($"UsedIndexNum {entry.UsedIndexNum}");
Console.WriteLine($"MaxShDataNum {entry.MaxShDataNum}");
Console.WriteLine($"UsedShDataNum {entry.UsedShDataNum}");
Console.WriteLine($"AABB_Max_Position {entry.Grid.AABB_Max_Position}");
Console.WriteLine($"AABB_Min_Position {entry.Grid.AABB_Min_Position}");
Console.WriteLine($"Voxel_Step_Position {entry.Grid.Voxel_Step_Position}");
Console.WriteLine($"DataBuffer {entry.DataBuffer.Length}");
Console.WriteLine($"IndexBuffer {entry.IndexBuffer.Length}");
}
}
}
private void LoadDataBuffer(aampv1.ParamEntry[] paramEntries, ProbeLighting.Entry probeEntry)
{
foreach (var entry in paramEntries)
{
if (entry.HashString == "type")
probeEntry.DataType = (uint)entry.Value;
if (entry.HashString == "used_data_num")
probeEntry.UsedShDataNum = (uint)entry.Value;
if (entry.HashString == "max_sh_data_num")
probeEntry.MaxShDataNum = (uint)entry.Value;
if (entry.HashString == "data_buffer")
{
if (entry.ParamType == aampv1.ParamType.BufferFloat)
probeEntry.DataBuffer = (float[])entry.Value;
}
}
}
private void LoadIndexBuffer(aampv1.ParamEntry[] paramEntries, ProbeLighting.Entry probeEntry)
{
foreach (var entry in paramEntries)
{
if (entry.HashString == "type")
probeEntry.IndexType = (uint)entry.Value;
if (entry.HashString == "used_index_num")
probeEntry.UsedIndexNum = (uint)entry.Value;
if (entry.HashString == "max_index_num")
probeEntry.MaxIndexNum = (uint)entry.Value;
if (entry.HashString == "index_buffer")
{
if (entry.ParamType == aampv1.ParamType.BufferUint)
probeEntry.IndexBuffer = (uint[])entry.Value;
//Experimental, just fill in indices
uint[] values = (uint[])entry.Value;
for (int i = 0; i < values.Length; i++)
{
values[i] = 0;
}
entry.Value = values;
}
}
}
private ProbeLighting.Grid LoadGridData(aampv1.ParamEntry[] paramEntries)
{
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") {
grid.AABB_Max_Position = Utils.ToVec3((Syroot.Maths.Vector3F)entry.Value);
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);
}
return grid;
}
private void LoadParameters(aampv2.AampFile aamp)
{
}
private void AddPathDrawable(string Name, IEnumerable<BasePathPoint> Groups, Color color, bool CanConnect = true)
{
@ -190,16 +357,38 @@ namespace FirstPlugin.Forms
private void viewIntroCameraToolStripMenuItem_Click(object sender, EventArgs e)
{
//Sort list by camera number/id
scene.IntroCameras.Sort((x, y) => x.CameraNum.CompareTo(y.CameraNum));
foreach (var camera in scene.IntroCameras)
{
var pathMove = scene.Paths[camera.Camera_Path];
var pathLookAt = scene.Paths[camera.Camera_AtPath];
//The time elapsed for each point
int PathTime = camera.CameraTime / pathMove.PathPoints.Count;
//Go through each point
for (int p = 0; p < pathMove.PathPoints.Count; p++)
{
//If lookat path is higher than the move path, break
if (pathLookAt.PathPoints.Count >= p)
break;
//Set our points
var pathMovePoint = pathMove.PathPoints[p];
var pathLookAtPoint = pathLookAt.PathPoints[p];
for (int frame = 0; frame < PathTime; frame++)
{
if (viewport.GL_ControlModern != null)
{
viewport.GL_ControlModern.CameraEye = pathLookAtPoint.Translate;
viewport.GL_ControlModern.CameraTarget = pathMovePoint.Translate;
viewport.UpdateViewport();
}
}
}
}
}
@ -216,6 +405,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)
@ -275,6 +481,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

@ -0,0 +1,21 @@
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 ProbeLightingWrapper : TreeNodeCustom
{
public ProbeLighting ProbeLightingConfig;
public ProbeLightingWrapper(ProbeLighting config) {
Text = "course.bglpbd (Probe Lighting)";
ProbeLightingConfig = config;
Checked = true;
}
}
}

View file

@ -362,6 +362,8 @@
<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">
<SubType>UserControl</SubType>

View file

@ -1 +1 @@
303eb09c135d9731661be3be002bdbe8c1380569
fb185deacd6b91f90d3d81f0920e25025a615d0b

View file

@ -36,7 +36,7 @@ namespace Switch_Toolbox.Library
if (ext == ".ply")
formatID = "ply";
if (v.ExportFile(scene, FileName, formatID))
if (v.ExportFile(scene, FileName, formatID, PostProcessSteps.FlipUVs))
MessageBox.Show($"Exported {FileName} Successfuly!");
else
MessageBox.Show($"Failed to export {FileName}!");
@ -110,7 +110,7 @@ namespace Switch_Toolbox.Library
else
mesh.Bones[boneInd].VertexWeights.Add(new VertexWeight(vertexID, 1));
}
else if ( v.boneWeights[j] > 0)
else if (v.boneWeights.Count == 0 || v.boneWeights[j] > 0)
mesh.Bones[boneInd].VertexWeights.Add(new VertexWeight(vertexID, 1));
}
}

View file

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using OpenTK;
namespace Switch_Toolbox.Library
{
public class OBJ
{
public static void ExportModel(string FileName, STGenericModel Model, List<STGenericTexture> Textures)
{
string fileNoExt = Path.GetFileNameWithoutExtension(FileName);
string fileMtlPath = FileName.Replace("obj", "mtl");
//Write model
StringBuilder writer = new StringBuilder();
SaveMeshes(writer, Model, $"{fileNoExt}.mtl");
File.WriteAllText(FileName, writer.ToString());
//Write materials
StringBuilder writerMtl = new StringBuilder();
SaveMaterials(writerMtl, Model);
File.WriteAllText(fileMtlPath, writerMtl.ToString());
}
private static void SaveMeshes(StringBuilder writer, STGenericModel Model, string MtlName)
{
writer.AppendLine($"mtllib {MtlName}");
int VertexCount = 1;
foreach (STGenericObject mesh in Model.Nodes[0].Nodes)
{
writer.AppendLine($"o {mesh.Text}");
writer.AppendLine($"g {mesh.Text}");
foreach (var v in mesh.vertices)
{
writer.AppendLine($"v {v.pos.X} {v.pos.Y} {v.pos.Z}");
writer.AppendLine($"vn {v.nrm.X} {v.nrm.Y} {v.nrm.Z}");
writer.AppendLine($"vt {v.uv0.X} {v.uv0.Y}");
}
var mat = GetMaterial(mesh.MaterialIndex, Model);
if (mat != null)
writer.AppendLine($"usemtl {mat.Text}");
for (int i = 0; i < mesh.faces.Count; i++)
{
int[] indices = new int[3]
{
mesh.faces[i++],
mesh.faces[i++],
mesh.faces[i]
};
writer.AppendLine($"f {indices[0] + VertexCount}/{indices[0] + VertexCount}/{indices[0] + VertexCount}" +
$" {indices[1] + VertexCount}/{indices[1] + VertexCount}/{indices[1] + VertexCount}" +
$" {indices[2] + VertexCount}/{indices[2] + VertexCount}/{indices[2] + VertexCount}");
}
VertexCount += mesh.vertices.Count;
}
}
private static STGenericMaterial GetMaterial(int MaterialIndex, STGenericModel Model)
{
if (MaterialIndex < Model.Nodes[1].Nodes.Count)
return (STGenericMaterial)Model.Nodes[1].Nodes[MaterialIndex];
else
return null;
}
public static float Ns = -3.921569f;
public static Vector3 Ka = new Vector3(1.000000f, 1.000000f, 1.000000f);
public static Vector3 Kd = new Vector3(0.640000f, 0.640000f, 0.640000f);
public static Vector3 Ks = new Vector3(0.500000f, 0.500000f, 0.500000f);
public static Vector3 Ke = new Vector3(0.000000f, 0.000000f, 0.000000f);
public static float Ni = -1f;
public static float d = -1f;
public static float illum = 2;
private static void SaveMaterials(StringBuilder writer, STGenericModel Model)
{
foreach (STGenericMaterial mat in Model.Nodes[1].Nodes)
{
writer.AppendLine($"newmtl {mat.Text}");
writer.AppendLine($"Ns {Ns}");
writer.AppendLine($"Ka {Ka.X} {Ka.Y} {Ka.Z}");
writer.AppendLine($"Kd {Kd.X} {Kd.Y} {Kd.Z}");
writer.AppendLine($"Ks {Ks.X} {Ks.Y} {Ks.Z}");
writer.AppendLine($"Ke {Ke.X} {Ke.Y} {Ke.Z}");
writer.AppendLine($"Ni {Ni}");
writer.AppendLine($"d {d}");
writer.AppendLine($"illum {illum}");
foreach (var tex in mat.TextureMaps)
{
if (tex.Type == STGenericMatTexture.TextureType.Diffuse)
writer.AppendLine($"map_Kd {tex.Name}.png");
}
}
}
}
}

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

@ -0,0 +1,317 @@
using System;
using System.Collections.Generic;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using System.Text;
using System.Threading.Tasks;
using GL_EditorFramework.GL_Core;
using GL_EditorFramework.Interfaces;
using GL_EditorFramework.EditorDrawables;
using GL_EditorFramework;
namespace Switch_Toolbox.Library.Rendering
{
public class ProbeLighting : AbstractGlDrawable
{
public List<Entry> Entries = new List<Entry>();
public class Entry
{
public bool IsVisable = true;
public string Name { get { return $"b_{Index}"; } }
public uint Index = 0;
public uint Type = 0;
public Grid Grid = new Grid();
//Index Buffer
public uint IndexType = 1;
public uint UsedIndexNum;
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)
{
}
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

@ -204,6 +204,7 @@
<Compile Include="FileFormats\APNG\CRC.cs" />
<Compile Include="FileFormats\Assimp\AssimpSaver.cs" />
<Compile Include="FileFormats\Animation\SEANIM.cs" />
<Compile Include="FileFormats\OBJ.cs" />
<Compile Include="Forms\BatchFormatExport.cs">
<SubType>Form</SubType>
</Compile>
@ -570,10 +571,12 @@
</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" />
<Compile Include="Rendering\DrawableXyzLines.cs" />
<Compile Include="Rendering\ProbeLighting.cs" />
<Compile Include="Rendering\RenderTools.cs" />
<Compile Include="Rendering\ScreenTriangle.cs" />
<Compile Include="Generics\STSkeleton.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;
@ -1154,7 +1154,7 @@ namespace Switch_Toolbox.Library
uint macroTileIndexY = y / macroTileHeight;
ulong macroTileOffset = (macroTileIndexX + macroTilesPerRow * macroTileIndexY) * macroTileBytes;
if (isBankSwappedTileMode(tileMode))
if (isBankSwappedTileMode(tileMode) != 0)
{
bankSwapWidth = computeSurfaceBankSwappedWidth(tileMode, bpp, 1, pitch);
swapIndex = macroTilePitch * macroTileIndexX / bankSwapWidth;
@ -1210,7 +1210,7 @@ namespace Switch_Toolbox.Library
if (DebugSurface)
Console.WriteLine("computeSurfaceMipLevelTileMode expTileMode " + expTileMode);
if (noRecursive || level == 0)
if (noRecursive != 0 || level == 0)
return expTileMode;
switch (bpp)
@ -1910,7 +1910,6 @@ namespace Switch_Toolbox.Library
tileMode,
padDims,
(flags.value >> 4) & 1,
(flags.value >> 7) & 1,
pitchAlign,
heightAlign,
microTileThickness);
@ -1996,7 +1995,6 @@ namespace Switch_Toolbox.Library
tileMode,
padDims,
(flags.value >> 4) & 1,
(flags.value >> 7) & 1,
pitchAlign,
heightAlign,
microTileThickness);
@ -2487,4 +2485,4 @@ namespace Switch_Toolbox.Library
return pSurfOut;
}
}
}
}

Binary file not shown.

Binary file not shown.

View file

@ -78,7 +78,10 @@ namespace Updater
continue;
if (File.Exists(Path.Combine(folderDir, Path.GetFileName(file))))
{
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(Path.Combine(folderDir, Path.GetFileName(file)));
}
File.Move(file, Path.Combine(folderDir, Path.GetFileName(file)));
}
}