diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 9468b60f..00000000
--- a/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
-
-.vs/Switch_Toolbox/v15/Server/sqlite3/db.lock
-*.resources
-Debug/
-Release/
diff --git a/GL_EditorFramework-master/.gitattributes b/GL_EditorFramework-master/.gitattributes
deleted file mode 100644
index dfe07704..00000000
--- a/GL_EditorFramework-master/.gitattributes
+++ /dev/null
@@ -1,2 +0,0 @@
-# Auto detect text files and perform LF normalization
-* text=auto
diff --git a/GL_EditorFramework-master/.gitignore b/GL_EditorFramework-master/.gitignore
deleted file mode 100644
index 3e759b75..00000000
--- a/GL_EditorFramework-master/.gitignore
+++ /dev/null
@@ -1,330 +0,0 @@
-## Ignore Visual Studio temporary files, build results, and
-## files generated by popular Visual Studio add-ons.
-##
-## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
-
-# User-specific files
-*.suo
-*.user
-*.userosscache
-*.sln.docstates
-
-# User-specific files (MonoDevelop/Xamarin Studio)
-*.userprefs
-
-# Build results
-[Dd]ebug/
-[Dd]ebugPublic/
-[Rr]elease/
-[Rr]eleases/
-x64/
-x86/
-bld/
-[Bb]in/
-[Oo]bj/
-[Ll]og/
-
-# Visual Studio 2015/2017 cache/options directory
-.vs/
-# Uncomment if you have tasks that create the project's static files in wwwroot
-#wwwroot/
-
-# Visual Studio 2017 auto generated files
-Generated\ Files/
-
-# MSTest test Results
-[Tt]est[Rr]esult*/
-[Bb]uild[Ll]og.*
-
-# NUNIT
-*.VisualState.xml
-TestResult.xml
-
-# Build Results of an ATL Project
-[Dd]ebugPS/
-[Rr]eleasePS/
-dlldata.c
-
-# Benchmark Results
-BenchmarkDotNet.Artifacts/
-
-# .NET Core
-project.lock.json
-project.fragment.lock.json
-artifacts/
-**/Properties/launchSettings.json
-
-# StyleCop
-StyleCopReport.xml
-
-# Files built by Visual Studio
-*_i.c
-*_p.c
-*_i.h
-*.ilk
-*.meta
-*.obj
-*.iobj
-*.pch
-*.pdb
-*.ipdb
-*.pgc
-*.pgd
-*.rsp
-*.sbr
-*.tlb
-*.tli
-*.tlh
-*.tmp
-*.tmp_proj
-*.log
-*.vspscc
-*.vssscc
-.builds
-*.pidb
-*.svclog
-*.scc
-
-# Chutzpah Test files
-_Chutzpah*
-
-# Visual C++ cache files
-ipch/
-*.aps
-*.ncb
-*.opendb
-*.opensdf
-*.sdf
-*.cachefile
-*.VC.db
-*.VC.VC.opendb
-
-# Visual Studio profiler
-*.psess
-*.vsp
-*.vspx
-*.sap
-
-# Visual Studio Trace Files
-*.e2e
-
-# TFS 2012 Local Workspace
-$tf/
-
-# Guidance Automation Toolkit
-*.gpState
-
-# ReSharper is a .NET coding add-in
-_ReSharper*/
-*.[Rr]e[Ss]harper
-*.DotSettings.user
-
-# JustCode is a .NET coding add-in
-.JustCode
-
-# TeamCity is a build add-in
-_TeamCity*
-
-# DotCover is a Code Coverage Tool
-*.dotCover
-
-# AxoCover is a Code Coverage Tool
-.axoCover/*
-!.axoCover/settings.json
-
-# Visual Studio code coverage results
-*.coverage
-*.coveragexml
-
-# NCrunch
-_NCrunch_*
-.*crunch*.local.xml
-nCrunchTemp_*
-
-# MightyMoose
-*.mm.*
-AutoTest.Net/
-
-# Web workbench (sass)
-.sass-cache/
-
-# Installshield output folder
-[Ee]xpress/
-
-# DocProject is a documentation generator add-in
-DocProject/buildhelp/
-DocProject/Help/*.HxT
-DocProject/Help/*.HxC
-DocProject/Help/*.hhc
-DocProject/Help/*.hhk
-DocProject/Help/*.hhp
-DocProject/Help/Html2
-DocProject/Help/html
-
-# Click-Once directory
-publish/
-
-# Publish Web Output
-*.[Pp]ublish.xml
-*.azurePubxml
-# Note: Comment the next line if you want to checkin your web deploy settings,
-# but database connection strings (with potential passwords) will be unencrypted
-*.pubxml
-*.publishproj
-
-# Microsoft Azure Web App publish settings. Comment the next line if you want to
-# checkin your Azure Web App publish settings, but sensitive information contained
-# in these scripts will be unencrypted
-PublishScripts/
-
-# NuGet Packages
-*.nupkg
-# The packages folder can be ignored because of Package Restore
-**/[Pp]ackages/*
-# except build/, which is used as an MSBuild target.
-!**/[Pp]ackages/build/
-# Uncomment if necessary however generally it will be regenerated when needed
-#!**/[Pp]ackages/repositories.config
-# NuGet v3's project.json files produces more ignorable files
-*.nuget.props
-*.nuget.targets
-
-# Microsoft Azure Build Output
-csx/
-*.build.csdef
-
-# Microsoft Azure Emulator
-ecf/
-rcf/
-
-# Windows Store app package directories and files
-AppPackages/
-BundleArtifacts/
-Package.StoreAssociation.xml
-_pkginfo.txt
-*.appx
-
-# Visual Studio cache files
-# files ending in .cache can be ignored
-*.[Cc]ache
-# but keep track of directories ending in .cache
-!*.[Cc]ache/
-
-# Others
-ClientBin/
-~$*
-*~
-*.dbmdl
-*.dbproj.schemaview
-*.jfm
-*.pfx
-*.publishsettings
-orleans.codegen.cs
-
-# Including strong name files can present a security risk
-# (https://github.com/github/gitignore/pull/2483#issue-259490424)
-#*.snk
-
-# Since there are multiple workflows, uncomment next line to ignore bower_components
-# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
-#bower_components/
-
-# RIA/Silverlight projects
-Generated_Code/
-
-# Backup & report files from converting an old project file
-# to a newer Visual Studio version. Backup files are not needed,
-# because we have git ;-)
-_UpgradeReport_Files/
-Backup*/
-UpgradeLog*.XML
-UpgradeLog*.htm
-ServiceFabricBackup/
-*.rptproj.bak
-
-# SQL Server files
-*.mdf
-*.ldf
-*.ndf
-
-# Business Intelligence projects
-*.rdl.data
-*.bim.layout
-*.bim_*.settings
-*.rptproj.rsuser
-
-# Microsoft Fakes
-FakesAssemblies/
-
-# GhostDoc plugin setting file
-*.GhostDoc.xml
-
-# Node.js Tools for Visual Studio
-.ntvs_analysis.dat
-node_modules/
-
-# Visual Studio 6 build log
-*.plg
-
-# Visual Studio 6 workspace options file
-*.opt
-
-# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
-*.vbw
-
-# Visual Studio LightSwitch build output
-**/*.HTMLClient/GeneratedArtifacts
-**/*.DesktopClient/GeneratedArtifacts
-**/*.DesktopClient/ModelManifest.xml
-**/*.Server/GeneratedArtifacts
-**/*.Server/ModelManifest.xml
-_Pvt_Extensions
-
-# Paket dependency manager
-.paket/paket.exe
-paket-files/
-
-# FAKE - F# Make
-.fake/
-
-# JetBrains Rider
-.idea/
-*.sln.iml
-
-# CodeRush
-.cr/
-
-# Python Tools for Visual Studio (PTVS)
-__pycache__/
-*.pyc
-
-# Cake - Uncomment if you are using it
-# tools/**
-# !tools/packages.config
-
-# Tabs Studio
-*.tss
-
-# Telerik's JustMock configuration file
-*.jmconfig
-
-# BizTalk build output
-*.btp.cs
-*.btm.cs
-*.odx.cs
-*.xsd.cs
-
-# OpenCover UI analysis results
-OpenCover/
-
-# Azure Stream Analytics local run output
-ASALocalRun/
-
-# MSBuild Binary and Structured Log
-*.binlog
-
-# NVidia Nsight GPU debugger configuration file
-*.nvuser
-
-# MFractors (Xamarin productivity tool) working folder
-.mfractor/
diff --git a/GL_EditorFramework-master/GL_Core/Cameras/Inspect.cs b/GL_EditorFramework-master/GL_Core/Cameras/Inspect.cs
deleted file mode 100644
index 38b4815f..00000000
--- a/GL_EditorFramework-master/GL_Core/Cameras/Inspect.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using GL_Core.Public_Interfaces;
-using OpenTK;
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace GL_Core.Cameras
-{
- public class InspectCamera : AbstractCamera
- {
- public InspectCamera()
- {
-
- }
- public override bool MouseMove(MouseEventArgs e, Point lastMouseLoc, float deltaX, float deltaY, ExtraArgs args, ref Vector3 camTarget, ref float rot, ref float lookup, ref float zoom)
- {
- if (e.Button == MouseButtons.Right)
- {
- rot += deltaX * 0.01f;
- lookup += deltaY * 0.01f;
- return true;
- }
- else if (e.Button == MouseButtons.Left)
- {
- deltaX *= Math.Min(0.1f, args.pickingDepth * args.factorX);
- deltaY *= Math.Min(0.1f, args.pickingDepth * args.factorY);
-
- camTarget += Vector3.UnitX * (float)Math.Cos(rot) * deltaX;
- camTarget -= Vector3.UnitX * (float)Math.Sin(rot) * (float)Math.Sin(lookup) * deltaY;
- camTarget -= Vector3.UnitY * (float)Math.Cos(lookup) * deltaY;
- camTarget += Vector3.UnitZ * (float)Math.Sin(rot) * deltaX;
- camTarget += Vector3.UnitZ * (float)Math.Cos(rot) * (float)Math.Sin(lookup) * deltaY;
- return true;
- }
- return false;
- }
-
- public override bool MouseWheel(MouseEventArgs e, float xoff, float yoff, ExtraArgs args, ref Vector3 camTarget, ref float rot, ref float lookup, ref float zoom)
- {
- zoom *= 1f - e.Delta * 0.001f;
- return true;
- }
- }
-}
diff --git a/GL_EditorFramework-master/GL_Core/Cameras/Walkaround.cs b/GL_EditorFramework-master/GL_Core/Cameras/Walkaround.cs
deleted file mode 100644
index 5c75b89d..00000000
--- a/GL_EditorFramework-master/GL_Core/Cameras/Walkaround.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-using GL_Core.Public_Interfaces;
-using OpenTK;
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace GL_Core.Cameras
-{
- public class WalkaroundCamera : AbstractCamera
- {
- public WalkaroundCamera()
- {
-
- }
- public override bool MouseMove(MouseEventArgs e, Point lastMouseLoc, float deltaX, float deltaY, ExtraArgs args, ref Vector3 camTarget, ref float rot, ref float lookup, ref float zoom)
- {
-
- if (e.Button == MouseButtons.Right)
- {
- rot += deltaX * 0.002f;
- lookup += deltaY * 0.002f;
- return true;
- }
- else if (e.Button == MouseButtons.Left)
- {
- //code from Whitehole
-
- deltaX *= Math.Min(0.1f, args.pickingDepth* args.factorX);
- deltaY *= Math.Min(0.1f, args.pickingDepth* args.factorY);
-
- camTarget += Vector3.UnitX * deltaX * (float)Math.Cos(rot);
- camTarget -= Vector3.UnitX * deltaY * (float)Math.Sin(rot) * (float)Math.Sin(lookup);
- camTarget -= Vector3.UnitY * deltaY * (float)Math.Cos(lookup);
- camTarget += Vector3.UnitZ * deltaX * (float)Math.Sin(rot);
- camTarget += Vector3.UnitZ * deltaY * (float)Math.Cos(rot) * (float)Math.Sin(lookup);
-
- return true;
- }
- return false;
- }
-
- public override bool MouseWheel(MouseEventArgs e, float xoff, float yoff, ExtraArgs args, ref Vector3 camTarget, ref float rot, ref float lookup, ref float zoom)
- {
- float delta = (float)(e.Delta * Math.Min(0.01f, args.pickingDepth / 500f));
- camTarget -= Vector3.UnitX * (float)Math.Sin(rot) * (float)Math.Cos(lookup) * delta;
- camTarget += Vector3.UnitY * (float)Math.Sin(lookup) * delta;
- camTarget += Vector3.UnitZ * (float)Math.Cos(rot) * (float)Math.Cos(lookup) * delta;
-
- float factoffX = (float)(-xoff * delta) * args.factorX;
- float factoffY = (float)(-yoff * delta) * args.factorY;
-
- camTarget += Vector3.UnitX * (float)Math.Cos(rot) * factoffX;
- camTarget -= Vector3.UnitX * (float)Math.Sin(rot) * (float)Math.Sin(lookup) * factoffY;
- camTarget -= Vector3.UnitY * (float)Math.Cos(lookup) * factoffY;
- camTarget += Vector3.UnitZ * (float)Math.Sin(rot) * factoffX;
- camTarget += Vector3.UnitZ * (float)Math.Cos(rot) * (float)Math.Sin(lookup) * factoffY;
- return true;
- }
- }
-}
diff --git a/GL_EditorFramework-master/GL_Core/GL_ControlLegacy.Designer.cs b/GL_EditorFramework-master/GL_Core/GL_ControlLegacy.Designer.cs
deleted file mode 100644
index 0354c89a..00000000
--- a/GL_EditorFramework-master/GL_Core/GL_ControlLegacy.Designer.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-namespace GL_Core
-{
- partial class GL_ControlLegacy
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Component Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- }
-
- #endregion
- }
-}
diff --git a/GL_EditorFramework-master/GL_Core/GL_ControlLegacy.cs b/GL_EditorFramework-master/GL_Core/GL_ControlLegacy.cs
deleted file mode 100644
index bdbcac2a..00000000
--- a/GL_EditorFramework-master/GL_Core/GL_ControlLegacy.cs
+++ /dev/null
@@ -1,338 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Drawing;
-using System.Data;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-using OpenTK;
-using OpenTK.Graphics.OpenGL;
-using GL_Core.Interfaces;
-using GL_Core.Public_Interfaces;
-using GL_Core.Cameras;
-
-namespace GL_Core
-{
- public partial class GL_ControlLegacy : GLControl
- {
- public GL_ControlLegacy():base(OpenTK.Graphics.GraphicsMode.Default,1,1, OpenTK.Graphics.GraphicsContextFlags.Default)
- {
- InitializeComponent();
- }
-
- private Point lastMouseLoc;
- private Point dragStartLoc;
- private float lastDepth = 1000f;
- private AbstractCamera activeCamera;
- float rot = 0;
- float lookup = 0;
- float zoom = -10f;
- Vector3 camTarget;
-
- float zfar = 1000f;
- float znear = 0.01f;
- float fov = MathHelper.PiOver4;
-
- uint[] pickingFrameBuffer = new uint[9];
- int pickingIndex;
- float pickingModelDepth = 0f;
- private float pickingDepth = 0f;
-
- public Matrix4 mtxMdl, mtxCam, mtxProj;
- private float factorX, factorY;
-
- bool stereoscopy;
-
- int viewPortX(int x) => stereoscopy ? x % (Width / 2) : x;
- int viewPortDX(int dx) => stereoscopy ? dx * 2 : dx;
- int viewPortXOff(int x) => stereoscopy ? (x - Width / 4)*2 : x - Width / 2;
- int viewPortWidth() => stereoscopy ? Width / 2 : Width;
-
- public bool Stereoscopy
- {
- get => stereoscopy;
- set
- {
- stereoscopy = value;
- OnResize(null);
- Refresh();
- }
- }
-
- AbstractGlDrawable mainDrawable;
-
- public AbstractGlDrawable MainDrawable
- {
- get => mainDrawable;
- set
- {
- if (value == null) return;
- mainDrawable = value;
- MakeCurrent();
- mainDrawable.Prepare(this);
- Refresh();
- }
- }
-
- public AbstractCamera ActiveCamera
- {
- get => activeCamera;
- set
- {
- if (value == null) return;
- activeCamera = value;
- MakeCurrent();
- Refresh();
- }
- }
-
- public Color nextPickingColor()
- {
- return Color.FromArgb(pickingIndex++);
- }
- public void UpdateModelMatrix(Matrix4 matrix)
- {
- mtxMdl = matrix;
- GL.MatrixMode(MatrixMode.Modelview);
- GL.LoadMatrix(ref mtxMdl);
- }
-
- public void ApplyModelTransform(Matrix4 matrix)
- {
- mtxMdl *= matrix;
- GL.MatrixMode(MatrixMode.Modelview);
- GL.LoadMatrix(ref mtxMdl);
- }
-
- public void ResetModelMatrix()
- {
- mtxMdl = Matrix4.Identity;
- GL.MatrixMode(MatrixMode.Modelview);
- GL.LoadMatrix(ref mtxMdl);
- }
-
- protected override void OnLoad(EventArgs e)
- {
- if (DesignMode) return;
-
- activeCamera = new WalkaroundCamera();
-
- GL.Enable(EnableCap.DepthTest);
- }
-
- protected override void OnResize(EventArgs e)
- {
- if (DesignMode || this.Context == null) return;
- MakeCurrent();
-
- float aspect_ratio;
- if (stereoscopy)
- aspect_ratio = Width / 2 / (float)Height;
- else
- aspect_ratio = Width / (float)Height;
-
- mtxProj = Matrix4.CreatePerspectiveFieldOfView(fov, aspect_ratio, znear, zfar);
-
- //using the calculation from whitehole
- factorX = (2f * (float)Math.Tan(fov * 0.5f) * aspect_ratio) / Width;
-
- factorY = (2f * (float)Math.Tan(fov * 0.5f)) / Height;
- }
-
- protected override void OnPaint(PaintEventArgs e)
- {
- if (mainDrawable == null || DesignMode)
- {
- e.Graphics.Clear(this.BackColor);
- e.Graphics.DrawString("Legacy Gl" + (stereoscopy ? " stereoscopy" : ""), SystemFonts.DefaultFont, SystemBrushes.ControlLight, 10f, 10f);
- return;
- }
-
- GL.ClearColor(0.125f, 0.125f, 0.125f, 1.0f);
- GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
-
- if (stereoscopy)
- {
- #region left eye
- GL.Viewport(0, 0, Width / 2, Height);
-
- mtxMdl = Matrix4.Identity;
- mtxCam =
- Matrix4.CreateTranslation(camTarget) *
- Matrix4.CreateRotationY(rot + 0.02f) *
- Matrix4.CreateRotationX(lookup) *
- Matrix4.CreateTranslation(0, 0, zoom);
-
- GL.MatrixMode(MatrixMode.Projection);
- Matrix4 computedMatrix = mtxCam * mtxProj;
- GL.LoadMatrix(ref computedMatrix);
-
- mainDrawable.Draw(this);
- #endregion
-
- #region right eye
- GL.Viewport(Width / 2, 0, Width / 2, Height);
-
- mtxMdl = Matrix4.Identity;
- mtxCam =
- Matrix4.CreateTranslation(camTarget) *
- Matrix4.CreateRotationY(rot - 0.02f) *
- Matrix4.CreateRotationX(lookup) *
- Matrix4.CreateTranslation(0, 0, zoom);
-
- computedMatrix = mtxCam * mtxProj;
- GL.LoadMatrix(ref computedMatrix);
- mainDrawable.Draw(this);
- #endregion
- }
- else
- {
- GL.Viewport(0, 0, Width, Height);
-
- mtxMdl = Matrix4.Identity;
- mtxCam =
- Matrix4.CreateTranslation(camTarget) *
- Matrix4.CreateRotationY(rot - 0.02f) *
- Matrix4.CreateRotationX(lookup) *
- Matrix4.CreateTranslation(0, 0, zoom);
-
- GL.MatrixMode(MatrixMode.Projection);
- Matrix4 computedMatrix = mtxCam * mtxProj;
- GL.LoadMatrix(ref computedMatrix);
- mainDrawable.Draw(this);
- }
-
- SwapBuffers();
- }
-
- protected override void OnMouseDown(MouseEventArgs e)
- {
- if (mainDrawable == null) return;
-
- lastMouseLoc = e.Location;
- lastDepth = pickingDepth;
- dragStartLoc = e.Location;
- if (mainDrawable.MouseDown(e) ||
- activeCamera.MouseDown(e, ref camTarget, ref rot, ref lookup, ref zoom))
- Refresh();
- }
-
- protected override void OnMouseMove(MouseEventArgs e)
- {
- if (mainDrawable == null) return;
-
- float deltaX = viewPortDX(e.Location.X - lastMouseLoc.X);
- float deltaY = e.Location.Y - lastMouseLoc.Y;
-
- bool shouldredraw = false;
- shouldredraw = shouldredraw || activeCamera.MouseMove(e, lastMouseLoc, deltaX, deltaY, new ExtraArgs(factorX, factorY, lastDepth), ref camTarget, ref rot, ref lookup, ref zoom);
-
- lastMouseLoc = e.Location;
-
- #region picking
- MakeCurrent();
-
- GL.ClearColor(0f, 0f, 0f, 0f);
- GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
-
- if (stereoscopy)
- GL.Viewport(0, 0, Width / 2, Height);
- else
- GL.Viewport(0, 0, Width, Height);
-
- int pickingMouseX = stereoscopy ? (lastMouseLoc.X % (Width / 2)) : lastMouseLoc.X;
-
- mtxMdl = Matrix4.Identity;
- mtxCam =
- Matrix4.CreateTranslation(camTarget) *
- Matrix4.CreateRotationY(rot - (stereoscopy ? 0.02f : 0f)) *
- Matrix4.CreateRotationX(lookup) *
- Matrix4.CreateTranslation(0, 0, zoom);
-
- GL.MatrixMode(MatrixMode.Projection);
- Matrix4 computedMatrix = mtxCam * mtxProj;
- GL.LoadMatrix(ref computedMatrix);
-
- pickingIndex = 1;
-
- mainDrawable.DrawPicking(this);
- GL.Flush();
-
- GL.ReadPixels(pickingMouseX, Height - lastMouseLoc.Y, 1, 1, PixelFormat.DepthComponent, PixelType.Float, ref pickingModelDepth);
-
- pickingModelDepth = -(zfar * znear / (pickingModelDepth * (zfar - znear) - zfar));
-
-
-
- GL.Flush();
-
- GL.ReadPixels(pickingMouseX - 1, Height - lastMouseLoc.Y + 1, 3, 3, PixelFormat.Bgra, PixelType.UnsignedByte, pickingFrameBuffer);
-
-
-
- // depth math from http://www.opengl.org/resources/faq/technical/depthbuffer.htm
-
- GL.ReadPixels(pickingMouseX, Height - lastMouseLoc.Y, 1, 1, PixelFormat.DepthComponent, PixelType.Float, ref pickingDepth);
-
- pickingDepth = -(zfar * znear / (pickingDepth * (zfar - znear) - zfar));
-
- shouldredraw = shouldredraw || mainDrawable.Picked(pickingFrameBuffer[4]);
-
- #endregion
-
- shouldredraw = shouldredraw || mainDrawable.MouseMove(e, lastMouseLoc, deltaX, deltaY, new ExtraArgs(factorX, factorY, lastDepth), rot, lookup);
-
- if (shouldredraw)
- Refresh();
- }
-
- protected override void OnMouseWheel(MouseEventArgs e)
- {
- if (mainDrawable == null) return;
-
- int x = viewPortX(e.X);
-
- if (mainDrawable.MouseWheel(e, viewPortXOff(x), e.Y - Height / 2, new ExtraArgs(factorX,factorY, lastDepth), rot, lookup) ||
- activeCamera.MouseWheel(e, viewPortXOff(x), e.Y - Height / 2, new ExtraArgs(factorX, factorY, lastDepth), ref camTarget, ref rot, ref lookup, ref zoom))
- Refresh();
- }
-
- protected override void OnMouseUp(MouseEventArgs e)
- {
- if (mainDrawable == null) return;
-
- bool shouldredraw = false;
-
- if ((Math.Abs(e.X - dragStartLoc.X) < 3) && (Math.Abs(e.Y - dragStartLoc.Y) < 3))
- {
- shouldredraw = shouldredraw || mainDrawable.MouseClick(e) ||
- activeCamera.MouseClick(e, ref camTarget, ref rot, ref lookup, ref zoom);
- }
- shouldredraw = shouldredraw || mainDrawable.MouseUp(e, dragStartLoc) ||
- activeCamera.MouseUp(e, dragStartLoc, ref camTarget, ref rot, ref lookup, ref zoom);
-
- if (shouldredraw)
- Refresh();
- }
-
- protected override void OnKeyDown(KeyEventArgs e)
- {
- if (mainDrawable == null) return;
-
- if (mainDrawable.KeyDown(e) ||
- activeCamera.KeyDown(e, ref camTarget, ref rot, ref lookup, ref zoom))
- Refresh();
- }
-
- protected override void OnKeyUp(KeyEventArgs e)
- {
- if (mainDrawable == null) return;
-
- if (mainDrawable.KeyUp(e) ||
- activeCamera.KeyUp(e, ref camTarget, ref rot, ref lookup, ref zoom))
- Refresh();
- }
- }
-}
diff --git a/GL_EditorFramework-master/GL_Core/GL_ControlModern.Designer.cs b/GL_EditorFramework-master/GL_Core/GL_ControlModern.Designer.cs
deleted file mode 100644
index 3741c91d..00000000
--- a/GL_EditorFramework-master/GL_Core/GL_ControlModern.Designer.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-namespace GL_Core
-{
- partial class GL_ControlModern
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Component Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- }
-
- #endregion
- }
-}
diff --git a/GL_EditorFramework-master/GL_Core/GL_ControlModern.cs b/GL_EditorFramework-master/GL_Core/GL_ControlModern.cs
deleted file mode 100644
index b30edc06..00000000
--- a/GL_EditorFramework-master/GL_Core/GL_ControlModern.cs
+++ /dev/null
@@ -1,352 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Drawing;
-using System.Data;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-using OpenTK;
-using OpenTK.Graphics.OpenGL;
-using GL_Core.Interfaces;
-using GL_Core.Public_Interfaces;
-using GL_Core.Cameras;
-
-namespace GL_Core
-{
- public partial class GL_ControlModern : GLControl
- {
- public GL_ControlModern()
- {
- InitializeComponent();
- }
-
- private Point lastMouseLoc;
- private Point dragStartLoc;
- private float lastDepth = 1000f;
- private ShaderProgram shader;
- private AbstractCamera activeCamera;
- float rot = 0;
- float lookup = 0;
- float zoom = -10f;
- Vector3 camTarget;
-
- public float zfar = 1000f;
- public float znear = 0.01f;
- public float PolyCount = 0;
- public float VertCount = 0;
- float fov = MathHelper.PiOver4;
-
- uint[] pickingFrameBuffer = new uint[9];
- int pickingIndex;
- float pickingModelDepth = 0f;
- private float pickingDepth = 0f;
-
- public Matrix4 mtxMdl, mtxCam, mtxProj;
- private float factorX, factorY;
-
- bool stereoscopy;
- bool displayPolyCount;
-
- int viewPortX(int x) => stereoscopy ? x % (Width / 2) : x;
- int viewPortDX(int dx) => stereoscopy ? dx * 2 : dx;
- int viewPortXOff(int x) => stereoscopy ? (x - Width / 4) * 2 : x - Width / 2;
- int viewPortWidth() => stereoscopy ? Width / 2 : Width;
-
- public bool DisplayPolyCount
- {
- get => displayPolyCount;
- set
- {
- displayPolyCount = value;
- OnResize(null);
- Refresh();
- }
- }
- public bool Stereoscopy
- {
- get => stereoscopy;
- set
- {
- stereoscopy = value;
- OnResize(null);
- Refresh();
- }
- }
-
- public ShaderProgram CurrentShader
- {
- get => shader;
- set
- {
- if (value == null) return;
- shader = value;
-
- shader.Setup(mtxMdl, mtxCam, mtxProj);
- }
- }
-
- AbstractGlDrawable mainDrawable;
- public List abstractGlDrawables = new List();
- public AbstractGlDrawable MainDrawable
- {
- get => mainDrawable;
- set
- {
- this.Visible = true;
-
- if (value == null) return;
- mainDrawable = value;
- MakeCurrent();
- mainDrawable.Prepare(this);
- Refresh();
- }
- }
-
- public AbstractCamera ActiveCamera
- {
- get => activeCamera;
- set
- {
- if (value == null || this.Context == null) return;
- activeCamera = value;
- MakeCurrent();
- Refresh();
- }
- }
-
- public Color nextPickingColor()
- {
- return Color.FromArgb(pickingIndex++);
- }
-
- public void UpdateModelMatrix(Matrix4 matrix)
- {
- shader.UpdateModelMatrix(mtxMdl = matrix);
- }
-
- public void ApplyModelTransform(Matrix4 matrix)
- {
- shader.UpdateModelMatrix(mtxMdl *= matrix);
- }
-
- public void ResetModelMatrix()
- {
- shader.UpdateModelMatrix(mtxMdl = Matrix4.Identity);
- }
-
- protected override void OnLoad(EventArgs e)
- {
- if (DesignMode) return;
-
- activeCamera = new InspectCamera();
-
- GL.Enable(EnableCap.DepthTest);
- }
-
- protected override void OnResize(EventArgs e)
- {
- if (DesignMode || this.Context == null) return;
- MakeCurrent();
-
- float aspect_ratio;
- if (stereoscopy)
- aspect_ratio = Width/2 / (float)Height;
- else
- aspect_ratio = Width / (float)Height;
-
- mtxProj = Matrix4.CreatePerspectiveFieldOfView(fov, aspect_ratio, znear, zfar);
-
- //using the calculation from whitehole
- factorX = (2f * (float)Math.Tan(fov * 0.5f) * aspect_ratio) / Width;
-
- factorY = (2f * (float)Math.Tan(fov * 0.5f)) / Height;
- }
-
- protected override void OnPaint(PaintEventArgs e)
- {
- if (mainDrawable == null || DesignMode)
- {
- e.Graphics.Clear(this.BackColor);
- e.Graphics.DrawString("Modern Gl" + (stereoscopy ? " stereoscopy" : ""), SystemFonts.DefaultFont, SystemBrushes.ControlLight, 10f, 10f);
- return;
- }
- // e.Graphics.DrawString((displayPolyCount ? $"poly count {PolyCount} vert count {VertCount}" : ""), SystemFonts.DefaultFont, SystemBrushes.ControlLight, 10f, 10f);
-
-
- MakeCurrent();
- GL.ClearColor(0.125f, 0.125f, 0.125f, 1.0f);
- GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
-
-
- if (stereoscopy)
- {
- #region left eye
- GL.Viewport(0, 0, Width / 2, Height);
-
- mtxMdl = Matrix4.Identity;
- mtxCam =
- Matrix4.CreateTranslation(camTarget) *
- Matrix4.CreateRotationY(rot + 0.02f) *
- Matrix4.CreateRotationX(lookup) *
- Matrix4.CreateTranslation(0, 0, zoom);
-
- mainDrawable.Draw(this);
- #endregion
-
- #region right eye
- GL.Viewport(Width / 2, 0, Width / 2, Height);
-
- mtxMdl = Matrix4.Identity;
- mtxCam =
- Matrix4.CreateTranslation(camTarget) *
- Matrix4.CreateRotationY(rot - 0.02f) *
- Matrix4.CreateRotationX(lookup) *
- Matrix4.CreateTranslation(0, 0, zoom);
-
- mainDrawable.Draw(this);
- #endregion
- }
- else
- {
- GL.Viewport(0, 0, Width, Height);
-
- mtxMdl = Matrix4.Identity;
- mtxCam =
- Matrix4.CreateTranslation(camTarget) *
- Matrix4.CreateRotationY(rot) *
- Matrix4.CreateRotationX(lookup) *
- Matrix4.CreateTranslation(0, 0, zoom);
-
- mainDrawable.Draw(this);
- }
-
- SwapBuffers();
- }
-
- protected override void OnMouseDown(MouseEventArgs e)
- {
- if (mainDrawable == null) return;
-
- lastMouseLoc = e.Location;
- lastDepth = pickingDepth;
- dragStartLoc = e.Location;
- if (mainDrawable.MouseDown(e) ||
- activeCamera.MouseDown(e, ref camTarget, ref rot, ref lookup, ref zoom))
- Refresh();
- }
-
- protected override void OnMouseMove(MouseEventArgs e)
- {
- if (mainDrawable == null) return;
-
- float deltaX = viewPortDX(e.Location.X - lastMouseLoc.X);
- float deltaY = (e.Location.Y - lastMouseLoc.Y);
-
- bool shouldredraw = false;
- shouldredraw = shouldredraw || activeCamera.MouseMove(e, lastMouseLoc, deltaX, deltaY, new ExtraArgs(factorX, factorY, lastDepth), ref camTarget, ref rot, ref lookup, ref zoom);
-
- lastMouseLoc = e.Location;
-
- #region picking
- MakeCurrent();
-
- GL.ClearColor(0f, 0f, 0f, 0f);
- GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
-
- if (stereoscopy)
- GL.Viewport(0, 0, Width / 2, Height);
- else
- GL.Viewport(0, 0, Width, Height);
-
- int pickingMouseX = stereoscopy ? (lastMouseLoc.X % (Width / 2)) : lastMouseLoc.X;
-
- mtxMdl = Matrix4.Identity;
- mtxCam =
- Matrix4.CreateTranslation(camTarget) *
- Matrix4.CreateRotationY(rot - (stereoscopy?0.02f:0f)) *
- Matrix4.CreateRotationX(lookup) *
- Matrix4.CreateTranslation(0, 0, zoom);
-
- pickingIndex = 1;
-
- mainDrawable.DrawPicking(this);
- GL.Flush();
-
- GL.ReadPixels(pickingMouseX, Height - lastMouseLoc.Y, 1, 1, PixelFormat.DepthComponent, PixelType.Float, ref pickingModelDepth);
-
- pickingModelDepth = -(zfar * znear / (pickingModelDepth * (zfar - znear) - zfar));
-
-
-
- GL.Flush();
-
- GL.ReadPixels(pickingMouseX - 1, Height - lastMouseLoc.Y + 1, 3, 3, PixelFormat.Bgra, PixelType.UnsignedByte, pickingFrameBuffer);
-
-
-
- // depth math from http://www.opengl.org/resources/faq/technical/depthbuffer.htm
-
- GL.ReadPixels(pickingMouseX, Height - lastMouseLoc.Y, 1, 1, PixelFormat.DepthComponent, PixelType.Float, ref pickingDepth);
-
- pickingDepth = -(zfar * znear / (pickingDepth * (zfar - znear) - zfar));
-
- shouldredraw = shouldredraw || mainDrawable.Picked(pickingFrameBuffer[4]);
-
- #endregion
-
- shouldredraw = shouldredraw || mainDrawable.MouseMove(e, lastMouseLoc, deltaX, deltaY, new ExtraArgs(factorX, factorY, lastDepth), rot, lookup);
-
- if (shouldredraw)
- Refresh();
- }
-
- protected override void OnMouseWheel(MouseEventArgs e)
- {
- if (mainDrawable == null) return;
-
- int x = viewPortX(e.X);
-
- if (mainDrawable.MouseWheel(e, viewPortXOff(x), e.Y - Height / 2, new ExtraArgs(factorX, factorY, lastDepth), rot, lookup) ||
- activeCamera.MouseWheel(e, viewPortXOff(x), e.Y - Height / 2, new ExtraArgs(factorX, factorY, lastDepth), ref camTarget, ref rot, ref lookup, ref zoom))
- Refresh();
- }
-
- protected override void OnMouseUp(MouseEventArgs e)
- {
- if (mainDrawable == null) return;
-
- bool shouldredraw = false;
-
- if ((Math.Abs(e.X - dragStartLoc.X) < 3) && (Math.Abs(e.Y - dragStartLoc.Y) < 3))
- {
- shouldredraw = shouldredraw || mainDrawable.MouseClick(e) ||
- activeCamera.MouseClick(e, ref camTarget, ref rot, ref lookup, ref zoom);
- }
- shouldredraw = shouldredraw || mainDrawable.MouseUp(e,dragStartLoc) ||
- activeCamera.MouseUp(e, dragStartLoc, ref camTarget, ref rot, ref lookup, ref zoom);
-
- if (shouldredraw)
- Refresh();
- }
-
- protected override void OnKeyDown(KeyEventArgs e)
- {
- if (mainDrawable == null) return;
-
- if (mainDrawable.KeyDown(e) ||
- activeCamera.KeyDown(e, ref camTarget, ref rot, ref lookup, ref zoom))
- Refresh();
- }
-
- protected override void OnKeyUp(KeyEventArgs e)
- {
- if (mainDrawable == null) return;
-
- if (mainDrawable.KeyUp(e) ||
- activeCamera.KeyUp(e, ref camTarget, ref rot, ref lookup, ref zoom))
- Refresh();
- }
- }
-}
diff --git a/GL_EditorFramework-master/GL_Core/GL_Core.csproj b/GL_EditorFramework-master/GL_Core/GL_Core.csproj
deleted file mode 100644
index 57c38c4f..00000000
--- a/GL_EditorFramework-master/GL_Core/GL_Core.csproj
+++ /dev/null
@@ -1,77 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- {29647BA5-2859-46F0-A99E-C3A387A9447A}
- Library
- Properties
- GL_Core
- GL_Core
- v4.6.2
- 512
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ..\..\Switch_Toolbox\Lib\OpenTK.dll
-
-
- ..\..\Switch_Toolbox\Lib\OpenTK.GLControl.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- UserControl
-
-
- GL_ControlLegacy.cs
-
-
- UserControl
-
-
- GL_ControlModern.cs
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/GL_EditorFramework-master/GL_Core/OldGlEmulator.cs b/GL_EditorFramework-master/GL_Core/OldGlEmulator.cs
deleted file mode 100644
index fff732b7..00000000
--- a/GL_EditorFramework-master/GL_Core/OldGlEmulator.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using OpenTK.Graphics.OpenGL;
-
-namespace GL_Core
-{
- public class OldGlEmulator : IDisposable
- {
- List dataList = new List();
-
- float current_r = 255f;
- float current_g = 255f;
- float current_b = 255f;
- float current_a = 255f;
- public OldGlEmulator()
- {
-
- }
-
- public void Vertex3(float x, float y, float z)
- {
- dataList.Add(x); dataList.Add(y); dataList.Add(z);
- dataList.Add(current_r); dataList.Add(current_g); dataList.Add(current_b); dataList.Add(current_a);
- }
-
- public void Color3(float r, float g, float b)
- {
- current_r = r;
- current_g = g;
- current_b = b;
- }
-
- public void WriteToBuffer(int buffer) {
- GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
- float[] arrayData = dataList.ToArray();
- GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * arrayData.Length, arrayData, BufferUsageHint.StaticDraw);
-
- GL.EnableVertexAttribArray(0);
- GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, sizeof(float) * 7, 0);
- GL.EnableVertexAttribArray(1);
- GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, false, sizeof(float) * 7, sizeof(float) * 3);
- }
-
- public void Dispose()
- {
-
- }
- }
-}
diff --git a/GL_EditorFramework-master/GL_Core/OpenTK.dll.config b/GL_EditorFramework-master/GL_Core/OpenTK.dll.config
deleted file mode 100644
index 7098d39e..00000000
--- a/GL_EditorFramework-master/GL_Core/OpenTK.dll.config
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/GL_EditorFramework-master/GL_Core/Properties/AssemblyInfo.cs b/GL_EditorFramework-master/GL_Core/Properties/AssemblyInfo.cs
deleted file mode 100644
index 72b2257d..00000000
--- a/GL_EditorFramework-master/GL_Core/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("GL_Core")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("GL_Core")]
-[assembly: AssemblyCopyright("Copyright © 2018")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("29647ba5-2859-46f0-a99e-c3a387a9447a")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/GL_EditorFramework-master/GL_Core/Public Interfaces/AbstractCamera.cs b/GL_EditorFramework-master/GL_Core/Public Interfaces/AbstractCamera.cs
deleted file mode 100644
index 433d508c..00000000
--- a/GL_EditorFramework-master/GL_Core/Public Interfaces/AbstractCamera.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using OpenTK;
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace GL_Core.Public_Interfaces
-{
- public abstract class AbstractCamera
- {
- public virtual bool MouseDown(MouseEventArgs e, ref Vector3 camTarget, ref float rot, ref float lookup, ref float zoom) { return false; }
- public virtual bool MouseMove(MouseEventArgs e, Point lastMouseLoc, float deltaX, float deltaY, ExtraArgs args, ref Vector3 camTarget, ref float rot, ref float lookup, ref float zoom) { return false; }
- public virtual bool MouseUp(MouseEventArgs e, Point dragStartMousePos, ref Vector3 camTarget, ref float rot, ref float lookup, ref float zoom) { return false; }
- public virtual bool MouseWheel(MouseEventArgs e, float xoff, float yoff, ExtraArgs args, ref Vector3 camTarget, ref float rot, ref float lookup, ref float zoom) { return false; }
- public virtual bool MouseClick(MouseEventArgs e, ref Vector3 camTarget, ref float rot, ref float lookup, ref float zoom) { return false; }
-
- public virtual bool KeyDown(KeyEventArgs e, ref Vector3 camTarget, ref float rot, ref float lookup, ref float zoom) { return false; }
- public virtual bool KeyUp(KeyEventArgs e, ref Vector3 camTarget, ref float rot, ref float lookup, ref float zoom) { return false; }
-
- public virtual bool TimeStep(ref Vector3 camTarget, ref float rot, ref float lookup, ref float zoom) { return false; }
- }
-
- public struct ExtraArgs{
- public float factorX, factorY, pickingDepth;
- public ExtraArgs(float factorX, float factorY, float pickingDepth)
- {
- this.factorX = factorX;
- this.factorY = factorY;
- this.pickingDepth = pickingDepth;
- }
-
- }
-}
diff --git a/GL_EditorFramework-master/GL_Core/Public Interfaces/AbstractGlDrawable.cs b/GL_EditorFramework-master/GL_Core/Public Interfaces/AbstractGlDrawable.cs
deleted file mode 100644
index fb0011a0..00000000
--- a/GL_EditorFramework-master/GL_Core/Public Interfaces/AbstractGlDrawable.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using GL_Core.Public_Interfaces;
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace GL_Core.Interfaces
-{
- public abstract class AbstractGlDrawable
- {
- public abstract void Prepare(GL_ControlModern control);
- public abstract void Prepare(GL_ControlLegacy control);
- public abstract void Draw(GL_ControlModern control);
- public abstract void Draw(GL_ControlLegacy control);
- public virtual void DrawPicking(GL_ControlModern control) { }
- public virtual void DrawPicking(GL_ControlLegacy control) { }
- public virtual bool Picked(uint index) { return false; }//handling for Picking
- public virtual uint GetPickableSpan() => 0;//tells how many pickable subobjects are in this object
-
- public virtual bool MouseDown(MouseEventArgs e) { return false; }
- public virtual bool MouseMove(MouseEventArgs e, Point lastMouseLoc, float deltaX, float deltaY, ExtraArgs args, float rot, float lookup) { return false; }
- public virtual bool MouseUp(MouseEventArgs e, Point dragStartMousePos) { return false; }
- public virtual bool MouseWheel(MouseEventArgs e, float xoff, float yoff, ExtraArgs args, float rot, float lookup) { return false; }
- public virtual bool MouseClick(MouseEventArgs e) { return false; }
-
- public virtual bool KeyDown(KeyEventArgs e) { return false; }
- public virtual bool KeyUp(KeyEventArgs e) { return false; }
-
- public virtual bool TimeStep() { return false; }
- }
-}
diff --git a/GL_EditorFramework-master/GL_Core/ShaderClass.cs b/GL_EditorFramework-master/GL_Core/ShaderClass.cs
deleted file mode 100644
index 77d86b29..00000000
--- a/GL_EditorFramework-master/GL_Core/ShaderClass.cs
+++ /dev/null
@@ -1,138 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using OpenTK;
-using OpenTK.Graphics.OpenGL;
-
-namespace GL_Core
-{
- public class ShaderProgram
- {
- private int fragSh, vertSh, program, mtxMdlLoc, mtxCamLoc;
- private Matrix4 modelMatrix;
- private Matrix4 computedCamMtx;
-
- public ShaderProgram(FragmentShader frag, VertexShader vert)
- {
- fragSh = frag.shader;
- vertSh = vert.shader;
- program = GL.CreateProgram();
- GL.AttachShader(program, vertSh);
- GL.AttachShader(program, fragSh);
- GL.LinkProgram(program);
- Console.WriteLine("fragment:");
- Console.WriteLine(GL.GetShaderInfoLog(fragSh));
- Console.WriteLine("vertex:");
- Console.WriteLine(GL.GetShaderInfoLog(fragSh));
-
- mtxMdlLoc = GL.GetUniformLocation(program, "mtxMdl");
- mtxCamLoc = GL.GetUniformLocation(program, "mtxCam");
- }
-
- public void AttachShader(ShaderGL shader)
- {
- GL.AttachShader(program, shader.shader);
- }
-
- public void DetachShader(ShaderGL shader)
- {
- GL.DetachShader(program, shader.shader);
- }
-
- public void LinkShaders()
- {
- GL.LinkProgram(program);
- }
-
- public void SetFragmentShader(FragmentShader shader)
- {
- GL.DetachShader(program, fragSh);
- GL.AttachShader(program, shader.shader);
- fragSh = shader.shader;
- GL.LinkProgram(program);
- }
-
- public void SetVertexShader(VertexShader shader)
- {
- GL.DetachShader(program, vertSh);
- GL.AttachShader(program, shader.shader);
- vertSh = shader.shader;
- GL.LinkProgram(program);
-
- mtxMdlLoc = GL.GetUniformLocation(program, "mtxMdl");
- mtxCamLoc = GL.GetUniformLocation(program, "mtxCam");
-
- GL.UniformMatrix4(mtxMdlLoc, false, ref modelMatrix);
- GL.UniformMatrix4(mtxCamLoc, false, ref computedCamMtx);
- }
-
-
- public void Setup(Matrix4 mtxMdl, Matrix4 mtxCam, Matrix4 mtxProj)
- {
- GL.UseProgram(program);
- modelMatrix = mtxMdl;
- GL.UniformMatrix4(mtxMdlLoc, false, ref modelMatrix);
- computedCamMtx = mtxCam * mtxProj;
- GL.UniformMatrix4(mtxCamLoc, false, ref computedCamMtx);
- }
-
- public void UpdateModelMatrix(Matrix4 matrix)
- {
- modelMatrix = matrix;
- GL.UniformMatrix4(mtxMdlLoc, false, ref matrix);
- }
-
- public void Activate()
- {
- GL.UseProgram(program);
- }
-
- public int this[string name]{
- get => GL.GetUniformLocation(program, name);
- }
- }
-
- public class ShaderGL
- {
- public ShaderGL(string src, ShaderType type)
- {
- shader = GL.CreateShader(type);
- GL.ShaderSource(shader, src);
- GL.CompileShader(shader);
- this.type = type;
- }
-
- public ShaderType type;
-
- public int shader;
- }
-
- public class FragmentShader : ShaderGL
- {
- public FragmentShader(string src)
- :base(src, ShaderType.FragmentShader)
- {
-
- }
- }
-
- public class GeomeryShader : ShaderGL
- {
- public GeomeryShader(string src)
- : base(src, ShaderType.GeometryShader)
- {
-
- }
- }
-
- public class VertexShader : ShaderGL
- {
- public VertexShader(string src)
- : base(src, ShaderType.VertexShader)
- {
-
- }
- }
-}
diff --git a/GL_EditorFramework-master/GL_Core/packages.config b/GL_EditorFramework-master/GL_Core/packages.config
deleted file mode 100644
index c96d3c76..00000000
--- a/GL_EditorFramework-master/GL_Core/packages.config
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/GL_EditorFramework-master/GL_EditorFramework.sln b/GL_EditorFramework-master/GL_EditorFramework.sln
deleted file mode 100644
index 76e2136b..00000000
--- a/GL_EditorFramework-master/GL_EditorFramework.sln
+++ /dev/null
@@ -1,31 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.27703.2035
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GL_Core", "GL_Core\GL_Core.csproj", "{29647BA5-2859-46F0-A99E-C3A387A9447A}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testing", "Testing\Testing.csproj", "{47680B79-3772-4339-8808-A97F84450CCE}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {29647BA5-2859-46F0-A99E-C3A387A9447A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {29647BA5-2859-46F0-A99E-C3A387A9447A}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {29647BA5-2859-46F0-A99E-C3A387A9447A}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {29647BA5-2859-46F0-A99E-C3A387A9447A}.Release|Any CPU.Build.0 = Release|Any CPU
- {47680B79-3772-4339-8808-A97F84450CCE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {47680B79-3772-4339-8808-A97F84450CCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {47680B79-3772-4339-8808-A97F84450CCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {47680B79-3772-4339-8808-A97F84450CCE}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {F399969A-9DEC-48B3-A7FA-4DBC9341DAA6}
- EndGlobalSection
-EndGlobal
diff --git a/GL_EditorFramework-master/README.md b/GL_EditorFramework-master/README.md
deleted file mode 100644
index 9a7d81f9..00000000
--- a/GL_EditorFramework-master/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# GL_EditorFramework
diff --git a/GL_EditorFramework-master/Testing/App.config b/GL_EditorFramework-master/Testing/App.config
deleted file mode 100644
index 731f6de6..00000000
--- a/GL_EditorFramework-master/Testing/App.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/GL_EditorFramework-master/Testing/MarioTposeTest.cs b/GL_EditorFramework-master/Testing/MarioTposeTest.cs
deleted file mode 100644
index ad818536..00000000
--- a/GL_EditorFramework-master/Testing/MarioTposeTest.cs
+++ /dev/null
@@ -1,431 +0,0 @@
-using GL_Core;
-using GL_Core.Interfaces;
-using OpenTK;
-using OpenTK.Graphics;
-using OpenTK.Graphics.OpenGL;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace Testing
-{
- public class MarioTposeTest : AbstractGlDrawable
- {
- int testVao;
- int marioTestVao;
- ShaderProgram defaultShaderProgram;
- FragmentShader defaultFrag;
- VertexShader defaultVert, pickingVert;
- ShaderProgram testShaderProgram;
-
- uint pickedIndex = 0;
- uint selectedIndex = 0;
-
- public MarioTposeTest()
- {
-
- }
-
- public override void Draw(GL_ControlModern control)
- {
- control.CurrentShader = testShaderProgram;
- control.ResetModelMatrix();
- GL.BindVertexArray(testVao);
- GL.DrawArrays(PrimitiveType.Quads, 0, 4);
-
- GL.BindVertexArray(marioTestVao);
-
- control.CurrentShader = defaultShaderProgram;
- defaultShaderProgram.SetVertexShader(defaultVert);
- control.ApplyModelTransform(Matrix4.CreateTranslation(-8, 0, 0));
-
- for (int i = 0; i < 5; i++)
- {
- if (i + 1 == selectedIndex)
- GL.Uniform4(defaultShaderProgram["highlightColor"], 1f, 1f, 0.2f, 0.5f);
- else if (i + 1 == pickedIndex)
- GL.Uniform4(defaultShaderProgram["highlightColor"], 1f, 1f, 0.5f, 0.2f);
- else
- GL.Uniform4(defaultShaderProgram["highlightColor"], 0f, 0f, 0f, 0f);
- GL.DrawArrays(PrimitiveType.Quads, 0, 11 * 4);
-
- control.ApplyModelTransform(Matrix4.CreateTranslation(4, 0, 0));
- }
- }
-
- public override void Draw(GL_ControlLegacy control)
- {
- control.ResetModelMatrix();
- GL.Begin(PrimitiveType.Quads);
- GL.Color3(1f, 0f, 0f);
- GL.Vertex3(-10f, -0.25f, 5f);
-
- GL.Color3(0f, 1f, 0f);
- GL.Vertex3(10f, -0.25f, 5f);
-
- GL.Color3(1f, 1f, 0f);
- GL.Vertex3(10f, -0.25f, -5f);
-
- GL.Color3(0f, 0f, 1f);
- GL.Vertex3(-10f, -0.25f, -5f);
- GL.End();
-
- control.ApplyModelTransform(Matrix4.CreateTranslation(-8, 0, 0));
-
- for (int i = 0; i < 5; i++)
- {
- GL.Begin(PrimitiveType.Quads);
- if(i+1==pickedIndex)
- GL.Color3(0f, 1f, 0f);
- else
- GL.Color3(1f, 0f, 0f);
- GL.Vertex3(-0.5f, 2f, 0f);
- GL.Vertex3(0.5f, 2f, 0f);
- GL.Vertex3(0.5f, 1.25f, 0f);
- GL.Vertex3(-0.5f, 1.25f, 0f);
-
- GL.Vertex3(-1.5f, 2.5f, 0f);
- GL.Vertex3(1.5f, 2.5f, 0f);
- GL.Vertex3(1.5f, 2f, 0f);
- GL.Vertex3(-1.5f, 2f, 0f);
-
- //trowsers
- if (i + 1 == selectedIndex)
- GL.Color3(1f, 1f, 1f);
- else
- GL.Color3(0, 0.2f, 1f);
- GL.Vertex3(-0.5f, 1.25f, 0f);
- GL.Vertex3(0.5f, 1.25f, 0f);
- GL.Vertex3(0.5f, 0.75f, 0f);
- GL.Vertex3(-0.5f, 0.75f, 0f);
-
- GL.Vertex3(-0.5f, 0.75f, 0f);
- GL.Vertex3(-0.125f, 0.75f, 0f);
- GL.Vertex3(-0.125f, -0.25f, 0f);
- GL.Vertex3(-0.5f, -0.25f, 0f);
-
- GL.Vertex3(0.125f, 0.75f, 0f);
- GL.Vertex3(0.5f, 0.75f, 0f);
- GL.Vertex3(0.5f, -0.25f, 0f);
- GL.Vertex3(0.125f, -0.25f, 0f);
-
- //stripes
- GL.Vertex3(-0.375f, 2.5f, -0.02f);
- GL.Vertex3(-0.125f, 2.5f, -0.02f);
- GL.Vertex3(-0.125f, 1.25f, -0.02f);
- GL.Vertex3(-0.375f, 1.25f, -0.02f);
-
- GL.Vertex3(0.125f, 2.5f, -0.02f);
- GL.Vertex3(0.375f, 2.5f, -0.02f);
- GL.Vertex3(0.375f, 1.25f, -0.02f);
- GL.Vertex3(0.125f, 1.25f, -0.02f);
-
- GL.Vertex3(-0.375f, 2.5f, 0.02f);
- GL.Vertex3(-0.125f, 2.5f, 0.02f);
- GL.Vertex3(-0.125f, 1.25f, 0.02f);
- GL.Vertex3(-0.375f, 1.25f, 0.02f);
-
- GL.Vertex3(0.125f, 2.5f, 0.02f);
- GL.Vertex3(0.375f, 2.5f, 0.02f);
- GL.Vertex3(0.375f, 1.25f, 0.02f);
- GL.Vertex3(0.125f, 1.25f, 0.02f);
-
- //knobs
- GL.Color3(1f, 1f, 0f);
- GL.Vertex3(-0.375f, 2.25f, 0.04f);
- GL.Vertex3(-0.125f, 2.25f, 0.04f);
- GL.Vertex3(-0.125f, 2f, 0.04f);
- GL.Vertex3(-0.375f, 2f, 0.04f);
-
- GL.Vertex3(0.125f, 2.25f, 0.04f);
- GL.Vertex3(0.375f, 2.25f, 0.04f);
- GL.Vertex3(0.375f, 2f, 0.04f);
- GL.Vertex3(0.125f, 2f, 0.04f);
- GL.End();
-
- control.ApplyModelTransform(Matrix4.CreateTranslation(4, 0, 0));
- }
- }
-
- public override void Prepare(GL_ControlModern control)
- {
- defaultFrag = new FragmentShader(
- @"#version 330
- in vec4 fragColor;
- void main(){
- gl_FragColor = fragColor;
- }");
- defaultVert = new VertexShader(
- @"#version 330
- layout(location = 0) in vec4 position;
- layout(location = 1) in vec4 color;
- uniform mat4 mtxMdl;
- uniform mat4 mtxCam;
- uniform vec4 highlightColor;
- out vec4 fragColor;
- void main(){
- gl_Position = mtxCam*mtxMdl*position;
- fragColor = color+highlightColor.xyz*highlightColor.w;
- }");
- pickingVert = new VertexShader(
- @"#version 330
- layout(location = 0) in vec4 position;
- uniform vec4 color;
- uniform mat4 mtxMdl;
- uniform mat4 mtxCam;
- out vec4 fragColor;
- void main(){
- gl_Position = mtxCam*mtxMdl*position;
- fragColor = color;
- }");
- defaultShaderProgram = new ShaderProgram(
- defaultFrag,defaultVert
- );
-
- testShaderProgram = new ShaderProgram(
- new FragmentShader(
- @"#version 330
- in vec4 vertPosition;
- in vec4 fragColor;
- void main(){
- float v = round(abs(mod(vertPosition.x,2.0)-1.0)+
- abs(mod(vertPosition.z,2.0)-1.0));
- gl_FragColor = fragColor*v;
- }"),
- new VertexShader(
- @"#version 330
- layout(location = 0) in vec4 position;
- layout(location = 1) in vec4 color;
- uniform mat4 mtxMdl;
- uniform mat4 mtxCam;
- out vec4 vertPosition;
- out vec4 fragColor;
- void main(){
- gl_Position = mtxMdl*mtxCam*position;
- vertPosition = position;
- fragColor = color;
- }"));
-
- control.CurrentShader = defaultShaderProgram;
-
- int buffer;
-
- GL.BindVertexArray(testVao = GL.GenVertexArray());
-
- GL.BindBuffer(BufferTarget.ArrayBuffer, buffer = GL.GenBuffer());
- float[] data = new float[] {
- -10f, -0.25f, 5f, 1f, 0f, 0f, 1f,
- 10f, -0.25f, 5f, 0f, 1f, 0f, 1f,
- 10f, -0.25f, -5f, 1f, 1f, 0f, 1f,
- -10f, -0.25f, -5f, 0f, 0f, 1f, 1f,
- };
- GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw);
-
- GL.EnableVertexAttribArray(0);
- GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, sizeof(float) * 7, 0);
- GL.EnableVertexAttribArray(1);
- GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, false, sizeof(float) * 7, sizeof(float) * 3);
-
- GL.BindVertexArray(marioTestVao = GL.GenVertexArray());
- using (OldGlEmulator GL = new OldGlEmulator())
- {
- //body
- GL.Color3(1f, 0f, 0f);
- GL.Vertex3(-0.5f, 2f, 0f);
- GL.Vertex3(0.5f, 2f, 0f);
- GL.Vertex3(0.5f, 1.25f, 0f);
- GL.Vertex3(-0.5f, 1.25f, 0f);
-
- GL.Vertex3(-1.5f, 2.5f, 0f);
- GL.Vertex3(1.5f, 2.5f, 0f);
- GL.Vertex3(1.5f, 2f, 0f);
- GL.Vertex3(-1.5f, 2f, 0f);
-
- //trowsers
- GL.Color3(0, 0.2f, 1f);
- GL.Vertex3(-0.5f, 1.25f, 0f);
- GL.Vertex3(0.5f, 1.25f, 0f);
- GL.Vertex3(0.5f, 0.75f, 0f);
- GL.Vertex3(-0.5f, 0.75f, 0f);
-
- GL.Vertex3(-0.5f, 0.75f, 0f);
- GL.Vertex3(-0.125f, 0.75f, 0f);
- GL.Vertex3(-0.125f, -0.25f, 0f);
- GL.Vertex3(-0.5f, -0.25f, 0f);
-
- GL.Vertex3(0.125f, 0.75f, 0f);
- GL.Vertex3(0.5f, 0.75f, 0f);
- GL.Vertex3(0.5f, -0.25f, 0f);
- GL.Vertex3(0.125f, -0.25f, 0f);
-
- //stripes
- GL.Vertex3(-0.375f, 2.5f, -0.02f);
- GL.Vertex3(-0.125f, 2.5f, -0.02f);
- GL.Vertex3(-0.125f, 1.25f, -0.02f);
- GL.Vertex3(-0.375f, 1.25f, -0.02f);
-
- GL.Vertex3(0.125f, 2.5f, -0.02f);
- GL.Vertex3(0.375f, 2.5f, -0.02f);
- GL.Vertex3(0.375f, 1.25f, -0.02f);
- GL.Vertex3(0.125f, 1.25f, -0.02f);
-
- GL.Vertex3(-0.375f, 2.5f, 0.02f);
- GL.Vertex3(-0.125f, 2.5f, 0.02f);
- GL.Vertex3(-0.125f, 1.25f, 0.02f);
- GL.Vertex3(-0.375f, 1.25f, 0.02f);
-
- GL.Vertex3(0.125f, 2.5f, 0.02f);
- GL.Vertex3(0.375f, 2.5f, 0.02f);
- GL.Vertex3(0.375f, 1.25f, 0.02f);
- GL.Vertex3(0.125f, 1.25f, 0.02f);
-
- //knobs
- GL.Color3(1f, 1f, 0f);
- GL.Vertex3(-0.375f, 2.25f, 0.04f);
- GL.Vertex3(-0.125f, 2.25f, 0.04f);
- GL.Vertex3(-0.125f, 2f, 0.04f);
- GL.Vertex3(-0.375f, 2f, 0.04f);
-
- GL.Vertex3(0.125f, 2.25f, 0.04f);
- GL.Vertex3(0.375f, 2.25f, 0.04f);
- GL.Vertex3(0.375f, 2f, 0.04f);
- GL.Vertex3(0.125f, 2f, 0.04f);
-
- GL.WriteToBuffer(buffer = OpenTK.Graphics.OpenGL.GL.GenBuffer());
- }
- }
-
- public override void Prepare(GL_ControlLegacy control)
- {
-
- }
-
- public override bool MouseClick(MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- selectedIndex = pickedIndex;
- return true;
- }
- return false;
- }
-
- public override void DrawPicking(GL_ControlModern control)
- {
- defaultShaderProgram.SetVertexShader(pickingVert);
- control.ResetModelMatrix();
- GL.Uniform4(defaultShaderProgram["color"], 0f, 0f, 0f, 0f);
- GL.BindVertexArray(testVao);
- GL.DrawArrays(PrimitiveType.Quads, 0, 4);
-
- GL.BindVertexArray(marioTestVao);
-
- control.ApplyModelTransform(Matrix4.CreateTranslation(-8, 0, 0));
-
- for (int i = 0; i < 5; i++)
- {
- GL.Uniform4(defaultShaderProgram["color"], control.nextPickingColor());
- GL.DrawArrays(PrimitiveType.Quads, 0, 11 * 4);
-
- control.ApplyModelTransform(Matrix4.CreateTranslation(4, 0, 0));
- }
- }
-
- public override void DrawPicking(GL_ControlLegacy control)
- {
- control.ResetModelMatrix();
- GL.Begin(PrimitiveType.Quads);
- GL.Color4(0,0,0,0);
- GL.Vertex3(-10f, -0.25f, 5f);
-
- GL.Vertex3(10f, -0.25f, 5f);
-
- GL.Vertex3(10f, -0.25f, -5f);
-
- GL.Vertex3(-10f, -0.25f, -5f);
- GL.End();
-
- control.ApplyModelTransform(Matrix4.CreateTranslation(-8, 0, 0));
-
- for (int i = 0; i < 5; i++)
- {
- GL.Begin(PrimitiveType.Quads);
- GL.Color4(control.nextPickingColor());
- GL.Vertex3(-0.5f, 2f, 0f);
- GL.Vertex3(0.5f, 2f, 0f);
- GL.Vertex3(0.5f, 1.25f, 0f);
- GL.Vertex3(-0.5f, 1.25f, 0f);
-
- GL.Vertex3(-1.5f, 2.5f, 0f);
- GL.Vertex3(1.5f, 2.5f, 0f);
- GL.Vertex3(1.5f, 2f, 0f);
- GL.Vertex3(-1.5f, 2f, 0f);
-
- //trowsers
- GL.Vertex3(-0.5f, 1.25f, 0f);
- GL.Vertex3(0.5f, 1.25f, 0f);
- GL.Vertex3(0.5f, 0.75f, 0f);
- GL.Vertex3(-0.5f, 0.75f, 0f);
-
- GL.Vertex3(-0.5f, 0.75f, 0f);
- GL.Vertex3(-0.125f, 0.75f, 0f);
- GL.Vertex3(-0.125f, -0.25f, 0f);
- GL.Vertex3(-0.5f, -0.25f, 0f);
-
- GL.Vertex3(0.125f, 0.75f, 0f);
- GL.Vertex3(0.5f, 0.75f, 0f);
- GL.Vertex3(0.5f, -0.25f, 0f);
- GL.Vertex3(0.125f, -0.25f, 0f);
-
- //stripes
- GL.Vertex3(-0.375f, 2.5f, -0.02f);
- GL.Vertex3(-0.125f, 2.5f, -0.02f);
- GL.Vertex3(-0.125f, 1.25f, -0.02f);
- GL.Vertex3(-0.375f, 1.25f, -0.02f);
-
- GL.Vertex3(0.125f, 2.5f, -0.02f);
- GL.Vertex3(0.375f, 2.5f, -0.02f);
- GL.Vertex3(0.375f, 1.25f, -0.02f);
- GL.Vertex3(0.125f, 1.25f, -0.02f);
-
- GL.Vertex3(-0.375f, 2.5f, 0.02f);
- GL.Vertex3(-0.125f, 2.5f, 0.02f);
- GL.Vertex3(-0.125f, 1.25f, 0.02f);
- GL.Vertex3(-0.375f, 1.25f, 0.02f);
-
- GL.Vertex3(0.125f, 2.5f, 0.02f);
- GL.Vertex3(0.375f, 2.5f, 0.02f);
- GL.Vertex3(0.375f, 1.25f, 0.02f);
- GL.Vertex3(0.125f, 1.25f, 0.02f);
-
- //knobs
- GL.Vertex3(-0.375f, 2.25f, 0.04f);
- GL.Vertex3(-0.125f, 2.25f, 0.04f);
- GL.Vertex3(-0.125f, 2f, 0.04f);
- GL.Vertex3(-0.375f, 2f, 0.04f);
-
- GL.Vertex3(0.125f, 2.25f, 0.04f);
- GL.Vertex3(0.375f, 2.25f, 0.04f);
- GL.Vertex3(0.375f, 2f, 0.04f);
- GL.Vertex3(0.125f, 2f, 0.04f);
- GL.End();
-
- control.ApplyModelTransform(Matrix4.CreateTranslation(4, 0, 0));
- }
- }
-
- public override bool Picked(uint index)
- {
- pickedIndex = index;
- Console.WriteLine(index);
- return true;
- }
-
- public override uint GetPickableSpan(){
- return 5;
- }
- }
-}
diff --git a/GL_EditorFramework-master/Testing/Program.cs b/GL_EditorFramework-master/Testing/Program.cs
deleted file mode 100644
index a5393954..00000000
--- a/GL_EditorFramework-master/Testing/Program.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace Testing
-{
- static class Program
- {
- ///
- /// The main entry point for the application.
- ///
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new TestingForm());
- }
- }
-}
diff --git a/GL_EditorFramework-master/Testing/Properties/AssemblyInfo.cs b/GL_EditorFramework-master/Testing/Properties/AssemblyInfo.cs
deleted file mode 100644
index 3e1d4450..00000000
--- a/GL_EditorFramework-master/Testing/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("GL_EditorFramework")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("GL_EditorFramework")]
-[assembly: AssemblyCopyright("Copyright © 2018")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("47680b79-3772-4339-8808-a97f84450cce")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/GL_EditorFramework-master/Testing/Properties/Resources.Designer.cs b/GL_EditorFramework-master/Testing/Properties/Resources.Designer.cs
deleted file mode 100644
index 10aa5c51..00000000
--- a/GL_EditorFramework-master/Testing/Properties/Resources.Designer.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// This code was generated by a tool.
-// Runtime Version:4.0.30319.42000
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-//
-//------------------------------------------------------------------------------
-
-namespace Testing.Properties
-{
-
-
- ///
- /// A strongly-typed resource class, for looking up localized strings, etc.
- ///
- // This class was auto-generated by the StronglyTypedResourceBuilder
- // class via a tool like ResGen or Visual Studio.
- // To add or remove a member, edit your .ResX file then rerun ResGen
- // with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Resources
- {
-
- private static global::System.Resources.ResourceManager resourceMan;
-
- private static global::System.Globalization.CultureInfo resourceCulture;
-
- [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Resources()
- {
- }
-
- ///
- /// Returns the cached ResourceManager instance used by this class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager
- {
- get
- {
- if ((resourceMan == null))
- {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GL_EditorFramework.Properties.Resources", typeof(Resources).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
- }
- }
-
- ///
- /// Overrides the current thread's CurrentUICulture property for all
- /// resource lookups using this strongly typed resource class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture
- {
- get
- {
- return resourceCulture;
- }
- set
- {
- resourceCulture = value;
- }
- }
- }
-}
diff --git a/GL_EditorFramework-master/Testing/Properties/Resources.resx b/GL_EditorFramework-master/Testing/Properties/Resources.resx
deleted file mode 100644
index af7dbebb..00000000
--- a/GL_EditorFramework-master/Testing/Properties/Resources.resx
+++ /dev/null
@@ -1,117 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
\ No newline at end of file
diff --git a/GL_EditorFramework-master/Testing/Properties/Settings.Designer.cs b/GL_EditorFramework-master/Testing/Properties/Settings.Designer.cs
deleted file mode 100644
index caf79bd0..00000000
--- a/GL_EditorFramework-master/Testing/Properties/Settings.Designer.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// This code was generated by a tool.
-// Runtime Version:4.0.30319.42000
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-//
-//------------------------------------------------------------------------------
-
-namespace Testing.Properties
-{
-
-
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
- internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
- {
-
- private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
-
- public static Settings Default
- {
- get
- {
- return defaultInstance;
- }
- }
- }
-}
diff --git a/GL_EditorFramework-master/Testing/Properties/Settings.settings b/GL_EditorFramework-master/Testing/Properties/Settings.settings
deleted file mode 100644
index 39645652..00000000
--- a/GL_EditorFramework-master/Testing/Properties/Settings.settings
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/GL_EditorFramework-master/Testing/TestForm.Designer.cs b/GL_EditorFramework-master/Testing/TestForm.Designer.cs
deleted file mode 100644
index 610119b9..00000000
--- a/GL_EditorFramework-master/Testing/TestForm.Designer.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-namespace Testing
-{
- partial class TestingForm
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- this.gL_ControlModern1 = new GL_Core.GL_ControlModern();
- this.checkBox1 = new System.Windows.Forms.CheckBox();
- this.SuspendLayout();
- //
- // gL_ControlModern1
- //
- this.gL_ControlModern1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.gL_ControlModern1.BackColor = System.Drawing.Color.Black;
- this.gL_ControlModern1.Location = new System.Drawing.Point(0, 35);
- this.gL_ControlModern1.MainDrawable = null;
- this.gL_ControlModern1.Name = "gL_ControlModern1";
- this.gL_ControlModern1.Size = new System.Drawing.Size(800, 467);
- this.gL_ControlModern1.Stereoscopy = false;
- this.gL_ControlModern1.TabIndex = 0;
- this.gL_ControlModern1.VSync = false;
- this.gL_ControlModern1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.gL_ControlModern1_MouseClick);
- //
- // checkBox1
- //
- this.checkBox1.AutoSize = true;
- this.checkBox1.Location = new System.Drawing.Point(12, 12);
- this.checkBox1.Name = "checkBox1";
- this.checkBox1.Size = new System.Drawing.Size(85, 17);
- this.checkBox1.TabIndex = 1;
- this.checkBox1.Text = "Stereoscopy";
- this.checkBox1.UseVisualStyleBackColor = true;
- this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
- //
- // TestingForm
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 501);
- this.Controls.Add(this.checkBox1);
- this.Controls.Add(this.gL_ControlModern1);
- this.Name = "TestingForm";
- this.Text = "Test Window";
- this.ResumeLayout(false);
- this.PerformLayout();
-
- }
-
- #endregion
-
- private GL_Core.GL_ControlModern gL_ControlModern1;
- private System.Windows.Forms.CheckBox checkBox1;
- }
-}
-
diff --git a/GL_EditorFramework-master/Testing/TestForm.cs b/GL_EditorFramework-master/Testing/TestForm.cs
deleted file mode 100644
index dfab666a..00000000
--- a/GL_EditorFramework-master/Testing/TestForm.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-using GL_Core;
-
-namespace Testing
-{
- public partial class TestingForm : Form
- {
- public TestingForm()
- {
- InitializeComponent();
- }
-
- private void gL_ControlModern1_MouseClick(object sender, MouseEventArgs e)
- {
- if(gL_ControlModern1.MainDrawable==null)
- gL_ControlModern1.MainDrawable = new MarioTposeTest();
- }
-
- private void checkBox1_CheckedChanged(object sender, EventArgs e)
- {
- gL_ControlModern1.Stereoscopy = checkBox1.Checked;
- }
- }
-}
diff --git a/GL_EditorFramework-master/Testing/TestForm.resx b/GL_EditorFramework-master/Testing/TestForm.resx
deleted file mode 100644
index 1af7de15..00000000
--- a/GL_EditorFramework-master/Testing/TestForm.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
\ No newline at end of file
diff --git a/GL_EditorFramework-master/Testing/Testing.csproj b/GL_EditorFramework-master/Testing/Testing.csproj
deleted file mode 100644
index 153c63bc..00000000
--- a/GL_EditorFramework-master/Testing/Testing.csproj
+++ /dev/null
@@ -1,95 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- {47680B79-3772-4339-8808-A97F84450CCE}
- WinExe
- GL_EditorFramework
- GL_EditorFramework
- v4.6.1
- 512
- true
-
-
- AnyCPU
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- AnyCPU
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ..\packages\OpenTK.3.0.1\lib\net20\OpenTK.dll
-
-
- ..\packages\OpenTK.GLControl.3.0.1\lib\net20\OpenTK.GLControl.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Form
-
-
- TestForm.cs
-
-
-
-
- TestForm.cs
-
-
- ResXFileCodeGenerator
- Resources.Designer.cs
- Designer
-
-
- True
- Resources.resx
-
-
- SettingsSingleFileGenerator
- Settings.Designer.cs
-
-
- True
- Settings.settings
- True
-
-
-
-
-
-
-
- {29647BA5-2859-46F0-A99E-C3A387A9447A}
- GL_Core
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
deleted file mode 100644
index 03378b9b..00000000
--- a/README.md
+++ /dev/null
@@ -1,127 +0,0 @@
-# Switch-Toolbox
-A tool to edit many formats of Nintendo Switch and some Wii U.
-
-## Changelog
-
-v0.8.5.1
- - Basic .nutexb dds injection. Must be same width/height and format due to .arc size limitations atm!
-
-v0.8.4 - v0.8.5
-- Textures for Wii U deswizzle properly thanks to AboodXD.
-- Zstb compressed files will be detected and decompressed automatically on open.
-- Textures BC1-BC5 will show properly if DirectXTex is not working on older windows versions. Small work around atm.
-- Improper transformations (like bad rotations) should be fixed now.
-- Basic GTX file viewing
-- Fixed BNTX texture alignment if there is only one texture present in the file.
-- Many more bug fixes to enhance the user experience.
-
-v0.8.3
-- Support all nutexb formats from .arc.
-- Fix brightness issues for nutexb srgb (using unorm for decoding atm).
-
-v0.8.2 Changelog
- - Fixed nutexb errors (incorrect sizes)
- - Batch exporting nutexb works properly now. Will export with offset for unique name.
- - DDS save properly to open in photoshop and other programs.
-
-v0.8.1 Changelog
- - Fixed error messages and freezes from nutexb.
-
-v0.8 Changelog
-- DDS compression reworked allowing png importing, and previewing of all DDS formats from [DirectXTex](https://github.com/Microsoft/DirectXTex).
-- Exporting/importing of all animation types as binary.
-- .Nutexb previewing/exporting. (and batch exporting)
-- DAE/FBX rigging supported. Models will no longer show invisible.
-- Improvements to BFRES library. Some games may work better now.
-- Channel types are now set on import. May fix normal map issues.
-- Archives use double click for opening files
-- DDS cubemaps can be imported
-- GFPAK repacking (untested)
-- Animations for skeleton animations can be played (thanks to smash forge).
-- Improvements to UI. May load quicker.
-- Update bake map placeholder textures to look proper.
-- Many improvements and big fixes!
-
-v0.72 Changelog
-- Fixed crashes from RGBA DDS.
-- Added an option to disable viewport. (May be quicker, and for those who use old GL versions).
-
-v0.71 Changelog
-- Stability improvements.
-- Add byml editor back in.
-- Some bug fixes and exception issues
-
-This tool currently features:
-- BFRES
- - Model importing (dae, fbx, obj, and csv)
- - Material editing (Render info, texture mapping, parameters, etc)
- - Material copying
- - Animation and model sub section can be exported/imported.
- - Can delete, add, replace individual objects from an fmdl.
-- BNTX
- - Can add/remove textures.
- - Can import textures as DDS. (Thanks to AboodXD! png/jpeg, etc planned later)
- - Can export as binary, dds, png, tga, etc.
- - Can preview mipmap and surface(array) levels.
-- NUTEXB
- - Can export as binary, dds, png, tga, etc.
- - Can preview.
-- SARC
- - Supported editing/saving data opened. (Automatically saves data opened in objectlist if supported)
- - Supports padding (Thanks to Exelix and AboodXD)
- - Can save sarcs in sarcs in sarcs.
-- BARS
- - Can extract and replace audio files.. (rebuilds the file)
-- KCL
- - Preview collision models.
- - Replace/Export as obj (Thanks to Exelix)
-- BFFNT
- - Can extract font images and preview their image arrays (BNTX)
-- GFPAK
- - Can extract, edit, and rebuild (untested).
-
-## Building
-To build make sure you have Visual Studio installed (I use 2017, older versions may not work) and open the .sln. Then build the solution as release. It should compile properly on the latest.
-
-In the event that the tool cannot compile, check references. All the libraries are stored in Switch-Toolbox/Lib folder.
-
-## This tool is in BETA and not final! Code also needs some major clean up!
-## Credits
-
-- Smash Forge Devs (SMG, Ploaj, jam1garner, smb123w64gb, etc) for some code ported over. Specifically animation stuff, GTX c# implementation, and some rendering.
-- Assimp devs for their massive asset library!
-- Wexos (helped figure out a few things, ie format list to assign each attribute)
-- JuPaHe64 for the base 3D renderer.
-- Every File Explorer devs (Gericom) for Yaz0 stuff
-- Exelix for Byaml, Sarc and KCL library
-- Syroot for helpful IO extensions and libraries
-- GDK Chan for some DDS decode methods
-- AboodXD for some foundation stuff with exelix's SARC library, GTX and BNTX texture swizzling and documentation
-- MelonSpeedruns for logo.
-
-Resources
-- [Treeview Icons by icons8](https://icons8.com/)
-- Smash Forge (Currently placeholders)
-
-Libraries
-- [Exelix (Sarc, kcl, and byml libraries)](https://github.com/exelix11/EditorCore/tree/master/FileFormatPlugins)
-- [ZstdNet (Compression)](https://github.com/skbkontur/ZstdNet)
-- [Be.HexEditor by Bernhard Elbl](https://sourceforge.net/projects/hexbox/)
-- GL EditorFramwork by jupahe64
-- [WeifenLuo for docking suite](http://dockpanelsuite.com/)
-- [SF Graphics by SMG (Experimental](https://github.com/ScanMountGoat/SFGraphics) (currently just a placeholder for shader workflow and some useful things)
-- [Audio & MIDI library](https://github.com/naudio/NAudio)
-- [VGAudio](https://github.com/Thealexbarney/VGAudio)
-- [Assimp](https://bitbucket.org/Starnick/assimpnet/src/master/)
-- [OpenTK](https://github.com/opentk/opentk)
-- [BezelEngineArchive Library](https://github.com/KillzXGaming/BEA-Library-Editor)
-- [Syroot BinaryData](https://gitlab.com/Syroot/BinaryData)
-- [Syroot Maths](https://gitlab.com/Syroot/Maths)
-- [Syroot Bfres Library (Wii U)](https://gitlab.com/Syroot/NintenTools.Bfres)
-- [Costura for embedding data for plugins](https://github.com/Fody/Costura)
-- [CsvHelper (unused atm but planned to be used](https://joshclose.github.io/CsvHelper/)
-
-License
- in Switch_Toolbox\Lib\Licenses
-
- Please note if you do not want your library used or if i'm missing credits!
diff --git a/Switch_FileFormatsMain/Config.cs b/Switch_FileFormatsMain/Config.cs
deleted file mode 100644
index 07bbd0f3..00000000
--- a/Switch_FileFormatsMain/Config.cs
+++ /dev/null
@@ -1,96 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Xml;
-using System.Drawing;
-using System.IO;
-using Switch_Toolbox.Library;
-
-namespace FirstPlugin
-{
- //Based on
- // https://github.com/jam1garner/Smash-Forge/blob/26e0dcbd84cdf8a4ffe3fbe0b0317520a4099286/Smash%20Forge/Filetypes/Application/Config.cs
- class Config
- {
- public static void StartupFromFile(string fileName)
- {
- if (!File.Exists(fileName))
- {
- Save();
- return;
- }
-
- ReadConfigFromFile(fileName);
- }
-
- private static void ReadConfigFromFile(string fileName)
- {
- int discordImageKey;
- XmlDocument doc = new XmlDocument();
- doc.Load(fileName);
- Queue que = new Queue();
-
- foreach (XmlNode node in doc.ChildNodes)
- que.Enqueue(node);
-
- while (que.Count > 0)
- {
- XmlNode node = que.Dequeue();
-
- foreach (XmlNode n in node.ChildNodes)
- que.Enqueue(n);
-
- switch (node.Name)
- {
- case "FSHPDockState":
- if (node.ParentNode != null && node.ParentNode.Name.Equals("DOCKSETTINGS"))
- Enum.TryParse(node.InnerText, out PluginRuntime.FSHPDockState);
- break;
- case "ExternalFMATPath":
- if (node.ParentNode != null && node.ParentNode.Name.Equals("PATHSETTINGS"))
- if (File.Exists(node.InnerText))
- PluginRuntime.ExternalFMATPath = node.InnerText;
- break;
- case "MarioOdysseyGamePath":
- if (node.ParentNode != null && node.ParentNode.Name.Equals("PATHSETTINGS"))
- if (File.Exists(node.InnerText))
- PluginRuntime.OdysseyGamePath = node.InnerText;
- break;
- }
- }
- }
- public static void Save()
- {
- XmlDocument doc = CreateXmlFromSettings();
- doc.Save("Lib/Plugins/config.xml");
- }
- private static XmlDocument CreateXmlFromSettings()
- {
- XmlDocument doc = new XmlDocument();
- XmlNode mainNode = doc.CreateElement("FORGECONFIG");
- doc.AppendChild(mainNode);
-
- AppendDOCKSettings(doc, mainNode);
- AppendPathSettings(doc, mainNode);
- return doc;
- }
- private static void AppendPathSettings(XmlDocument doc, XmlNode parentNode)
- {
- XmlNode pathSettingsNode = doc.CreateElement("PATHSETTINGS");
- parentNode.AppendChild(pathSettingsNode);
- pathSettingsNode.AppendChild(createNode(doc, "ExternalFMATPath", PluginRuntime.ExternalFMATPath));
- pathSettingsNode.AppendChild(createNode(doc, "MarioOdysseyGamePath", PluginRuntime.OdysseyGamePath));
- }
- private static void AppendDOCKSettings(XmlDocument doc, XmlNode parentNode)
- {
- XmlNode renderSettingsNode = doc.CreateElement("DOCKSETTINGS");
- parentNode.AppendChild(renderSettingsNode);
- renderSettingsNode.AppendChild(createNode(doc, "FSHPDockState", PluginRuntime.FSHPDockState.ToString()));
- }
- public static XmlNode createNode(XmlDocument doc, string el, string v)
- {
- XmlNode floorstyle = doc.CreateElement(el);
- floorstyle.InnerText = v;
- return floorstyle;
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/AAMP.cs b/Switch_FileFormatsMain/FileFormats/AAMP.cs
deleted file mode 100644
index 07ff21f7..00000000
--- a/Switch_FileFormatsMain/FileFormats/AAMP.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-
-namespace FirstPlugin
-{
- public class AAMP : IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "AAMP" };
- public string[] Extension { get; set; } = new string[] { "*.aamp" };
- public string Magic { get; set; } = "AAMP";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public int Alignment { get; set; } = 0;
- public string FilePath { get; set; }
- public IFileInfo IFileInfo { get; set; }
-
- public Type[] Types
- {
- get
- {
- List types = new List();
- return types.ToArray();
- }
- }
-
- public void Load()
- {
- IsActive = true;
- }
- public void Unload()
- {
-
- }
- public byte[] Save()
- {
- return null;
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/AAMP.zip b/Switch_FileFormatsMain/FileFormats/AAMP.zip
deleted file mode 100644
index b7b51fbd..00000000
Binary files a/Switch_FileFormatsMain/FileFormats/AAMP.zip and /dev/null differ
diff --git a/Switch_FileFormatsMain/FileFormats/BARS.cs b/Switch_FileFormatsMain/FileFormats/BARS.cs
deleted file mode 100644
index f207bfcc..00000000
--- a/Switch_FileFormatsMain/FileFormats/BARS.cs
+++ /dev/null
@@ -1,238 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using Switch_Toolbox.Library.IO;
-using BarsLib;
-using WeifenLuo.WinFormsUI.Docking;
-using VGAudio.Formats;
-using VGAudio;
-using VGAudio.Containers.NintendoWare;
-using VGAudio.Containers.Wave;
-using NAudio.Wave;
-
-namespace FirstPlugin
-{
- public class BARS : TreeNodeFile, IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "Sound Archive" };
- public string[] Extension { get; set; } = new string[] { "*.bars" };
- public string Magic { get; set; } = "BARS";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public int Alignment { get; set; } = 0;
- public string FilePath { get; set; }
- public IFileInfo IFileInfo { get; set; }
-
- public Type[] Types
- {
- get
- {
- List types = new List();
- return types.ToArray();
- }
- }
-
- public class AudioEntry : TreeNodeCustom
- {
- public AudioType Type;
- public byte[] Data;
- BFAVEditor BFAVEditor;
-
- public AudioEntry()
- {
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
-
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- }
- public void SetupMusic()
- {
- if (Type == AudioType.Bfwav)
- {
- ImageKey = "bfwav";
- SelectedImageKey = "bfwav";
- }
- else if (Type == AudioType.Bfstp)
- {
- ImageKey = "bfstp";
- SelectedImageKey = "bfstp";
- }
- else
- {
- ImageKey = "fileBlank";
- SelectedImageKey = "fileBlank";
- }
- }
- public AudioData GetAudioData()
- {
- BCFstmReader reader = new BCFstmReader();
- return reader.Read(Data);
- }
- public byte[] BfwavToWav()
- {
- MemoryStream mem = new MemoryStream();
- WaveWriter writer = new WaveWriter();
-
- AudioData audioData = GetAudioData();
- writer.WriteToStream(audioData, mem);
-
- return mem.ToArray();
- }
-
- private void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.FileName = Text;
- sfd.DefaultExt = Path.GetExtension(Text);
- sfd.Filter = "All files(*.*)|*.*";
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- File.WriteAllBytes(sfd.FileName, Data);
- }
- }
-
- private void Replace(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.FileName = Text;
- ofd.DefaultExt = Path.GetExtension(Text);
- ofd.Filter = "All files(*.*)|*.*";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- Data = File.ReadAllBytes(ofd.FileName);
- UpdateEditor();
- }
- }
- public void UpdateEditor()
- {
- if (Viewport.Instance.gL_ControlModern1.Visible == false)
- PluginRuntime.FSHPDockState = WeifenLuo.WinFormsUI.Docking.DockState.Document;
-
- BFAVEditor docked = (BFAVEditor)LibraryGUI.Instance.GetContentDocked(new BFAVEditor());
- if (docked == null)
- {
- docked = new BFAVEditor();
- LibraryGUI.Instance.LoadDockContent(docked, PluginRuntime.FSHPDockState);
- }
- docked.Text = Text;
- docked.Dock = DockStyle.Fill;
- docked.LoadFile(this);
- }
-
- public override void OnClick(TreeView treeview)
- {
- if (Type == AudioType.Bfwav)
- {
- UpdateEditor();
- }
-
- } bool EditorIsActive(DockContent dock)
- {
- foreach (Control ctrl in dock.Controls)
- {
- if (ctrl is BFAVEditor)
- {
- dock.Text = Text;
- ((BFAVEditor)ctrl).LoadFile(this);
- return true;
- }
- }
-
- return false;
- }
- }
-
- public BarsLib.BARS bars;
- public void Load()
- {
- IsActive = true;
- CanSave = true;
-
- Text = FileName;
-
- bars = new BarsLib.BARS(new MemoryStream(Data));
- Nodes.Add("AMTA");
- Nodes.Add("Audio");
- for (int i = 0; i < bars.AmtaList.Count; i++)
- {
- string audioName = bars.AmtaList[i].Name;
-
- Nodes[0].Nodes.Add(audioName + ".amta");
- BARSAudioFile audio = bars.audioList[i];
-
- AudioEntry node = new AudioEntry();
- node.Type = audio.AudioType;
- node.Data = audio.data;
- node.SetupMusic();
-
- if (audio.AudioType == AudioType.Bfwav)
- node.Text = audioName + ".bfwav";
- else if (audio.AudioType == AudioType.Bfstp)
- node.Text = audioName + ".bfstp";
- else
- node.Text = audioName + ".UNKOWN";
-
- Nodes[1].Nodes.Add(node);
- }
-
- ContextMenu = new ContextMenu();
- MenuItem save = new MenuItem("Save");
- ContextMenu.MenuItems.Add(save);
- save.Click += Save;
- }
- public void Unload()
- {
-
- }
- private void Save(object sender, EventArgs args)
- {
- List formats = new List();
-
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = Utils.GetAllFilters(formats);
- sfd.FileName = FileName;
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- STFileSaver.SaveFileFormat(this, sfd.FileName);
- }
- }
- public byte[] Save()
- {
- MemoryStream mem = new MemoryStream();
-
- foreach (TreeNode node in Nodes[1].Nodes)
- {
- for (int i = 0; i < bars.AmtaList.Count; i++)
- {
- string audioName = bars.AmtaList[i].Name;
-
- if (Path.GetFileNameWithoutExtension(node.Text) == audioName)
- {
- Console.WriteLine(audioName);
- bars.audioList[i].data = ((AudioEntry)node).Data;
- }
- }
- }
-
- bars.Save(mem);
- return mem.ToArray();
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BEA.cs b/Switch_FileFormatsMain/FileFormats/BEA.cs
deleted file mode 100644
index 8a279f29..00000000
--- a/Switch_FileFormatsMain/FileFormats/BEA.cs
+++ /dev/null
@@ -1,536 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Switch_Toolbox;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using System.IO;
-using BezelEngineArchive_Lib;
-using Switch_Toolbox.Library.IO;
-using Switch_Toolbox.Library.Forms;
-
-namespace FirstPlugin
-{
- public class BEA : TreeNode, IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "Bevel Engine Archive" };
- public string[] Extension { get; set; } = new string[] { "*.bea" };
- public string Magic { get; set; } = "SCNE";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public int Alignment { get; set; } = 0;
- public string FilePath { get; set; }
- public IFileInfo IFileInfo { get; set; }
-
- public Type[] Types
- {
- get
- {
- List types = new List();
- types.Add(typeof(MenuExt));
- return types.ToArray();
- }
- }
- class MenuExt : IFileMenuExtension
- {
- public ToolStripItemDark[] NewFileMenuExtensions => null;
- public ToolStripItemDark[] ToolsMenuExtensions => null;
- public ToolStripItemDark[] TitleBarExtensions => null;
- public ToolStripItemDark[] CompressionMenuExtensions => null;
- public ToolStripItemDark[] ExperimentalMenuExtensions => experimentalMenu;
-
- ToolStripItemDark[] experimentalMenu = new ToolStripItemDark[1];
- public MenuExt()
- {
- experimentalMenu[0] = new ToolStripItemDark("BEA");
-
- ToolStripItemDark batchLUA = new ToolStripItemDark("Batch Extract LUA");
- batchLUA.Click += BatchExtractLUA;
-
-
- experimentalMenu[0].DropDownItems.Add(batchLUA);
- }
-
- private void BatchExtractLUA(object sender, EventArgs e)
- {
- FolderSelectDialog ofd = new FolderSelectDialog();
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- string folderPath = ofd.SelectedPath;
-
- foreach (string file in Directory.GetFiles(folderPath))
- {
- Console.WriteLine(file);
-
- if (Path.GetExtension(file) == ".bea")
- {
- BEA bea = new BEA();
- bea.Data = File.ReadAllBytes(file);
- bea.FileName = file;
- bea.Load();
-
- foreach (FileEntry asset in bea.Nodes)
- {
- if (Path.GetExtension(asset.FullName) == ".lua")
- {
- try
- {
- if (!String.IsNullOrWhiteSpace(Path.GetDirectoryName($"{folderPath}/{bea.Name}/{asset.FullName}")))
- {
- if (!File.Exists(asset.FullName))
- {
- if (!Directory.Exists($"{folderPath}/{bea.Name}/{asset.FullName}"))
- {
- Directory.CreateDirectory(Path.GetDirectoryName($"{folderPath}/{bea.Name}/{asset.FullName}"));
- }
- }
- }
- File.WriteAllBytes($"{folderPath}/{bea.Name}/{asset.FullName}", GetASSTData(asset));
- }
- catch
- {
-
- }
- }
- }
- }
- }
- }
- }
- }
-
- public static BezelEngineArchive beaFile;
- static ProgressBarWindow progressBar;
-
- public void Load()
- {
- Text = FileName;
-
- IsActive = true;
- CanSave = true;
-
- beaFile = new BezelEngineArchive(new MemoryStream(Data));
- FillTreeNodes(this, beaFile.FileList);
-
- ContextMenu = new ContextMenu();
- MenuItem save = new MenuItem("Save");
- ContextMenu.MenuItems.Add(save);
- save.Click += Save;
- MenuItem previewFiles = new MenuItem("Preview Window");
- ContextMenu.MenuItems.Add(previewFiles);
- previewFiles.Click += PreviewWindow;
- MenuItem exportAll = new MenuItem("Export All");
- ContextMenu.MenuItems.Add(exportAll);
- exportAll.Click += ExportAll;
- }
- public void Unload()
- {
-
- }
-
- IEnumerable Collect(TreeNodeCollection nodes)
- {
- foreach (TreeNode node in nodes)
- {
- yield return node;
-
- foreach (var child in Collect(node.Nodes))
- yield return child;
- }
- }
- private void Save(object sender, EventArgs args)
- {
- Cursor.Current = Cursors.WaitCursor;
- List formats = new List();
- formats.Add(this);
-
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = Utils.GetAllFilters(formats);
- sfd.FileName = FileName;
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- STFileSaver.SaveFileFormat(this, sfd.FileName);
- }
- GC.Collect();
- }
- public byte[] Save()
- {
- beaFile.FileList.Clear();
- beaFile.FileDictionary.Clear();
-
- foreach (TreeNode node in Collect(Nodes))
- {
- if (node is TreeNodeFile && node != this)
- {
- IFileFormat fileFormat = (IFileFormat)node;
- if (fileFormat != null)
- {
- byte[] uncomrompressedData = fileFormat.Data;
-
- //Save any active files in the editor if supported
- if (fileFormat.CanSave)
- uncomrompressedData = fileFormat.Save();
-
- //Create a new asset entry
- ASST asset = new ASST();
- asset.unk = 2;
- asset.unk2 = 2;
- asset.UncompressedSize = uncomrompressedData.LongLength;
-
- if (fileFormat.FileIsCompressed)
- asset.FileData = STLibraryCompression.ZSTD.Compress(uncomrompressedData);
- else
- asset.FileData = fileFormat.Data;
-
- asset.FileName = fileFormat.FilePath;
- beaFile.FileList.Add(fileFormat.FilePath, asset);
- beaFile.FileDictionary.Add(fileFormat.FilePath);
- }
- }
- else if (node is FileEntry)
- {
- ASST asset = new ASST();
- asset.unk = ((FileEntry)node).unk1;
- asset.unk2 = ((FileEntry)node).unk2;
- asset.FileName = ((FileEntry)node).FullName;
- asset.FileData = ((FileEntry)node).data;
- byte[] uncomp = GetASSTData((FileEntry)node);
- asset.UncompressedSize = uncomp.Length;
- beaFile.FileList.Add(asset.FileName, asset);
- beaFile.FileDictionary.Add(asset.FileName);
- }
- }
-
- MemoryStream mem = new MemoryStream();
- beaFile.Save(mem);
- return mem.ToArray();
- }
- private void ExportAll(object sender, EventArgs args)
- {
- FolderSelectDialog fsd = new FolderSelectDialog();
-
- if (fsd.ShowDialog() == DialogResult.OK)
- {
- progressBar = new ProgressBarWindow();
- progressBar.Task = "Extracing Files...";
- progressBar.Refresh();
- progressBar.Value = 0;
- progressBar.StartPosition = FormStartPosition.CenterScreen;
- progressBar.Show();
-
- ExportAll(fsd.SelectedPath, progressBar);
- }
- }
- private void ExportAll(string Folder, ProgressBarWindow progressBar)
- {
- int Curfile = 0;
- foreach (FileEntry asst in Nodes)
- {
- int value = (Curfile * 100) / beaFile.FileList.Count;
- progressBar.Value = value;
- progressBar.Refresh();
-
- try
- {
- if (!String.IsNullOrWhiteSpace(Path.GetDirectoryName($"{Folder}/{beaFile.Name}/{asst.FullName}")))
- {
- if (!File.Exists(asst.FullName))
- {
- if (!Directory.Exists($"{Folder}/{beaFile.Name}/{asst.FullName}"))
- {
- Directory.CreateDirectory(Path.GetDirectoryName($"{Folder}/{beaFile.Name}/{asst.FullName}"));
- }
- }
- }
- File.WriteAllBytes($"{Folder}/{beaFile.Name}/{asst.FullName}", GetASSTData(asst));
- }
- catch
- {
-
- }
-
- Curfile++;
- if (value == 99)
- value = 100;
- progressBar.Value = value;
- progressBar.Refresh();
- }
- }
- private void CallRecursive(TreeView treeView)
- {
- // Print each node recursively.
- TreeNodeCollection nodes = treeView.Nodes;
- foreach (TreeNode n in nodes)
- {
- PrintRecursive(n);
- }
- }
- private void PrintRecursive(TreeNode treeNode)
- {
- // Print each node recursively.
- foreach (TreeNode tn in treeNode.Nodes)
- {
- PrintRecursive(tn);
- }
- }
-
- public void PreviewWindow(object sender, EventArgs args)
- {
- PreviewFormatList previewFormatList = new PreviewFormatList();
-
- if (previewFormatList.ShowDialog() == DialogResult.OK)
- {
- CallRecursive(TreeView);
- Console.WriteLine("Loaded files");
- Console.WriteLine(PluginRuntime.bntxContainers.Count);
- PreviewEditor previewWindow = new PreviewEditor();
- previewWindow.Show();
- }
- }
- public bool Compressed;
- public class FolderEntry : TreeNode
- {
- public FolderEntry()
- {
- ImageKey = "folder";
- SelectedImageKey = "folder";
- }
-
- public FolderEntry(string Name)
- {
- Text = Name;
- }
- }
- public class FileEntry : TreeNodeCustom
- {
- public FileEntry()
- {
- ImageKey = "fileBlank";
- SelectedImageKey = "fileBlank";
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
-
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- }
-
- public string FullName;
- public IFileFormat FileHandle; //Load file instance to save later if possible
- public byte[] data;
- public ushort unk1;
- public ushort unk2;
- public bool IsCompressed;
-
- private void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.FileName = Text;
- sfd.DefaultExt = Path.GetExtension(Text);
- sfd.Filter = "All files(*.*)|*.*";
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- File.WriteAllBytes(sfd.FileName, GetASSTData(this));
- }
- }
-
- private void Replace(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.FileName = Text;
- ofd.DefaultExt = Path.GetExtension(Text);
- ofd.Filter = "All files(*.*)|*.*";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- SetASST(this, File.ReadAllBytes(ofd.FileName));
- }
- }
-
- public override void OnDoubleMouseClick(TreeView treeview)
- {
- if (GetASSTData(this) != null)
- {
- TreeNode node = STFileLoader.GetNodeFileFormat(FullName, GetASSTData(this), true, "", this, IsCompressed, CompressionType.Zstb);
-
- if (node != null)
- ReplaceNode(this.Parent, this, node);
- }
- }
- }
-
- public static void ReplaceNode(TreeNode node, TreeNode replaceNode, TreeNode NewNode)
- {
- int index = node.Nodes.IndexOf(replaceNode);
- node.Nodes.RemoveAt(index);
- node.Nodes.Insert(index, NewNode);
- }
-
- public static byte[] GetASSTData(FileEntry entry)
- {
- if (entry.IsCompressed)
- return STLibraryCompression.ZSTD.Decompress(entry.data);
- else
- return entry.data;
- }
- public static void SetASST(FileEntry fileEntry, byte[] data)
- {
- if (fileEntry.IsCompressed)
- fileEntry.data = STLibraryCompression.ZSTD.Compress(data);
- else
- fileEntry.data = data;
- }
-
- void FillTreeNodes(TreeNode root, Dictionary files)
- {
- var rootText = root.Text;
- var rootTextLength = rootText.Length;
- var nodeStrings = files;
- foreach (var node in nodeStrings)
- {
- string nodeString = node.Key;
-
- var roots = nodeString.Split(new char[] { '/' },
- StringSplitOptions.RemoveEmptyEntries);
-
- // The initial parent is the root node
- TreeNode parentNode = root;
- var sb = new StringBuilder(rootText, nodeString.Length + rootTextLength);
- for (int rootIndex = 0; rootIndex < roots.Length; rootIndex++)
- {
- // Build the node name
- var parentName = roots[rootIndex];
- sb.Append("/");
- sb.Append(parentName);
- var nodeName = sb.ToString();
-
- // Search for the node
- var index = parentNode.Nodes.IndexOfKey(nodeName);
- if (index == -1)
- {
- // Node was not found, add it
-
- var temp = new TreeNode(parentName, 0, 0);
- if (rootIndex == roots.Length - 1)
- temp = SetupFileEntry(node.Value,parentName, node.Value.FileName, node.Value.IsCompressed);
- else
- temp = SetupFolderEntry(temp);
-
- temp.Name = nodeName;
- parentNode.Nodes.Add(temp);
- parentNode = temp;
- }
- else
- {
- // Node was found, set that as parent and continue
- parentNode = parentNode.Nodes[index];
- }
- }
- }
- }
-
- public FolderEntry SetupFolderEntry(TreeNode node)
- {
- FolderEntry folder = new FolderEntry();
- folder.Text = node.Text;
-
- return folder;
- }
-
- List BuildFinalList(List paths)
- {
- var finalList = new List();
- foreach (var path in paths)
- {
- bool found = false;
- foreach (var item in finalList)
- {
- if (item.StartsWith(path, StringComparison.Ordinal))
- {
- found = true;
- break;
- }
- }
- if (!found)
- {
- finalList.Add(path);
- }
- }
- return finalList;
- }
-
- public FileEntry SetupFileEntry(ASST asset,string name, string fullName, bool IsCompressed)
- {
- FileEntry fileEntry = new FileEntry();
- fileEntry.FullName = fullName;
- fileEntry.Name = name;
- fileEntry.Text = name;
- fileEntry.unk1 = asset.unk;
- fileEntry.unk2 = asset.unk2;
- fileEntry.IsCompressed = IsCompressed;
- fileEntry.data = asset.FileData;
-
- //Now check magic
- //Todo clean this part up
- byte[] data = asset.FileData;
- if (IsCompressed)
- {
- try
- {
- data = STLibraryCompression.ZSTD.Decompress(asset.FileData);
- }
- catch
- {
- Console.WriteLine("Unkwon compression for file " + fileEntry.Name);
- }
- }
-
-
- string ext = Path.GetExtension(name);
- string SarcEx = SARCExt.SARC.GuessFileExtension(data);
- if (name.EndsWith("bfres") || name.EndsWith("fmdb") || name.EndsWith("fskb") ||
- name.EndsWith("ftsb") || name.EndsWith("fvmb") || name.EndsWith("fvbb") ||
- name.EndsWith("fspb") || name.EndsWith("fsnb"))
- {
- fileEntry.ImageKey = "bfres";
- fileEntry.SelectedImageKey = "bfres";
- }
- if (SarcEx == ".bntx")
- {
- fileEntry.ImageKey = "bntx";
- fileEntry.SelectedImageKey = "bntx";
- }
- if (SarcEx == ".byaml")
- {
- fileEntry.ImageKey = "byaml";
- fileEntry.SelectedImageKey = "byaml";
- }
- if (SarcEx == ".aamp")
- {
- fileEntry.ImageKey = "aamp";
- fileEntry.SelectedImageKey = "aamp";
- }
- if (ext == ".lua")
- {
-
- }
- data = null;
-
- return fileEntry;
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFFNT.cs b/Switch_FileFormatsMain/FileFormats/BFFNT.cs
deleted file mode 100644
index 0eafdaeb..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFFNT.cs
+++ /dev/null
@@ -1,212 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Switch_Toolbox;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using System.IO;
-using Switch_Toolbox.Library.IO;
-
-namespace FirstPlugin
-{
- public class BFFNT : TreeNode, IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "Cafe Font" };
- public string[] Extension { get; set; } = new string[] { "*.bffnt" };
- public string Magic { get; set; } = "FFNT";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public int Alignment { get; set; } = 0;
- public string FilePath { get; set; }
- public IFileInfo IFileInfo { get; set; }
-
- public Type[] Types
- {
- get
- {
- List types = new List();
- return types.ToArray();
- }
- }
-
- public void Load()
- {
- IsActive = true;
- FFNT bffnt = new FFNT();
- bffnt.Read(new FileReader(new MemoryStream(Data)));
-
- TGLP tglp = bffnt.finf.tglp;
-
- int i = 0;
- foreach (byte[] texture in tglp.SheetDataList)
- {
- SheetEntry sheet = new SheetEntry();
- sheet.data = texture;
- sheet.Text = "Sheet" + i++;
- }
- }
- public void Unload()
- {
-
- }
- public byte[] Save()
- {
- return null;
- }
-
-
- public class SheetEntry : TreeNodeCustom
- {
- public SheetEntry()
- {
- ImageKey = "fileBlank";
- SelectedImageKey = "fileBlank";
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
-
- }
- public byte[] data;
-
- public override void OnClick(TreeView treeview)
- {
-
- }
-
- private void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.FileName = Text;
- sfd.DefaultExt = "bntx";
- sfd.Filter = "Supported Formats|*.bntx;|" +
- "All files(*.*)|*.*";
-
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- File.WriteAllBytes(sfd.FileName, data);
- }
- }
- }
- }
-
- public class FFNT
- {
- public ushort BOM;
- public uint Version;
- public FINF finf;
-
- public void Read(FileReader reader)
- {
- string Signature = reader.ReadString(4, Encoding.ASCII);
- if (Signature != "FFNT")
- throw new Exception($"Invalid signature {Signature}! Expected FFNT.");
-
- char[] Magic = reader.ReadChars(4);
- BOM = reader.ReadUInt16();
- Version = reader.ReadUInt32();
- uint FileSize = reader.ReadUInt16();
- uint BlockCount = reader.ReadUInt16();
- uint unk = reader.ReadUInt16();
-
- finf = new FINF();
- finf.Read(reader);
-
- }
- }
- public class FINF
- {
- public uint Size;
- public uint Type;
- public uint Width;
- public uint Height;
- public uint Ascend;
- public uint LineFeed;
- public uint AlterCharIndex;
- public uint DefaultLeftWidth;
- public uint DefaultGlyphWidth;
- public uint DefaultCharWidth;
- public uint CharEncoding;
- public TGLP tglp;
-
- public void Read(FileReader reader)
- {
- string Signature = reader.ReadString(4, Encoding.ASCII);
- if (Signature != "FINF")
- throw new Exception($"Invalid signature {Signature}! Expected FINF.");
- Size = reader.ReadUInt32();
- Type = reader.ReadByte();
- Height = reader.ReadByte();
- Width = reader.ReadByte();
- Ascend = reader.ReadByte();
- LineFeed = reader.ReadUInt16();
- AlterCharIndex = reader.ReadUInt16();
- DefaultLeftWidth = reader.ReadByte();
- DefaultGlyphWidth = reader.ReadByte();
- DefaultCharWidth = reader.ReadByte();
- CharEncoding = reader.ReadByte();
- uint tglpOffset = reader.ReadUInt32();
- uint cwdhOffset = reader.ReadUInt32();
- uint cmapOffset = reader.ReadUInt32();
-
- tglp = new TGLP();
- using (reader.TemporarySeek(tglpOffset - 8, SeekOrigin.Begin))
- {
- tglp.Read(reader);
- }
- }
- }
- public class TGLP
- {
- public uint Size;
- public uint CellWidth;
- public uint CellHeight;
- public uint MaxCharWidth;
- public uint SheetSize;
- public uint BaseLinePos;
- public uint Format;
- public uint ColumnCount;
- public uint RowCount;
- public uint SheetWidth;
- public uint SheetHeight;
- public List SheetDataList = new List();
-
- public void Read(FileReader reader)
- {
- string Signature = reader.ReadString(4, Encoding.ASCII);
- if (Signature != "TGLP")
- throw new Exception($"Invalid signature {Signature}! Expected TGLP.");
- Size = reader.ReadUInt32();
- CellWidth = reader.ReadByte();
- CellHeight = reader.ReadByte();
- byte SheetCount = reader.ReadByte();
- MaxCharWidth = reader.ReadByte();
- SheetSize = reader.ReadUInt32();
- BaseLinePos = reader.ReadUInt16();
- Format = reader.ReadUInt16();
- ColumnCount = reader.ReadUInt16();
- RowCount = reader.ReadUInt16();
- SheetWidth = reader.ReadUInt16();
- SheetHeight = reader.ReadUInt16();
- uint sheetOffset = reader.ReadUInt32();
-
- using (reader.TemporarySeek(sheetOffset, SeekOrigin.Begin))
- {
- for (int i = 0; i < SheetCount; i++)
- {
- }
- SheetDataList.Add(reader.ReadBytes((int)SheetSize * SheetCount));
- }
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFLAN.cs b/Switch_FileFormatsMain/FileFormats/BFLAN.cs
deleted file mode 100644
index 7367cd51..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFLAN.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Switch_Toolbox;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-
-namespace FirstPlugin
-{
- public class BFLAN : IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "Cafe Layout Animation (GUI)" };
- public string[] Extension { get; set; } = new string[] { "*.bflan" };
- public string Magic { get; set; } = "FLAN";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public int Alignment { get; set; } = 0;
- public string FilePath { get; set; }
- public IFileInfo IFileInfo { get; set; }
-
- public Type[] Types
- {
- get
- {
- List types = new List();
- return types.ToArray();
- }
- }
-
- public void Load()
- {
- IsActive = true;
- }
- public void Unload()
- {
-
- }
- public byte[] Save()
- {
- return null;
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFLYT.cs b/Switch_FileFormatsMain/FileFormats/BFLYT.cs
deleted file mode 100644
index a7a3692d..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFLYT.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Switch_Toolbox;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-
-namespace FirstPlugin
-{
- public class BFLYT : IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "Cafe Layout (GUI)" };
- public string[] Extension { get; set; } = new string[] { "*.bflyt" };
- public string Magic { get; set; } = "FLYT";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public int Alignment { get; set; } = 0;
- public string FilePath { get; set; }
- public IFileInfo IFileInfo { get; set; }
-
- public Type[] Types
- {
- get
- {
- List types = new List();
- return types.ToArray();
- }
- }
-
- public void Load()
- {
- IsActive = true;
- }
- public void Unload()
- {
-
- }
- public byte[] Save()
- {
- return null;
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES.cs b/Switch_FileFormatsMain/FileFormats/BFRES.cs
deleted file mode 100644
index 3e56574b..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES.cs
+++ /dev/null
@@ -1,658 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.IO;
-using System.Threading.Tasks;
-using Switch_Toolbox;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using Switch_Toolbox.Library.Forms;
-using Switch_Toolbox.Library.IO;
-using Bfres.Structs;
-using ResU = Syroot.NintenTools.Bfres;
-using Syroot.NintenTools.NSW.Bfres;
-
-namespace FirstPlugin
-{
- public class BFRES : TreeNodeFile, IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "BFRES", "*BFRES", "*BFRES" };
- public string[] Extension { get; set; } = new string[] { "*.bfres", "*.sbfres" };
- public string Magic { get; set; } = "FRES";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public string FilePath { get; set; }
-
- public IFileInfo IFileInfo { get; set; }
-
- public Type[] Types
- {
- get
- {
- List types = new List();
- return types.ToArray();
- }
- }
-
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public int Alignment { get; set; } = 0;
- public bool IsWiiU
- {
- get
- {
- if (Data == null)
- return false;
-
- using (FileReader reader = new FileReader(new MemoryStream(Data)))
- {
- reader.Seek(4);
- if (reader.ReadInt32() != 0x20202020)
- {
- return true;
- }
- else
- return false;
- }
- }
- }
-
- public BFRESRender BFRESRender;
- public void Load()
- {
- IsActive = true;
- CanSave = true;
-
-
-
- ImageKey = "bfres";
- SelectedImageKey = "bfres";
-
- ContextMenu = new ContextMenu();
- MenuItem save = new MenuItem("Save");
- ContextMenu.MenuItems.Add(save);
- save.Click += Save;
-
- MenuItem newMenu = new MenuItem("New");
- MenuItem import = new MenuItem("Import");
- // ContextMenu.MenuItems.Add(newMenu);
- // ContextMenu.MenuItems.Add(import);
-
- MenuItem rename = new MenuItem("Rename");
- ContextMenu.MenuItems.Add(rename);
- rename.Click += Rename;
- MenuItem remove = new MenuItem("Remove");
- ContextMenu.MenuItems.Add(remove);
- remove.Click += Remove;
-
- if (Parent == null)
- remove.Enabled = false;
-
- if (IsWiiU)
- {
-
- }
- else
- {
- MenuItem model = new MenuItem("Model");
- MenuItem fska = new MenuItem("Skeletal Animation");
- MenuItem fmaa = new MenuItem("Material Animation");
- MenuItem bonevis = new MenuItem("Bone Visual Animation");
- MenuItem shape = new MenuItem("Shape Animation");
- MenuItem scene = new MenuItem("Scene Animation");
- MenuItem embedded = new MenuItem("Embedded File");
- MenuItem texture = new MenuItem("Texture File");
- texture.Click += NewTextureFile;
- newMenu.MenuItems.Add(model);
- newMenu.MenuItems.Add(fska);
- newMenu.MenuItems.Add(fmaa);
- newMenu.MenuItems.Add(bonevis);
- newMenu.MenuItems.Add(shape);
- newMenu.MenuItems.Add(scene);
- newMenu.MenuItems.Add(embedded);
- newMenu.MenuItems.Add(texture);
-
- MenuItem importmodel = new MenuItem("Model");
- MenuItem importfska = new MenuItem("Skeletal Animation");
- MenuItem importfmaa = new MenuItem("Material Animation");
- MenuItem importbonevis = new MenuItem("Bone Visual Animation");
- MenuItem importshape = new MenuItem("Shape Animation");
- MenuItem importscene = new MenuItem("Scene Animation");
- MenuItem importembedded = new MenuItem("Embedded File");
- MenuItem importtexture = new MenuItem("Texture File");
- import.MenuItems.Add(importmodel);
- import.MenuItems.Add(importfska);
- import.MenuItems.Add(importfmaa);
- import.MenuItems.Add(importbonevis);
- import.MenuItems.Add(importshape);
- import.MenuItems.Add(importscene);
- import.MenuItems.Add(importembedded);
- import.MenuItems.Add(importtexture);
- }
-
- BFRESRender = new BFRESRender();
- BFRESRender.ResFileNode = this;
-
- if (IsWiiU)
- {
- BFRESRender.LoadFile(new Syroot.NintenTools.Bfres.ResFile(new System.IO.MemoryStream(Data)));
- }
- else
- {
- BFRESRender.LoadFile(new Syroot.NintenTools.NSW.Bfres.ResFile(new System.IO.MemoryStream(Data)));
- }
-
- Runtime.abstractGlDrawables.Add(BFRESRender);
- }
- public void Unload()
- {
- BFRESRender.Destroy();
- BFRESRender.ResFileNode.Nodes.Clear();
- }
-
- public byte[] Save()
- {
- MemoryStream mem = new MemoryStream();
-
- if (IsWiiU)
- SaveWiiU(mem);
- else
- SaveSwitch(mem);
-
- return mem.ToArray();
- }
-
- public ResFile resFile = null;
- public ResU.ResFile resFileU = null;
-
- public TreeNode TextureFolder = new TreeNode("Textures");
-
- public override void OnClick(TreeView treeView)
- {
- if (Viewport.Instance.gL_ControlModern1 == null)
- return;
-
- //If has models
- if (Nodes.ContainsKey("FMDL"))
- {
- LibraryGUI.Instance.LoadViewport(Viewport.Instance);
- Viewport.Instance.gL_ControlModern1.MainDrawable = BFRESRender;
-
- BFRESRender.UpdateVertexData();
- }
- }
- public void Load(ResU.ResFile res)
- {
- resFileU = res;
-
- Text = resFileU.Name;
-
- if (resFileU.Models.Count > 0)
- Nodes.Add(new FmdlFolder());
- if (resFileU.Textures.Count > 0)
- AddFTEXTextures(resFileU);
- if (resFileU.SkeletalAnims.Count > 0)
- AddSkeletonAnims(resFileU);
- if (resFileU.ShaderParamAnims.Count > 0)
- Nodes.Add(new FshuFolder());
- if (resFileU.ColorAnims.Count > 0)
- Nodes.Add(new FshuColorFolder());
- if (resFileU.TexSrtAnims.Count > 0)
- Nodes.Add(new TexSrtFolder());
- if (resFileU.TexPatternAnims.Count > 0)
- Nodes.Add(new TexPatFolder());
- if (resFileU.ShapeAnims.Count > 0)
- Nodes.Add(new FshpaFolder());
- if (resFileU.BoneVisibilityAnims.Count > 0)
- Nodes.Add(new FbnvFolder());
- if (resFileU.SceneAnims.Count > 0)
- Nodes.Add(new FscnFolder());
- if (resFileU.ExternalFiles.Count > 0)
- Nodes.Add(new EmbeddedFilesFolder());
-
- foreach (var anim in resFileU.ShaderParamAnims)
- Nodes["FSHA"].Nodes.Add(anim.Key);
- foreach (var anim in resFileU.ColorAnims)
- Nodes["FSHAColor"].Nodes.Add(anim.Key);
- foreach (var anim in resFileU.TexSrtAnims)
- Nodes["TEXSRT"].Nodes.Add(anim.Key);
- foreach (var anim in resFileU.TexPatternAnims)
- Nodes["TEXPAT"].Nodes.Add(anim.Key);
-
- int ext = 0;
- foreach (var extfile in resFileU.ExternalFiles)
- {
- string Name = extfile.Key;
-
- FileReader f = new FileReader(extfile.Value.Data);
- string Magic = f.ReadMagic(0, 4);
- if (Magic == "FSHA")
- {
- Nodes["EXT"].Nodes.Add(new BfshaFileData(extfile.Value.Data, Name));
- }
- else
- Nodes["EXT"].Nodes.Add(new ExternalFileData(extfile.Value.Data, Name));
-
- f.Dispose();
- f.Close();
-
- ext++;
- }
- }
- public void Load(ResFile res)
- {
- resFile = res;
-
- Text = resFile.Name;
- UpdateTree(resFile);
-
- foreach (ShapeAnim anim in resFile.ShapeAnims)
- Nodes["FSHPA"].Nodes.Add(anim.Name);
- foreach (VisibilityAnim anim in resFile.BoneVisibilityAnims)
- Nodes["FBNV"].Nodes.Add(anim.Name);
-
- int ext = 0;
- foreach (ExternalFile extfile in resFile.ExternalFiles)
- {
- string Name = resFile.ExternalFileDict.GetKey(ext);
-
- FileReader f = new FileReader(extfile.Data);
- string Magic = f.ReadMagic(0, 4);
- if (Magic == "BNTX")
- {
- BNTX bntx = new BNTX();
- bntx.Data = extfile.Data;
- bntx.FileName = Name;
- bntx.Load();
- bntx.IFileInfo.InArchive = true;
- Nodes["EXT"].Nodes.Add(bntx);
- }
- else if (Magic == "FSHA")
- {
- Nodes["EXT"].Nodes.Add(new BfshaFileData(extfile.Data, Name));
- }
- else
- Nodes["EXT"].Nodes.Add(new ExternalFileData(extfile.Data, Name));
-
- f.Dispose();
- f.Close();
-
- ext++;
- }
- }
- private void NewTextureFile(object sender, EventArgs args)
- {
- string Name = "textures";
- for (int i = 0; i < resFile.ExternalFiles.Count; i++)
- {
- if (resFile.ExternalFileDict.GetKey(i) == Name)
- Name = Name + i;
- }
- if (!Nodes.ContainsKey("EXT"))
- {
- Nodes.Add(new EmbeddedFilesFolder());
- }
- BNTX bntx = new BNTX();
- bntx.Data = new byte[0];
- bntx.FileName = "textures";
- Nodes["EXT"].Nodes.Add(bntx);
- }
- private void NewEmbeddedFile(object sender, EventArgs args)
- {
- }
- private void Save(object sender, EventArgs args)
- {
- List formats = new List();
- formats.Add(this);
-
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = Utils.GetAllFilters(formats);
- sfd.FileName = FileName;
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- STFileSaver.SaveFileFormat(this, sfd.FileName, Alignment);
- }
- }
- private void Rename(object sender, EventArgs args)
- {
- RenameDialog dialog = new RenameDialog();
- dialog.SetString(Text);
-
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- Text = dialog.textBox1.Text;
- }
- }
- private void Remove(object sender, EventArgs args)
- {
- BFRESRender.DisposeFile();
- }
- private void UpdateTree(ResFile resFile)
- {
- if (resFile.Models.Count > 0)
- Nodes.Add(new FmdlFolder());
- if (resFile.SkeletalAnims.Count > 0)
- AddSkeletonAnims(resFile);
- if (resFile.MaterialAnims.Count > 0)
- AddMaterialAnims(resFile);
- if (resFile.ShapeAnims.Count > 0)
- AddShapeAnims(resFile);
- if (resFile.BoneVisibilityAnims.Count > 0)
- AddBoneVisAnims(resFile);
- if (resFile.SceneAnims.Count > 0)
- AddSceneAnims(resFile);
- if (resFile.ExternalFiles.Count > 0)
- Nodes.Add(new EmbeddedFilesFolder());
- }
- private void AddFTEXTextures(ResU.ResFile resFile)
- {
- FTEXContainer ftexContainer = new FTEXContainer();
- Nodes.Add(ftexContainer);
- foreach (ResU.Texture tex in resFile.Textures.Values)
- {
- string TextureName = tex.Name;
- FTEX texture = new FTEX();
- ftexContainer.Nodes.Add(texture);
- texture.Read(tex);
- ftexContainer.Textures.Add(texture.Text, texture);
- }
- PluginRuntime.ftexContainers.Add(ftexContainer);
- }
- private void AddSkeletonAnims(ResU.ResFile resFile)
- {
- FskaFolder fksaFolder = new FskaFolder();
- Nodes.Add(fksaFolder);
- foreach (ResU.SkeletalAnim ska in resFile.SkeletalAnims.Values)
- {
- FSKA skeletonAnim = new FSKA(ska.Name);
- skeletonAnim.Read(ska);
- fksaFolder.Nodes.Add(skeletonAnim);
- }
- }
- private void AddSkeletonAnims(ResFile resFile)
- {
- FskaFolder fksaFolder = new FskaFolder();
- Nodes.Add(fksaFolder);
- foreach (SkeletalAnim ska in resFile.SkeletalAnims)
- {
- FSKA skeletonAnim = new FSKA(ska.Name);
- skeletonAnim.Read(ska);
- fksaFolder.Nodes.Add(skeletonAnim);
- }
- }
- private void AddSceneAnims(ResU.ResFile resFile)
- {
- FscnFolder FSCN = new FscnFolder();
- Nodes.Add(FSCN);
- }
- private void AddSceneAnims(ResFile resFile)
- {
- FscnFolder fscnFolder = new FscnFolder();
- Nodes.Add(fscnFolder);
- foreach (var scn in resFile.SceneAnims)
- {
- FSCN sceneAnim = new FSCN();
- sceneAnim.Text = scn.Name;
- sceneAnim.Read(scn);
- fscnFolder.Nodes.Add(sceneAnim);
- }
- }
- private void AddMaterialAnims(ResFile resFile)
- {
- FmaaFolder fmaaFolder = new FmaaFolder();
- Nodes.Add(fmaaFolder);
- foreach (var fmaa in resFile.MaterialAnims)
- {
- FMAA materialAnim = new FMAA();
- materialAnim.Text = fmaa.Name;
- materialAnim.BFRESRender = BFRESRender;
- materialAnim.Read(fmaa);
- fmaaFolder.Nodes.Add(materialAnim);
- }
- }
- private void AddShapeAnims(ResFile resFile)
- {
- FshpaFolder fshaFolder = new FshpaFolder();
- Nodes.Add(fshaFolder);
- foreach (var fsha in resFile.ShapeAnims)
- {
- FSHA shapeAnim = new FSHA();
- shapeAnim.Text = fsha.Name;
- shapeAnim.Read(fsha);
- fshaFolder.Nodes.Add(shapeAnim);
- }
- }
- private void AddBoneVisAnims(ResFile resFile)
- {
- FbnvFolder fbnvFolder = new FbnvFolder();
- Nodes.Add(fbnvFolder);
- foreach (var fbnv in resFile.BoneVisibilityAnims)
- {
- FBNV boneVis = new FBNV();
- boneVis.Text = fbnv.Name;
- boneVis.Read(fbnv);
- fbnvFolder.Nodes.Add(boneVis);
- }
- }
- private void SaveSwitch(MemoryStream mem)
- {
- var resFile = BFRESRender.ResFileNode.resFile;
-
- resFile.Models.Clear();
- resFile.SkeletalAnims.Clear();
- resFile.MaterialAnims.Clear();
- resFile.SceneAnims.Clear();
- resFile.ShapeAnims.Clear();
- resFile.BoneVisibilityAnims.Clear();
- resFile.ModelDict.Clear();
- resFile.SkeletalAnimDict.Clear();
- resFile.MaterialAnimDict.Clear();
- resFile.SceneAnimDict.Clear();
- resFile.ShapeAnimDict.Clear();
- resFile.BoneVisibilityAnimDict.Clear();
-
-
- int CurMdl = 0;
- if (Nodes.ContainsKey("FMDL"))
- {
- foreach (FMDL model in Nodes["FMDL"].Nodes)
- resFile.Models.Add(BfresSwitch.SetModel(model));
- }
- if (Nodes.ContainsKey("FSKA"))
- {
- foreach (FSKA ska in Nodes["FSKA"].Nodes)
- resFile.SkeletalAnims.Add(ska.SkeletalAnim);
- }
- if (Nodes.ContainsKey("FMAA"))
- {
- foreach (FMAA fmaa in Nodes["FMAA"].Nodes)
- resFile.MaterialAnims.Add(fmaa.MaterialAnim);
- }
- if (Nodes.ContainsKey("FBNV"))
- {
- foreach (FBNV fbnv in Nodes["FBNV"].Nodes)
- resFile.BoneVisibilityAnims.Add(fbnv.VisibilityAnim);
- }
- if (Nodes.ContainsKey("FSHPA"))
- {
- foreach (FSHA fsha in Nodes["FSHPA"].Nodes)
- resFile.ShapeAnims.Add(fsha.ShapeAnim);
- }
- if (Nodes.ContainsKey("FSCN"))
- {
- foreach (FSCN fscn in Nodes["FSCN"].Nodes)
- resFile.SceneAnims.Add(fscn.SceneAnim);
- }
-
- ErrorCheck();
-
- BfresSwitch.WriteExternalFiles(resFile, this);
- resFile.Save(mem);
- }
- private void SaveWiiU(MemoryStream mem)
- {
- var resFileU = BFRESRender.ResFileNode.resFileU;
- resFileU.Models.Clear();
- resFileU.SkeletalAnims.Clear();
- // resFileU.SceneAnims.Clear();
- // resFileU.ShapeAnims.Clear();
- // resFileU.BoneVisibilityAnims.Clear();
- resFileU.Textures.Clear();
-
-
- int CurMdl = 0;
- if (Nodes.ContainsKey("FMDL"))
- {
- foreach (FMDL model in Nodes["FMDL"].Nodes)
- resFileU.Models.Add(model.Text, BfresWiiU.SetModel(model));
- }
- if (Nodes.ContainsKey("FTEX"))
- {
- foreach (FTEX tex in Nodes["FTEX"].Nodes)
- {
- tex.texture.Name = tex.Text;
- resFileU.Textures.Add(tex.Text, tex.texture);
- }
- }
- if (Nodes.ContainsKey("FSKA"))
- {
- foreach (FSKA ska in Nodes["FSKA"].Nodes)
- {
- ska.SkeletalAnimU.Name = ska.Text;
- resFileU.SkeletalAnims.Add(ska.Text, ska.SkeletalAnimU);
- }
- }
-
- else
- throw new Exception("Failed to find textures");
-
- ErrorCheck();
- resFileU.Save(mem);
- }
-
- public static void SetShaderAssignAttributes(FMAT.ShaderAssign shd, FSHP shape)
- {
- foreach (var att in shape.vertexAttributes)
- {
- if (!shd.attributes.ContainsValue(att.Name) && !shd.attributes.ContainsKey(att.Name))
- shd.attributes.Add(att.Name, att.Name);
- }
- foreach (var tex in shape.GetMaterial().TextureMaps)
- {
- if (!shd.samplers.ContainsValue(((MatTexture)tex).SamplerName))
- shd.samplers.Add(((MatTexture)tex).SamplerName, ((MatTexture)tex).SamplerName);
- }
- }
-
-
- private void SetDuplicateShapeName(FSHP shape)
- {
- DialogResult dialogResult = MessageBox.Show($"A shape {shape.Text} already exists with that name", "", MessageBoxButtons.OK);
-
- if (dialogResult == DialogResult.OK)
- {
- RenameDialog renameDialog = new RenameDialog();
- renameDialog.Text = "Rename Texture";
- if (renameDialog.ShowDialog() == DialogResult.OK)
- {
- shape.Text = renameDialog.textBox1.Text;
- }
- }
- }
-
- public static void CheckMissingTextures(FSHP shape)
- {
- bool ImportMissingTextures = false;
- foreach (BNTX bntx in PluginRuntime.bntxContainers)
- {
- foreach (MatTexture tex in shape.GetMaterial().TextureMaps)
- {
- if (!bntx.Textures.ContainsKey(tex.Name))
- {
- if (!ImportMissingTextures)
- {
- DialogResult result = MessageBox.Show("Missing textures found! Would you like to use placeholders?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
-
- if (result == DialogResult.Yes)
- {
- ImportMissingTextures = true;
- }
- else
- {
- return;
- }
- }
-
- if (ImportMissingTextures)
- bntx.ImportPlaceholderTexture(tex.Name);
- }
- }
- }
- }
-
- public void ErrorCheck()
- {
- if (BFRESRender != null)
- {
- List Errors = new List();
- foreach (FMDL model in BFRESRender.models)
- {
- foreach (FSHP shp in model.shapes)
- {
- if (!IsWiiU)
- {
- Syroot.NintenTools.NSW.Bfres.VertexBuffer vtx = shp.VertexBuffer;
- Syroot.NintenTools.NSW.Bfres.Material mat = shp.GetMaterial().Material;
- Syroot.NintenTools.NSW.Bfres.ShaderAssign shdr = mat.ShaderAssign;
-
- for (int att = 0; att < vtx.Attributes.Count; att++)
- {
- if (!shdr.AttribAssigns.Contains(vtx.Attributes[att].Name))
- MessageBox.Show($"Error! Attribute {vtx.Attributes[att].Name} is unlinked!");
- }
- for (int att = 0; att < mat.TextureRefs.Count; att++)
- {
- if (!shdr.SamplerAssigns.Contains(mat.SamplerDict.GetKey(att))) //mat.SamplerDict[att]
- MessageBox.Show($"Error! Sampler {mat.SamplerDict.GetKey(att)} is unlinked!");
- }
- }
- else
- {
- Syroot.NintenTools.Bfres.VertexBuffer vtx = shp.VertexBufferU;
- Syroot.NintenTools.Bfres.Material mat = shp.GetMaterial().MaterialU;
- Syroot.NintenTools.Bfres.ShaderAssign shdr = mat.ShaderAssign;
-
- for (int att = 0; att < vtx.Attributes.Count; att++)
- {
- if (!shdr.AttribAssigns.ContainsKey(vtx.Attributes[att].Name))
- MessageBox.Show($"Error! Attribute {vtx.Attributes[att].Name} is unlinked!");
- }
- for (int att = 0; att < mat.TextureRefs.Count; att++)
- {
- string samp = "";
- mat.Samplers.TryGetKey(mat.Samplers[att], out samp);
- if (!shdr.SamplerAssigns.ContainsKey(samp)) //mat.SamplerDict[att]
- MessageBox.Show($"Error! Sampler {samp} is unlinked!");
- }
- }
- }
- }
- // ErrorList errorList = new ErrorList();
- // errorList.LoadList(Errors);
- // errorList.Show();
- }
- }
- public class Errors
- {
- public string Section = "None";
- public string Section2 = "None";
- public string Message = "";
- public string Type = "Unkown";
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/BFSHA.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/BFSHA.cs
deleted file mode 100644
index 077ce526..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/BFSHA.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using System;
-using System.Windows.Forms;
-
-namespace Bfres.Structs
-{
- public class BfshaFileData : TreeNode
- {
- public byte[] Data;
- public BfshaFileData(byte[] data, string Name)
- {
- Text = Name;
- ImageKey = "bfsha";
- SelectedImageKey = "bfsha";
- Data = data;
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Import;
- }
-
-
- private void Import(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "All files(*.*)|*.*";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- Data = System.IO.File.ReadAllBytes(ofd.FileName);
- }
- }
-
- private void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "All files(*.*)|*.*";
- sfd.DefaultExt = System.IO.Path.GetExtension(Text);
- sfd.FileName = Text;
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- System.IO.File.WriteAllBytes(sfd.FileName, Data);
-
- }
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/ExternalFiles.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/ExternalFiles.cs
deleted file mode 100644
index 7c457dcb..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/ExternalFiles.cs
+++ /dev/null
@@ -1,102 +0,0 @@
-using System;
-using Switch_Toolbox.Library;
-using System.Windows.Forms;
-using FirstPlugin;
-
-namespace Bfres.Structs
-{
- public class EmbeddedFilesFolder : TreeNodeCustom
- {
- public EmbeddedFilesFolder()
- {
- Text = "Embedded Files";
- Name = "EXT";
-
- ContextMenu = new ContextMenu();
- MenuItem import = new MenuItem("Import");
- ContextMenu.MenuItems.Add(import);
- import.Click += Import;
- MenuItem exportAll = new MenuItem("Export All");
- ContextMenu.MenuItems.Add(exportAll);
- exportAll.Click += ExportAll;
- MenuItem clear = new MenuItem("Clear");
- ContextMenu.MenuItems.Add(clear);
- clear.Click += Clear;
- }
- public void Import(object sender, EventArgs args)
- {
-
- }
- public void ExportAll(object sender, EventArgs args)
- {
-
- }
- private void Clear(object sender, EventArgs args)
- {
- DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove all external files? This cannot be undone!", "", MessageBoxButtons.YesNo);
-
- if (dialogResult == DialogResult.Yes)
- {
- foreach (var ext in Nodes)
- {
- if (ext is BNTX)
- {
- PluginRuntime.bntxContainers.Remove((BNTX)ext);
- }
- }
-
- Nodes.Clear();
- Viewport.Instance.Refresh();
- }
- }
- public override void OnClick(TreeView treeView)
- {
- FormLoader.LoadEditor(this, Text);
- }
- }
- public class ExternalFileData : TreeNode
- {
- public byte[] Data;
- public ExternalFileData(byte[] data, string Name)
- {
- Text = Name;
- ImageKey = "folder";
- Data = data;
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Import;
- }
-
-
- private void Import(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "All files(*.*)|*.*";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- Data = System.IO.File.ReadAllBytes(ofd.FileName);
- }
- }
-
- private void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "All files(*.*)|*.*";
-
- sfd.DefaultExt = System.IO.Path.GetExtension(Text);
- sfd.FileName = Text;
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- System.IO.File.WriteAllBytes(sfd.FileName, Data);
-
- }
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FBNV.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FBNV.cs
deleted file mode 100644
index e4307588..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FBNV.cs
+++ /dev/null
@@ -1,109 +0,0 @@
-using System;
-using Switch_Toolbox.Library;
-using System.Windows.Forms;
-using FirstPlugin;
-using Syroot.NintenTools.NSW.Bfres;
-
-namespace Bfres.Structs
-{
- public class FbnvFolder : TreeNodeCustom
- {
- public FbnvFolder()
- {
- Text = "Bone Visabilty Animations";
- Name = "FBNV";
-
- ContextMenu = new ContextMenu();
- MenuItem import = new MenuItem("Import");
- ContextMenu.MenuItems.Add(import);
- import.Click += Import;
- MenuItem exportAll = new MenuItem("Export All");
- ContextMenu.MenuItems.Add(exportAll);
- exportAll.Click += ExportAll;
- MenuItem clear = new MenuItem("Clear");
- ContextMenu.MenuItems.Add(clear);
- clear.Click += Clear;
- }
- public void Import(object sender, EventArgs args)
- {
-
- }
- public void ExportAll(object sender, EventArgs args)
- {
- FolderSelectDialog sfd = new FolderSelectDialog();
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string folderPath = sfd.SelectedPath;
- foreach (FBNV fbnv in Nodes)
- {
- string FileName = folderPath + '\\' + fbnv.Text + ".bfska";
- ((FBNV)fbnv).VisibilityAnim.Export(FileName, fbnv.GetResFile());
- }
- }
- }
- public void Clear(object sender, EventArgs args)
- {
- DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove all visibility animations? This cannot be undone!", "", MessageBoxButtons.YesNo);
-
- if (dialogResult == DialogResult.Yes)
- {
- Nodes.Clear();
- }
- }
-
- public override void OnClick(TreeView treeView)
- {
- FormLoader.LoadEditor(this, Text);
- }
- }
- public class FBNV : TreeNodeCustom
- {
- public VisibilityAnim VisibilityAnim;
- public FBNV()
- {
- ImageKey = "visibilityAnim";
- SelectedImageKey = "visibilityAnim";
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- }
-
- public ResFile GetResFile()
- {
- return ((BFRES)Parent.Parent).resFile;
- }
-
- private void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Supported Formats|*.bfvis;";
- sfd.FileName = Text;
- sfd.DefaultExt = ".bfvis";
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- VisibilityAnim.Export(sfd.FileName, GetResFile());
- }
- }
- private void Replace(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Supported Formats|*.bfvis;";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- VisibilityAnim.Import(ofd.FileName);
- }
- VisibilityAnim.Name = Text;
- }
- public void Read(VisibilityAnim vis)
- {
- VisibilityAnim = vis;
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAA.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAA.cs
deleted file mode 100644
index 17bd0a3c..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAA.cs
+++ /dev/null
@@ -1,108 +0,0 @@
-using System;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using FirstPlugin;
-using Syroot.NintenTools.NSW.Bfres;
-
-namespace Bfres.Structs
-{
- public class FmaaFolder : TreeNodeCustom
- {
- public FmaaFolder()
- {
- Text = "Material Animations";
- Name = "FMAA";
-
- ContextMenu = new ContextMenu();
- MenuItem import = new MenuItem("Import");
- ContextMenu.MenuItems.Add(import);
- import.Click += Import;
- MenuItem exportAll = new MenuItem("Export All");
- ContextMenu.MenuItems.Add(exportAll);
- exportAll.Click += ExportAll;
- MenuItem clear = new MenuItem("Clear");
- ContextMenu.MenuItems.Add(clear);
- clear.Click += Clear;
- }
- public void Import(object sender, EventArgs args)
- {
-
- }
- public void ExportAll(object sender, EventArgs args)
- {
- FolderSelectDialog sfd = new FolderSelectDialog();
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string folderPath = sfd.SelectedPath;
- foreach (FMAA fmaa in Nodes)
- {
- string FileName = folderPath + '\\' + fmaa.Text + ".bfmaa";
- ((FMAA)fmaa).MaterialAnim.Export(FileName, fmaa.GetResFile());
- }
- }
- }
- private void Clear(object sender, EventArgs args)
- {
- DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove all material animations? This cannot be undone!", "", MessageBoxButtons.YesNo);
- if (dialogResult == DialogResult.Yes)
- {
- Nodes.Clear();
- }
- }
- public override void OnClick(TreeView treeView)
- {
- FormLoader.LoadEditor(this, Text);
- }
- }
-
- public class FMAA : TreeNodeCustom
- {
- public BFRESRender BFRESRender;
- public MaterialAnim MaterialAnim;
- public FMAA()
- {
- ImageKey = "materialAnim";
- SelectedImageKey = "materialAnim";
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- }
-
- public ResFile GetResFile()
- {
- return ((BFRES)Parent.Parent).resFile;
- }
- public void Read(MaterialAnim anim)
- {
- MaterialAnim = anim;
- }
- private void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Supported Formats|*.bfmaa;";
- sfd.FileName = Text;
- sfd.DefaultExt = ".bfska";
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- MaterialAnim.Export(sfd.FileName, GetResFile());
- }
- }
- private void Replace(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Supported Formats|*.bfmaa;";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- MaterialAnim.Import(ofd.FileName);
- }
- MaterialAnim.Name = Text;
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAT.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAT.cs
deleted file mode 100644
index 31f9ee69..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAT.cs
+++ /dev/null
@@ -1,442 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Syroot.NintenTools.NSW.Bfres;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using Switch_Toolbox.Library.IO;
-using Switch_Toolbox.Library.Rendering;
-using Switch_Toolbox.Library.Forms;
-using ResU = Syroot.NintenTools.Bfres;
-using FirstPlugin;
-using OpenTK;
-
-
-namespace Bfres.Structs
-{
- public class FMATFolder : TreeNodeCustom
- {
- public FMATFolder()
- {
- Text = "Materials";
- Name = "FmatFolder";
-
- ContextMenu = new ContextMenu();
- MenuItem import = new MenuItem("Add Material");
- ContextMenu.MenuItems.Add(import);
- import.Click += Import;
- }
- public void Import(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Bfres Material |*.bfmat;";
- ofd.Multiselect = true;
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- foreach (string file in ofd.FileNames)
- ((FMDL)Parent).AddMaterials(file, false);
- }
- }
- public override void OnClick(TreeView treeView)
- {
-
- }
- }
- public class FMAT : STGenericMaterial
- {
- public FMAT()
- {
- Checked = true;
- ImageKey = "material";
- SelectedImageKey = "material";
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- MenuItem copy = new MenuItem("Copy");
- ContextMenu.MenuItems.Add(copy);
- copy.Click += Copy;
- MenuItem rename = new MenuItem("Rename");
- ContextMenu.MenuItems.Add(rename);
- rename.Click += Rename;
- }
-
- public bool Enabled = true;
-
- public override void OnClick(TreeView treeView)
- {
- UpdateFMATEditor();
- }
- public void UpdateFMATEditor()
- {
- FMATEditor docked = (FMATEditor)LibraryGUI.Instance.GetContentDocked(new FMATEditor());
- if (docked == null)
- {
- docked = new FMATEditor();
- LibraryGUI.Instance.LoadDockContent(docked, PluginRuntime.FSHPDockState);
- }
- docked.Text = Text;
- docked.Dock = DockStyle.Fill;
- docked.LoadMaterial(this);
- }
- public ResFile GetResFile()
- {
- //ResourceFile -> FMDL -> Material Folder -> this
- return ((FMDL)Parent.Parent).GetResFile();
- }
- public ResU.ResFile GetResFileU()
- {
- return ((FMDL)Parent.Parent).GetResFileU();
- }
-
- public void UpdateTextureMaps()
- {
- ((BFRES)Parent.Parent.Parent.Parent).BFRESRender.UpdateSingleMaterialTextureMaps(this);
- }
-
- public void SetActiveGame()
- {
- Runtime.activeGame = Runtime.ActiveGame.SMO;
- return;
-
- string ShaderName = shaderassign.ShaderArchive;
- string ShaderModel = shaderassign.ShaderModel;
-
- if (ShaderName == "alRenderMaterial" || ShaderName == "alRenderCloudLayer" || ShaderName == "alRenderSky")
- Runtime.activeGame = Runtime.ActiveGame.SMO;
- else if (ShaderName == "Turbo_UBER")
- Runtime.activeGame = Runtime.ActiveGame.MK8D;
- else if (ShaderName.Contains("uking_mat"))
- Runtime.activeGame = Runtime.ActiveGame.BOTW;
- else if (ShaderName.Contains("Blitz_UBER"))
- Runtime.activeGame = Runtime.ActiveGame.Splatoon2;
- else
- Runtime.activeGame = Runtime.ActiveGame.KSA;
- }
- private void Rename(object sender, EventArgs args)
- {
- RenameDialog dialog = new RenameDialog();
- dialog.SetString(Text);
-
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- ((FMDL)Parent.Parent).materials.Remove(Text);
- Text = dialog.textBox1.Text;
- ((FMDL)Parent.Parent).materials.Add(Text, this);
- }
- }
- private void Copy(object sender, EventArgs args)
- {
- ((FMDL)Parent.Parent).CopyMaterial(this);
- }
- private void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Supported Formats|*.bfmat;";
-
- sfd.DefaultExt = ".bfmat";
- sfd.FileName = Text;
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- if (GetResFileU() != null)
- MaterialU.Export(sfd.FileName, GetResFileU());
- else
- Material.Export(sfd.FileName, GetResFile());
- }
- }
- private void Replace(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Supported Formats|*.bfmat;";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- if (GetResFileU() != null)
- {
- MaterialU.Import(ofd.FileName, GetResFileU());
- MaterialU.Name = Text;
- BfresWiiU.ReadMaterial(this, MaterialU);
- }
- else
- {
- Material.Import(ofd.FileName);
- Material.Name = Text;
- BfresSwitch.ReadMaterial(this, Material);
- }
- }
- }
-
- public Dictionary anims = new Dictionary();
- public Dictionary Samplers = new Dictionary();
- public List renderinfo = new List();
- public List samplerinfo = new List();
- public Dictionary matparam = new Dictionary();
-
- public Material Material;
- public ResU.Material MaterialU;
-
- public ShaderAssign shaderassign = new ShaderAssign();
-
- public class ShaderAssign
- {
- public string ShaderModel = "";
- public string ShaderArchive = "";
-
-
- public Dictionary options = new Dictionary();
- public Dictionary samplers = new Dictionary();
- public Dictionary attributes = new Dictionary();
- }
- public class SamplerInfo
- {
- public int WrapModeU;
- public int WrapModeV;
- public int WrapModeW;
- }
- public bool HasDiffuseMap = false;
- public bool HasNormalMap = false;
- public bool HasSpecularMap = false;
- public bool HasEmissionMap = false;
- public bool HasDiffuseLayer = false;
- public bool HasTeamColorMap = false; //Splatoon uses this (TLC)
- public bool HasTransparencyMap = false;
- public bool HasShadowMap = false;
- public bool HasAmbientOcclusionMap = false;
- public bool HasLightMap = false;
- public bool HasSphereMap = false;
- public bool HasSubSurfaceScatteringMap = false;
-
- //PBR (Switch) data
- public bool HasMetalnessMap = false;
- public bool HasRoughnessMap = false;
- public bool HasMRA = false;
- }
- public class BfresShaderParam
- {
- public ShaderParamType Type;
- public string Name;
-
- public float[] ValueFloat;
- public bool[] ValueBool;
- public uint[] ValueUint;
- public int[] ValueInt;
- public byte[] ValueReserved;
-
- public Srt2D ValueSrt2D;
- public Srt3D ValueSrt3D;
- public TexSrt ValueTexSrt;
- public TexSrtEx ValueTexSrtEx;
-
- //If a data set is not defined then defaults in this to save back properly
- //Note this may be rarely needed or not at all
- public byte[] Value_Unk;
-
-
- private void ReadSRT2D(FileReader reader)
- {
- ValueSrt2D = new Srt2D();
- ValueSrt2D.Scaling = reader.ReadVec2SY();
- ValueSrt2D.Rotation = reader.ReadSingle();
- ValueSrt2D.Translation = reader.ReadVec2SY();
- }
- private void ReadSRT3D(FileReader reader)
- {
- ValueSrt3D = new Srt3D();
- ValueSrt3D.Scaling = reader.ReadVec3SY();
- ValueSrt3D.Rotation = reader.ReadVec3SY();
- ValueSrt3D.Translation = reader.ReadVec3SY();
- }
- private void ReadTexSrt(FileReader reader)
- {
- ValueTexSrt = new TexSrt();
- ValueTexSrt.Mode = reader.ReadEnum(false);
- ValueTexSrt.Scaling = reader.ReadVec2SY();
- ValueTexSrt.Rotation = reader.ReadSingle();
- ValueTexSrt.Translation = reader.ReadVec2SY();
- }
- private void ReadTexSrtEx(FileReader reader)
- {
- ValueTexSrtEx = new TexSrtEx();
- ValueTexSrtEx.Mode = reader.ReadEnum(true);
- ValueTexSrtEx.Scaling = reader.ReadVec2SY();
- ValueTexSrtEx.Rotation = reader.ReadSingle();
- ValueTexSrtEx.Translation = reader.ReadVec2SY();
- ValueTexSrtEx.MatrixPointer = reader.ReadUInt32();
- }
- public ShaderParamType GetTypeWiiU(ResU.ShaderParamType type)
- {
- return (ShaderParamType)System.Enum.Parse(typeof(ShaderParamType), type.ToString());
- }
- public ResU.ShaderParamType SetTypeWiiU(ShaderParamType type)
- {
- return (ResU.ShaderParamType)System.Enum.Parse(typeof(ResU.ShaderParamType), type.ToString());
- }
-
- public void ReadValue(FileReader reader, int Size)
- {
- switch (Type)
- {
- case ShaderParamType.Bool:
- case ShaderParamType.Bool2:
- case ShaderParamType.Bool3:
- case ShaderParamType.Bool4:
- ValueBool = reader.ReadBooleans(Size / sizeof(bool)); break;
- case ShaderParamType.Float:
- case ShaderParamType.Float2:
- case ShaderParamType.Float3:
- case ShaderParamType.Float4:
- case ShaderParamType.Float2x2:
- case ShaderParamType.Float2x3:
- case ShaderParamType.Float2x4:
- case ShaderParamType.Float4x2:
- case ShaderParamType.Float4x3:
- case ShaderParamType.Float4x4:
- ValueFloat = reader.ReadSingles(Size / sizeof(float)); break;
- case ShaderParamType.Int:
- case ShaderParamType.Int2:
- case ShaderParamType.Int3:
- case ShaderParamType.Int4:
- ValueInt = reader.ReadInt32s(Size / sizeof(int)); break;
- case ShaderParamType.Reserved2:
- case ShaderParamType.Reserved3:
- case ShaderParamType.Reserved4:
- ValueReserved = reader.ReadBytes(Size / sizeof(byte)); break;
- case ShaderParamType.Srt2D:
- ReadSRT2D(reader); break;
- case ShaderParamType.Srt3D:
- ReadSRT3D(reader); break;
- case ShaderParamType.TexSrt:
- ReadTexSrt(reader); break;
- case ShaderParamType.TexSrtEx:
- ReadTexSrtEx(reader); break;
- case ShaderParamType.UInt:
- case ShaderParamType.UInt2:
- case ShaderParamType.UInt3:
- case ShaderParamType.UInt4:
- ValueUint = reader.ReadUInt32s(Size / sizeof(uint)); break;
- // Invalid
- default:
- throw new ArgumentException($"Invalid {nameof(ShaderParamType)} {Type}.",
- nameof(Type));
- }
- }
- public void WriteValue(FileWriter writer)
- {
- switch (Type)
- {
- case ShaderParamType.Bool:
- case ShaderParamType.Bool2:
- case ShaderParamType.Bool3:
- case ShaderParamType.Bool4:
- writer.Write(ValueBool); break;
- case ShaderParamType.Float:
- case ShaderParamType.Float2:
- case ShaderParamType.Float3:
- case ShaderParamType.Float4:
- case ShaderParamType.Float2x2:
- case ShaderParamType.Float2x3:
- case ShaderParamType.Float2x4:
- case ShaderParamType.Float4x2:
- case ShaderParamType.Float4x3:
- case ShaderParamType.Float4x4:
- writer.Write(ValueFloat); break;
- case ShaderParamType.Int:
- case ShaderParamType.Int2:
- case ShaderParamType.Int3:
- case ShaderParamType.Int4:
- writer.Write(ValueInt); break;
- case ShaderParamType.Reserved2:
- case ShaderParamType.Reserved3:
- case ShaderParamType.Reserved4:
- writer.Write(ValueInt); break;
- case ShaderParamType.Srt2D:
- WriteSRT2D(writer); break;
- case ShaderParamType.Srt3D:
- WriteSRT3D(writer); break;
- case ShaderParamType.TexSrt:
- WriteTexSrt(writer); break;
- case ShaderParamType.TexSrtEx:
- WriteTexSrtEx(writer); break;
- case ShaderParamType.UInt:
- case ShaderParamType.UInt2:
- case ShaderParamType.UInt3:
- case ShaderParamType.UInt4:
- writer.Write(ValueUint); break;
- // Invalid
- default:
- throw new ArgumentException($"Invalid {nameof(ShaderParamType)} {Type}.",
- nameof(Type));
- }
- }
- private void WriteSRT2D(FileWriter writer)
- {
- writer.Write(ValueSrt2D.Scaling);
- writer.Write(ValueSrt2D.Rotation);
- writer.Write(ValueSrt2D.Translation);
- }
- private void WriteSRT3D(FileWriter writer)
- {
- writer.Write(ValueSrt3D.Scaling);
- writer.Write(ValueSrt3D.Rotation);
- writer.Write(ValueSrt3D.Translation);
- }
- private void WriteTexSrt(FileWriter writer)
- {
- writer.Write((uint)ValueTexSrt.Mode);
- writer.Write(ValueTexSrt.Scaling);
- writer.Write(ValueTexSrt.Rotation);
- writer.Write(ValueTexSrt.Translation);
- }
- private void WriteTexSrtEx(FileWriter writer)
- {
- writer.Write((uint)ValueTexSrtEx.Mode);
- writer.Write(ValueTexSrtEx.Scaling);
- writer.Write(ValueTexSrtEx.Rotation);
- writer.Write(ValueTexSrtEx.Translation);
- writer.Write(ValueTexSrtEx.MatrixPointer);
-
- }
- }
- public class BfresRenderInfo
- {
- public string Name;
- public long DataOffset;
- public RenderInfoType Type;
- public int ArrayLength;
-
- //Data Section by "Type"
-
- public int[] ValueInt;
- public string[] ValueString;
- public float[] ValueFloat;
-
- public RenderInfoType GetTypeWiiU(ResU.RenderInfoType type)
- {
- return (RenderInfoType)System.Enum.Parse(typeof(RenderInfoType), type.ToString());
- }
- public ResU.RenderInfoType SetTypeWiiU(RenderInfoType type)
- {
- return (ResU.RenderInfoType)System.Enum.Parse(typeof(ResU.RenderInfoType), type.ToString());
- }
-
- }
- public class MatTexture : STGenericMatTexture
- {
- public int hash;
- public string SamplerName;
- //Note samplers will get converted to another sampler type sometimes in the shader assign section
- //Use this string if not empty for our bfres fragment shader to produce the accurate affects
- //An example of a conversion maybe be like a1 - t0 so texture gets used as a transparent map/alpha texture
- public string FragShaderSampler = "";
-
- public MatTexture()
- {
-
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMDL.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMDL.cs
deleted file mode 100644
index c25436a5..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMDL.cs
+++ /dev/null
@@ -1,745 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Syroot.NintenTools.NSW.Bfres;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using Switch_Toolbox.Library.Rendering;
-using Switch_Toolbox.Library.Forms;
-using ResU = Syroot.NintenTools.Bfres;
-using ResUGX2 = Syroot.NintenTools.Bfres.GX2;
-using ResGFX = Syroot.NintenTools.NSW.Bfres.GFX;
-using FirstPlugin;
-
-namespace Bfres.Structs
-{
- public class FmdlFolder : TreeNodeCustom
- {
- public FmdlFolder()
- {
- Text = "Models";
- Name = "FMDL";
-
- ContextMenu = new ContextMenu();
- MenuItem import = new MenuItem("Import");
- ContextMenu.MenuItems.Add(import);
- import.Click += Import;
- MenuItem exportAll = new MenuItem("Export All");
- ContextMenu.MenuItems.Add(exportAll);
- exportAll.Click += ExportAll;
- MenuItem clear = new MenuItem("Clear");
- ContextMenu.MenuItems.Add(clear);
- clear.Click += Clear;
- }
- public void Import(object sender, EventArgs args)
- {
-
- }
- public void ExportAll(object sender, EventArgs args)
- {
-
- }
- private void Clear(object sender, EventArgs args)
- {
- DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove all objects? This cannot be undone!", "", MessageBoxButtons.YesNo);
-
- if (dialogResult == DialogResult.Yes)
- {
- Nodes.Clear();
- ((BFRES)Parent).BFRESRender.models.Clear();
- ((BFRES)Parent).BFRESRender.UpdateVertexData();
- }
- }
- public override void OnClick(TreeView treeView)
- {
- FormLoader.LoadEditor(this, Text);
- }
- }
-
- public class FMDL : STGenericModel
- {
- public List shapes = new List();
- public Dictionary materials = new Dictionary();
- public Model Model;
- public ResU.Model ModelU;
-
- public ResFile GetResFile()
- {
- //ResourceFile -> FMDL -> Material Folder -> this
- return ((BFRES)Parent.Parent).resFile;
- }
- public ResU.ResFile GetResFileU()
- {
- return ((BFRES)Parent.Parent).resFileU;
- }
- public void UpdateVertexData()
- {
- ((BFRES)Parent.Parent).BFRESRender.UpdateVertexData();
- }
- public List GetModelList()
- {
- return ((BFRES)Parent.Parent).BFRESRender.models;
- }
-
- public bool IsWiiU
- {
- get
- {
- return GetResFileU() != null;
- }
- }
-
-
- public FMDL()
- {
- ImageKey = "model";
- SelectedImageKey = "model";
-
- Nodes.Add(new FSHPFolder());
- Nodes.Add(new FMATFolder());
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export Model");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace Model");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- MenuItem rename = new MenuItem("Rename");
- ContextMenu.MenuItems.Add(rename);
- rename.Click += Rename;
- MenuItem calcTansBitans = new MenuItem("Calculate Tangents/Bitangents");
- ContextMenu.MenuItems.Add(calcTansBitans);
- calcTansBitans.Click += CalcTansBitansAllShapes;
- MenuItem normals = new MenuItem("Normals");
- ContextMenu.MenuItems.Add(normals);
- MenuItem smoothNormals = new MenuItem("Smooth");
- normals.MenuItems.Add(smoothNormals);
- smoothNormals.Click += SmoothNormals;
- MenuItem recalculateNormals = new MenuItem("Recalculate");
- normals.MenuItems.Add(recalculateNormals);
- recalculateNormals.Click += RecalculateNormals;
- }
- private void SmoothNormals(object sender, EventArgs args)
- {
- Cursor.Current = Cursors.WaitCursor;
- foreach (FSHP shp in shapes)
- {
- bool HasNormals = shp.vertexAttributes.Any(x => x.Name == "_n0");
- if (HasNormals)
- shp.SmoothNormals();
-
- shp.SaveVertexBuffer(IsWiiU);
- }
- UpdateVertexData();
- Cursor.Current = Cursors.Default;
- }
- private void RecalculateNormals(object sender, EventArgs args)
- {
- Cursor.Current = Cursors.WaitCursor;
- foreach (FSHP shp in shapes)
- {
- bool HasNormals = shp.vertexAttributes.Any(x => x.Name == "_n0");
- if (HasNormals)
- shp.CalculateNormals();
-
- shp.SaveVertexBuffer(IsWiiU);
- }
- UpdateVertexData();
- Cursor.Current = Cursors.Default;
- }
- private void Rename(object sender, EventArgs args)
- {
- RenameDialog dialog = new RenameDialog();
- dialog.SetString(Text);
-
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- Text = dialog.textBox1.Text;
- }
- }
- private void CalcTansBitansAllShapes(object sender, EventArgs args)
- {
- Cursor.Current = Cursors.WaitCursor;
- foreach (FSHP shp in shapes)
- {
- bool HasTans = shp.vertexAttributes.Any(x => x.Name == "_t0");
- bool HasBiTans = shp.vertexAttributes.Any(x => x.Name == "_b0");
-
- if (!shp.HasUV0())
- {
- MessageBox.Show($"Error! {Text} does not have UVs!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
-
- if (!HasBiTans)
- {
- DialogResult dialogResult2 = MessageBox.Show("Mesh does not have bitangents. Do you want to create them? (will make file size bigger)", "", MessageBoxButtons.YesNo);
-
- FSHP.VertexAttribute att2 = new FSHP.VertexAttribute();
- att2.Name = "_b0";
- att2.Format = ResGFX.AttribFormat.Format_10_10_10_2_SNorm;
-
- if (dialogResult2 == DialogResult.Yes)
- {
- if (!HasBiTans)
- shp.vertexAttributes.Add(att2);
- }
- }
-
- if (!HasTans)
- {
- DialogResult dialogResult = MessageBox.Show("Mesh does not have tangets. Do you want to create them? (will make file size bigger)", "", MessageBoxButtons.YesNo);
-
- FSHP.VertexAttribute att = new FSHP.VertexAttribute();
- att.Name = "_t0";
- att.Format = ResGFX.AttribFormat.Format_10_10_10_2_SNorm;
-
-
- if (dialogResult == DialogResult.Yes)
- {
- if (!HasTans)
- shp.vertexAttributes.Add(att);
- }
- }
-
- shp.CalculateTangentBitangent();
- shp.SaveVertexBuffer(IsWiiU);
- }
-
- UpdateVertexData();
- Cursor.Current = Cursors.Default;
- }
- public void CopyMaterial(FMAT selectedMaterial)
- {
- CopyMaterialMenu menu = new CopyMaterialMenu();
- menu.LoadMaterials(selectedMaterial.Text, GetModelList());
- if (menu.ShowDialog() == DialogResult.OK)
- {
- foreach (TreeNode mdl in menu.materialTreeView.Nodes)
- {
- foreach (TreeNode n in mdl.Nodes)
- {
- if (n.Checked)
- {
- if (materials.ContainsKey(n.Text))
- SetCopiedMaterialData(menu, selectedMaterial, materials[n.Text]);
- }
- }
- }
- Viewport.Instance.UpdateViewport();
- }
- }
- private void SetCopiedMaterialData(CopyMaterialMenu menu,
- FMAT selectedMaterial, FMAT targetMaterial)
- {
- targetMaterial.Material.Flags = selectedMaterial.Material.Flags;
- targetMaterial.Material.UserDatas = selectedMaterial.Material.UserDatas;
- targetMaterial.Material.UserDataDict = selectedMaterial.Material.UserDataDict;
-
- if (menu.chkBoxRenderInfo.Checked)
- {
- targetMaterial.Material.RenderInfoDict = selectedMaterial.Material.RenderInfoDict;
- targetMaterial.Material.RenderInfos = selectedMaterial.Material.RenderInfos;
- }
- if (menu.chkBoxShaderOptions.Checked)
- {
- targetMaterial.Material.ShaderAssign = selectedMaterial.Material.ShaderAssign;
- }
- if (menu.chkBoxShaderParams.Checked)
- {
- targetMaterial.Material.ShaderParamData = selectedMaterial.Material.ShaderParamData;
- targetMaterial.Material.ShaderParamDict = selectedMaterial.Material.ShaderParamDict;
- targetMaterial.Material.ShaderParams = selectedMaterial.Material.ShaderParams;
- targetMaterial.Material.VolatileFlags = selectedMaterial.Material.VolatileFlags;
- }
- if (menu.chkBoxTextures.Checked)
- {
- targetMaterial.Material.SamplerDict = selectedMaterial.Material.SamplerDict;
- targetMaterial.Material.Samplers = selectedMaterial.Material.Samplers;
- targetMaterial.Material.SamplerSlotArray = selectedMaterial.Material.SamplerSlotArray;
- targetMaterial.Material.TextureSlotArray = selectedMaterial.Material.TextureSlotArray;
- targetMaterial.Material.TextureRefs = selectedMaterial.Material.TextureRefs;
- }
- targetMaterial.ReadMaterial(targetMaterial.Material);
- }
- public void ExportAll()
- {
- FolderSelectDialog sfd = new FolderSelectDialog();
-
- List Formats = new List();
- Formats.Add("Bfres object (.bfobj)");
- Formats.Add("CSV (.csv)");
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string folderPath = sfd.SelectedPath;
-
- TextureFormatExport form = new TextureFormatExport(Formats);
- if (form.ShowDialog() == DialogResult.OK)
- {
- foreach (FSHP shp in shapes)
- {
- if (form.Index == 0)
- shp.ExportBinaryObject(folderPath + '\\' + shp.Text + ".bfobj");
- }
- }
- }
- }
- public void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Supported Formats|*.bfmdl;*.fbx;*.dae; *.obj;*.csv;|" +
- "Bfres Model|*.bfmdl|" +
- "FBX |*.fbx|" +
- "DAE |*.dae|" +
- "OBJ |*.obj|" +
- "CSV |*.csv|" +
- "All files(*.*)|*.*";
- sfd.DefaultExt = ".bfobj";
- sfd.FileName = Text;
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string ext = System.IO.Path.GetExtension(sfd.FileName);
- ext = ext.ToLower();
-
- switch (ext)
- {
- case ".bfmdl":
- if (GetResFileU() != null)
- {
-
- }
- else
- Model.Export(sfd.FileName, GetResFile());
- break;
- case ".csv":
- CsvModel csv = new CsvModel();
- foreach (FSHP shape in shapes)
- {
- STGenericObject obj = new STGenericObject();
- obj.ObjectName = shape.Text;
- obj.vertices = shape.vertices;
- obj.faces = shape.lodMeshes[shape.DisplayLODIndex].faces;
- csv.objects.Add(obj);
-
- int CurVtx = 0;
- foreach (Vertex v in shape.vertices)
- {
- if (v.boneIds[0] != 0)
- obj.vertices[CurVtx].boneNames.Add(shape.GetBoneNameFromIndex(this, v.boneIds[0]));
- if (v.boneIds[1] != 0)
- obj.vertices[CurVtx].boneNames.Add(shape.GetBoneNameFromIndex(this, v.boneIds[1]));
- if (v.boneIds[2] != 0)
- obj.vertices[CurVtx].boneNames.Add(shape.GetBoneNameFromIndex(this, v.boneIds[2]));
- if (v.boneIds[3] != 0)
- obj.vertices[CurVtx].boneNames.Add(shape.GetBoneNameFromIndex(this, v.boneIds[3]));
-
- CurVtx++;
- }
- }
- System.IO.File.WriteAllBytes(sfd.FileName, csv.Save());
- break;
- default:
- List Surfaces = new List();
- foreach (FSHP fshp in shapes)
- {
- foreach (var bntx in PluginRuntime.bntxContainers)
- {
- foreach (var tex in fshp.GetMaterial().TextureMaps)
- {
- if (bntx.Textures.ContainsKey(tex.Name))
- {
- Surfaces.Add(bntx.Textures[tex.Name]);
- }
- }
- }
- foreach (var ftex in PluginRuntime.ftexContainers)
- {
- foreach (var tex in fshp.GetMaterial().TextureMaps)
- {
- if (ftex.Textures.ContainsKey(tex.Name))
- {
- Surfaces.Add(ftex.Textures[tex.Name]);
- }
- }
- }
- }
- Console.WriteLine("tex count " + Surfaces.Count);
-
- AssimpData assimp = new AssimpData();
- assimp.SaveFromModel(this, sfd.FileName, Surfaces);
- break;
- }
- }
- }
-
- public void Replace(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Supported Formats|*.bfobj;*.fbx;*.dae;*.obj;*.csv;|" +
- "Bfres Object (shape/vertices) |*.bfobj|" +
- "FBX |*.fbx|" +
- "DAE |*.dae|" +
- "OBJ |*.obj|" +
- "CSV |*.csv|" +
- "All files(*.*)|*.*";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- AddOjects(ofd.FileName);
- }
-
- }
- //Function addes shapes, vertices and meshes
- public void AddOjects(string FileName, bool Replace = true)
- {
- bool IsWiiU = (GetResFileU() != null);
-
- int MatStartIndex = materials.Count;
- string ext = System.IO.Path.GetExtension(FileName);
- ext = ext.ToLower();
-
- switch (ext)
- {
- case ".bfobj":
- Cursor.Current = Cursors.WaitCursor;
-
- if (Replace)
- {
- shapes.Clear();
- Nodes["FshpFolder"].Nodes.Clear();
- }
-
- Shape shpS = new Shape();
- VertexBuffer vertexBuffer = new VertexBuffer();
- shpS.Import(FileName, vertexBuffer);
-
- FSHP shapeS = new FSHP();
- shapeS.Shape = shpS;
- BfresSwitch.ReadShapesVertices(shapeS, shpS, vertexBuffer, this);
- shapes.Add(shapeS);
- Nodes["FshpFolder"].Nodes.Add(shapeS);
- Cursor.Current = Cursors.Default;
- break;
- case ".bfmdl":
- Cursor.Current = Cursors.WaitCursor;
-
- if (Replace)
- {
- shapes.Clear();
- Nodes["FshpFolder"].Nodes.Clear();
- }
-
- Model mdl = new Model();
- mdl.Import(FileName, GetResFile());
- mdl.Name = Text;
- shapes.Clear();
- foreach (Shape shp in mdl.Shapes)
- {
- FSHP shape = new FSHP();
- shape.Shape = shp;
- BfresSwitch.ReadShapesVertices(shape, shp, mdl.VertexBuffers[shp.VertexBufferIndex], this);
- shapes.Add(shape);
- Nodes["FshpFolder"].Nodes.Add(shape);
- }
- Cursor.Current = Cursors.Default;
- break;
- case ".csv":
- CsvModel csvModel = new CsvModel();
- csvModel.LoadFile(FileName, true);
-
- if (csvModel.objects.Count == 0)
- {
- MessageBox.Show("No models found!");
- return;
- }
- BfresModelImportSettings csvsettings = new BfresModelImportSettings();
- csvsettings.DisableMaterialEdits();
- csvsettings.SetModelAttributes(csvModel.objects[0]);
- if (csvsettings.ShowDialog() == DialogResult.OK)
- {
- if (Replace)
- {
- shapes.Clear();
- Nodes["FshpFolder"].Nodes.Clear();
- }
-
- Cursor.Current = Cursors.WaitCursor;
-
- foreach (STGenericObject obj in csvModel.objects)
- {
- FSHP shape = new FSHP();
- shape.VertexBufferIndex = shapes.Count;
- shape.vertices = obj.vertices;
- shape.MaterialIndex = 0;
- shape.vertexAttributes = csvsettings.CreateNewAttributes();
- shape.boneIndx = 0;
- shape.Text = obj.ObjectName;
- shape.lodMeshes = obj.lodMeshes;
- shape.CreateNewBoundingBoxes();
- shape.CreateBoneList(obj, this);
- shape.CreateIndexList(obj, this);
- shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount();
- shape.ApplyImportSettings(csvsettings, GetMaterial(shape.MaterialIndex));
- shape.SaveShape(IsWiiU);
- shape.SaveVertexBuffer(IsWiiU);
- shape.BoneIndices = new List();
-
- Nodes["FshpFolder"].Nodes.Add(shape);
- shapes.Add(shape);
- }
- Cursor.Current = Cursors.Default;
- }
- break;
- default:
- AssimpData assimp = new AssimpData();
- assimp.LoadFile(FileName);
-
- if (assimp.objects.Count == 0)
- {
- MessageBox.Show("No models found!");
- return;
- }
- BfresModelImportSettings settings = new BfresModelImportSettings();
- settings.SetModelAttributes(assimp.objects[0]);
- if (settings.ShowDialog() == DialogResult.OK)
- {
- if (Replace)
- {
- shapes.Clear();
- Nodes["FshpFolder"].Nodes.Clear();
- }
-
- Cursor.Current = Cursors.WaitCursor;
- if (Replace)
- {
- materials.Clear();
- Nodes["FmatFolder"].Nodes.Clear();
- MatStartIndex = 0;
- }
- foreach (STGenericMaterial mat in assimp.materials)
- {
- FMAT fmat = new FMAT();
- if (settings.ExternalMaterialPath != string.Empty)
- {
- if (GetResFileU() != null)
- {
- fmat.MaterialU = new ResU.Material();
- fmat.MaterialU.Import(settings.ExternalMaterialPath, GetResFileU());
- BfresWiiU.ReadMaterial(fmat, fmat.MaterialU);
- }
- else
- {
- fmat.Material = new Material();
- fmat.Material.Import(settings.ExternalMaterialPath);
- fmat.ReadMaterial(fmat.Material);
- }
- }
-
- fmat.Text = mat.Text;
- //Setup placeholder textures
- //Note we can't add/remove samplers so we must fill these slots
- foreach (var t in fmat.TextureMaps)
- {
- t.wrapModeS = 0;
- t.wrapModeT = 0;
-
- switch (t.Type)
- {
- case STGenericMatTexture.TextureType.Diffuse:
- t.Name = "Basic_Alb";
- break;
- case STGenericMatTexture.TextureType.Emission:
- t.Name = "Basic_Emm";
- break;
- case STGenericMatTexture.TextureType.Normal:
- t.Name = "Basic_Nrm";
- break;
- case STGenericMatTexture.TextureType.Specular:
- t.Name = "Basic_Spm";
- break;
- case STGenericMatTexture.TextureType.SphereMap:
- t.Name = "Basic_Sphere";
- break;
- case STGenericMatTexture.TextureType.Metalness:
- t.Name = "Basic_Mtl";
- break;
- case STGenericMatTexture.TextureType.Roughness:
- t.Name = "Basic_Rgh";
- break;
- case STGenericMatTexture.TextureType.MRA:
- t.Name = "Basic_MRA";
- break;
- case STGenericMatTexture.TextureType.Shadow:
- t.Name = "Basic_Bake_st0";
- break;
- case STGenericMatTexture.TextureType.Light:
- t.Name = "Basic_Bake_st1";
- break;
- }
- }
-
- if (PluginRuntime.bntxContainers.Count > 0)
- {
- foreach (var node in Parent.Parent.Nodes["EXT"].Nodes)
- {
- if (node is BNTX)
- {
- var bntx = (BNTX)node;
-
- bntx.ImportBasicTextures("Basic_Alb");
- bntx.ImportBasicTextures("Basic_Nrm");
- bntx.ImportBasicTextures("Basic_Spm");
- bntx.ImportBasicTextures("Basic_Sphere");
- bntx.ImportBasicTextures("Basic_Mtl");
- bntx.ImportBasicTextures("Basic_Rgh");
- bntx.ImportBasicTextures("Basic_MRA");
- bntx.ImportBasicTextures("Basic_Bake_st0");
- bntx.ImportBasicTextures("Basic_Bake_st1");
- bntx.ImportBasicTextures("Basic_Emm");
- }
- }
- }
-
- foreach (var tex in mat.TextureMaps)
- {
- foreach (var t in fmat.TextureMaps)
- {
- if (t.Type == tex.Type)
- {
- t.Name = tex.Name;
- t.wrapModeS = tex.wrapModeS;
- t.wrapModeT = tex.wrapModeT;
- t.wrapModeW = tex.wrapModeW;
- t.Type = tex.Type;
- }
- }
- }
-
- List keyList = new List(materials.Keys);
- fmat.Text = Utils.RenameDuplicateString(keyList, fmat.Text);
-
- materials.Add(fmat.Text, fmat);
- Nodes["FmatFolder"].Nodes.Add(fmat);
-
- if (GetResFileU() != null)
- {
- fmat.MaterialU.Name = Text;
- fmat.SetMaterial(fmat.MaterialU);
- }
- else
- {
- fmat.Material.Name = Text;
- fmat.SetMaterial(fmat.Material);
- }
- }
-
-
- foreach (STGenericObject obj in assimp.objects)
- {
- FSHP shape = new FSHP();
- shape.VertexBufferIndex = shapes.Count;
- shape.vertices = obj.vertices;
- shape.VertexSkinCount = obj.MaxSkinInfluenceCount;
- shape.vertexAttributes = settings.CreateNewAttributes();
- shape.boneIndx = obj.BoneIndex;
- shape.MaterialIndex = obj.MaterialIndex + MatStartIndex;
-
- shape.Text = obj.ObjectName;
- shape.lodMeshes = obj.lodMeshes;
- shape.CreateNewBoundingBoxes();
- shape.CreateBoneList(obj, this);
- shape.CreateIndexList(obj, this);
- shape.ApplyImportSettings(settings, GetMaterial(shape.MaterialIndex));
- shape.SaveShape(IsWiiU);
- shape.SaveVertexBuffer(IsWiiU);
- shape.BoneIndices = new List();
-
- List keyList = shapes.Select(o => o.Text).ToList();
-
- shape.Text = Utils.RenameDuplicateString(keyList, shape.Text);
-
- Nodes["FshpFolder"].Nodes.Add(shape);
- shapes.Add(shape);
- }
- Console.WriteLine("Finshed Importing Model");
-
- Cursor.Current = Cursors.Default;
- }
- break;
- }
- UpdateVertexData();
- }
- public FMAT GetMaterial(int index)
- {
- return materials.Values.ElementAt(index);
- }
- public void AddMaterials(string FileName, bool Replace = true)
- {
- string ext = System.IO.Path.GetExtension(FileName);
- ext = ext.ToLower();
-
- switch (ext)
- {
- case ".bfmat":
- Cursor.Current = Cursors.WaitCursor;
- if (Replace)
- {
- materials.Clear();
- Nodes["FmatFolder"].Nodes.Clear();
- }
- FMAT mat = new FMAT();
- mat.Material = new Material();
- mat.Material.Import(FileName);
- mat.ReadMaterial(mat.Material);
- mat.Text = mat.Material.Name;
-
- materials.Add(mat.Text, mat);
- Nodes["FmatFolder"].Nodes.Add(mat);
- break;
- }
- }
- public override void OnClick(TreeView treeView)
- {
-
- }
- private void CreateSkeleton()
- {
-
- }
- private void CreateBones(STBone bone)
- {
- Bone bn = new Bone();
- bn.BillboardIndex = (ushort)bone.BillboardIndex;
- bn.Flags = BoneFlags.Visible;
- bn.FlagsRotation = BoneFlagsRotation.EulerXYZ;
- bn.FlagsTransform = BoneFlagsTransform.None;
- bn.FlagsTransformCumulative = BoneFlagsTransformCumulative.None;
- bn.Name = bone.Text;
- bn.RigidMatrixIndex = 0;
- bn.Rotation = new Syroot.Maths.Vector4F(bone.rotation[0],
- bone.rotation[1], bone.rotation[2], bone.rotation[3]);
- bn.Position = new Syroot.Maths.Vector3F(bone.position[0],
- bone.position[1], bone.position[2]);
- bn.Scale = new Syroot.Maths.Vector3F(bone.scale[0],
- bone.scale[1], bone.scale[2]);
- bn.UserData = new List();
- bn.UserDataDict = new ResDict();
- }
-
- public FSKL Skeleton
- {
- get
- {
- return skeleton;
- }
- set
- {
- skeleton = value;
- }
- }
- private FSKL skeleton = new FSKL();
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSCN.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSCN.cs
deleted file mode 100644
index 9ff32a4c..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSCN.cs
+++ /dev/null
@@ -1,109 +0,0 @@
-using System;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using FirstPlugin;
-using Syroot.NintenTools.NSW.Bfres;
-
-namespace Bfres.Structs
-{
- public class FscnFolder : TreeNodeCustom
- {
- public FscnFolder()
- {
- Text = "Scene Animations";
- Name = "FSCN";
-
- ContextMenu = new ContextMenu();
- MenuItem import = new MenuItem("Import");
- ContextMenu.MenuItems.Add(import);
- import.Click += Import;
- MenuItem exportAll = new MenuItem("Export All");
- ContextMenu.MenuItems.Add(exportAll);
- exportAll.Click += ExportAll;
- MenuItem clear = new MenuItem("Clear");
- ContextMenu.MenuItems.Add(clear);
- clear.Click += Clear;
- }
- private void Import(object sender, EventArgs args)
- {
-
- }
- private void ExportAll(object sender, EventArgs args)
- {
- FolderSelectDialog sfd = new FolderSelectDialog();
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string folderPath = sfd.SelectedPath;
- foreach (FSCN fscn in Nodes)
- {
- string FileName = folderPath + '\\' + fscn.Text + ".bfscn";
- ((FSCN)fscn).SceneAnim.Export(FileName, fscn.GetResFile());
- }
- }
- }
- private void Clear(object sender, EventArgs args)
- {
- DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove all scene animations? This cannot be undone!", "", MessageBoxButtons.YesNo);
- if (dialogResult == DialogResult.Yes)
- {
- Nodes.Clear();
- }
- }
-
- public override void OnClick(TreeView treeView)
- {
- FormLoader.LoadEditor(this, Text);
- }
- }
-
- public class FSCN : TreeNodeCustom
- {
- public SceneAnim SceneAnim;
- public FSCN()
- {
- ImageKey = "sceneAnimation";
- SelectedImageKey = "sceneAnimation";
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- }
-
- public ResFile GetResFile()
- {
- return ((BFRES)Parent.Parent).resFile;
- }
-
- private void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Supported Formats|*.bfscn;";
- sfd.FileName = Text;
- sfd.DefaultExt = ".bfska";
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- SceneAnim.Export(sfd.FileName, GetResFile());
- }
- }
- private void Replace(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Supported Formats|*.bfscn;";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- SceneAnim.Import(ofd.FileName);
- }
- SceneAnim.Name = Text;
- }
- public void Read(SceneAnim scn)
- {
- SceneAnim = scn;
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHA.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHA.cs
deleted file mode 100644
index 54dff038..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHA.cs
+++ /dev/null
@@ -1,108 +0,0 @@
-using System;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using FirstPlugin;
-using Syroot.NintenTools.NSW.Bfres;
-
-namespace Bfres.Structs
-{
- public class FshpaFolder : TreeNodeCustom
- {
- public FshpaFolder()
- {
- Text = "Shape Animations";
- Name = "FSHPA";
-
- ContextMenu = new ContextMenu();
- MenuItem import = new MenuItem("Import");
- ContextMenu.MenuItems.Add(import);
- import.Click += Import;
- MenuItem exportAll = new MenuItem("Export All");
- ContextMenu.MenuItems.Add(exportAll);
- exportAll.Click += ExportAll;
- MenuItem clear = new MenuItem("Clear");
- ContextMenu.MenuItems.Add(clear);
- clear.Click += Clear;
- }
- private void Import(object sender, EventArgs args)
- {
-
- }
- public void ExportAll(object sender, EventArgs args)
- {
- FolderSelectDialog sfd = new FolderSelectDialog();
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string folderPath = sfd.SelectedPath;
- foreach (FSHA fsha in Nodes)
- {
- string FileName = folderPath + '\\' + fsha.Text + ".bfshpa";
- ((FSHA)fsha).ShapeAnim.Export(FileName, fsha.GetResFile());
- }
- }
- }
- private void Clear(object sender, EventArgs args)
- {
- DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove all shape animations? This cannot be undone!", "", MessageBoxButtons.YesNo);
-
- if (dialogResult == DialogResult.Yes)
- {
- Nodes.Clear();
- }
- }
- public override void OnClick(TreeView treeView)
- {
- FormLoader.LoadEditor(this, Text);
- }
- }
- public class FSHA : TreeNodeCustom
- {
- public ShapeAnim ShapeAnim;
- public FSHA()
- {
- ImageKey = "shapeAnimation";
- SelectedImageKey = "shapeAnimation";
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- }
-
- public ResFile GetResFile()
- {
- return ((BFRES)Parent.Parent).resFile;
- }
-
- private void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Supported Formats|*.bfshpa;";
- sfd.FileName = Text;
- sfd.DefaultExt = ".bfshpa";
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- ShapeAnim.Export(sfd.FileName, GetResFile());
- }
- }
- private void Replace(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Supported Formats|*.bfshpa;";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- ShapeAnim.Import(ofd.FileName);
- }
- ShapeAnim.Name = Text;
- }
- public void Read(ShapeAnim shapeAnim)
- {
- ShapeAnim = shapeAnim;
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHP.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHP.cs
deleted file mode 100644
index 404fc510..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHP.cs
+++ /dev/null
@@ -1,946 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Syroot.NintenTools.NSW.Bfres;
-using Syroot.NintenTools.NSW.Bfres.Helpers;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using Switch_Toolbox.Library.Rendering;
-using Switch_Toolbox.Library.Forms;
-using ResU = Syroot.NintenTools.Bfres;
-using ResUGX2 = Syroot.NintenTools.Bfres.GX2;
-using ResGFX = Syroot.NintenTools.NSW.Bfres.GFX;
-using FirstPlugin;
-using OpenTK;
-
-namespace Bfres.Structs
-{
- public class FSHPFolder : TreeNodeCustom
- {
- public FSHPFolder()
- {
- Text = "Objects";
- Name = "FshpFolder";
-
- ContextMenu = new ContextMenu();
- MenuItem import = new MenuItem("Add Object");
- ContextMenu.MenuItems.Add(import);
- import.Click += Import;
- MenuItem exportAll = new MenuItem("Export All Objects");
- ContextMenu.MenuItems.Add(exportAll);
- exportAll.Click += ExportAll;
- MenuItem clear = new MenuItem("Clear All Objects");
- ContextMenu.MenuItems.Add(clear);
- clear.Click += Clear;
- }
- private void Clear(object sender, EventArgs args)
- {
- DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove all objects? This cannot be undone!", "", MessageBoxButtons.YesNo);
-
- if (dialogResult == DialogResult.Yes)
- {
- Nodes.Clear();
- ((FMDL)Parent).shapes.Clear();
- ((FMDL)Parent).UpdateVertexData();
- }
- }
- private void ExportAll(object sender, EventArgs args)
- {
- ((FMDL)Parent).ExportAll();
- }
- private void Import(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Supported Formats|*.bfobj;*.fbx;*.dae; *.obj;*.csv;|" +
- "Bfres Object (shape/vertices) |*.bfobj|" +
- "FBX |*.fbx|" +
- "DAE |*.dae|" +
- "OBJ |*.obj|" +
- "CSV |*.csv|" +
- "All files(*.*)|*.*";
- ofd.Multiselect = true;
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- foreach (string file in ofd.FileNames)
- ((FMDL)Parent).AddOjects(file, false);
- }
- }
-
-
- public override void OnClick(TreeView treeView)
- {
-
- }
- }
- public struct DisplayVertex
- {
- // Used for rendering.
- public Vector3 pos;
- public Vector3 nrm;
- public Vector3 tan;
- public Vector3 bit;
- public Vector2 uv;
- public Vector4 col;
- public Vector4 node;
- public Vector4 weight;
- public Vector2 uv2;
- public Vector2 uv3;
- public Vector3 pos1;
- public Vector3 pos2;
-
- public static int Size = 4 * (3 + 3 + 3 + 3 + 2 + 4 + 4 + 4 + 2 + 2 + 3 + 3);
- }
- public class FSHP : STGenericObject
- {
- public bool IsWiiU
- {
- get
- {
- return GetResFileU() != null;
- }
- }
-
- public FSHP()
- {
- Checked = true;
- ImageKey = "mesh";
- SelectedImageKey = "mesh";
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export Mesh");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace Mesh");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- MenuItem remove = new MenuItem("Delete Mesh");
- ContextMenu.MenuItems.Add(remove);
- remove.Click += Remove;
- MenuItem calcTansBitans = new MenuItem("Recalulate Tangents/Bitangents");
- ContextMenu.MenuItems.Add(calcTansBitans);
- calcTansBitans.Click += CalcTansBitans;
- MenuItem flipUVsY = new MenuItem("Flip UVs (Vertical)");
- ContextMenu.MenuItems.Add(flipUVsY);
- flipUVsY.Click += FlipUvsVertical;
- MenuItem flipUVsX = new MenuItem("Flip UVs (Horizontal)");
- ContextMenu.MenuItems.Add(flipUVsX);
- flipUVsX.Click += FlipUvsHorizontal;
- MenuItem normals = new MenuItem("Normals");
- ContextMenu.MenuItems.Add(normals);
- MenuItem smoothNormals = new MenuItem("Smooth");
- normals.MenuItems.Add(smoothNormals);
- smoothNormals.Click += SmoothNormals;
- MenuItem recalculateNormals = new MenuItem("Recalculate");
- normals.MenuItems.Add(recalculateNormals);
- recalculateNormals.Click += RecalculateNormals;
-
- MenuItem matEditor = new MenuItem("Open Material Editor");
- ContextMenu.MenuItems.Add(matEditor);
- matEditor.Click += OpenMaterialEditor;
-
- MenuItem rename = new MenuItem("Rename");
- ContextMenu.MenuItems.Add(rename);
- rename.Click += Rename;
- }
- public int ModelIndex; //For getting the model the shape is in
-
- public VertexBuffer VertexBuffer;
- public Shape Shape;
- public ResU.VertexBuffer VertexBufferU;
- public ResU.Shape ShapeU;
-
- public ResFile GetResFile()
- {
- //ResourceFile -> FMDL -> Material Folder -> this
- return ((FMDL)Parent.Parent).GetResFile();
- }
- public ResU.ResFile GetResFileU()
- {
- return ((FMDL)Parent.Parent).GetResFileU();
- }
- public void UpdateVertexData()
- {
- ((FMDL)Parent.Parent).UpdateVertexData();
- }
- public List GetModelList()
- {
- return ((FMDL)Parent.Parent).GetModelList();
- }
-
- public FMAT GetMaterial()
- {
- return ((FMDL)Parent.Parent).materials.Values.ElementAt(MaterialIndex);
- }
- public void SetMaterial(FMAT material)
- {
- ((FMDL)Parent.Parent).materials[material.Text] = material;
- }
-
- public override void OnClick(TreeView treeView)
- {
- UpdateFSHPEditor();
- }
- public void UpdateFSHPEditor()
- {
- FSHPEditor docked = (FSHPEditor)LibraryGUI.Instance.GetContentDocked(new FSHPEditor());
- if (docked == null)
- {
- docked = new FSHPEditor();
- LibraryGUI.Instance.LoadDockContent(docked, PluginRuntime.FSHPDockState);
- }
- docked.Text = Text;
- docked.Dock = DockStyle.Fill;
- docked.LoadObject((FMDL)Parent.Parent, this);
- }
- private void SmoothNormals(object sender, EventArgs args)
- {
- Cursor.Current = Cursors.WaitCursor;
- SmoothNormals();
- SaveVertexBuffer(IsWiiU);
- UpdateVertexData();
- Cursor.Current = Cursors.Default;
- }
- private void RecalculateNormals(object sender, EventArgs args)
- {
- Cursor.Current = Cursors.WaitCursor;
- CalculateNormals();
- SaveVertexBuffer(IsWiiU);
- UpdateVertexData();
- Cursor.Current = Cursors.Default;
- }
- private void Rename(object sender, EventArgs args)
- {
- RenameDialog dialog = new RenameDialog();
- dialog.SetString(Text);
-
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- Text = dialog.textBox1.Text;
- }
- }
- private void Remove(object sender, EventArgs args)
- {
- DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove this object? This cannot be undone!", "", MessageBoxButtons.YesNo);
-
- if (dialogResult == DialogResult.Yes)
- {
- ((FMDL)Parent.Parent).shapes.Remove(this);
- ((FMDL)Parent.Parent).UpdateVertexData();
- Parent.Nodes.Remove(this);
- }
- }
- public void ApplyImportSettings(BfresModelImportSettings settings, FMAT mat)
- {
- if (settings.FlipUVsVertical)
- {
- foreach (Vertex v in vertices)
- {
- v.uv0 = new Vector2(v.uv0.X, 1 - v.uv0.Y);
- }
- }
- if (settings.RecalculateNormals)
- {
- CalculateNormals();
- }
- if (settings.Rotate90DegreesY)
- {
- TransformPosition(Vector3.Zero, new Vector3(90, 0, 0), new Vector3(1));
- }
- if (settings.Rotate90DegreesNegativeY)
- {
- TransformPosition(Vector3.Zero, new Vector3(-90, 0, 0), new Vector3(1));
- }
- if (settings.EnableTangents)
- {
- try
- {
- CalculateTangentBitangent();
- }
- catch
- {
- MessageBox.Show($"Failed to generate tangents for mesh {Text}");
- }
- }
- if (settings.SetDefaultParamData)
- {
- foreach (var param in mat.matparam.Values)
- {
- switch (param.Name)
- {
- case "const_color0":
- case "const_color1":
- case "const_color2":
- case "const_color3":
- case "base_color_mul_color":
- case "uniform0_mul_color":
- case "uniform1_mul_color":
- case "uniform2_mul_color":
- case "uniform3_mul_color":
- case "uniform4_mul_color":
- case "proc_texture_2d_mul_color":
- case "proc_texture_3d_mul_color":
- case "displacement1_color":
- case "ripple_emission_color":
- case "hack_color":
- case "stain_color":
- case "displacement_color":
- param.ValueFloat = new float[] { 1, 1, 1, 1 };
- break;
- case "gsys_bake_st0":
- case "gsys_bake_st1":
- param.ValueFloat = new float[] { 1, 1, 0, 0 };
- break;
- }
- }
- }
- }
- public void TransformPosition(Vector3 Position, Vector3 Rotation, Vector3 Scale)
- {
- Matrix4 BonePosExtra = Utils.TransformValues(Position, Rotation, Scale);
- foreach (Vertex v in vertices)
- {
- v.pos = Vector3.TransformPosition(v.pos, BonePosExtra);
- v.nrm = Vector3.TransformNormal(v.pos, BonePosExtra);
- }
- }
- private void OpenMaterialEditor(object sender, EventArgs args)
- {
- GetMaterial().UpdateFMATEditor();
- }
- private void CalcTansBitans(object sender, EventArgs args)
- {
- Cursor.Current = Cursors.WaitCursor;
-
- bool HasTans = vertexAttributes.Any(x => x.Name == "_t0");
- bool HasBiTans = vertexAttributes.Any(x => x.Name == "_b0");
-
- if (!HasUV0())
- {
- MessageBox.Show($"Error! {Text} does not have UVs!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
-
- if (!HasBiTans)
- {
- DialogResult dialogResult2 = MessageBox.Show("Mesh does not have bitangents. Do you want to create them? (will make file size bigger)", "", MessageBoxButtons.YesNo);
-
- VertexAttribute att2 = new VertexAttribute();
- att2.Name = "_b0";
- att2.Format = ResGFX.AttribFormat.Format_10_10_10_2_SNorm;
-
- if (dialogResult2 == DialogResult.Yes)
- {
- if (!HasBiTans)
- vertexAttributes.Add(att2);
- }
- }
-
- if (!HasTans)
- {
- DialogResult dialogResult = MessageBox.Show("Mesh does not have tangets. Do you want to create them? (will make file size bigger)", "", MessageBoxButtons.YesNo);
-
- VertexAttribute att = new VertexAttribute();
- att.Name = "_t0";
- att.Format = ResGFX.AttribFormat.Format_10_10_10_2_SNorm;
-
-
- if (dialogResult == DialogResult.Yes)
- {
- if (!HasTans)
- vertexAttributes.Add(att);
- }
- }
-
- CalculateTangentBitangent();
- SaveVertexBuffer(IsWiiU);
- UpdateVertexData();
- Cursor.Current = Cursors.Default;
- }
- public bool HasUV0()
- {
- return vertexAttributes.Any(x => x.Name == "_u0");
- }
- public bool HasUV1()
- {
- return vertexAttributes.Any(x => x.Name == "_u1");
- }
- public bool HasUV2()
- {
- return vertexAttributes.Any(x => x.Name == "_u2");
- }
- public void FlipUvsVertical(object sender, EventArgs args)
- {
- if (!HasUV0())
- {
- MessageBox.Show($"Error! {Text} does not have UVs!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
-
- FlipUvsVertical();
- SaveVertexBuffer(IsWiiU);
- UpdateVertexData();
- }
- public void FlipUvsHorizontal(object sender, EventArgs args)
- {
- if (!HasUV0())
- {
- MessageBox.Show($"Error! {Text} does not have UVs!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
-
- FlipUvsHorizontal();
- SaveVertexBuffer(IsWiiU);
- UpdateVertexData();
- }
- public void ExportMaterials(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Materials|*.bfmat;";
- sfd.DefaultExt = ".bfmat";
- sfd.FileName = GetMaterial().Text;
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- GetMaterial().Material.Export(sfd.FileName, GetResFile());
- }
- }
- public void ReplaceMaterials(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Materials|*.bfmat;";
- ofd.DefaultExt = ".bfmat";
- ofd.FileName = GetMaterial().Text;
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- GetMaterial().Material.Import(ofd.FileName);
- }
- }
- public void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Supported Formats|*.bfobj;*.fbx;*.dae; *.obj;|" +
- "Bfres Object (shape/vertices) |*.bfobj|" +
- "FBX |*.fbx|" +
- "DAE |*.dae|" +
- "OBJ |*.obj|" +
- "All files(*.*)|*.*";
- sfd.DefaultExt = ".bfobj";
- sfd.FileName = Text;
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string ext = System.IO.Path.GetExtension(sfd.FileName);
- ext = ext.ToLower();
-
- switch (ext)
- {
- case ".bfobj":
- ExportBinaryObject(sfd.FileName);
- break;
- default:
- AssimpData assimp = new AssimpData();
- assimp.SaveFromObject(vertices, lodMeshes[DisplayLODIndex].faces, Text, sfd.FileName);
- break;
- }
- }
- }
- public void ExportBinaryObject(string FileName)
- {
- Shape.Export(FileName, GetResFile());
- }
- public void Replace(object sender, EventArgs args)
- {
- bool IsWiiU = (GetResFileU() != null);
-
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Supported Formats|*.bfobj;*.fbx;*.dae; *.obj;|" +
- "Bfres Object (shape/vertices) |*.bfobj|" +
- "FBX |*.fbx|" +
- "DAE |*.dae|" +
- "OBJ |*.obj|" +
- "All files(*.*)|*.*";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- string ext = System.IO.Path.GetExtension(ofd.FileName);
- ext = ext.ToLower();
-
- switch (ext)
- {
- case ".bfobj":
- Shape shp = new Shape();
- shp.Import(ofd.FileName, VertexBuffer);
- shp.Name = Text;
- shp.MaterialIndex = (ushort)MaterialIndex;
- BfresSwitch.ReadShapesVertices(this, shp, VertexBuffer, GetModelList()[ModelIndex]);
- break;
- default:
- AssimpData assimp = new AssimpData();
- assimp.LoadFile(ofd.FileName);
- AssimpMeshSelector selector = new AssimpMeshSelector();
- selector.LoadMeshes(assimp, Index);
-
- if (selector.ShowDialog() == DialogResult.OK)
- {
- if (assimp.objects.Count == 0)
- {
- MessageBox.Show("No models found!");
- return;
- }
- BfresModelImportSettings settings = new BfresModelImportSettings();
- settings.SetModelAttributes(assimp.objects[0]);
- if (settings.ShowDialog() == DialogResult.OK)
- {
- STGenericObject obj = selector.GetSelectedMesh();
-
- Cursor.Current = Cursors.WaitCursor;
- VertexBufferIndex = obj.VertexBufferIndex;
- vertices = obj.vertices;
- CreateBoneList(obj, (FMDL)Parent.Parent);
- VertexSkinCount = obj.MaxSkinInfluenceCount;
- vertexAttributes = settings.CreateNewAttributes();
- lodMeshes = obj.lodMeshes;
- CreateNewBoundingBoxes();
- SaveShape(IsWiiU);
- SaveVertexBuffer(IsWiiU);
- Cursor.Current = Cursors.Default;
- }
- }
- break;
- }
- UpdateVertexData();
- }
- }
- public void CreateIndexList(STGenericObject ob, FMDL mdl = null)
- {
- BoneIndices = new List();
-
- List boneNames = new List();
- foreach (Vertex v in ob.vertices)
- {
- foreach (string bn in v.boneNames)
- {
- if (!boneNames.Contains(bn))
- boneNames.Add(bn);
- }
- }
-
- int index = 0;
- foreach (STBone bone in mdl.Skeleton.bones)
- {
- foreach (string bnam in boneNames)
- {
- if (bone.Text == bnam)
- {
- BoneIndices.Add((ushort)index);
- }
- }
- index++;
- }
- }
- public void CreateBoneList(STGenericObject ob, FMDL mdl)
- {
- string[] nodeArrStrings = new string[mdl.Skeleton.Node_Array.Length];
-
- int CurNode = 0;
- foreach (int thing in mdl.Skeleton.Node_Array)
- nodeArrStrings[CurNode++] = mdl.Skeleton.bones[thing].Text;
-
-
- foreach (Vertex v in ob.vertices)
- {
- foreach (string bn in v.boneNames)
- {
- foreach (var defBn in nodeArrStrings.Select((Value, Index) => new { Value, Index }))
- {
- if (bn == defBn.Value)
- {
- v.boneIds.Add(defBn.Index);
- }
- }
- }
- }
- }
- public void CreateNewBoundingBoxes()
- {
- boundingBoxes.Clear();
- boundingRadius.Clear();
- foreach (LOD_Mesh mesh in lodMeshes)
- {
- BoundingBox box = CalculateBoundingBox();
- boundingBoxes.Add(box);
- boundingRadius.Add((float)(box.Center.Length + box.Extend.Length));
- foreach (LOD_Mesh.SubMesh sub in mesh.subMeshes)
- boundingBoxes.Add(box);
- }
- }
- private BoundingBox CalculateBoundingBox()
- {
- Vector3 Max = new Vector3();
- Vector3 Min = new Vector3();
-
- Min = Max = vertices[0].pos;
-
- Min = CalculateBBMin(vertices);
- Max = CalculateBBMax(vertices);
- Vector3 center = (Max + Min);
- Vector3 extend = Max - Min;
-
- return new BoundingBox() { Center = center, Extend = extend };
- }
- private Vector3 CalculateBBMin(List positionVectors)
- {
- Vector3 minimum = new Vector3();
- foreach (Vertex vtx in positionVectors)
- {
- if (vtx.pos.X < minimum.X) minimum.X = vtx.pos.X;
- if (vtx.pos.Y < minimum.Y) minimum.Y = vtx.pos.Y;
- if (vtx.pos.Z < minimum.Z) minimum.Z = vtx.pos.Z;
- }
-
- return minimum;
- }
-
- private Vector3 CalculateBBMax(List positionVectors)
- {
- Vector3 maximum = new Vector3();
- foreach (Vertex vtx in positionVectors)
- {
- if (vtx.pos.X > maximum.X) maximum.X = vtx.pos.X;
- if (vtx.pos.Y > maximum.Y) maximum.Y = vtx.pos.Y;
- if (vtx.pos.Z > maximum.Z) maximum.Z = vtx.pos.Z;
- }
-
- return maximum;
- }
-
- private void UpdateShaderAssignAttributes(FMAT material)
- {
- material.shaderassign.attributes.Clear();
- foreach (VertexAttribute att in vertexAttributes)
- {
- material.shaderassign.attributes.Add(att.Name, att.Name);
- }
- }
-
- public int[] Faces;
- public List BoneIndices = new List();
-
- // for drawing
- public int[] display;
- public int VertexSkinCount;
- public int DisplayId;
- public int boneIndx;
- public int VertexBufferIndex;
- public int TargetAttribCount;
-
- public List boundingRadius = new List();
- public List boundingBoxes = new List();
- public class BoundingBox
- {
- public Vector3 Center;
- public Vector3 Extend;
- }
- public int DisplayLODIndex = 0;
-
- public List vertexAttributes = new List();
- public class VertexAttribute
- {
- public string Name;
- public ResGFX.AttribFormat Format;
-
- public override string ToString()
- {
- return Name;
- }
-
- public ResGFX.AttribFormat GetTypeWiiU(ResUGX2.GX2AttribFormat type)
- {
- return (ResGFX.AttribFormat)System.Enum.Parse(typeof(ResGFX.AttribFormat), $"{type.ToString()}");
- }
- public ResUGX2.GX2AttribFormat SetTypeWiiU(ResGFX.AttribFormat type)
- {
- return (ResUGX2.GX2AttribFormat)System.Enum.Parse(typeof(ResUGX2.GX2AttribFormat), type.ToString());
- }
- }
- public void SaveShape(bool IsWiiU)
- {
- if (IsWiiU)
- ShapeU = BfresWiiU.SaveShape(this);
- else
- Shape = BfresSwitch.SaveShape(this);
- }
- public IList GetIndices()
- {
- IList indices = new List();
-
- List BoneNodes = new List();
- foreach (Vertex vtx in vertices)
- {
-
- }
- return indices;
- }
- public Vector3 TransformLocal(Vector3 position, bool IsPos = true)
- {
- Matrix4 trans = Matrix4.CreateTranslation(0, 0, 0);
-
- if (IsPos)
- return Vector3.TransformPosition(position, trans);
- else
- return Vector3.TransformNormal(position, trans);
- }
- public void SaveVertexBuffer(bool IsWiiU)
- {
- if (IsWiiU)
- {
- BfresWiiU.SaveVertexBuffer(this);
- return;
- }
-
- VertexBufferHelper helpernx = new VertexBufferHelper(new VertexBuffer(), Syroot.BinaryData.ByteOrder.LittleEndian);
- List atrib = new List();
- UpdateVertices();
-
- foreach (VertexAttribute att in vertexAttributes)
- {
- if (att.Name == "_p0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = verts.ToArray();
- vert.Format = att.Format;
- atrib.Add(vert);
- }
- if (att.Name == "_n0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = norms.ToArray();
- vert.Format = att.Format;
- atrib.Add(vert);
- }
- if (att.Name == "_u0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = uv0.ToArray();
- vert.Format = att.Format;
- atrib.Add(vert);
- }
- if (att.Name == "_u1")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = uv1.ToArray();
- vert.Format = att.Format;
- atrib.Add(vert);
- }
- if (att.Name == "_u2")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = uv2.ToArray();
- vert.Format = att.Format;
- atrib.Add(vert);
- }
- if (att.Name == "_w0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = weights.ToArray();
- vert.Format = att.Format;
- atrib.Add(vert);
- }
- if (att.Name == "_i0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = boneInd.ToArray();
- vert.Format = att.Format;
- atrib.Add(vert);
- }
- if (att.Name == "_b0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = bitans.ToArray();
- vert.Format = att.Format;
- atrib.Add(vert);
- }
- if (att.Name == "_t0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = tans.ToArray();
- vert.Format = att.Format;
- atrib.Add(vert);
- }
- if (att.Name == "_c0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = colors.ToArray();
- vert.Format = att.Format;
- atrib.Add(vert);
- }
- }
- if (atrib.Count == 0)
- {
- MessageBox.Show("Attributes are empty?");
- return;
- }
- helpernx.Attributes = atrib;
- VertexBuffer = helpernx.ToVertexBuffer();
- }
-
- internal List verts = new List();
- internal List norms = new List();
- internal List uv0 = new List();
- internal List uv1 = new List();
- internal List uv2 = new List();
- internal List tans = new List();
- internal List bitans = new List();
- internal List weights = new List();
- internal List boneInd = new List();
- internal List colors = new List();
-
- public string GetBoneNameFromIndex(FMDL mdl, int index)
- {
- if (index == 0)
- return "";
-
- return mdl.Skeleton.bones[mdl.Skeleton.Node_Array[index]].Text;
- }
-
- public void UpdateVertices()
- {
- // CalculateTangentBitangent();
-
- foreach (Vertex vtx in vertices)
- {
- if (VertexSkinCount == 0 || VertexSkinCount == 1)
- {
- // Console.WriteLine("Old " + vtx.pos);
- // vtx.pos = TransformLocal(vtx.pos);
- // vtx.nrm = TransformLocal(vtx.nrm, false);
- // Console.WriteLine("New " + vtx.pos);
- }
- //Console.WriteLine($"Weight count {vtx.boneWeights.Count}");
- //Console.WriteLine($"Index count {vtx.boneIds.Count}");
-
- verts.Add(new Syroot.Maths.Vector4F(vtx.pos.X, vtx.pos.Y, vtx.pos.Z, 1.0f));
- norms.Add(new Syroot.Maths.Vector4F(vtx.nrm.X, vtx.nrm.Y, vtx.nrm.Z, 0));
- uv0.Add(new Syroot.Maths.Vector4F(vtx.uv0.X, vtx.uv0.Y, 0, 0));
- uv1.Add(new Syroot.Maths.Vector4F(vtx.uv1.X, vtx.uv1.Y, 0, 0));
- uv2.Add(new Syroot.Maths.Vector4F(vtx.uv2.X, vtx.uv2.Y, 0, 0));
- tans.Add(new Syroot.Maths.Vector4F(vtx.tan.X, vtx.tan.Y, vtx.tan.Z, vtx.tan.W));
- bitans.Add(new Syroot.Maths.Vector4F(vtx.bitan.X, vtx.bitan.Y, vtx.bitan.Z, vtx.bitan.W));
-
-
- if (vtx.boneWeights.Count == 0)
- {
- vtx.boneWeights.Add(0);
- vtx.boneWeights.Add(0);
- vtx.boneWeights.Add(0);
- vtx.boneWeights.Add(0);
- }
- if (vtx.boneWeights.Count == 1)
- {
- vtx.boneWeights.Add(0);
- vtx.boneWeights.Add(0);
- vtx.boneWeights.Add(0);
- }
- if (vtx.boneWeights.Count == 2)
- {
- vtx.boneWeights.Add(0);
- vtx.boneWeights.Add(0);
- }
- if (vtx.boneWeights.Count == 3)
- {
- vtx.boneWeights.Add(0);
- }
- if (vtx.boneIds.Count == 0)
- {
- vtx.boneIds.Add(0);
- vtx.boneIds.Add(0);
- vtx.boneIds.Add(0);
- vtx.boneIds.Add(0);
- }
- if (vtx.boneIds.Count == 1)
- {
- vtx.boneIds.Add(0);
- vtx.boneIds.Add(0);
- vtx.boneIds.Add(0);
- }
- if (vtx.boneIds.Count == 2)
- {
- vtx.boneIds.Add(0);
- vtx.boneIds.Add(0);
- }
- if (vtx.boneIds.Count == 3)
- {
- vtx.boneIds.Add(0);
- }
- weights.Add(new Syroot.Maths.Vector4F(vtx.boneWeights[0], vtx.boneWeights[1], vtx.boneWeights[2], vtx.boneWeights[3]));
- boneInd.Add(new Syroot.Maths.Vector4F(vtx.boneIds[0], vtx.boneIds[1], vtx.boneIds[2], vtx.boneIds[3]));
- colors.Add(new Syroot.Maths.Vector4F(vtx.col.X, vtx.col.Y, vtx.col.Z, vtx.col.W));
- }
- }
-
- public List CreateDisplayVertices()
- {
- // rearrange faces
- display = lodMeshes[DisplayLODIndex].getDisplayFace().ToArray();
-
- List displayVertList = new List();
-
- if (lodMeshes[DisplayLODIndex].faces.Count <= 3)
- return displayVertList;
-
- foreach (Vertex v in vertices)
- {
- DisplayVertex displayVert = new DisplayVertex()
- {
- pos = v.pos,
- nrm = v.nrm,
- tan = v.tan.Xyz,
- bit = v.bitan.Xyz,
- col = v.col,
- uv = v.uv0,
- uv2 = v.uv1,
- uv3 = v.uv2,
- node = new Vector4(
- v.boneIds.Count > 0 ? v.boneIds[0] : -1,
- v.boneIds.Count > 1 ? v.boneIds[1] : -1,
- v.boneIds.Count > 2 ? v.boneIds[2] : -1,
- v.boneIds.Count > 3 ? v.boneIds[3] : -1),
- weight = new Vector4(
- v.boneWeights.Count > 0 ? v.boneWeights[0] : 0,
- v.boneWeights.Count > 1 ? v.boneWeights[1] : 0,
- v.boneWeights.Count > 2 ? v.boneWeights[2] : 0,
- v.boneWeights.Count > 3 ? v.boneWeights[3] : 0),
- };
-
- displayVertList.Add(displayVert);
-
-
- /* Console.WriteLine($"---------------------------------------------------------------------------------------");
- Console.WriteLine($"Position {displayVert.pos.X} {displayVert.pos.Y} {displayVert.pos.Z}");
- Console.WriteLine($"Normal {displayVert.nrm.X} {displayVert.nrm.Y} {displayVert.nrm.Z}");
- Console.WriteLine($"Binormal {displayVert.bit.X} {displayVert.bit.Y} {displayVert.bit.Z}");
- Console.WriteLine($"Tanget {displayVert.tan.X} {displayVert.tan.Y} {displayVert.tan.Z}");
- Console.WriteLine($"Color {displayVert.col.X} {displayVert.col.Y} {displayVert.col.Z} {displayVert.col.W}");
- Console.WriteLine($"UV Layer 1 {displayVert.uv.X} {displayVert.uv.Y}");
- Console.WriteLine($"UV Layer 2 {displayVert.uv2.X} {displayVert.uv2.Y}");
- Console.WriteLine($"UV Layer 3 {displayVert.uv3.X} {displayVert.uv3.Y}");
- Console.WriteLine($"Bone Index {displayVert.node.X} {displayVert.node.Y} {displayVert.node.Z} {displayVert.node.W}");
- Console.WriteLine($"Weights {displayVert.weight.X} {displayVert.weight.Y} {displayVert.weight.Z} {displayVert.weight.W}");
- Console.WriteLine($"---------------------------------------------------------------------------------------");*/
- }
-
- return displayVertList;
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKA.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKA.cs
deleted file mode 100644
index 4e5984ea..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKA.cs
+++ /dev/null
@@ -1,487 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Syroot.NintenTools.NSW.Bfres;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using ResU = Syroot.NintenTools.Bfres;
-using FirstPlugin;
-using OpenTK;
-
-namespace Bfres.Structs
-{
- public class FskaFolder : AnimationGroupNode
- {
- public FskaFolder()
- {
- Text = "Skeleton Animations";
- Name = "FSKA";
-
- ContextMenu = new ContextMenu();
- MenuItem import = new MenuItem("Import");
- ContextMenu.MenuItems.Add(import);
- import.Click += Import;
- MenuItem exportAll = new MenuItem("Export All");
- ContextMenu.MenuItems.Add(exportAll);
- exportAll.Click += ExportAll;
- MenuItem clear = new MenuItem("Clear");
- ContextMenu.MenuItems.Add(clear);
- clear.Click += Clear;
- }
- public void Import(object sender, EventArgs args)
- {
-
- }
- public void ExportAll(object sender, EventArgs args)
- {
- FolderSelectDialog sfd = new FolderSelectDialog();
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string folderPath = sfd.SelectedPath;
- foreach (FSKA fska in Nodes)
- {
- string FileName = folderPath + '\\' + fska.Text + ".bfska";
-
- if (fska.GetResFileU() != null)
- ((FSKA)fska).SkeletalAnimU.Export(FileName, fska.GetResFileU());
- else
- ((FSKA)fska).SkeletalAnim.Export(FileName, fska.GetResFile());
- }
- }
- }
- private void Clear(object sender, EventArgs args)
- {
- DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove all skeletal animations? This cannot be undone!", "", MessageBoxButtons.YesNo);
- if (dialogResult == DialogResult.Yes)
- {
- Nodes.Clear();
- }
- }
- }
-
- public class FSKA : Animation
- {
- public enum TrackType
- {
- XSCA = 0x4,
- YSCA = 0x8,
- ZSCA = 0xC,
- XPOS = 0x10,
- YPOS = 0x14,
- ZPOS = 0x18,
- XROT = 0x20,
- YROT = 0x24,
- ZROT = 0x28,
- }
- public SkeletalAnim SkeletalAnim;
- public ResU.SkeletalAnim SkeletalAnimU;
-
- public FSKA()
- {
- ImageKey = "skeletonAnimation";
- SelectedImageKey = "skeletonAnimation";
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- }
- public FSKA(string name)
- {
- Text = name;
-
- ImageKey = "skeletonAnimation";
- SelectedImageKey = "skeletonAnimation";
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- }
- public ResFile GetResFile()
- {
- //ResourceFile -> FMDL -> Material Folder -> this
- return ((BFRES)Parent.Parent).resFile;
- }
- public ResU.ResFile GetResFileU()
- {
- //ResourceFile -> FMDL -> Material Folder -> this
- return ((BFRES)Parent.Parent).resFileU;
- }
- private void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Supported Formats|*.bfska;";
- sfd.FileName = Text;
- sfd.DefaultExt = ".bfska";
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- if (GetResFileU() != null)
- {
- SkeletalAnimU.Export(sfd.FileName, GetResFileU());
- }
- else
- {
- SkeletalAnim.Export(sfd.FileName, GetResFile());
- }
- }
- }
- private void Replace(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Supported Formats|*.bfska;";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- if (GetResFileU() != null)
- {
- SkeletalAnimU.Import(ofd.FileName, GetResFileU());
- SkeletalAnimU.Name = Text;
- Read(SkeletalAnimU);
- }
- else
- {
- SkeletalAnim.Import(ofd.FileName);
- SkeletalAnim.Name = Text;
- Read(SkeletalAnim);
- }
- }
- }
-
- public void Read(ResU.SkeletalAnim ska)
- {
- Nodes.Clear();
- Bones.Clear();
-
- FrameCount = ska.FrameCount;
- SkeletalAnimU = ska;
-
- foreach (ResU.BoneAnim bn in ska.BoneAnims)
- {
- FSKANode bonean = new FSKANode(bn);
-
- Animation.KeyNode bone = new Animation.KeyNode("");
- Bones.Add(bone);
- if (ska.FlagsRotate == ResU.SkeletalAnimFlagsRotate.EulerXYZ)
- bone.RotType = Animation.RotationType.EULER;
- else
- bone.RotType = Animation.RotationType.QUATERNION;
-
- bone.Text = bonean.Text;
-
-
- for (int Frame = 0; Frame < ska.FrameCount; Frame++)
- {
- if (Frame == 0)
- {
- if (bn.FlagsBase.HasFlag(ResU.BoneAnimFlagsBase.Scale))
- {
- bone.XSCA.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.sca.X });
- bone.YSCA.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.sca.Y });
- bone.ZSCA.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.sca.Z });
- }
- if (bn.FlagsBase.HasFlag(ResU.BoneAnimFlagsBase.Rotate))
- {
- bone.XROT.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.rot.X });
- bone.YROT.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.rot.Y });
- bone.ZROT.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.rot.Z });
- bone.WROT.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.rot.W });
- }
- if (bn.FlagsBase.HasFlag(ResU.BoneAnimFlagsBase.Translate))
- {
- bone.XPOS.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.pos.X });
- bone.YPOS.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.pos.Y });
- bone.ZPOS.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.pos.Z });
- }
- }
- foreach (FSKATrack track in bonean.tracks)
- {
- KeyFrame frame = new KeyFrame();
- frame.InterType = Animation.InterpolationType.HERMITE;
- frame.Frame = Frame;
-
- FSKAKey left = track.GetLeft(Frame);
- FSKAKey right = track.GetRight(Frame);
- float value;
-
- value = Animation.Hermite(Frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1);
-
- // interpolate the value and apply
- switch (track.flag)
- {
- case (int)TrackType.XPOS: frame.Value = value; bone.XPOS.Keys.Add(frame); break;
- case (int)TrackType.YPOS: frame.Value = value; bone.YPOS.Keys.Add(frame); break;
- case (int)TrackType.ZPOS: frame.Value = value; bone.ZPOS.Keys.Add(frame); break;
- case (int)TrackType.XROT: frame.Value = value; bone.XROT.Keys.Add(frame); break;
- case (int)TrackType.YROT: frame.Value = value; bone.YROT.Keys.Add(frame); break;
- case (int)TrackType.ZROT: frame.Value = value; bone.ZROT.Keys.Add(frame); break;
- case (int)TrackType.XSCA: frame.Value = value; bone.XSCA.Keys.Add(frame); break;
- case (int)TrackType.YSCA: frame.Value = value; bone.YSCA.Keys.Add(frame); break;
- case (int)TrackType.ZSCA: frame.Value = value; bone.ZSCA.Keys.Add(frame); break;
- }
- }
- }
- }
- }
- public void Read(SkeletalAnim ska)
- {
- Nodes.Clear();
- Bones.Clear();
-
- FrameCount = ska.FrameCount;
- SkeletalAnim = ska;
- foreach (BoneAnim bn in ska.BoneAnims)
- {
- FSKANode bonean = new FSKANode(bn);
-
- Animation.KeyNode bone = new Animation.KeyNode("");
- Bones.Add(bone);
- if (ska.FlagsRotate == SkeletalAnimFlagsRotate.EulerXYZ)
- bone.RotType = Animation.RotationType.EULER;
- else
- bone.RotType = Animation.RotationType.QUATERNION;
-
- bone.Text = bonean.Text;
-
-
- for (int Frame = 0; Frame < ska.FrameCount; Frame++)
- {
- if (Frame == 0)
- {
- if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Scale))
- {
- bone.XSCA.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.sca.X });
- bone.YSCA.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.sca.Y });
- bone.ZSCA.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.sca.Z });
- }
- if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Rotate))
- {
- bone.XROT.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.rot.X });
- bone.YROT.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.rot.Y });
- bone.ZROT.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.rot.Z });
- bone.WROT.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.rot.W });
- }
- if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Translate))
- {
- bone.XPOS.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.pos.X });
- bone.YPOS.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.pos.Y });
- bone.ZPOS.Keys.Add(new KeyFrame() { Frame = 0, Value = bonean.pos.Z });
- }
- }
- foreach (FSKATrack track in bonean.tracks)
- {
- KeyFrame frame = new KeyFrame();
- frame.InterType = Animation.InterpolationType.HERMITE;
- frame.Frame = Frame;
-
- FSKAKey left = track.GetLeft(Frame);
- FSKAKey right = track.GetRight(Frame);
- float value;
-
- value = Animation.Hermite(Frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1);
-
- // interpolate the value and apply
- switch (track.flag)
- {
- case (int)TrackType.XPOS: frame.Value = value; bone.XPOS.Keys.Add(frame); break;
- case (int)TrackType.YPOS: frame.Value = value; bone.YPOS.Keys.Add(frame); break;
- case (int)TrackType.ZPOS: frame.Value = value; bone.ZPOS.Keys.Add(frame); break;
- case (int)TrackType.XROT: frame.Value = value; bone.XROT.Keys.Add(frame); break;
- case (int)TrackType.YROT: frame.Value = value; bone.YROT.Keys.Add(frame); break;
- case (int)TrackType.ZROT: frame.Value = value; bone.ZROT.Keys.Add(frame); break;
- case (int)TrackType.XSCA: frame.Value = value; bone.XSCA.Keys.Add(frame); break;
- case (int)TrackType.YSCA: frame.Value = value; bone.YSCA.Keys.Add(frame); break;
- case (int)TrackType.ZSCA: frame.Value = value; bone.ZSCA.Keys.Add(frame); break;
- }
- }
- }
- }
-
- }
- public class FSKANode
- {
- public int flags;
- public int flags2;
- public int stride;
- public int BeginRotate;
- public int BeginTranslate;
- public long offBase;
- public int trackCount;
- public int trackFlag;
- public long offTrack;
- public string Text;
-
- public Vector3 sca, pos;
- public Vector4 rot;
- public List tracks = new List();
- public FSKANode(ResU.BoneAnim b)
- {
- Text = b.Name;
-
- sca = new Vector3(b.BaseData.Scale.X, b.BaseData.Scale.Y, b.BaseData.Scale.Z);
- rot = new Vector4(b.BaseData.Rotate.X, b.BaseData.Rotate.Y, b.BaseData.Rotate.Z, b.BaseData.Rotate.W);
- pos = new Vector3(b.BaseData.Translate.X, b.BaseData.Translate.Y, b.BaseData.Translate.Z);
-
- foreach (ResU.AnimCurve tr in b.Curves)
- {
-
- FSKATrack t = new FSKATrack();
- t.flag = (int)tr.AnimDataOffset;
- tracks.Add(t);
-
- float tanscale = tr.Delta;
- if (tanscale == 0)
- tanscale = 1;
-
- for (int i = 0; i < (ushort)tr.Frames.Length; i++)
- {
- if (tr.CurveType == ResU.AnimCurveType.Cubic)
- {
- int framedata = (int)tr.Frames[i];
- float keydata = tr.Offset + ((tr.Keys[i, 0] * tr.Scale));
- float keydata2 = tr.Offset + ((tr.Keys[i, 1] * tr.Scale));
- float keydata3 = tr.Offset + ((tr.Keys[i, 2] * tr.Scale));
- float keydata4 = tr.Offset + ((tr.Keys[i, 3] * tr.Scale));
-
- }
- if (tr.KeyType == ResU.AnimCurveKeyType.Int16)
- {
-
- }
- else if (tr.KeyType == ResU.AnimCurveKeyType.Single)
- {
-
- }
- else if (tr.KeyType == ResU.AnimCurveKeyType.SByte)
- {
-
- }
- t.keys.Add(new FSKAKey()
- {
- frame = (int)tr.Frames[i],
- unk1 = tr.Offset + ((tr.Keys[i, 0] * tr.Scale)),
- unk2 = tr.Offset + ((tr.Keys[i, 1] * tr.Scale)),
- unk3 = tr.Offset + ((tr.Keys[i, 2] * tr.Scale)),
- unk4 = tr.Offset + ((tr.Keys[i, 3] * tr.Scale)),
- });
- }
- }
- }
- public FSKANode(BoneAnim b)
- {
- Text = b.Name;
-
- sca = new Vector3(b.BaseData.Scale.X, b.BaseData.Scale.Y, b.BaseData.Scale.Z);
- rot = new Vector4(b.BaseData.Rotate.X, b.BaseData.Rotate.Y, b.BaseData.Rotate.Z, b.BaseData.Rotate.W);
- pos = new Vector3(b.BaseData.Translate.X, b.BaseData.Translate.Y, b.BaseData.Translate.Z);
-
- foreach (AnimCurve tr in b.Curves)
- {
-
- FSKATrack t = new FSKATrack();
- t.flag = (int)tr.AnimDataOffset;
- tracks.Add(t);
-
- float tanscale = tr.Delta;
- if (tanscale == 0)
- tanscale = 1;
-
- for (int i = 0; i < (ushort)tr.Frames.Length; i++)
- {
- if (tr.CurveType == AnimCurveType.Cubic)
- {
- int framedata = (int)tr.Frames[i];
- float keydata = tr.Offset + ((tr.Keys[i, 0] * tr.Scale));
- float keydata2 = tr.Offset + ((tr.Keys[i, 1] * tr.Scale));
- float keydata3 = tr.Offset + ((tr.Keys[i, 2] * tr.Scale));
- float keydata4 = tr.Offset + ((tr.Keys[i, 3] * tr.Scale));
-
- }
- if (tr.KeyType == AnimCurveKeyType.Int16)
- {
-
- }
- else if (tr.KeyType == AnimCurveKeyType.Single)
- {
-
- }
- else if (tr.KeyType == AnimCurveKeyType.SByte)
- {
-
- }
- t.keys.Add(new FSKAKey()
- {
- frame = (int)tr.Frames[i],
- unk1 = tr.Offset + ((tr.Keys[i, 0] * tr.Scale)),
- unk2 = tr.Offset + ((tr.Keys[i, 1] * tr.Scale)),
- unk3 = tr.Offset + ((tr.Keys[i, 2] * tr.Scale)),
- unk4 = tr.Offset + ((tr.Keys[i, 3] * tr.Scale)),
- });
- }
- }
- }
- }
-
- public class FSKATrack
- {
- public short type;
- public short keyCount;
- public int flag;
- public int unk2;
- public int padding1;
- public int padding2;
- public int padding3;
- public float frameCount;
- public float scale, init, unkf3;
- public long offtolastKeys, offtolastData;
- public List keys = new List();
-
- public int offset;
-
- public FSKAKey GetLeft(int frame)
- {
- FSKAKey prev = keys[0];
-
- for (int i = 0; i < keys.Count - 1; i++)
- {
- FSKAKey key = keys[i];
- if (key.frame > frame && prev.frame <= frame)
- break;
- prev = key;
- }
-
- return prev;
- }
- public FSKAKey GetRight(int frame)
- {
- FSKAKey cur = keys[0];
- FSKAKey prev = keys[0];
-
- for (int i = 1; i < keys.Count; i++)
- {
- FSKAKey key = keys[i];
- cur = key;
- if (key.frame > frame && prev.frame <= frame)
- break;
- prev = key;
- }
-
- return cur;
- }
- }
-
- public class FSKAKey
- {
- public int frame;
- public float unk1, unk2, unk3, unk4;
-
- public int offset;
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKL.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKL.cs
deleted file mode 100644
index b90d71b4..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKL.cs
+++ /dev/null
@@ -1,151 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Syroot.NintenTools.NSW.Bfres;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using ResU = Syroot.NintenTools.Bfres;
-using FirstPlugin;
-using OpenTK;
-
-namespace Bfres.Structs
-{
-
- public class FSKL : STSkeleton
- {
- public int[] Node_Array;
- public List matrices = new List();
- public fsklNode node;
- public class fsklNode : TreeNodeCustom
- {
- public Skeleton Skeleton;
- public ResU.Skeleton SkeletonU;
-
- public BFRESRender BFRESRender;
- public fsklNode()
- {
- Text = "Skeleton";
- ImageKey = "skeleton";
- SelectedImageKey = "skeleton";
-
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- }
- public void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Bfres Skeleton|*.bfskl;";
- sfd.FileName = Text;
- sfd.DefaultExt = ".bfskl";
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- Skeleton.Export(sfd.FileName, ((FMDL)Parent).GetResFile());
- }
- }
- public void Replace(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Supported Formats|*.bfska;|" +
- "Bfres Object (shape/vertices) |*.bfska|" +
- "All files(*.*)|*.*";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- Skeleton.Import(ofd.FileName);
- }
- }
- public override void OnClick(TreeView treeView)
- {
-
- }
- }
- public FSKL()
- {
-
- }
- public FSKL(Skeleton skl)
- {
- node = new fsklNode();
- node.Skeleton = skl;
- BfresSwitch.ReadSkeleton(node, skl, this);
- }
- public FSKL(ResU.Skeleton skl)
- {
- node = new fsklNode();
- node.SkeletonU = skl;
- BfresWiiU.SetSkeleton(node, skl, this);
- }
- }
- public class BfresBone : STBone
- {
- public bool IsVisable = true;
- public BoneFlagsBillboard billboard;
- public BoneFlagsRotation rotationFlags;
- public BoneFlagsTransform transformFlags;
-
- public Bone Bone;
- public ResU.Bone BoneU;
-
- public BFRESRender BFRESRender;
- public BfresBone()
- {
- ImageKey = "bone";
- SelectedImageKey = "bone";
-
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- }
- public ResFile GetResFile()
- {
- //ResourceFile -> FMDL -> Material Folder -> this
- return ((FMDL)Parent.Parent).GetResFile();
- }
- public void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Bfres Bone|*.bfbn;";
- sfd.FileName = Text;
- sfd.DefaultExt = ".bfbn";
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- Bone.Export(sfd.FileName, GetResFile());
- }
- }
- public void Replace(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Supported Formats|*.bfska;|" +
- "Bfres Object (shape/vertices) |*.bfska|" +
- "All files(*.*)|*.*";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- Bone.Import(ofd.FileName);
- }
- Bone.Name = Text;
- }
-
- public BfresBone(STSkeleton skeleton)
- {
- skeletonParent = skeleton;
- }
- public override void OnClick(TreeView treeView)
- {
- FormLoader.LoadBoneEditor(this);
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/ResourceFile.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/ResourceFile.cs
deleted file mode 100644
index 6f347aa8..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/ResourceFile.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Syroot.NintenTools.NSW.Bfres;
-using Syroot.NintenTools.NSW.Bfres.Helpers;
-using OpenTK;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using Switch_Toolbox.Library.Rendering;
-using WeifenLuo.WinFormsUI.Docking;
-using Switch_Toolbox.Library.IO;
-using Switch_Toolbox.Library.Forms;
-using FirstPlugin;
-
-namespace Bfres.Structs
-{
- public class Misc
- {
- public static List HackyTextureList = new List(new string[] {
- "Alb", "alb", "Base", "base", "bonbon.167300917","Eye.00","EyeIce.00", "FaceDummy", "Eye01.17", "Dee.00",
- "rainbow.758540574", "Mucus._1700670200", "Eye.11", "CapTail00","eye.0","pallet_texture","Mark.930799313","InEye.1767598300","Face.00",
- "ThunderHair_Thunder_BaseColor.1751853236","FireHair_Thunder_BaseColor._162539711","IceHair_Thunder_BaseColor.674061150","BodyEnemy.1866226988",
- "Common_Scroll01._13827715"
- });
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/Wii U/FSHU.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/Wii U/FSHU.cs
deleted file mode 100644
index eb60aeec..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/Wii U/FSHU.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-using Switch_Toolbox.Library;
-using System.Windows.Forms;
-using FirstPlugin;
-
-namespace Bfres.Structs
-{
- public class TexSrtFolder : TreeNodeCustom
- {
- public TexSrtFolder()
- {
- Text = "Texture SRT Animations";
- Name = "TEXSRT";
- }
- public override void OnClick(TreeView treeView)
- {
- FormLoader.LoadEditor(this, Text);
- }
- }
- public class FshuFolder : TreeNodeCustom
- {
- public FshuFolder()
- {
- Text = "Shader Parameter Animations";
- Name = "FSHA";
- }
- public override void OnClick(TreeView treeView)
- {
- FormLoader.LoadEditor(this, Text);
- }
- }
- public class FshuColorFolder : TreeNodeCustom
- {
- public FshuColorFolder()
- {
- Text = "Color Animations";
- Name = "FSHAColor";
- }
- public override void OnClick(TreeView treeView)
- {
- FormLoader.LoadEditor(this, Text);
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/Wii U/FTXP.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/Wii U/FTXP.cs
deleted file mode 100644
index e30f7511..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/Wii U/FTXP.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Switch_Toolbox.Library;
-using System.Windows.Forms;
-using FirstPlugin;
-
-namespace Bfres.Structs
-{
- public class TexPatFolder : TreeNodeCustom
- {
- public TexPatFolder()
- {
- Text = "Texture Pattern Animations";
- Name = "TEXPAT";
- }
- public override void OnClick(TreeView treeView)
- {
- FormLoader.LoadEditor(this, Text);
- }
- }
-
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/BfresSwitch.cs b/Switch_FileFormatsMain/FileFormats/BFRES/BfresSwitch.cs
deleted file mode 100644
index 5d3bc669..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/BfresSwitch.cs
+++ /dev/null
@@ -1,988 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Syroot.NintenTools.NSW.Bfres;
-using Syroot.NintenTools.NSW.Bfres.Helpers;
-using Syroot.NintenTools.NSW.Bfres.GFX;
-using Switch_Toolbox.Library.IO;
-using Switch_Toolbox.Library;
-using Switch_Toolbox.Library.Rendering;
-using OpenTK;
-using System.Windows.Forms;
-using Bfres.Structs;
-
-namespace FirstPlugin
-{
- public static class BfresSwitch
- {
- public static Model SetModel(FMDL fmdl)
- {
- Model model = new Model();
- model.Name = fmdl.Text;
- model.Path = "";
- model.Shapes = new List();
- model.VertexBuffers = new List();
- model.Materials = new List();
- model.UserData = new List();
- model.Skeleton = new Skeleton();
- model.Skeleton = fmdl.Skeleton.node.Skeleton;
- model.ShapeDict = new ResDict();
- model.MaterialDict = new ResDict();
- model.UserDataDict = new ResDict();
-
- int i = 0;
- var duplicates = fmdl.shapes.GroupBy(c => c.Text).Where(g => g.Skip(1).Any()).SelectMany(c => c);
- foreach (var shape in duplicates)
- shape.Text += i++;
-
- foreach (FSHP shape in fmdl.shapes)
- {
- BFRES.CheckMissingTextures(shape);
- SetShape(shape, shape.Shape);
-
- model.Shapes.Add(shape.Shape);
- model.VertexBuffers.Add(shape.VertexBuffer);
- shape.Shape.VertexBufferIndex = (ushort)(model.VertexBuffers.Count - 1);
-
- BFRES.SetShaderAssignAttributes(shape.GetMaterial().shaderassign, shape);
- }
- foreach (FMAT mat in fmdl.materials.Values)
- {
-
- SetMaterial(mat, mat.Material);
- model.Materials.Add(mat.Material);
- }
- return model;
- }
- public static void Read(BFRESRender renderer, ResFile resFile, TreeNode ResFileNode)
- {
- int CurMdl = 0;
- foreach (Model mdl in resFile.Models)
- {
- FMDL model = new FMDL();
- model.Text = mdl.Name;
- model.Skeleton = new FSKL(mdl.Skeleton);
- model.Nodes.Add(model.Skeleton.node);
- model.Skeleton.reset();
- model.Skeleton.update();
- model.Skeleton.node.BFRESRender = renderer;
- model.Model = mdl;
- foreach (Material mat in mdl.Materials)
- {
- FMAT FMAT = new FMAT();
- FMAT.Text = mat.Name;
- FMAT.ReadMaterial(mat);
- model.Nodes[1].Nodes.Add(FMAT);
- model.materials.Add(FMAT.Text, FMAT);
- }
- foreach (Shape shp in mdl.Shapes)
- {
- VertexBuffer vertexBuffer = mdl.VertexBuffers[shp.VertexBufferIndex];
- Material material = mdl.Materials[shp.MaterialIndex];
- FSHP mesh = new FSHP();
- mesh.ModelIndex = CurMdl;
- ReadShapesVertices(mesh, shp, vertexBuffer, model);
- mesh.MaterialIndex = shp.MaterialIndex;
-
- model.Nodes[0].Nodes.Add(mesh);
- model.shapes.Add(mesh);
- }
- ResFileNode.Nodes[0].Nodes.Add(model);
- renderer.models.Add(model);
-
- CurMdl++;
- }
- }
- public static Shape SaveShape(FSHP fshp)
- {
- Shape Shape = new Shape();
- Shape.VertexSkinCount = (byte)fshp.VertexSkinCount;
- Shape.Flags = ShapeFlags.HasVertexBuffer;
- Shape.BoneIndex = (ushort)fshp.boneIndx;
- Shape.MaterialIndex = (ushort)fshp.MaterialIndex;
- Shape.VertexBufferIndex = (ushort)fshp.VertexBufferIndex;
- Shape.KeyShapes = new List();
- Shape.KeyShapeDict = new ResDict();
- Shape.Name = fshp.Text;
- Shape.SkinBoneIndices = fshp.GetIndices();
- Shape.TargetAttribCount = (byte)fshp.TargetAttribCount;
- Shape.SkinBoneIndices = fshp.BoneIndices;
- Shape.SubMeshBoundings = new List();
- Shape.RadiusArray = new List();
- Shape.RadiusArray = fshp.boundingRadius;
-
- Shape.Meshes = new List();
-
- foreach (FSHP.BoundingBox box in fshp.boundingBoxes)
- {
- Bounding bnd = new Bounding();
- bnd.Center = new Syroot.Maths.Vector3F(box.Center.X, box.Center.Y, box.Center.Z);
- bnd.Extent = new Syroot.Maths.Vector3F(box.Extend.X, box.Extend.Y, box.Extend.Z);
- Shape.SubMeshBoundings.Add(bnd);
- }
-
- foreach (FSHP.LOD_Mesh mesh in fshp.lodMeshes)
- {
- Mesh msh = new Mesh();
- msh.MemoryPool = new MemoryPool();
- msh.SubMeshes = new List();
- msh.PrimitiveType = (PrimitiveType)mesh.PrimitiveType;
- msh.FirstVertex = mesh.FirstVertex;
-
- foreach (FSHP.LOD_Mesh.SubMesh sub in mesh.subMeshes)
- {
- SubMesh subMesh = new SubMesh();
- subMesh.Offset = sub.offset;
- subMesh.Count = (uint)mesh.faces.Count;
- msh.SubMeshes.Add(subMesh);
- }
-
- IList faceList = new List();
- foreach (int f in mesh.faces)
- {
- faceList.Add((uint)f);
- }
- if (faceList.Count > 65000)
- {
- MessageBox.Show($"Warning! Your poly count for a single mesh {fshp.Text} is pretty high! ({faceList.Count})." +
- $" You may want to split this!");
- msh.SetIndices(faceList, IndexFormat.UInt32);
- }
- else
- msh.SetIndices(faceList, IndexFormat.UInt16);
-
- Shape.Meshes.Add(msh);
- break;
- }
- return Shape;
- }
- public static void ReadShapesVertices(FSHP fshp, Shape shp, VertexBuffer vertexBuffer, FMDL model)
- {
- fshp.boundingBoxes.Clear();
- fshp.boundingRadius.Clear();
- fshp.BoneIndices.Clear();
-
- foreach (Bounding bnd in shp.SubMeshBoundings)
- {
- FSHP. BoundingBox box = new FSHP.BoundingBox();
- box.Center = new Vector3(bnd.Center.X, bnd.Center.Y, bnd.Center.Z);
- box.Extend = new Vector3(bnd.Extent.X, bnd.Extent.Y, bnd.Extent.Z);
- fshp. boundingBoxes.Add(box);
- }
- foreach (float rad in shp.RadiusArray)
- {
- fshp.boundingRadius.Add(rad);
- }
-
- fshp.VertexBufferIndex = shp.VertexBufferIndex;
- fshp.Shape = shp;
- fshp.VertexBuffer = vertexBuffer;
- fshp.VertexSkinCount = shp.VertexSkinCount;
- fshp.boneIndx = shp.BoneIndex;
- fshp.Text = shp.Name;
- fshp.TargetAttribCount = shp.TargetAttribCount;
- fshp.MaterialIndex = shp.MaterialIndex;
-
- if (shp.SkinBoneIndices != null)
- {
- foreach (ushort bn in shp.SkinBoneIndices)
- fshp.BoneIndices.Add(bn);
- }
-
- ReadMeshes(fshp, shp);
- ReadVertexBuffer(fshp, vertexBuffer, model);
- }
- private static void ReadMeshes(FSHP fshp, Shape shp)
- {
- fshp.lodMeshes.Clear();
-
- foreach (Mesh msh in shp.Meshes)
- {
- uint FaceCount = msh.IndexCount;
- uint[] indicesArray = msh.GetIndices().ToArray();
-
- FSHP.LOD_Mesh lod = new FSHP.LOD_Mesh();
- foreach (SubMesh subMsh in msh.SubMeshes)
- {
- FSHP.LOD_Mesh.SubMesh sub = new FSHP.LOD_Mesh.SubMesh();
- sub.size = subMsh.Count;
- sub.offset = subMsh.Offset;
- lod.subMeshes.Add(sub);
- }
- lod.IndexFormat = (STIndexFormat)msh.IndexFormat;
- lod.PrimitiveType = (STPolygonType)msh.PrimitiveType;
- lod.FirstVertex = msh.FirstVertex;
-
- for (int face = 0; face < FaceCount; face++)
- lod.faces.Add((int)indicesArray[face] + (int)msh.FirstVertex);
-
- fshp.lodMeshes.Add(lod);
- }
- }
- private static void ReadVertexBuffer(FSHP fshp, VertexBuffer vtx, FMDL model)
- {
- fshp.vertices.Clear();
- fshp.vertexAttributes.Clear();
-
- //Create a buffer instance which stores all the buffer data
- VertexBufferHelper helper = new VertexBufferHelper(vtx);
-
- //Set each array first from the lib if exist. Then add the data all in one loop
- Syroot.Maths.Vector4F[] vec4Positions = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4Normals = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4uv0 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4uv1 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4uv2 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4c0 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4t0 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4b0 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4w0 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4i0 = new Syroot.Maths.Vector4F[0];
-
- //For shape morphing
- Syroot.Maths.Vector4F[] vec4Positions1 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4Positions2 = new Syroot.Maths.Vector4F[0];
-
- foreach (VertexAttrib att in vtx.Attributes)
- {
- FSHP.VertexAttribute attr = new FSHP.VertexAttribute();
- attr.Name = att.Name;
- attr.Format = att.Format;
-
- if (att.Name == "_p0")
- vec4Positions = AttributeData(att, helper, "_p0");
- if (att.Name == "_n0")
- vec4Normals = AttributeData(att, helper, "_n0");
- if (att.Name == "_u0")
- vec4uv0 = AttributeData(att, helper, "_u0");
- if (att.Name == "_u1")
- vec4uv1 = AttributeData(att, helper, "_u1");
- if (att.Name == "_u2")
- vec4uv2 = AttributeData(att, helper, "_u2");
- if (att.Name == "_c0")
- vec4c0 = AttributeData(att, helper, "_c0");
- if (att.Name == "_t0")
- vec4t0 = AttributeData(att, helper, "_t0");
- if (att.Name == "_b0")
- vec4b0 = AttributeData(att, helper, "_b0");
- if (att.Name == "_w0")
- vec4w0 = AttributeData(att, helper, "_w0");
- if (att.Name == "_i0")
- vec4i0 = AttributeData(att, helper, "_i0");
-
- if (att.Name == "_p1")
- vec4Positions1 = AttributeData(att, helper, "_p1");
- if (att.Name == "_p2")
- vec4Positions2 = AttributeData(att, helper, "_p2");
-
- fshp.vertexAttributes.Add(attr);
- }
- for (int i = 0; i < vec4Positions.Length; i++)
- {
- Vertex v = new Vertex();
- if (vec4Positions.Length > 0)
- v.pos = new Vector3(vec4Positions[i].X, vec4Positions[i].Y, vec4Positions[i].Z);
- if (vec4Positions1.Length > 0)
- v.pos1 = new Vector3(vec4Positions1[i].X, vec4Positions1[i].Y, vec4Positions1[i].Z);
- if (vec4Positions2.Length > 0)
- v.pos2 = new Vector3(vec4Positions2[i].X, vec4Positions2[i].Y, vec4Positions2[i].Z);
- if (vec4Normals.Length > 0)
- v.nrm = new Vector3(vec4Normals[i].X, vec4Normals[i].Y, vec4Normals[i].Z);
- if (vec4uv0.Length > 0)
- v.uv0 = new Vector2(vec4uv0[i].X, vec4uv0[i].Y);
- if (vec4uv1.Length > 0)
- v.uv1 = new Vector2(vec4uv1[i].X, vec4uv1[i].Y);
- if (vec4uv2.Length > 0)
- v.uv2 = new Vector2(vec4uv2[i].X, vec4uv2[i].Y);
- if (vec4w0.Length > 0)
- {
- v.boneWeights.Add(vec4w0[i].X);
- v.boneWeights.Add(vec4w0[i].Y);
- v.boneWeights.Add(vec4w0[i].Z);
- v.boneWeights.Add(vec4w0[i].W);
- }
- if (vec4i0.Length > 0)
- {
- v.boneIds.Add((int)vec4i0[i].X);
- v.boneIds.Add((int)vec4i0[i].Y);
- v.boneIds.Add((int)vec4i0[i].Z);
- v.boneIds.Add((int)vec4i0[i].W);
- }
-
- if (vec4t0.Length > 0)
- v.tan = new Vector4(vec4t0[i].X, vec4t0[i].Y, vec4t0[i].Z, vec4t0[i].W);
- if (vec4b0.Length > 0)
- v.bitan = new Vector4(vec4b0[i].X, vec4b0[i].Y, vec4b0[i].Z, vec4b0[i].W);
- if (vec4c0.Length > 0)
- v.col = new Vector4(vec4c0[i].X, vec4c0[i].Y, vec4c0[i].Z, vec4c0[i].W);
-
- if (fshp.VertexSkinCount == 1)
- {
- Matrix4 sb = model.Skeleton.bones[model.Skeleton.Node_Array[v.boneIds[0]]].transform;
- v.pos = Vector3.TransformPosition(v.pos, sb);
- v.nrm = Vector3.TransformNormal(v.nrm, sb);
- }
- if (fshp.VertexSkinCount == 0)
- {
- Matrix4 NoBindFix = model.Skeleton.bones[fshp.boneIndx].transform;
- v.pos = Vector3.TransformPosition(v.pos, NoBindFix);
- v.nrm = Vector3.TransformNormal(v.nrm, NoBindFix);
- }
- fshp.vertices.Add(v);
- }
- }
- private static Syroot.Maths.Vector4F[] AttributeData(VertexAttrib att, VertexBufferHelper helper, string attName)
- {
- VertexBufferHelperAttrib attd = helper[attName];
- return attd.Data;
- }
- public static SkeletalAnim SetSkeletalAniamtion(FSKA anim)
- {
- SkeletalAnim animation = new SkeletalAnim();
-
- animation.Name = anim.Text;
- animation.FrameCount = anim.FrameCount;
- animation.FlagsAnimSettings = SkeletalAnimFlags.Looping;
- animation.FlagsRotate = SkeletalAnimFlagsRotate.EulerXYZ;
- animation.FlagsScale = SkeletalAnimFlagsScale.Maya;
- animation.BindIndices = new ushort[anim.Bones.Count];
- animation.BindSkeleton = new Skeleton();
- animation.BakedSize = 0;
- animation.BoneAnims = new List();
- animation.UserDataDict = new ResDict();
- animation.UserDatas = new List();
-
- foreach (var bone in anim.Bones)
- animation.BoneAnims.Add(createBoneAnim(bone, anim));
-
- return animation;
- }
- private static BoneAnim createBoneAnim(Animation.KeyNode bone, FSKA anim)
- {
- BoneAnim boneAnim = new BoneAnim();
- boneAnim.Name = bone.Name;
- var posx = bone.XPOS.GetValue(0);
- var posy = bone.YPOS.GetValue(0);
- var posz = bone.ZPOS.GetValue(0);
- var scax = bone.XSCA.GetValue(0);
- var scay = bone.YSCA.GetValue(0);
- var scaz = bone.ZSCA.GetValue(0);
- var rotx = bone.XROT.GetValue(0);
- var roty = bone.YROT.GetValue(0);
- var rotz = bone.ZROT.GetValue(0);
- var rotw = bone.WROT.GetValue(0);
-
- BoneAnimData boneBaseData = new BoneAnimData();
- boneBaseData.Translate = new Syroot.Maths.Vector3F(posx, posy, posz);
- boneBaseData.Scale = new Syroot.Maths.Vector3F(scax, scay, scaz);
- boneBaseData.Rotate = new Syroot.Maths.Vector4F(rotx, roty, rotz, rotw);
- boneAnim.BaseData = boneBaseData;
- boneAnim.BeginBaseTranslate = 0;
- boneAnim.BeginRotate = 0;
- boneAnim.BeginTranslate = 0;
- boneAnim.Curves = new List();
- boneAnim.FlagsBase = BoneAnimFlagsBase.Translate | BoneAnimFlagsBase.Scale | BoneAnimFlagsBase.Rotate;
- boneAnim.FlagsTransform = BoneAnimFlagsTransform.Identity;
-
- if (bone.XPOS.HasAnimation())
- {
- boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateX;
- boneAnim.Curves.Add(SetAnimationCurve(bone.XPOS));
- }
- if (bone.YPOS.HasAnimation())
- {
- boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateY;
- boneAnim.Curves.Add(SetAnimationCurve(bone.YPOS));
- }
- if (bone.ZPOS.HasAnimation())
- {
- boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateZ;
- boneAnim.Curves.Add(SetAnimationCurve(bone.ZPOS));
- }
- if (bone.XSCA.HasAnimation())
- {
- boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleX;
- boneAnim.Curves.Add(SetAnimationCurve(bone.XSCA));
- }
- if (bone.YSCA.HasAnimation())
- {
- boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleY;
- boneAnim.Curves.Add(SetAnimationCurve(bone.YSCA));
- }
- if (bone.ZSCA.HasAnimation())
- {
- boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleZ;
- boneAnim.Curves.Add(SetAnimationCurve(bone.ZSCA));
- }
- if (bone.XROT.HasAnimation())
- {
- boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateX;
- boneAnim.Curves.Add(SetAnimationCurve(bone.XROT));
- }
- if (bone.YROT.HasAnimation())
- {
- boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateY;
- boneAnim.Curves.Add(SetAnimationCurve(bone.YROT));
- }
- if (bone.ZROT.HasAnimation())
- {
- boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateZ;
- boneAnim.Curves.Add(SetAnimationCurve(bone.ZROT));
- }
- if (bone.WROT.HasAnimation())
- {
- boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateW;
- boneAnim.Curves.Add(SetAnimationCurve(bone.WROT));
- }
-
- return boneAnim;
- }
- private static AnimCurve SetAnimationCurve(Animation.KeyGroup keyGroup)
- {
- AnimCurve curve = new AnimCurve();
- curve.Frames = new float[(int)keyGroup.Keys.Count];
- curve.FrameType = AnimCurveFrameType.Single;
- curve.KeyType = AnimCurveKeyType.Single;
- curve.EndFrame = keyGroup.FrameCount;
- curve.AnimDataOffset = 0;
- curve.Delta = 0;
- curve.Scale = 1;
- curve.StartFrame = 0;
- curve.Offset = 0;
-
- var frame = keyGroup.GetKeyFrame(0);
- int valuesLength = 1;
- if (frame.InterType == Animation.InterpolationType.HERMITE)
- {
- curve.CurveType = AnimCurveType.Cubic;
- curve.Keys = new float[keyGroup.Keys.Count, 4];
- for (int k = 0; k < keyGroup.Keys.Count; k++)
- {
- float value = keyGroup.GetValue(keyGroup.Keys[k].Frame);
- curve.Keys[k, 0] = value;
- curve.Keys[k, 1] = 0;
- curve.Keys[k, 2] = 0;
- curve.Keys[k, 3] = 0;
-
- curve.Frames[k] = keyGroup.Keys[k].Frame;
- }
- }
- if (frame.InterType == Animation.InterpolationType.LINEAR)
- {
- curve.CurveType = AnimCurveType.Linear;
- curve.Keys = new float[keyGroup.Keys.Count, 2];
- }
- if (frame.InterType == Animation.InterpolationType.STEP)
- {
- curve.CurveType = AnimCurveType.StepInt;
- curve.Keys = new float[keyGroup.Keys.Count, 1];
- }
- if (frame.InterType == Animation.InterpolationType.STEPBOOL)
- {
- curve.CurveType = AnimCurveType.StepBool;
- curve.Keys = new float[keyGroup.Keys.Count, 1];
- }
- return curve;
- }
- public static void ReadSkeleton(this TreeNodeCustom skl, Skeleton skeleton, FSKL RenderableSkeleton)
- {
- if (skeleton.MatrixToBoneList == null)
- skeleton.MatrixToBoneList = new List();
-
- RenderableSkeleton.Node_Array = new int[skeleton.MatrixToBoneList.Count];
- int nodes = 0;
- foreach (ushort node in skeleton.MatrixToBoneList)
- {
- RenderableSkeleton.Node_Array[nodes] = node;
- nodes++;
- }
-
- foreach (Bone bone in skeleton.Bones)
- {
- BfresBone STBone = new BfresBone(RenderableSkeleton);
- ReadBone(STBone, bone);
- RenderableSkeleton.bones.Add(STBone);
- }
- RenderableSkeleton.update();
- RenderableSkeleton.reset();
-
- // foreach (var bone in RenderableSkeleton.bones)
- // if (bone.Parent == null)
- // skl.Nodes.Add(bone);
-
- Runtime.abstractGlDrawables.Add(RenderableSkeleton);
- }
- public static void ReadBone(this BfresBone bone, Bone bn)
- {
- bone.Bone = bn;
- bone.Text = bn.Name;
- bone.BillboardIndex = bn.BillboardIndex;
- bone.parentIndex = bn.ParentIndex;
- bone.scale = new float[3];
- bone.rotation = new float[4];
- bone.position = new float[3];
- if (bn.FlagsRotation == BoneFlagsRotation.Quaternion)
- bone.boneRotationType = 1;
- else
- bone.boneRotationType = 0;
- bone.scale[0] = bn.Scale.X;
- bone.scale[1] = bn.Scale.Y;
- bone.scale[2] = bn.Scale.Z;
- bone.rotation[0] = bn.Rotation.X;
- bone.rotation[1] = bn.Rotation.Y;
- bone.rotation[2] = bn.Rotation.Z;
- bone.rotation[3] = bn.Rotation.W;
- bone.position[0] = bn.Position.X;
- bone.position[1] = bn.Position.Y;
- bone.position[2] = bn.Position.Z;
- }
- public static void SetShape(this FSHP s, Shape shp)
- {
- shp.Name = s.Text;
- shp.MaterialIndex = (ushort)s.MaterialIndex;
- shp.BoneIndex = (ushort)s.boneIndx;
- }
- public static void CreateNewMaterial(string Name)
- {
- FMAT mat = new FMAT();
- mat.Text = Name;
- mat.Material = new Material();
-
- SetMaterial(mat, mat.Material);
- }
- public static void SetMaterial(this FMAT m, Material mat)
- {
- mat.Name = m.Text;
-
- if (m.Enabled)
- mat.Flags = MaterialFlags.Visible;
- else
- mat.Flags = MaterialFlags.None;
-
- if (mat.ShaderParamData == null)
- mat.ShaderParamData = new byte[0];
-
- byte[] ParamData = WriteShaderParams(m, mat);
-
- if (ParamData.Length != mat.ShaderParamData.Length)
- throw new Exception("Param size mis match!");
- else
- mat.ShaderParamData = ParamData;
-
- WriteRenderInfo(m, mat);
- WriteTextureRefs(m, mat);
- WriteShaderAssign(m.shaderassign, mat);
- }
- public static void ReadMaterial(this FMAT m, Material mat)
- {
- if (mat.Flags == MaterialFlags.Visible)
- m.Enabled = true;
- else
- m.Enabled = false;
-
- m.ReadRenderInfo(mat);
- m.ReadShaderAssign(mat);
- m.SetActiveGame();
- m.ReadShaderParams(mat);
- m.Material = mat;
- m.ReadTextureRefs(mat);
- }
- public static void ReadTextureRefs(this FMAT m, Material mat)
- {
- m.TextureMaps.Clear();
-
- int AlbedoCount = 0;
- int id = 0;
- string TextureName = "";
- if (mat.TextureRefs == null)
- mat.TextureRefs = new List();
-
- foreach (string tex in mat.TextureRefs)
- {
- TextureName = tex;
-
- MatTexture texture = new MatTexture();
-
- texture.wrapModeS = (int)mat.Samplers[id].WrapModeU;
- texture.wrapModeT = (int)mat.Samplers[id].WrapModeV;
- texture.wrapModeW = (int)mat.Samplers[id].WrapModeW;
- texture.SamplerName = mat.SamplerDict.GetKey(id);
-
- bool IsAlbedo = Misc.HackyTextureList.Any(TextureName.Contains);
-
- if (Runtime.activeGame == Runtime.ActiveGame.MK8D)
- {
- if (texture.SamplerName == "_a0")
- {
- if (AlbedoCount == 0)
- {
- m.HasDiffuseMap = true;
- AlbedoCount++;
- texture.hash = 0;
- texture.Type = MatTexture.TextureType.Diffuse;
- }
- }
- if (texture.SamplerName == "_n0")
- {
- texture.hash = 1;
- m.HasNormalMap = true;
- texture.Type = MatTexture.TextureType.Normal;
- }
- if (texture.SamplerName == "_e0")
- {
- texture.hash = 8;
- m.HasEmissionMap = true;
- texture.Type = MatTexture.TextureType.Emission;
- }
- if (texture.SamplerName == "_s0")
- {
- texture.hash = 4;
- m.HasSpecularMap = true;
- texture.Type = MatTexture.TextureType.Specular;
- }
- if (texture.SamplerName == "_x0")
- {
- texture.hash = 6;
- m.HasSphereMap = true;
- texture.Type = MatTexture.TextureType.SphereMap;
- }
- if (texture.SamplerName == "_b0")
- {
- texture.hash = 2;
- m.HasShadowMap = true;
- texture.Type = MatTexture.TextureType.Shadow;
- }
- if (texture.SamplerName == "_b1")
- {
- texture.hash = 3;
- m.HasLightMap = true;
- texture.Type = MatTexture.TextureType.Light;
- }
- }
- else if (Runtime.activeGame == Runtime.ActiveGame.SMO)
- {
- if (texture.SamplerName == "_a0")
- {
- if (AlbedoCount == 0)
- {
- m.HasDiffuseMap = true;
- AlbedoCount++;
- texture.hash = 0;
- texture.Type = MatTexture.TextureType.Diffuse;
- }
- }
- if (texture.SamplerName == "_n0")
- {
- texture.hash = 1;
- m.HasNormalMap = true;
- texture.Type = MatTexture.TextureType.Normal;
- }
- if (texture.SamplerName == "_e0")
- {
- texture.hash = 8;
- m.HasEmissionMap = true;
- texture.Type = MatTexture.TextureType.Emission;
- }
- if (TextureName.Contains("mtl"))
- {
- texture.hash = 16;
- m.HasMetalnessMap = true;
- texture.Type = MatTexture.TextureType.Metalness;
- }
- else if (TextureName.Contains("rgh"))
- {
- texture.Type = MatTexture.TextureType.Roughness;
- texture.hash = 18;
- m.HasRoughnessMap = true;
- }
- else if (TextureName.Contains("sss"))
- {
-
- texture.Type = MatTexture.TextureType.SubSurfaceScattering;
- texture.hash = 19;
- m.HasSubSurfaceScatteringMap = true;
- }
- }
- else
- {
- //This works decently for now. I tried samplers but Kirby Star Allies doesn't map with samplers properly?
- if (IsAlbedo)
- {
- if (AlbedoCount == 0)
- {
- m.HasDiffuseMap = true;
- AlbedoCount++;
- texture.hash = 0;
- texture.Type = MatTexture.TextureType.Diffuse;
- }
- if (AlbedoCount == 1)
- {
- // poly.material.HasDiffuseLayer = true;
- // texture.hash = 19;
- // texture.Type = MatTexture.TextureType.DiffuseLayer2;
-
- }
- }
-
- else if (TextureName.Contains("Nrm") || TextureName.Contains("Norm") || TextureName.Contains("norm") || TextureName.Contains("nrm"))
- {
- texture.hash = 1;
- m.HasNormalMap = true;
- texture.Type = MatTexture.TextureType.Normal;
- }
- else if (TextureName.Contains("Emm"))
- {
- texture.hash = 8;
- m.HasEmissionMap = true;
- texture.Type = MatTexture.TextureType.Emission;
- }
- else if (TextureName.Contains("Spm"))
- {
- texture.hash = 4;
- m.HasSpecularMap = true;
- texture.Type = MatTexture.TextureType.Specular;
- }
- else if (TextureName.Contains("b00"))
- {
- texture.hash = 2;
- m.HasShadowMap = true;
- texture.Type = MatTexture.TextureType.Shadow;
- }
- else if (TextureName.Contains("Moc") || TextureName.Contains("AO"))
- {
- texture.hash = 2;
- m.HasAmbientOcclusionMap = true;
- texture.Type = MatTexture.TextureType.AO;
- }
- else if (TextureName.Contains("b01"))
- {
- texture.hash = 3;
- m.HasLightMap = true;
- texture.Type = MatTexture.TextureType.Light;
- }
- else if (TextureName.Contains("MRA")) //Metalness, Roughness, and Cavity Map in one
- {
- texture.hash = 17;
- m.HasRoughnessMap = true;
- texture.Type = MatTexture.TextureType.MRA;
- }
- else if (TextureName.Contains("mtl"))
- {
- texture.hash = 16;
- m.HasMetalnessMap = true;
- texture.Type = MatTexture.TextureType.Metalness;
- }
- else if (TextureName.Contains("rgh"))
- {
- texture.Type = MatTexture.TextureType.Roughness;
- texture.hash = 18;
- m.HasRoughnessMap = true;
- }
- else if (TextureName.Contains("sss"))
- {
-
- texture.Type = MatTexture.TextureType.SubSurfaceScattering;
- texture.hash = 19;
- m.HasSubSurfaceScatteringMap = true;
- }
- }
-
- texture.Name = TextureName;
-
- m.TextureMaps.Add(texture);
-
- id++;
- }
- }
- public static void ReadShaderParams(this FMAT m, Material mat)
- {
- m.matparam.Clear();
-
- if (mat.ShaderParamData == null)
- return;
-
- using (FileReader reader = new FileReader(new System.IO.MemoryStream(mat.ShaderParamData)))
- {
- reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;
- foreach (ShaderParam param in mat.ShaderParams)
- {
- BfresShaderParam shaderParam = new BfresShaderParam();
- shaderParam.Type = param.Type;
- shaderParam.Name = param.Name;
-
- reader.Seek(param.DataOffset, System.IO.SeekOrigin.Begin);
- shaderParam.ReadValue(reader, (int)param.DataSize);
-
- m.matparam.Add(param.Name, shaderParam);
- }
- reader.Close();
- }
- }
- public static byte[] WriteShaderParams(this FMAT m, Material mat)
- {
- mat.ShaderParams = new List();
-
- System.IO.MemoryStream mem = new System.IO.MemoryStream();
- using (FileWriter writer = new FileWriter(mem))
- {
- uint Offset = 0;
- int index = 0;
- writer.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;
- foreach (BfresShaderParam shaderParam in m.matparam.Values)
- {
- ShaderParam param = new ShaderParam();
- param.Name = shaderParam.Name;
- param.Type = shaderParam.Type;
- param.DataOffset = (ushort)Offset;
- param.DependedIndex = (ushort)index;
- param.DependIndex = (ushort)index;
-
- writer.Seek(param.DataOffset, System.IO.SeekOrigin.Begin);
- shaderParam.WriteValue(writer);
-
- Offset += param.DataSize;
- mat.ShaderParams.Add(param);
- index++;
- }
- writer.Close();
- }
- return mem.ToArray();
- }
- public static void ReadRenderInfo(this FMAT m, Material mat)
- {
- m.renderinfo.Clear();
-
- foreach (RenderInfo rnd in mat.RenderInfos)
- {
- BfresRenderInfo r = new BfresRenderInfo();
- r.Name = rnd.Name;
- r.Type = rnd.Type;
- switch (rnd.Type)
- {
- case RenderInfoType.Int32: r.ValueInt = rnd.GetValueInt32s(); break;
- case RenderInfoType.Single: r.ValueFloat = rnd.GetValueSingles(); break;
- case RenderInfoType.String: r.ValueString = rnd.GetValueStrings(); break;
- }
- m.renderinfo.Add(r);
- }
- }
- public static void WriteTextureRefs(this FMAT m, Material mat)
- {
- mat.TextureRefs = new List();
- mat.TextureRefs.Clear();
-
- foreach (var textu in m.TextureMaps)
- mat.TextureRefs.Add(textu.Name);
-
- }
- public static void WriteRenderInfo(this FMAT m, Material mat)
- {
- if (mat.RenderInfos == null)
- mat.RenderInfos = new List();
-
- mat.RenderInfos.Clear();
- foreach (BfresRenderInfo rnd in m.renderinfo)
- {
- RenderInfo r = new RenderInfo();
- r.Name = rnd.Name;
- switch (rnd.Type)
- {
- case RenderInfoType.Int32: r.SetValue(rnd.ValueInt); break;
- case RenderInfoType.Single: r.SetValue(rnd.ValueFloat); break;
- case RenderInfoType.String: r.SetValue(rnd.ValueString); break;
- }
- mat.RenderInfos.Add(r);
- }
- }
- public static void ReadShaderAssign(this FMAT m, Material mat)
- {
- m.shaderassign = new FMAT.ShaderAssign();
-
- if (mat.ShaderAssign == null)
- mat.ShaderAssign = new ShaderAssign();
- if (mat.ShaderAssign.ShaderOptions == null)
- mat.ShaderAssign.ShaderOptions = new List();
- if (mat.ShaderAssign.AttribAssigns == null)
- mat.ShaderAssign.AttribAssigns = new List();
- if (mat.ShaderAssign.SamplerAssigns == null)
- mat.ShaderAssign.SamplerAssigns = new List();
-
- m.shaderassign.options.Clear();
- m.shaderassign.samplers.Clear();
- m.shaderassign.attributes.Clear();
-
- m.shaderassign = new FMAT.ShaderAssign();
- m.shaderassign.ShaderArchive = mat.ShaderAssign.ShaderArchiveName;
- m.shaderassign.ShaderModel = mat.ShaderAssign.ShadingModelName;
-
- for (int op = 0; op < mat.ShaderAssign.ShaderOptions.Count; op++)
- m.shaderassign.options.Add(mat.ShaderAssign.ShaderOptionDict.GetKey(op), mat.ShaderAssign.ShaderOptions[op]);
-
- if (mat.ShaderAssign.SamplerAssigns != null)
- {
- for (int op = 0; op < mat.ShaderAssign.SamplerAssigns.Count; op++)
- m.shaderassign.samplers.Add(mat.ShaderAssign.SamplerAssignDict.GetKey(op), mat.ShaderAssign.SamplerAssigns[op]);
- }
- if (mat.ShaderAssign.AttribAssigns != null)
- {
- for (int op = 0; op < mat.ShaderAssign.AttribAssigns.Count; op++)
- m.shaderassign.attributes.Add(mat.ShaderAssign.AttribAssignDict.GetKey(op), mat.ShaderAssign.AttribAssigns[op]);
- }
-
-
-
-
-
- }
- public static void WriteShaderAssign(this FMAT.ShaderAssign shd, Material mat)
- {
- mat.ShaderAssign = new ShaderAssign();
- mat.ShaderAssign.ShaderOptionDict = new ResDict();
- mat.ShaderAssign.SamplerAssignDict = new ResDict();
- mat.ShaderAssign.AttribAssignDict = new ResDict();
- mat.ShaderAssign.ShaderOptions = new List();
- mat.ShaderAssign.AttribAssigns = new List();
- mat.ShaderAssign.SamplerAssigns = new List();
-
- mat.ShaderAssign.ShaderArchiveName = shd.ShaderArchive;
- mat.ShaderAssign.ShadingModelName = shd.ShaderModel;
-
- foreach (var option in shd.options)
- {
- mat.ShaderAssign.ShaderOptionDict.Add(option.Key);
- mat.ShaderAssign.ShaderOptions.Add(option.Value);
- }
- foreach (var samp in shd.samplers)
- {
- mat.ShaderAssign.SamplerAssignDict.Add(samp.Key);
- mat.ShaderAssign.SamplerAssigns.Add(samp.Value);
- }
- foreach (var att in shd.attributes)
- {
- mat.ShaderAssign.AttribAssignDict.Add(att.Key);
- mat.ShaderAssign.AttribAssigns.Add(att.Value);
- }
- }
- public static void WriteExternalFiles(ResFile resFile, TreeNode EditorRoot)
- {
- resFile.ExternalFiles.Clear();
- if (EditorRoot.Nodes.ContainsKey("EXT"))
- {
- foreach (TreeNode node in EditorRoot.Nodes["EXT"].Nodes)
- {
- ExternalFile ext = new ExternalFile();
- if (node is BNTX)
- ext.Data = ((BNTX)node).Save();
- else if (node is BfshaFileData)
- ext.Data = ((BfshaFileData)node).Data;
- else
- ext.Data = ((ExternalFileData)node).Data;
-
- resFile.ExternalFiles.Add(ext);
- }
- }
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/BfresWiiU.cs b/Switch_FileFormatsMain/FileFormats/BFRES/BfresWiiU.cs
deleted file mode 100644
index 24d65399..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFRES/BfresWiiU.cs
+++ /dev/null
@@ -1,938 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Syroot.NintenTools.Bfres;
-using Syroot.NintenTools.Bfres.Helpers;
-using Syroot.NintenTools.Bfres.GX2;
-using System.Windows.Forms;
-using Bfres.Structs;
-using Switch_Toolbox.Library.IO;
-using Switch_Toolbox.Library;
-using Switch_Toolbox.Library.Rendering;
-using OpenTK;
-using ResNSW = Syroot.NintenTools.NSW.Bfres;
-
-
-namespace FirstPlugin
-{
- public static class BfresWiiU
- {
- public static Model SetModel(FMDL fmdl)
- {
- Model model = new Model();
- model.Name = fmdl.Text;
- model.Path = "";
- model.Shapes = new ResDict();
- model.VertexBuffers = new List();
- model.Materials = new ResDict();
- model.UserData = new ResDict();
- model.Skeleton = new Skeleton();
- model.Skeleton = fmdl.Skeleton.node.SkeletonU;
-
- int i = 0;
- var duplicates = fmdl.shapes.GroupBy(c => c.Text).Where(g => g.Skip(1).Any()).SelectMany(c => c);
- foreach (var shape in duplicates)
- shape.Text += i++;
-
- foreach (FSHP shape in fmdl.shapes)
- {
- BFRES.CheckMissingTextures(shape);
- SetShape(shape, shape.ShapeU);
- model.Shapes.Add(shape.Text, shape.ShapeU);
- model.VertexBuffers.Add(shape.VertexBufferU);
- shape.ShapeU.VertexBufferIndex = (ushort)(model.VertexBuffers.Count - 1);
-
- // BFRES.SetShaderAssignAttributes(shape.GetMaterial().shaderassign, shape);
- }
-
- foreach (FMAT mat in fmdl.materials.Values)
- {
- SetMaterial(mat, mat.MaterialU);
- model.Materials.Add(mat.Text, mat.MaterialU);
- }
- return model;
- }
- public static void Read(BFRESRender renderer, ResFile resFile, TreeNode ResFileNode)
- {
- int CurMdl = 0;
- foreach (Model mdl in resFile.Models.Values)
- {
- FMDL model = new FMDL();
- model.Text = mdl.Name;
- model.Skeleton = new FSKL(mdl.Skeleton);
- model.Nodes.Add(model.Skeleton.node);
- model.Skeleton.reset();
- model.Skeleton.update();
- model.Skeleton.node.BFRESRender = renderer;
- model.ModelU = mdl;
- foreach (Material mat in mdl.Materials.Values)
- {
- FMAT FMAT = new FMAT();
- FMAT.Text = mat.Name;
- FMAT.ReadMaterial(mat);
- model.Nodes[1].Nodes.Add(FMAT);
- model.materials.Add(FMAT.Text, FMAT);
- }
- foreach (Shape shp in mdl.Shapes.Values)
- {
- VertexBuffer vertexBuffer = mdl.VertexBuffers[shp.VertexBufferIndex];
- Material material = mdl.Materials[shp.MaterialIndex];
- FSHP mesh = new FSHP();
- mesh.ModelIndex = CurMdl;
- ReadShapesVertices(mesh, shp, vertexBuffer, model);
- mesh.MaterialIndex = shp.MaterialIndex;
-
- model.Nodes[0].Nodes.Add(mesh);
- model.shapes.Add(mesh);
- }
- ResFileNode.Nodes[0].Nodes.Add(model);
- renderer.models.Add(model);
-
- CurMdl++;
- }
- }
-
- public static void ReadShapesVertices(FSHP fshp, Shape shp, VertexBuffer vertexBuffer, FMDL model)
- {
- fshp.boundingBoxes.Clear();
- fshp.boundingRadius.Clear();
- fshp.BoneIndices.Clear();
-
- foreach (Bounding bnd in shp.SubMeshBoundings)
- {
- FSHP.BoundingBox box = new FSHP.BoundingBox();
- box.Center = new Vector3(bnd.Center.X, bnd.Center.Y, bnd.Center.Z);
- box.Extend = new Vector3(bnd.Extent.X, bnd.Extent.Y, bnd.Extent.Z);
- fshp.boundingBoxes.Add(box);
- }
- foreach (float rad in shp.RadiusArray)
- {
- fshp.boundingRadius.Add(rad);
- }
-
- fshp.VertexBufferIndex = shp.VertexBufferIndex;
- fshp.ShapeU = shp;
- fshp.VertexBufferU = vertexBuffer;
- fshp.VertexSkinCount = shp.VertexSkinCount;
- fshp.boneIndx = shp.BoneIndex;
- fshp.Text = shp.Name;
- fshp.TargetAttribCount = shp.TargetAttribCount;
- fshp.MaterialIndex = shp.MaterialIndex;
-
- if (shp.SkinBoneIndices != null)
- {
- foreach (ushort bn in shp.SkinBoneIndices)
- fshp.BoneIndices.Add(bn);
- }
-
- ReadMeshes(fshp, shp);
- ReadVertexBuffer(fshp, vertexBuffer, model);
- }
- private static void ReadMeshes(FSHP fshp, Shape shp)
- {
- fshp.lodMeshes.Clear();
-
- foreach (Mesh msh in shp.Meshes)
- {
- uint FaceCount = msh.IndexCount;
- uint[] indicesArray = msh.GetIndices().ToArray();
-
- FSHP.LOD_Mesh lod = new FSHP.LOD_Mesh();
- foreach (SubMesh subMsh in msh.SubMeshes)
- {
- FSHP.LOD_Mesh.SubMesh sub = new FSHP.LOD_Mesh.SubMesh();
- sub.size = subMsh.Count;
- sub.offset = subMsh.Offset;
- lod.subMeshes.Add(sub);
- }
- lod.IndexFormat = (STIndexFormat)msh.IndexFormat;
- lod.PrimitiveType = (STPolygonType)msh.PrimitiveType;
- lod.FirstVertex = msh.FirstVertex;
-
- for (int face = 0; face < FaceCount; face++)
- lod.faces.Add((int)indicesArray[face] + (int)msh.FirstVertex);
-
- fshp.lodMeshes.Add(lod);
- }
- }
- private static void ReadVertexBuffer(FSHP fshp, VertexBuffer vtx, FMDL model)
- {
- fshp.vertices.Clear();
- fshp.vertexAttributes.Clear();
-
- //Create a buffer instance which stores all the buffer data
- VertexBufferHelper helper = new VertexBufferHelper(vtx, Syroot.BinaryData.ByteOrder.BigEndian);
-
- //Set each array first from the lib if exist. Then add the data all in one loop
- Syroot.Maths.Vector4F[] vec4Positions = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4Normals = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4uv0 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4uv1 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4uv2 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4c0 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4t0 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4b0 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4w0 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4i0 = new Syroot.Maths.Vector4F[0];
-
- //For shape morphing
- Syroot.Maths.Vector4F[] vec4Positions1 = new Syroot.Maths.Vector4F[0];
- Syroot.Maths.Vector4F[] vec4Positions2 = new Syroot.Maths.Vector4F[0];
-
- foreach (VertexAttrib att in vtx.Attributes.Values)
- {
- FSHP.VertexAttribute attr = new FSHP.VertexAttribute();
- attr.Name = att.Name;
- attr.Format = attr.GetTypeWiiU(att.Format);
-
- if (att.Name == "_p0")
- vec4Positions = AttributeData(att, helper, "_p0");
- if (att.Name == "_n0")
- vec4Normals = AttributeData(att, helper, "_n0");
- if (att.Name == "_u0")
- vec4uv0 = AttributeData(att, helper, "_u0");
- if (att.Name == "_u1")
- vec4uv1 = AttributeData(att, helper, "_u1");
- if (att.Name == "_u2")
- vec4uv2 = AttributeData(att, helper, "_u2");
- if (att.Name == "_c0")
- vec4c0 = AttributeData(att, helper, "_c0");
- if (att.Name == "_t0")
- vec4t0 = AttributeData(att, helper, "_t0");
- if (att.Name == "_b0")
- vec4b0 = AttributeData(att, helper, "_b0");
- if (att.Name == "_w0")
- vec4w0 = AttributeData(att, helper, "_w0");
- if (att.Name == "_i0")
- vec4i0 = AttributeData(att, helper, "_i0");
-
- if (att.Name == "_p1")
- vec4Positions1 = AttributeData(att, helper, "_p1");
- if (att.Name == "_p2")
- vec4Positions2 = AttributeData(att, helper, "_p2");
-
- fshp.vertexAttributes.Add(attr);
- }
- for (int i = 0; i < vec4Positions.Length; i++)
- {
- Vertex v = new Vertex();
- if (vec4Positions.Length > 0)
- v.pos = new Vector3(vec4Positions[i].X, vec4Positions[i].Y, vec4Positions[i].Z);
- if (vec4Positions1.Length > 0)
- v.pos1 = new Vector3(vec4Positions1[i].X, vec4Positions1[i].Y, vec4Positions1[i].Z);
- if (vec4Positions2.Length > 0)
- v.pos2 = new Vector3(vec4Positions2[i].X, vec4Positions2[i].Y, vec4Positions2[i].Z);
- if (vec4Normals.Length > 0)
- v.nrm = new Vector3(vec4Normals[i].X, vec4Normals[i].Y, vec4Normals[i].Z);
- if (vec4uv0.Length > 0)
- v.uv0 = new Vector2(vec4uv0[i].X, vec4uv0[i].Y);
- if (vec4uv1.Length > 0)
- v.uv1 = new Vector2(vec4uv1[i].X, vec4uv1[i].Y);
- if (vec4uv2.Length > 0)
- v.uv2 = new Vector2(vec4uv2[i].X, vec4uv2[i].Y);
- if (vec4w0.Length > 0)
- {
- v.boneWeights.Add(vec4w0[i].X);
- v.boneWeights.Add(vec4w0[i].Y);
- v.boneWeights.Add(vec4w0[i].Z);
- v.boneWeights.Add(vec4w0[i].W);
- }
- if (vec4i0.Length > 0)
- {
- v.boneIds.Add((int)vec4i0[i].X);
- v.boneIds.Add((int)vec4i0[i].Y);
- v.boneIds.Add((int)vec4i0[i].Z);
- v.boneIds.Add((int)vec4i0[i].W);
- }
-
- if (vec4t0.Length > 0)
- v.tan = new Vector4(vec4t0[i].X, vec4t0[i].Y, vec4t0[i].Z, vec4t0[i].W);
- if (vec4b0.Length > 0)
- v.bitan = new Vector4(vec4b0[i].X, vec4b0[i].Y, vec4b0[i].Z, vec4b0[i].W);
- if (vec4c0.Length > 0)
- v.col = new Vector4(vec4c0[i].X, vec4c0[i].Y, vec4c0[i].Z, vec4c0[i].W);
-
- if (fshp.VertexSkinCount == 1)
- {
- // Matrix4 sb = model.Skeleton.bones[model.Skeleton.Node_Array[v.boneIds[0]]].transform;
- // v.pos = Vector3.TransformPosition(v.pos, sb);
- // v.nrm = Vector3.TransformNormal(v.nrm, sb);
- }
- if (fshp.VertexSkinCount == 0)
- {
- // Matrix4 NoBindFix = model.Skeleton.bones[fshp.boneIndx].transform;
- // v.pos = Vector3.TransformPosition(v.pos, NoBindFix);
- // v.nrm = Vector3.TransformNormal(v.nrm, NoBindFix);
- }
- fshp.vertices.Add(v);
- }
- }
- private static Syroot.Maths.Vector4F[] AttributeData(VertexAttrib att, VertexBufferHelper helper, string attName)
- {
- VertexBufferHelperAttrib attd = helper[attName];
- return attd.Data;
- }
-
- public static void SetSkeleton(this TreeNodeCustom skl, Skeleton skeleton, FSKL RenderableSkeleton)
- {
- if (skeleton.MatrixToBoneList == null)
- skeleton.MatrixToBoneList = new List();
-
- RenderableSkeleton.Node_Array = new int[skeleton.MatrixToBoneList.Count];
- int nodes = 0;
- foreach (ushort node in skeleton.MatrixToBoneList)
- {
- RenderableSkeleton.Node_Array[nodes] = node;
- nodes++;
- }
- for (int i = 0; i < skeleton.Bones.Count; i++)
- {
- if (skeleton.InverseModelMatrices == null)
- break;
-
- if (i < skeleton.InverseModelMatrices.Count)
- RenderableSkeleton.matrices.Add(Utils.ToMat3x4(skeleton.InverseModelMatrices[i]));
- else
- RenderableSkeleton.matrices.Add(Matrix3x4.Zero);
- }
- foreach (Bone bone in skeleton.Bones.Values)
- {
- BfresBone STBone = new BfresBone(RenderableSkeleton);
- SetBone(STBone, bone);
- STBone.BFRESRender = RenderableSkeleton.node.BFRESRender; //to update viewport on bone edits
- RenderableSkeleton.bones.Add(STBone);
-
- if (bone.InverseMatrix != null)
- RenderableSkeleton.matrices.Add(Utils.ToMat3x4(bone.InverseMatrix));
- }
- RenderableSkeleton.update();
- RenderableSkeleton.reset();
-
- // foreach (var bone in RenderableSkeleton.bones)
- // if (bone.Parent == null)
- // skl.Nodes.Add(bone);
-
- Runtime.abstractGlDrawables.Add(RenderableSkeleton);
- }
- public static void SetBone(this BfresBone bone, Bone bn)
- {
- bone.BoneU = bn;
- bone.Text = bn.Name;
- bone.BillboardIndex = bn.BillboardIndex;
- bone.parentIndex = bn.ParentIndex;
- bone.scale = new float[3];
- bone.rotation = new float[4];
- bone.position = new float[3];
- if (bn.FlagsRotation == BoneFlagsRotation.Quaternion)
- bone.boneRotationType = 1;
- else
- bone.boneRotationType = 0;
- bone.scale[0] = bn.Scale.X;
- bone.scale[1] = bn.Scale.Y;
- bone.scale[2] = bn.Scale.Z;
- bone.rotation[0] = bn.Rotation.X;
- bone.rotation[1] = bn.Rotation.Y;
- bone.rotation[2] = bn.Rotation.Z;
- bone.rotation[3] = bn.Rotation.W;
- bone.position[0] = bn.Position.X;
- bone.position[1] = bn.Position.Y;
- bone.position[2] = bn.Position.Z;
- }
- public static void SetShape(this FSHP s, Shape shp)
- {
- shp.Name = s.Text;
- shp.MaterialIndex = (ushort)s.MaterialIndex;
- }
- public static void CreateNewMaterial(string Name)
- {
- FMAT mat = new FMAT();
- mat.Text = Name;
- mat.MaterialU = new Material();
-
- SetMaterial(mat, mat.MaterialU);
- }
- public static void SetMaterial(this FMAT m, Material mat)
- {
- mat.Name = m.Text;
-
- if (m.Enabled)
- mat.Flags = MaterialFlags.Visible;
- else
- mat.Flags = MaterialFlags.None;
-
- if (mat.ShaderParamData == null)
- mat.ShaderParamData = new byte[0];
-
- byte[] ParamData = WriteShaderParams(m, mat);
-
- if (ParamData.Length != mat.ShaderParamData.Length)
- throw new Exception("Param size mis match!");
- else
- mat.ShaderParamData = ParamData;
-
- WriteRenderInfo(m, mat);
- WriteTextureRefs(m, mat);
- WriteShaderAssign(m.shaderassign, mat);
- }
- public static void ReadMaterial(this FMAT m, Material mat)
- {
- if (mat.Flags == MaterialFlags.Visible)
- m.Enabled = true;
- else
- m.Enabled = false;
-
- m.ReadRenderInfo(mat);
- m.ReadShaderAssign(mat);
- m.SetActiveGame();
- m.ReadShaderParams(mat);
- m.MaterialU = mat;
- m.ReadTextureRefs(mat);
- m.ReadRenderState(mat.RenderState);
- }
- public static void ReadRenderState(this FMAT m, RenderState renderState)
- {
-
- }
- public static void ReadTextureRefs(this FMAT m, Material mat)
- {
- m.TextureMaps.Clear();
-
- int AlbedoCount = 0;
- int id = 0;
- string TextureName = "";
- if (mat.TextureRefs == null)
- mat.TextureRefs = new List();
-
- foreach (var tex in mat.TextureRefs)
- {
- TextureName = tex.Name;
-
- MatTexture texture = new MatTexture();
-
- texture.wrapModeS = (int)mat.Samplers[id].TexSampler.ClampX;
- texture.wrapModeT = (int)mat.Samplers[id].TexSampler.ClampY;
- texture.wrapModeW = (int)mat.Samplers[id].TexSampler.ClampZ;
- mat.Samplers.TryGetKey(mat.Samplers[id], out texture.SamplerName);
-
- if (mat.Samplers[id].TexSampler.MinFilter == GX2TexXYFilterType.Bilinear)
- {
- texture.magFilter = 0;
- }
- if (mat.Samplers[id].TexSampler.MagFilter == GX2TexXYFilterType.Bilinear)
- {
-
- }
- if (Runtime.activeGame == Runtime.ActiveGame.MK8D)
- {
- if (texture.SamplerName == "_a0")
- {
- if (AlbedoCount == 0)
- {
- m.HasDiffuseMap = true;
- AlbedoCount++;
- texture.hash = 0;
- texture.Type = MatTexture.TextureType.Diffuse;
- }
- }
- if (texture.SamplerName == "_n0")
- {
- texture.hash = 1;
- m.HasNormalMap = true;
- texture.Type = MatTexture.TextureType.Normal;
- }
- if (texture.SamplerName == "_e0")
- {
- texture.hash = 8;
- m.HasEmissionMap = true;
- texture.Type = MatTexture.TextureType.Emission;
- }
- if (texture.SamplerName == "_s0")
- {
- texture.hash = 4;
- m.HasSpecularMap = true;
- texture.Type = MatTexture.TextureType.Specular;
- }
- if (texture.SamplerName == "_x0")
- {
- texture.hash = 6;
- m.HasSphereMap = true;
- texture.Type = MatTexture.TextureType.SphereMap;
- }
- if (texture.SamplerName == "_b0")
- {
- texture.hash = 2;
- m.HasShadowMap = true;
- texture.Type = MatTexture.TextureType.Shadow;
- }
- if (texture.SamplerName == "_b1")
- {
- texture.hash = 3;
- m.HasLightMap = true;
- texture.Type = MatTexture.TextureType.Light;
- }
- }
- else if (Runtime.activeGame == Runtime.ActiveGame.SMO)
- {
- if (texture.SamplerName == "_a0")
- {
- if (AlbedoCount == 0)
- {
- m.HasDiffuseMap = true;
- AlbedoCount++;
- texture.hash = 0;
- texture.Type = MatTexture.TextureType.Diffuse;
- }
- }
- if (texture.SamplerName == "_n0")
- {
- texture.hash = 1;
- m.HasNormalMap = true;
- texture.Type = MatTexture.TextureType.Normal;
- }
- if (texture.SamplerName == "_e0")
- {
- texture.hash = 8;
- m.HasEmissionMap = true;
- texture.Type = MatTexture.TextureType.Emission;
- }
- if (TextureName.Contains("mtl"))
- {
- texture.hash = 16;
- m.HasMetalnessMap = true;
- texture.Type = MatTexture.TextureType.Metalness;
- }
- else if (TextureName.Contains("rgh"))
- {
- texture.Type = MatTexture.TextureType.Roughness;
- texture.hash = 18;
- m.HasRoughnessMap = true;
- }
- else if (TextureName.Contains("sss"))
- {
-
- texture.Type = MatTexture.TextureType.SubSurfaceScattering;
- texture.hash = 19;
- m.HasSubSurfaceScatteringMap = true;
- }
- }
- else
- {
- if (texture.SamplerName == "_a0")
- {
- m.HasDiffuseMap = true;
- AlbedoCount++;
- texture.hash = 0;
- texture.Type = MatTexture.TextureType.Diffuse;
- }
- if (texture.SamplerName == "_n0")
- {
- texture.hash = 1;
- m.HasNormalMap = true;
- texture.Type = MatTexture.TextureType.Normal;
- }
- else if (TextureName.Contains("Emm"))
- {
- texture.hash = 8;
- m.HasEmissionMap = true;
- texture.Type = MatTexture.TextureType.Emission;
- }
- else if (TextureName.Contains("Spm"))
- {
- texture.hash = 4;
- m.HasSpecularMap = true;
- texture.Type = MatTexture.TextureType.Specular;
- }
- else if (TextureName.Contains("b00"))
- {
- texture.hash = 2;
- m.HasShadowMap = true;
- texture.Type = MatTexture.TextureType.Shadow;
- }
- else if (TextureName.Contains("Moc") || TextureName.Contains("AO"))
- {
- texture.hash = 2;
- m.HasAmbientOcclusionMap = true;
- texture.Type = MatTexture.TextureType.AO;
- }
- else if (TextureName.Contains("b01"))
- {
- texture.hash = 3;
- m.HasLightMap = true;
- texture.Type = MatTexture.TextureType.Light;
- }
- else if (TextureName.Contains("MRA")) //Metalness, Roughness, and Cavity Map in one
- {
- texture.hash = 17;
- m.HasRoughnessMap = true;
- texture.Type = MatTexture.TextureType.MRA;
- }
- else if (TextureName.Contains("mtl"))
- {
- texture.hash = 16;
- m.HasMetalnessMap = true;
- texture.Type = MatTexture.TextureType.Metalness;
- }
- else if (TextureName.Contains("rgh"))
- {
- texture.Type = MatTexture.TextureType.Roughness;
- texture.hash = 18;
- m.HasRoughnessMap = true;
- }
- else if (TextureName.Contains("sss"))
- {
- texture.Type = MatTexture.TextureType.SubSurfaceScattering;
- texture.hash = 19;
- m.HasSubSurfaceScatteringMap = true;
- }
- }
- texture.Name = TextureName;
- m.TextureMaps.Add(texture);
-
- id++;
- }
- }
- public static void ReadShaderParams(this FMAT m, Material mat)
- {
- m.matparam.Clear();
-
- if (mat.ShaderParamData == null)
- return;
-
- using (FileReader reader = new FileReader(new System.IO.MemoryStream(mat.ShaderParamData)))
- {
- reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
- foreach (ShaderParam param in mat.ShaderParams.Values)
- {
- BfresShaderParam shaderParam = new BfresShaderParam();
- shaderParam.Type = shaderParam.GetTypeWiiU(param.Type);
- shaderParam.Name = param.Name;
-
- reader.Seek(param.DataOffset, System.IO.SeekOrigin.Begin);
- Console.WriteLine(shaderParam.Name + " " + shaderParam.Type);
- shaderParam.ReadValue(reader, (int)param.DataSize);
-
- m.matparam.Add(param.Name, shaderParam);
- }
- reader.Close();
- }
- }
- public static byte[] WriteShaderParams(this FMAT m, Material mat)
- {
- mat.ShaderParams = new ResDict();
-
- System.IO.MemoryStream mem = new System.IO.MemoryStream();
- using (FileWriter writer = new FileWriter(mem))
- {
- uint Offset = 0;
- int index = 0;
- writer.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
- foreach (BfresShaderParam shaderParam in m.matparam.Values)
- {
- ShaderParam param = new ShaderParam();
- param.Name = shaderParam.Name;
- param.Type = shaderParam.SetTypeWiiU(shaderParam.Type);
- param.DataOffset = (ushort)Offset;
- param.DependedIndex = (ushort)index;
- param.DependIndex = (ushort)index;
-
- writer.Seek(param.DataOffset, System.IO.SeekOrigin.Begin);
- shaderParam.WriteValue(writer);
-
- Offset += param.DataSize;
- mat.ShaderParams.Add(param.Name, param);
- index++;
- }
- writer.Close();
- }
- return mem.ToArray();
- }
- public static void ReadRenderInfo(this FMAT m, Material mat)
- {
- m.renderinfo.Clear();
-
- foreach (RenderInfo rnd in mat.RenderInfos.Values)
- {
- BfresRenderInfo r = new BfresRenderInfo();
- r.Name = rnd.Name;
- r.Type = r.GetTypeWiiU(rnd.Type);
- switch (rnd.Type)
- {
- case RenderInfoType.Int32: r.ValueInt = rnd.GetValueInt32s(); break;
- case RenderInfoType.Single: r.ValueFloat = rnd.GetValueSingles(); break;
- case RenderInfoType.String: r.ValueString = rnd.GetValueStrings(); break;
- }
- m.renderinfo.Add(r);
- }
- }
- public static void WriteTextureRefs(this FMAT m, Material mat)
- {
- mat.TextureRefs = new List();
- mat.TextureRefs.Clear();
-
- foreach (var textu in m.TextureMaps)
- {
- TextureRef texref = new TextureRef();
- texref.Name = textu.Name;
- Texture texMapped = new Texture();
- m.GetResFileU().Textures.TryGetValue(textu.Name, out texMapped);
- texref.Texture = texMapped;
- mat.TextureRefs.Add(texref);
- }
- }
- public static void WriteRenderInfo(this FMAT m, Material mat)
- {
- if (mat.RenderInfos == null)
- mat.RenderInfos = new ResDict();
-
- mat.RenderInfos.Clear();
- foreach (BfresRenderInfo rnd in m.renderinfo)
- {
- RenderInfo r = new RenderInfo();
- r.Name = rnd.Name;
-
- switch (rnd.Type)
- {
- case ResNSW.RenderInfoType.Int32: r.SetValue(rnd.ValueInt); break;
- case ResNSW.RenderInfoType.Single: r.SetValue(rnd.ValueFloat); break;
- case ResNSW.RenderInfoType.String: r.SetValue(rnd.ValueString); break;
- }
- mat.RenderInfos.Add(r.Name, r);
- }
- }
- public static void ReadShaderAssign(this FMAT m, Material mat)
- {
- m.shaderassign = new FMAT.ShaderAssign();
-
- if (mat.ShaderAssign == null)
- mat.ShaderAssign = new ShaderAssign();
- if (mat.ShaderAssign.ShaderOptions == null)
- mat.ShaderAssign.ShaderOptions = new ResDict();
- if (mat.ShaderAssign.AttribAssigns == null)
- mat.ShaderAssign.AttribAssigns = new ResDict();
- if (mat.ShaderAssign.SamplerAssigns == null)
- mat.ShaderAssign.SamplerAssigns = new ResDict();
-
- m.shaderassign.options.Clear();
- m.shaderassign.samplers.Clear();
- m.shaderassign.attributes.Clear();
-
- m.shaderassign = new FMAT.ShaderAssign();
- m.shaderassign.ShaderArchive = mat.ShaderAssign.ShaderArchiveName;
- m.shaderassign.ShaderModel = mat.ShaderAssign.ShadingModelName;
-
- foreach (var op in mat.ShaderAssign.ShaderOptions)
- m.shaderassign.options.Add(op.Key, op.Value);
-
- if (mat.ShaderAssign.SamplerAssigns != null)
- {
- foreach (var op in mat.ShaderAssign.SamplerAssigns)
- m.shaderassign.samplers.Add(op.Key, op.Value);
- }
- if (mat.ShaderAssign.AttribAssigns != null)
- {
- foreach (var op in mat.ShaderAssign.AttribAssigns)
- m.shaderassign.attributes.Add(op.Key, op.Value);
- }
- }
- public static void WriteShaderAssign(this FMAT.ShaderAssign shd, Material mat)
- {
- mat.ShaderAssign = new ShaderAssign();
- mat.ShaderAssign.ShaderOptions = new ResDict();
- mat.ShaderAssign.AttribAssigns = new ResDict();
- mat.ShaderAssign.SamplerAssigns = new ResDict();
-
- mat.ShaderAssign.ShaderArchiveName = shd.ShaderArchive;
- mat.ShaderAssign.ShadingModelName = shd.ShaderModel;
- foreach (var option in shd.options)
- mat.ShaderAssign.ShaderOptions.Add(option.Key, option.Value);
- foreach (var samp in shd.samplers)
- mat.ShaderAssign.SamplerAssigns.Add(samp.Key, samp.Value);
- foreach (var att in shd.attributes)
- mat.ShaderAssign.AttribAssigns.Add(att.Key, att.Value);
- }
-
- public static Shape SaveShape(FSHP fshp)
- {
- Shape ShapeU = new Shape();
- ShapeU.VertexSkinCount = (byte)fshp.VertexSkinCount;
- ShapeU.Flags = ShapeFlags.HasVertexBuffer;
- ShapeU.BoneIndex = (ushort)fshp.boneIndx;
- ShapeU.MaterialIndex = (ushort)fshp.MaterialIndex;
- ShapeU.VertexBufferIndex = (ushort)fshp.VertexBufferIndex;
- ShapeU.KeyShapes = new ResDict();
- ShapeU.Name = fshp.Text;
- ShapeU.SkinBoneIndices = fshp.GetIndices();
- ShapeU.TargetAttribCount = (byte)fshp.TargetAttribCount;
- ShapeU.SkinBoneIndices = fshp.BoneIndices;
- ShapeU.SubMeshBoundings = new List();
- ShapeU.RadiusArray = new List();
- ShapeU.RadiusArray = fshp.boundingRadius;
- ShapeU.Meshes = new List();
-
- foreach (FSHP.BoundingBox box in fshp.boundingBoxes)
- {
- Bounding bnd = new Bounding();
- bnd.Center = new Syroot.Maths.Vector3F(box.Center.X, box.Center.Y, box.Center.Z);
- bnd.Extent = new Syroot.Maths.Vector3F(box.Extend.X, box.Extend.Y, box.Extend.Z);
- ShapeU.SubMeshBoundings.Add(bnd);
- }
-
- foreach (FSHP.LOD_Mesh mesh in fshp.lodMeshes)
- {
- Mesh msh = new Mesh();
- msh.SubMeshes = new List();
- msh.PrimitiveType = (GX2PrimitiveType)mesh.PrimitiveType;
- msh.FirstVertex = mesh.FirstVertex;
-
- foreach (FSHP.LOD_Mesh.SubMesh sub in mesh.subMeshes)
- {
- SubMesh subMesh = new SubMesh();
- subMesh.Offset = sub.offset;
- subMesh.Count = (uint)mesh.faces.Count;
- msh.SubMeshes.Add(subMesh);
- }
-
- IList faceList = new List();
- msh.IndexBuffer = new Syroot.NintenTools.Bfres.Buffer();
- foreach (int f in mesh.faces)
- {
- faceList.Add((uint)f);
- }
- if (faceList.Count > 65000)
- {
- MessageBox.Show($"Warning! Your poly count for a single mesh {fshp.Text} is pretty high! ({faceList.Count})." +
- $" You may want to split this!");
- msh.SetIndices(faceList, GX2IndexFormat.UInt32);
- }
- else
- msh.SetIndices(faceList, GX2IndexFormat.UInt16);
-
- ShapeU.Meshes.Add(msh);
- break;
- }
- return ShapeU;
- }
- public static void SaveVertexBuffer(FSHP fshp)
- {
- VertexBuffer buffer = new VertexBuffer();
- buffer.Attributes = new ResDict();
-
- VertexBufferHelper helper = new VertexBufferHelper(buffer, Syroot.BinaryData.ByteOrder.BigEndian);
- List atrib = new List();
- fshp.UpdateVertices();
-
- foreach (FSHP.VertexAttribute att in fshp.vertexAttributes)
- {
- if (att.Name == "_p0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = fshp.verts.ToArray();
- vert.Format = att.SetTypeWiiU(att.Format);
- atrib.Add(vert);
- }
- if (att.Name == "_n0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = fshp.norms.ToArray();
- vert.Format = att.SetTypeWiiU(att.Format);
- atrib.Add(vert);
- }
- if (att.Name == "_u0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = fshp.uv0.ToArray();
- vert.Format = att.SetTypeWiiU(att.Format);
- atrib.Add(vert);
- }
- if (att.Name == "_u1")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = fshp.uv1.ToArray();
- vert.Format = att.SetTypeWiiU(att.Format);
- atrib.Add(vert);
- }
- if (att.Name == "_u2")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = fshp.uv2.ToArray();
- vert.Format = att.SetTypeWiiU(att.Format);
- atrib.Add(vert);
- }
- if (att.Name == "_w0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = fshp.weights.ToArray();
- vert.Format = att.SetTypeWiiU(att.Format);
- atrib.Add(vert);
- }
- if (att.Name == "_i0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = fshp.boneInd.ToArray();
- vert.Format = att.SetTypeWiiU(att.Format);
- atrib.Add(vert);
- }
- if (att.Name == "_b0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = fshp.bitans.ToArray();
- vert.Format = att.SetTypeWiiU(att.Format);
- atrib.Add(vert);
- }
- if (att.Name == "_t0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = fshp.tans.ToArray();
- vert.Format = att.SetTypeWiiU(att.Format);
- atrib.Add(vert);
- }
- if (att.Name == "_c0")
- {
- VertexBufferHelperAttrib vert = new VertexBufferHelperAttrib();
- vert.Name = att.Name;
- vert.Data = fshp.colors.ToArray();
- vert.Format = att.SetTypeWiiU(att.Format);
- atrib.Add(vert);
- }
- }
- if (atrib.Count == 0)
- {
- MessageBox.Show("Attributes are empty?");
- return;
- }
- helper.Attributes = atrib;
- fshp.VertexBufferU = helper.ToVertexBuffer();
- }
-
- public static void WriteExternalFiles(ResFile resFile, TreeNode EditorRoot)
- {
- resFile.ExternalFiles.Clear();
- if (EditorRoot.Nodes.ContainsKey("EXT"))
- {
- foreach (TreeNode node in EditorRoot.Nodes["EXT"].Nodes)
- {
- ExternalFile ext = new ExternalFile();
- if (node is BNTX)
- ext.Data = ((BNTX)node).Save();
- else if (node is BfshaFileData)
- ext.Data = ((BfshaFileData)node).Data;
- else
- ext.Data = ((ExternalFileData)node).Data;
-
- resFile.ExternalFiles.Add(node.Text, ext);
- }
- }
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFSAR.cs b/Switch_FileFormatsMain/FileFormats/BFSAR.cs
deleted file mode 100644
index 667f1055..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFSAR.cs
+++ /dev/null
@@ -1,244 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using System.Threading.Tasks;
-using Switch_Toolbox;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using Switch_Toolbox.Library.IO;
-
-namespace FirstPlugin
-{
- public class BFSAR : TreeNodeFile, IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "Cafe Sound Archive" };
- public string[] Extension { get; set; } = new string[] { "*.bfsar" };
- public string Magic { get; set; } = "FSAR";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public int Alignment { get; set; } = 0;
- public string FilePath { get; set; }
- public IFileInfo IFileInfo { get; set; }
-
- public Type[] Types
- {
- get
- {
- List types = new List();
- return types.ToArray();
- }
- }
-
- public void Load()
- {
- IsActive = true;
- FSAR bfsar = new FSAR();
- bfsar.Read(new FileReader(new MemoryStream(Data)));
-
- Text = FileName;
- Nodes.Add("Audio List");
- Nodes.Add("Audio Set List");
- Nodes.Add("Bank List");
- Nodes.Add("Group List");
- Nodes.Add("Players List");
- }
- public void Unload()
- {
-
- }
- public byte[] Save()
- {
- return null;
- }
-
- private static uint FileSizeOffset;
- public class FSAR
- {
- public uint Size;
- private ushort BOM;
- public ushort HeaderSize;
- public uint Version;
- public ushort SectionCount;
- public STRG STRG;
- public INFO INFO;
- public FILE FILE;
-
- public void Read(FileReader reader)
- {
- string Signature = reader.ReadString(4, Encoding.ASCII);
- if (Signature != "FSAR")
- throw new Exception($"Invalid signature {Signature}! Expected FSAR.");
- BOM = reader.ReadUInt16();
- HeaderSize = reader.ReadUInt16();
- Version = reader.ReadUInt32();
- uint FileSize = reader.ReadUInt32();
- SectionCount = reader.ReadUInt16();
- ushort padding = reader.ReadUInt16();
-
- for (int i = 0; i < SectionCount; i++)
- {
- ushort Identifier = reader.ReadUInt16();
- ushort padding2 = reader.ReadUInt16();
- uint Offset = reader.ReadUInt32();
- uint Size = reader.ReadUInt32();
-
- if (Identifier == 8192)
- {
- reader.Seek(Offset, SeekOrigin.Begin);
- STRG = new STRG();
- STRG.Read(reader);
- }
- if (Identifier == 8193)
- {
- reader.Seek(Offset, SeekOrigin.Begin);
- INFO = new INFO();
- INFO.Read(reader);
- }
- if (Identifier == 8194)
- {
- reader.Seek(Offset, SeekOrigin.Begin);
- FILE = new FILE();
- FILE.Read(reader, INFO);
- }
- }
- }
- public void Write(FileWriter writer)
- {
- writer.WriteSignature("FSAR");
- writer.Write(BOM);
- writer.Write(HeaderSize);
- writer.Write(Version);
- FileSizeOffset = (uint)writer.Position;
- writer.Write(SectionCount);
- writer.Write((ushort)0);
- for (int i = 0; i < SectionCount; i++)
- {
-
- }
- }
- }
- public class INFO
- {
- public uint SectionSize;
- public AudioList audioList;
-
- public void Read(FileReader reader)
- {
- string Signature = reader.ReadString(4, Encoding.ASCII);
- if (Signature != "INFO")
- throw new Exception($"Invalid signature {Signature}! Expected INFO.");
-
- SectionSize = reader.ReadUInt32();
- long Pos = reader.Position;
- uint AudioListOffset = reader.ReadUInt32();
-
- if (AudioListOffset != 0)
- {
- using (reader.TemporarySeek(AudioListOffset + Pos, SeekOrigin.Begin))
- {
- audioList = new AudioList();
- audioList.Read(reader);
- }
- }
- }
- }
- public class AudioList
- {
- public void Read(FileReader reader)
- {
-
- }
- }
- public class FILE
- {
- public uint SectionSize;
- public void Read(FileReader reader, INFO INFO)
- {
- string Signature = reader.ReadString(4, Encoding.ASCII);
- if (Signature != "FILE")
- throw new Exception($"Invalid signature {Signature}! Expected FILE.");
-
- SectionSize = reader.ReadUInt32();
- byte[] padding = reader.ReadBytes(0x18);
-
-
- }
- }
- public class STRG
- {
- public uint Size;
- private uint BOM;
- public uint SectionSize;
- public uint Version;
- public ushort SectionCount;
- public StringTable stringTable;
- public LookupTable lookupTable;
-
- public void Read(FileReader reader)
- {
- string Signature = reader.ReadString(4, Encoding.ASCII);
- if (Signature != "STRG")
- throw new Exception($"Invalid signature {Signature}! Expected STRG.");
-
- SectionSize = reader.ReadUInt32();
- long pos = reader.Position;
-
- uint unk = reader.ReadUInt32();
- uint Stringtableoffset = reader.ReadUInt32();
- uint unk2 = reader.ReadUInt32();
- uint LookupTableOffset = reader.ReadUInt32();
-
- if (Stringtableoffset != 0)
- {
- reader.Seek(Stringtableoffset + pos, SeekOrigin.Begin);
- stringTable = new StringTable();
- stringTable.Read(reader);
- }
- if (LookupTableOffset != 0)
- {
- reader.Seek(LookupTableOffset + pos, SeekOrigin.Begin);
- lookupTable = new LookupTable();
- lookupTable.Read(reader);
- }
- }
- public class StringTable
- {
- public List Names = new List();
-
- public void Read(FileReader reader)
- {
- long pos = reader.Position;
- uint Count = reader.ReadUInt32();
-
- for (int i = 0; i < Count; i++)
- {
- uint unk = reader.ReadUInt32();
- uint Offset = reader.ReadUInt32();
- uint Size = reader.ReadUInt32();
-
- using (reader.TemporarySeek(Offset + pos, SeekOrigin.Begin))
- {
- Names.Add(reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated));
- }
- }
- foreach (string name in Names)
- Console.WriteLine(name);
- }
- }
- public class LookupTable
- {
- public void Read(FileReader reader)
- {
-
- }
- }
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BFSHA.cs b/Switch_FileFormatsMain/FileFormats/BFSHA.cs
deleted file mode 100644
index 5f0696fd..00000000
--- a/Switch_FileFormatsMain/FileFormats/BFSHA.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace FirstPlugin
-{
- public class BFSHA
- {
-
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/BYAML.cs b/Switch_FileFormatsMain/FileFormats/BYAML.cs
deleted file mode 100644
index 77df18b3..00000000
--- a/Switch_FileFormatsMain/FileFormats/BYAML.cs
+++ /dev/null
@@ -1,187 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.IO;
-using System.Threading.Tasks;
-using Switch_Toolbox;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using ByamlExt.Byaml;
-using ByamlExt;
-using WeifenLuo.WinFormsUI.Docking;
-
-namespace FirstPlugin
-{
- public class BYAML : TreeNodeFile, IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "BYAML" };
- public string[] Extension { get; set; } = new string[] { "*.byaml", "*.byml", "*.bprm", "*.sbyml" };
- public string Magic { get; set; } = "YB";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public string FilePath { get; set; }
- public IFileInfo IFileInfo { get; set; }
- public Type[] Types
- {
- get
- {
- List types = new List();
- return types.ToArray();
- }
- }
-
- class EditableNode
- {
- public Type type { get => Node[Index].GetType(); }
- dynamic Node;
- dynamic Index;
-
- public dynamic Get() => Node[Index];
- public void Set(dynamic value) => Node[Index] = value;
- public string GetTreeViewString()
- {
- if (Index is int)
- return Node[Index].ToString();
- else
- return Index + " : " + Node[Index].ToString();
- }
-
- public EditableNode(dynamic _node, dynamic _index)
- {
- Node = _node;
- Index = _index;
- }
- }
-
- MemoryStream mem;
- public void Load()
- {
- IsActive = false;
- CanSave = false;
-
- mem = new MemoryStream(Data);
- ByamlViewer.OpenByml(mem, FileName);
-
- // BymlFileData byamlFile = ByamlFile.LoadN(new System.IO.MemoryStream(Data), false, Syroot.BinaryData.ByteOrder.LittleEndian);
-
- // LoadDockedEditor(byamlFile);
- }
- public void Unload()
- {
-
- }
-
- public TreeNode LoadByamlNodes(dynamic root)
- {
- TreeNode node = new TreeNode();
-
- if (root == null)
- return node;
- if (root is Dictionary)
- {
- parseDictNode(root, node.Nodes);
- }
- else if (root is List)
- {
- if (((List)root).Count == 0)
- {
- MessageBox.Show("This byml is empty");
- }
- parseArrayNode(root, node.Nodes);
- }
- else if (root is List)
- {
-
- }
-
- return node;
- }
-
- void parseArrayNode(IList list, TreeNodeCollection addto)
- {
- int index = 0;
- foreach (dynamic k in list)
- {
- if (k is IDictionary)
- {
- TreeNode current = addto.Add("");
- current.Tag = ((IDictionary)k);
- current.Nodes.Add("✯✯dummy✯✯");
- }
- else if (k is IList)
- {
- TreeNode current = addto.Add("");
- current.Tag = ((IList)k);
- current.Nodes.Add("✯✯dummy✯✯");
- }
- else if (k is IList)
- {
- TreeNode current = addto.Add("");
- current.Tag = ((IList)k);
- parsePathPointArray(k, current.Nodes);
- }
- else
- {
- var n = addto.Add(k == null ? "" : k.ToString());
- if (k != null) n.Tag = new EditableNode(list, index);
- }
- index++;
- }
- }
-
- void parseDictNode(IDictionary node, TreeNodeCollection addto)
- {
- foreach (string k in node.Keys)
- {
- TreeNode current = addto.Add(k);
- if (node[k] is IDictionary)
- {
- current.Text += " : ";
- current.Tag = node[k];
- current.Nodes.Add("✯✯dummy✯✯"); //a text that can't be in a byml
- }
- else if (node[k] is IList)
- {
- current.Text += " : ";
- current.Tag = ((IList)node[k]);
- current.Nodes.Add("✯✯dummy✯✯");
- }
- else if (node[k] is IList)
- {
- current.Text += " : ";
- current.Tag = ((IList)node[k]);
- parsePathPointArray(node[k], current.Nodes);
- }
- else
- {
- current.Text = current.Text + " : " + (node[k] == null ? "" : node[k].ToString());
- if (node[k] != null) current.Tag = new EditableNode(node, k);
- }
- }
- }
- void parsePathPointArray(IList list, TreeNodeCollection addto)
- {
- int index = 0;
- foreach (var k in list)
- {
- index++;
- var n = addto.Add(k == null ? "" : k.ToString());
- if (k != null) n.Tag = new EditableNode(list, index);
- }
- }
-
- public byte[] Save()
- {
- if (mem != null)
- return mem.ToArray();
-
- return null;
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/CsvModels.cs b/Switch_FileFormatsMain/FileFormats/CsvModels.cs
deleted file mode 100644
index fe266023..00000000
--- a/Switch_FileFormatsMain/FileFormats/CsvModels.cs
+++ /dev/null
@@ -1,345 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using System.Threading.Tasks;
-using Switch_Toolbox.Library;
-using Switch_Toolbox.Library.Rendering;
-using System.Windows.Forms;
-using OpenTK;
-
-namespace FirstPlugin
-{
- public class CsvModel : IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "CSV Model" };
- public string[] Extension { get; set; } = new string[] { "*.csv" };
- public string Magic { get; set; } = "";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public string FilePath { get; set; }
- public IFileInfo IFileInfo { get; set; }
- public Type[] Types
- {
- get
- {
- List types = new List();
- return types.ToArray();
- }
- }
-
- public List objects = new List();
-
- public class Model
- {
- public string Name { get; set; }
- public int UVChannelCount { get; set; }
- public DataType type;
- public DataSubType subType;
-
- public List bones = new List();
- public List weights = new List();
- }
- public enum DataType : int
- {
- vertex = 1,
- faces = 2,
- bones = 3,
- }
- public enum DataSubType : int
- {
- position = 0,
- normals = 1,
- colors = 2,
- uv0 = 3,
- uv1 = 4,
- uv2 = 5,
- uv3 = 6,
- }
-
- float X, Y, Z, W;
- public void Load()
- {
- LoadFile(FilePath);
- }
- public void LoadFile(string FileName, bool IsModel = false)
- {
- if (!IsModel)
- {
- MessageBox.Show("Not valid model csv");
- return;
- }
-
- string line = null;
-
- List models = new List();
-
- TextReader csv = new StreamReader(FileName);
- Model model = new Model();
- STGenericObject STobj = new STGenericObject();
- Vertex vtx = new Vertex();
- STGenericObject.LOD_Mesh lod = new STGenericObject.LOD_Mesh();
- int Index = 0;
- int ww = 0;
- while (true)
- {
- line = csv.ReadLine();
- if (line != null)
- {
- if (line.StartsWith("Obj Name"))
- {
- model = new Model();
- STobj = new STGenericObject();
- model.Name = line.Split(':')[1].Replace("\n", "");
- model.subType = DataSubType.position;
- models.Add(model);
-
- STobj.ObjectName = model.Name;
- lod = new STGenericObject.LOD_Mesh();
- lod.IndexFormat = STIndexFormat.UInt16;
- lod.PrimitiveType = STPolygonType.Triangle;
- STobj.lodMeshes.Add(lod);
- STobj.VertexBufferIndex = Index;
- objects.Add(STobj);
- Index++;
- }
- else if (line.StartsWith("tex_Array:"))
- {
-
- }
- else if (line.StartsWith("Bone_Suport"))
- {
-
- }
- else if (line.StartsWith("Color_Suport"))
- {
-
- }
- else if (line.StartsWith("UV_Num:"))
- {
- int uvCount;
- int.TryParse(line.Split(':')[1].Replace("\n", ""), out uvCount);
- model.UVChannelCount = uvCount;
- }
- else if (line.StartsWith("vert_Array"))
- {
- model.type = DataType.vertex;
- }
- else if (line.StartsWith("face_Array"))
- {
- model.type = DataType.faces;
- }
- else if (line.StartsWith("bone_Array"))
- {
- model.type = DataType.bones;
- }
- else
- {
- string[] values = line.Replace("\n", "").Replace("\r", "").Split(',');
-
- if (model.type == DataType.vertex)
- {
- switch (model.subType)
- {
- case DataSubType.position:
- vtx = new Vertex();
- STobj.vertices.Add(vtx);
-
- STobj.HasPos = true;
-
- float.TryParse(values[0], out X);
- float.TryParse(values[1], out Y);
- float.TryParse(values[2], out Z);
- vtx.pos = new Vector3(X, Y, Z);
- model.subType = DataSubType.normals;
- break;
- case DataSubType.normals:
- STobj.HasNrm = true;
-
- float.TryParse(values[0], out X);
- float.TryParse(values[1], out Y);
- float.TryParse(values[2], out Z);
- vtx.nrm = new Vector3(X, Y, Z);
- model.subType = DataSubType.colors;
- break;
- case DataSubType.colors:
- STobj.HasVertColors = true;
-
- float.TryParse(values[0], out X);
- float.TryParse(values[1], out Y);
- float.TryParse(values[2], out Z);
- float.TryParse(values[3], out W);
- vtx.col = new Vector4(X / 255, Y / 255, Z / 255, W / 255);
- model.subType = DataSubType.uv0;
- break;
- case DataSubType.uv0:
- STobj.HasUv0 = true;
-
- float.TryParse(values[0], out X);
- float.TryParse(values[1], out Y);
- vtx.uv0 = new Vector2(X, Y);
- if (model.UVChannelCount == 1)
- model.subType = DataSubType.position;
- else
- model.subType = DataSubType.uv1;
- break;
- case DataSubType.uv1:
- STobj.HasUv1 = true;
-
- float.TryParse(values[0], out X);
- float.TryParse(values[1], out Y);
- vtx.uv1 = new Vector2(X, Y);
- if (model.UVChannelCount == 2)
- model.subType = DataSubType.position;
- else
- model.subType = DataSubType.uv2;
- break;
- case DataSubType.uv2:
- STobj.HasUv2 = true;
-
- float.TryParse(values[0], out X);
- float.TryParse(values[1], out Y);
- vtx.uv2 = new Vector2(X, Y);
- if (model.UVChannelCount == 3)
- model.subType = DataSubType.position;
- else
- model.subType = DataSubType.uv3;
- break;
- case DataSubType.uv3:
- float.TryParse(values[0], out X);
- float.TryParse(values[1], out Y);
- model.subType = DataSubType.position;
- break;
- }
- }
- if (model.type == DataType.faces)
- {
- int face;
- foreach (string v in values)
- {
- var cleaned = v.Replace(".0", string.Empty);
- int.TryParse(cleaned, out face);
- lod.faces.Add(face-1);
- }
- }
- if (model.type == DataType.bones)
- {
- STobj.HasWeights = true;
- STobj.HasIndices = true;
-
- Array.Resize(ref values, values.Length - 1);
-
- List bones = new List();
- List weights = new List();
-
- int bbs = 0;
- foreach (string obj in values)
- {
- if (bbs == 0)
- {
- bones.Add(obj);
- bbs += 1;
- }
- else
- {
- float.TryParse(obj, out X);
- weights.Add(X);
- bbs = 0;
- }
- }
-
- STobj.bones.Add(bones.ToArray());
- STobj.weightsT.Add(weights.ToArray());
- }
- }
- }
- else
- break;
- }
-
- if (objects[0].weightsT.Count != objects[0].vertices.Count)
- throw new Exception("Incorrect vertex amount");
-
- foreach (STGenericObject obj in objects)
- {
- obj.lodMeshes[0].GenerateSubMesh();
- for (int v = 0; v < obj.vertices.Count; v++)
- {
- foreach (string bn in obj.bones[v])
- obj.vertices[v].boneNames.Add(bn);
- foreach (float f in obj.weightsT[v])
- obj.vertices[v].boneWeights.Add(f);
- }
- foreach (Vertex v in obj.vertices)
- {
- if (v.boneNames.Count == 1)
- Console.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]}");
- if (v.boneNames.Count == 2)
- Console.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]} {v.boneNames[1]} {v.boneWeights[1]}");
- if (v.boneNames.Count == 3)
- Console.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]} {v.boneNames[1]} {v.boneWeights[1]} {v.boneNames[2]} {v.boneWeights[2]}");
- if (v.boneNames.Count == 4)
- Console.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]} {v.boneNames[1]} {v.boneWeights[1]} {v.boneNames[2]} {v.boneWeights[2]} {v.boneNames[3]} {v.boneWeights[3]}");
- }
- }
-
- csv.Close();
- csv = null;
- }
- public void Unload()
- {
-
- }
- public byte[] Save()
- {
- MemoryStream mem = new MemoryStream();
-
- using (System.IO.StreamWriter file = new System.IO.StreamWriter(mem))
- {
- foreach (STGenericObject obj in objects)
- {
- file.WriteLine($"Obj Name:" + obj.ObjectName);
- file.WriteLine($"Bone_Suport");
- file.WriteLine($"UV_Num:1");
- file.WriteLine($"vert_Array");
-
- foreach (Vertex v in obj.vertices)
- {
- file.WriteLine($"{v.pos.X},{v.pos.Y},{v.pos.Z}");
- file.WriteLine($"{v.nrm.X},{v.nrm.Y},{v.nrm.Z}");
- file.WriteLine($"{v.col.X * 255},{v.col.Y * 255},{v.col.Z * 255},{v.col.W * 255}");
- file.WriteLine($"{v.uv0.X},{v.uv0.Y}");
- // file.WriteLine($"{v.uv1.X},{v.uv1.Y}");
- }
- file.WriteLine($"face_Array");
- for (int f = 0; f < obj.faces.Count / 3; f++)
- {
- file.WriteLine($"{obj.faces[f] + 1},{obj.faces[f++] + 1},{obj.faces[f++] + 1}");
- }
- file.WriteLine($"bone_Array");
- foreach (Vertex v in obj.vertices)
- {
- if (v.boneNames.Count == 1)
- file.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]}");
- if (v.boneNames.Count == 2)
- file.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]} {v.boneNames[1]} {v.boneWeights[1]}");
- if (v.boneNames.Count == 3)
- file.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]} {v.boneNames[1]} {v.boneWeights[1]} {v.boneNames[2]} {v.boneWeights[2]}");
- if (v.boneNames.Count == 4)
- file.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]} {v.boneNames[1]} {v.boneWeights[1]} {v.boneNames[2]} {v.boneWeights[2]} {v.boneNames[3]} {v.boneWeights[3]}");
- }
- }
- file.Close();
- }
-
-
- return mem.ToArray();
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/GFPAK.cs b/Switch_FileFormatsMain/FileFormats/GFPAK.cs
deleted file mode 100644
index f8c45e18..00000000
--- a/Switch_FileFormatsMain/FileFormats/GFPAK.cs
+++ /dev/null
@@ -1,390 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Switch_Toolbox;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using System.IO;
-using Switch_Toolbox.Library.IO;
-
-namespace FirstPlugin
-{
- public class GFPAK : TreeNodeFile, IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "Graphic Package" };
- public string[] Extension { get; set; } = new string[] { "*.gfpak" };
- public string Magic { get; set; } = "GFLX";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public int Alignment { get; set; } = 0;
- public string FilePath { get; set; }
- public IFileInfo IFileInfo { get; set; }
- public Type[] Types
- {
- get
- {
- List types = new List();
- return types.ToArray();
- }
- }
-
- public void Load()
- {
- IsActive = true;
- IFileInfo = new IFileInfo();
-
- Read(new FileReader(new MemoryStream(Data)));
-
- Text = FileName;
-
- ContextMenu = new ContextMenu();
- MenuItem save = new MenuItem("Save");
- ContextMenu.MenuItems.Add(save);
- save.Click += Save;
- MenuItem previewFiles = new MenuItem("Preview Window");
- ContextMenu.MenuItems.Add(previewFiles);
- previewFiles.Click += PreviewWindow;
- }
- public void Unload()
- {
-
- }
- public byte[] Save()
- {
- MemoryStream mem = new MemoryStream();
- Write(new FileWriter(mem));
- return mem.ToArray();
- }
-
- private void Save(object sender, EventArgs args)
- {
- List formats = new List();
-
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = Utils.GetAllFilters(formats);
- sfd.FileName = FileName;
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- STFileSaver.SaveFileFormat(this, sfd.FileName, IFileInfo.Alignment);
- }
- }
-
- private void PreviewWindow(object sender, EventArgs args)
- {
- PreviewFormatList previewFormatList = new PreviewFormatList();
-
- if (previewFormatList.ShowDialog() == DialogResult.OK)
- {
- CallRecursive(TreeView);
- PreviewEditor previewWindow = new PreviewEditor();
- previewWindow.Show();
- }
- }
- private void CallRecursive(TreeView treeView)
- {
- // Print each node recursively.
- TreeNodeCollection nodes = treeView.Nodes;
- foreach (TreeNode n in nodes)
- {
- PrintRecursive(n);
- }
- }
- private void PrintRecursive(TreeNode treeNode)
- {
- // Print each node recursively.
- foreach (TreeNode tn in treeNode.Nodes)
- {
- PrintRecursive(tn);
- }
- }
-
- public ushort BOM;
- public uint Version;
- public List files = new List();
- public List hashes = new List();
- public List hashIndices = new List();
-
- public int version;
- public int FolderCount;
-
- public void Read(FileReader reader)
- {
- string Signature = reader.ReadString(8, Encoding.ASCII);
- if (Signature != "GFLXPACK")
- throw new Exception($"Invalid signature {Signature}! Expected GFLXPACK.");
-
- version = reader.ReadInt32();
- uint padding = reader.ReadUInt32();
- uint FileCount = reader.ReadUInt32();
- FolderCount = reader.ReadInt32();
- ulong FileInfoOffset = reader.ReadUInt64();
- ulong hashArrayOffset = reader.ReadUInt64();
- ulong hashArrayIndexOffset = reader.ReadUInt64();
-
- reader.Seek((long)hashArrayOffset, SeekOrigin.Begin);
- for (int i = 0; i < FileCount; i++)
- {
- ulong hash = reader.ReadUInt64();
- hashes.Add(hash);
- }
- reader.Seek((long)hashArrayIndexOffset, SeekOrigin.Begin);
- for (int i = 0; i < FileCount; i++)
- {
- HashIndex hashindex = new HashIndex();
- hashindex.Read(reader);
- hashIndices.Add(hashindex);
- }
-
- reader.Seek((long)FileInfoOffset, SeekOrigin.Begin);
- for (int i = 0; i < FileCount; i++)
- {
- FileEntry fileEntry = new FileEntry();
- fileEntry.Read(reader);
- fileEntry.Text = hashes[i].ToString();
- Nodes.Add(fileEntry);
- files.Add(fileEntry);
- }
- }
- public void Write(FileWriter writer)
- {
- writer.WriteSignature("GFLXPACK");
- writer.Write(version);
- writer.Write(0);
- writer.Write(files.Count);
- writer.Write(FolderCount);
- long FileInfoOffset = writer.Position;
- writer.Write(0L);
- long HashArrayOffset = writer.Position;
- writer.Write(0L);
- long HashIndexArrOffset = writer.Position;
- writer.Write(0L);
- //Now write all sections
- writer.WriteUint64Offset(HashArrayOffset);
- writer.Write(hashes);
-
- writer.WriteUint64Offset(HashIndexArrOffset);
- foreach (var hashIndx in hashIndices)
- hashIndx.Write(writer);
-
- writer.WriteUint64Offset(FileInfoOffset);
- foreach (var fileTbl in files)
- fileTbl.Write(writer);
-
- //Save data blocks
- foreach (var fileTbl in files)
- {
- fileTbl.WriteBlock(writer);
- }
- }
- public class HashIndex
- {
- public ulong hash;
- public int Index;
- public uint unkown;
-
- public void Read(FileReader reader)
- {
- hash = reader.ReadUInt64();
- Index = reader.ReadInt32();
- unkown = reader.ReadUInt32(); //Always 0xCC?
- }
- public void Write(FileWriter writer)
- {
- writer.Write(hash);
- writer.Write(Index);
- writer.Write(unkown);
- }
- }
- public class FileEntry : TreeNodeCustom
- {
- public FileEntry()
- {
- ImageKey = "fileBlank";
- SelectedImageKey = "fileBlank";
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
-
- }
- public uint unkown;
- public uint CompressionType;
- public byte[] data;
- private long DataOffset;
- private byte[] CompressedData;
- public IFileFormat FileHandler;
-
- public void Read(FileReader reader)
- {
- unkown = reader.ReadUInt16(); //Usually 9?
- CompressionType = reader.ReadUInt16();
- uint DecompressedFileSize = reader.ReadUInt32();
- uint CompressedFileSize = reader.ReadUInt32();
- uint padding = reader.ReadUInt32();
- ulong FileOffset = reader.ReadUInt64();
-
- using (reader.TemporarySeek((long)FileOffset, SeekOrigin.Begin))
- {
- data = reader.ReadBytes((int)CompressedFileSize);
- data = STLibraryCompression.Type_LZ4.Decompress(data, 0, (int)CompressedFileSize, (int)DecompressedFileSize);
-
- string ext = SARCExt.SARC.GuessFileExtension(data);
-
- if (ext == ".bntx")
- {
- ImageKey = "bntx";
- SelectedImageKey = "bntx";
- }
- if (ext == ".byaml")
- {
- ImageKey = "byaml";
- SelectedImageKey = "byaml";
- }
- if (ext == ".aamp")
- {
- ImageKey = "aamp";
- SelectedImageKey = "aamp";
- }
- if (ext == ".lua")
- {
-
- }
- }
- }
- public void Write(FileWriter writer)
- {
- if (FileHandler != null && FileHandler.CanSave)
- {
- data = FileHandler.Save();
- }
-
- CompressedData = Compress(data, CompressionType);
-
- writer.Write((ushort)unkown);
- writer.Write((ushort)CompressionType);
- writer.Write(data.Length);
- writer.Write(CompressedData.Length);
- writer.Write(0);
- DataOffset = writer.Position;
- writer.Write(0L);
- }
- public void WriteBlock(FileWriter writer)
- {
- writer.WriteUint64Offset(DataOffset);
- writer.Write(CompressedData);
- }
- public static byte[] Compress(byte[] data, uint Type)
- {
- if (Type == 2)
- {
- return STLibraryCompression.Type_LZ4.Compress(data);
- }
- else
- throw new Exception("Unkown compression type?");
- }
- public override void OnClick(TreeView treeview)
- {
-
- }
- public override void OnMouseLeftClick(TreeView treeView)
- {
- ReplaceNode(this.Parent, this, OpenFile(Name, data, this));
- }
- private void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.FileName = Text;
- sfd.Filter = "All files(*.*)|*.*";
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- File.WriteAllBytes(sfd.FileName, data);
- }
- }
- }
- public static TreeNode OpenFile(string FileName, byte[] data, FileEntry fileEntry, bool Compressed = false, CompressionType CompType = 0)
- {
- Cursor.Current = Cursors.WaitCursor;
- FileReader fileReader = new FileReader(data);
- string Magic4 = fileReader.ReadMagic(0, 4);
- string Magic2 = fileReader.ReadMagic(0, 2);
- if (Magic4 == "Yaz0")
- {
- data = EveryFileExplorer.YAZ0.Decompress(data);
- return OpenFile(FileName, data, fileEntry, true, (CompressionType)1);
- }
- if (Magic4 == "ZLIB")
- {
- data = FileReader.InflateZLIB(fileReader.getSection(64, data.Length - 64));
- return OpenFile(FileName, data, fileEntry, true, (CompressionType)2);
- }
- fileReader.Dispose();
- fileReader.Close();
- foreach (IFileFormat fileFormat in FileManager.GetFileFormats())
- {
- if (fileFormat.Magic == Magic4 || fileFormat.Magic == Magic2)
- {
- fileFormat.CompressionType = CompType;
- fileFormat.FileIsCompressed = Compressed;
- fileFormat.Data = data;
- fileFormat.Load();
- fileFormat.FileName = Path.GetFileName(FileName);
- fileFormat.FilePath = FileName;
- fileFormat.IFileInfo = new IFileInfo();
- fileFormat.IFileInfo.InArchive = true;
-
- if (fileFormat is TreeNode)
- {
- ((TreeNode)fileFormat).Text = fileEntry.Text;
- ((TreeNode)fileFormat).ImageKey = fileEntry.ImageKey;
- ((TreeNode)fileFormat).SelectedImageKey = fileEntry.SelectedImageKey;
- return (TreeNode)fileFormat;
- }
- }
- if (fileFormat.Magic == string.Empty)
- {
- foreach (string str3 in fileFormat.Extension)
- {
- if (str3.Remove(0, 1) == Path.GetExtension(FileName))
- {
- fileFormat.Data = data;
- fileFormat.Load();
- fileFormat.FileName = Path.GetFileName(FileName);
- fileFormat.FilePath = FileName;
- fileFormat.IFileInfo = new IFileInfo();
- fileFormat.IFileInfo.InArchive = true;
-
- if (fileFormat is TreeNode)
- {
- ((TreeNode)fileFormat).Text = fileEntry.Text;
- ((TreeNode)fileFormat).ImageKey = fileEntry.ImageKey;
- ((TreeNode)fileFormat).SelectedImageKey = fileEntry.SelectedImageKey;
- return (TreeNode)fileFormat;
- }
- }
- }
- }
- }
- return (TreeNode)null;
- }
- public static void ReplaceNode(TreeNode node, TreeNode replaceNode, TreeNode NewNode)
- {
- if (NewNode == null)
- return;
-
- int index = node.Nodes.IndexOf(replaceNode);
- node.Nodes.RemoveAt(index);
- node.Nodes.Insert(index, NewNode);
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/KCL.cs b/Switch_FileFormatsMain/FileFormats/KCL.cs
deleted file mode 100644
index b4bd5034..00000000
--- a/Switch_FileFormatsMain/FileFormats/KCL.cs
+++ /dev/null
@@ -1,571 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-using SFGraphics.GLObjects.Shaders;
-using Smash_Forge.Rendering;
-using GL_Core.Interfaces;
-using OpenTK.Graphics.OpenGL;
-using OpenTK;
-using Switch_Toolbox.Library.Rendering;
-using WeifenLuo.WinFormsUI.Docking;
-using GL_Core;
-using System.Drawing;
-using Switch_Toolbox.Library.IO;
-
-namespace FirstPlugin
-{
- public class KCL : TreeNodeFile, IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "KCL" };
- public string[] Extension { get; set; } = new string[] { "*.kcl" };
- public string Magic { get; set; } = "";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public string FilePath { get; set; }
- public IFileInfo IFileInfo { get; set; }
-
- public Type[] Types
- {
- get
- {
- List types = new List();
- return types.ToArray();
- }
- }
-
- public void Load()
- {
- IsActive = true;
- IFileInfo = new IFileInfo();
-
- Text = FileName;
- Renderer = new KCLRendering();
- Read(Data);
-
- ContextMenu = new ContextMenu();
- MenuItem save = new MenuItem("Save");
- ContextMenu.MenuItems.Add(save);
- save.Click += Save;
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
- }
- public void Unload()
- {
-
- }
- public byte[] Save()
- {
- return Data;
- }
- public enum GameSet : ushort
- {
- MarioOdyssey = 0x0,
- MarioKart8D = 0x1,
- Splatoon2 = 0x2,
- }
-
- public enum CollisionType_MarioOdssey : ushort
- {
-
- }
- public enum CollisionType_MK8D : ushort
- {
- Road_Default = 0,
- Road_Bumpy = 2,
- Road_Sand = 4,
- Offroad_Sand = 6,
- Road_HeavySand = 8,
- Road_IcyRoad = 9,
- OrangeBooster = 10,
- AntiGravityPanel = 11,
- Latiku = 16,
- Wall5 = 17,
- Wall4 = 19,
- Wall = 23,
- Latiku2 = 28,
- Glider = 31,
- SidewalkSlope = 32,
- Road_Dirt = 33,
- Unsolid = 56,
- Water = 60,
- Road_Stone = 64,
- Wall1 = 81,
- Wall2 = 84,
- FinishLine = 93,
- RedFlowerEffect = 95,
- Wall3 = 113,
- WhiteFlowerEffect = 127,
- Road_Metal = 128,
- Road_3DS_MP_Piano = 129,
- Road_RoyalR_Grass = 134,
- TopPillar = 135,
- YoshiCuiruit_Grass = 144,
- YellowFlowerEffect = 159,
-
- Road_MetalGating = 160,
- Road_3DS_MP_Xylophone = 161,
- Road_3DS_MP_Vibraphone = 193,
- SNES_RR_road = 227,
- Offroad_Mud = 230,
- Trick = 4096,
- BoosterStunt = 4106,
- TrickEndOfRamp = 4108,
- Trick3 = 4130,
- Trick6 = 4160,
- Trick4 = 4224,
- Trick5 = 8192,
- BoostTrick = 8202,
- }
-
- public void Save(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Supported Formats|*.kcl";
- sfd.FileName = Text;
- sfd.DefaultExt = ".kcl";
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- STFileSaver.SaveFileFormat(this, sfd.FileName, IFileInfo.Alignment);
- }
- }
- public void Export(object sender, EventArgs args)
- {
- if (kcl == null)
- return;
-
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Supported Formats|*.obj";
- sfd.FileName = Text;
- sfd.DefaultExt = ".obj";
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- kcl.ToOBJ().toWritableObj().WriteObj(sfd.FileName + ".obj");
- }
- }
- public void Replace(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Supported Formats|*.obj";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- var mod = EditorCore.Common.OBJ.Read(new MemoryStream(File.ReadAllBytes(ofd.FileName)), null);
- if (mod.Faces.Count > 65535)
- {
- MessageBox.Show("this model has too many faces, only models with less than 65535 triangles can be converted");
- return;
- }
- kcl = MarioKart.MK7.KCL.FromOBJ(mod);
- Data = kcl.Write(Syroot.BinaryData.ByteOrder.LittleEndian);
- Read(Data);
- }
- }
-
- KCLRendering Renderer;
- public override void OnClick(TreeView treeView)
- {
- LibraryGUI.Instance.LoadViewport(Viewport.Instance);
- Viewport.Instance.gL_ControlModern1.MainDrawable = Renderer;
-
- Renderer.UpdateVertexData();
- }
-
- public MarioKart.MK7.KCL kcl = null;
- public void Read(byte[] file_data)
- {
- try
- {
- kcl = new MarioKart.MK7.KCL(file_data, Syroot.BinaryData.ByteOrder.LittleEndian);
- }
- catch
- {
- kcl = new MarioKart.MK7.KCL(file_data, Syroot.BinaryData.ByteOrder.BigEndian);
- }
- Read(kcl);
- Renderer.UpdateVertexData();
- }
- public void Read(MarioKart.MK7.KCL kcl)
- {
- Nodes.Clear();
- Renderer.models.Clear();
-
- int CurModelIndx = 0;
- foreach (MarioKart.MK7.KCL.KCLModel mdl in kcl.Models)
- {
- KCLModel kclmodel = new KCLModel();
-
- kclmodel.Text = "Model " + CurModelIndx;
-
- int ft = 0;
- foreach (var plane in mdl.Planes)
- {
- var triangle = mdl.GetTriangle(plane);
- var normal = triangle.Normal;
- var pointA = triangle.PointA;
- var pointB = triangle.PointB;
- var pointC = triangle.PointC;
-
- Vertex vtx = new Vertex();
- Vertex vtx2 = new Vertex();
- Vertex vtx3 = new Vertex();
-
- vtx.pos = new Vector3(Vec3D_To_Vec3(pointA));
- vtx2.pos = new Vector3(Vec3D_To_Vec3(pointB));
- vtx3.pos = new Vector3(Vec3D_To_Vec3(pointC));
- vtx.nrm = new Vector3(Vec3D_To_Vec3(normal));
- vtx2.nrm = new Vector3(Vec3D_To_Vec3(normal));
- vtx3.nrm = new Vector3(Vec3D_To_Vec3(normal));
-
- KCLModel.Face face = new KCLModel.Face();
- face.Text = triangle.Collision.ToString();
- face.MaterialFlag = triangle.Collision;
-
- var col = MarioKart.MK7.KCLColors.GetMaterialColor(plane.CollisionType);
- Vector3 ColorSet = new Vector3(col.R, col.G, col.B);
-
- vtx.col = new Vector4(ColorSet, 1);
- vtx2.col = new Vector4(ColorSet, 1);
- vtx3.col = new Vector4(ColorSet, 1);
-
- kclmodel.faces.Add(ft);
- kclmodel.faces.Add(ft + 1);
- kclmodel.faces.Add(ft + 2);
-
- ft += 3;
-
- kclmodel.vertices.Add(vtx);
- kclmodel.vertices.Add(vtx2);
- kclmodel.vertices.Add(vtx3);
- }
-
- Renderer.models.Add(kclmodel);
- Nodes.Add(kclmodel);
-
- CurModelIndx++;
- }
- }
-
- public class KCLRendering : AbstractGlDrawable
- {
- // gl buffer objects
- int vbo_position;
- int ibo_elements;
-
- //Set the game's material list
- public GameSet GameMaterialSet = GameSet.MarioKart8D;
- public List models = new List();
- public Shader shader = null;
-
- private void GenerateBuffers()
- {
- GL.GenBuffers(1, out vbo_position);
- GL.GenBuffers(1, out ibo_elements);
- }
-
- public void Destroy()
- {
- GL.DeleteBuffer(vbo_position);
- GL.DeleteBuffer(ibo_elements);
- }
-
- public void UpdateVertexData()
- {
- if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Unitialized)
- return;
-
- DisplayVertex[] Vertices;
- int[] Faces;
-
- int poffset = 0;
- int voffset = 0;
- List Vs = new List();
- List Ds = new List();
- foreach (KCLModel m in models)
- {
- m.Offset = poffset * 4;
- List pv = m.CreateDisplayVertices();
- Vs.AddRange(pv);
-
- for (int i = 0; i < m.displayFaceSize; i++)
- {
- Ds.Add(m.display[i] + voffset);
- }
- poffset += m.displayFaceSize;
- voffset += pv.Count;
- }
-
- // Binds
- Vertices = Vs.ToArray();
- Faces = Ds.ToArray();
-
- // Bind only once!
- GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_position);
- GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Vertices.Length * DisplayVertex.Size), Vertices, BufferUsageHint.StaticDraw);
-
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo_elements);
- GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(Faces.Length * sizeof(int)), Faces, BufferUsageHint.StaticDraw);
-
- Viewport.Instance.UpdateViewport();
- }
-
- string FileName;
- public bool EditorIsViewportActive(DockContent dock)
- {
- if (dock is Viewport)
- {
- dock.Text = FileName;
- ((Viewport)dock).gL_ControlModern1.MainDrawable = this;
- return true;
- }
- return false;
- }
-
- public override void Prepare(GL_ControlModern control)
- {
- }
-
- public override void Prepare(GL_ControlLegacy control)
- {
-
- }
- public override void Draw(GL_ControlLegacy control)
- {
-
- }
- public override void Draw(GL_ControlModern control)
- {
- bool buffersWereInitialized = ibo_elements != 0 && vbo_position != 0;
- if (!buffersWereInitialized)
- GenerateBuffers();
-
- if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Unitialized)
- return;
-
- shader = OpenTKSharedResources.shaders["KCL"];
- shader.UseProgram();
-
- shader.EnableVertexAttributes();
- SetRenderSettings(shader);
-
- Matrix4 previewScale = Utils.TransformValues(Vector3.Zero, Vector3.Zero, Runtime.previewScale);
-
- Matrix4 camMat = previewScale * control.mtxCam * control.mtxProj;
-
- shader.SetVector3("difLightDirection", Vector3.TransformNormal(new Vector3(0f, 0f, -1f), camMat.Inverted()).Normalized());
- shader.SetVector3("difLightColor", new Vector3(1));
- shader.SetVector3("ambLightColor", new Vector3(1));
-
- shader.EnableVertexAttributes();
- SetRenderSettings(shader);
-
- shader.SetMatrix4x4("mvpMatrix", ref camMat);
-
- foreach (KCLModel mdl in models)
- {
- DrawModel(mdl, shader);
- }
-
- shader.DisableVertexAttributes();
- }
- private void SetRenderSettings(Shader shader)
- {
- shader.SetBoolToInt("renderVertColor", Runtime.renderVertColor);
- shader.SetInt("renderType", (int)Runtime.viewportShading);
- }
- private void DrawModel(KCLModel m, Shader shader, bool drawSelection = false)
- {
- if (m.faces.Count <= 3)
- return;
-
- SetVertexAttributes(m, shader);
-
- if (m.Checked)
- {
- if ((m.IsSelected))
- {
- DrawModelSelection(m, shader);
- }
- else
- {
- if (Runtime.RenderModelWireframe)
- {
- DrawModelWireframe(m, shader);
- }
-
- if (Runtime.RenderModels)
- {
- GL.DrawElements(PrimitiveType.Triangles, m.displayFaceSize, DrawElementsType.UnsignedInt, m.Offset);
- }
- }
- }
- }
- private static void DrawModelSelection(KCLModel p, Shader shader)
- {
- //This part needs to be reworked for proper outline. Currently would make model disappear
-
- GL.DrawElements(PrimitiveType.Triangles, p.displayFaceSize, DrawElementsType.UnsignedInt, p.Offset);
-
- GL.Enable(EnableCap.StencilTest);
- // use vertex color for wireframe color
- shader.SetInt("colorOverride", 1);
- GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);
- GL.Enable(EnableCap.LineSmooth);
- GL.LineWidth(1.5f);
- GL.DrawElements(PrimitiveType.Triangles, p.displayFaceSize, DrawElementsType.UnsignedInt, p.Offset);
- GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
- shader.SetInt("colorOverride", 0);
-
- GL.Enable(EnableCap.DepthTest);
- }
- private void SetVertexAttributes(KCLModel m, Shader shader)
- {
- GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_position);
- GL.VertexAttribPointer(shader.GetAttribLocation("vPosition"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 0);
- GL.VertexAttribPointer(shader.GetAttribLocation("vNormal"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 12);
- GL.VertexAttribPointer(shader.GetAttribLocation("vColor"), 3, VertexAttribPointerType.Float, false, DisplayVertex.Size, 24);
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo_elements);
- }
- private static void DrawModelWireframe(KCLModel p, Shader shader)
- {
- // use vertex color for wireframe color
- shader.SetInt("colorOverride", 1);
- GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);
- GL.Enable(EnableCap.LineSmooth);
- GL.LineWidth(1.5f);
- GL.DrawElements(PrimitiveType.Triangles, p.displayFaceSize, DrawElementsType.UnsignedInt, p.Offset);
- GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
- shader.SetInt("colorOverride", 0);
- }
- }
-
- //Convert KCL lib vec3 to opentk one so i can use the cross and dot methods
- public static Vector3 Vec3D_To_Vec3(System.Windows.Media.Media3D.Vector3D v)
- {
- return new Vector3((float)v.X, (float)v.Y, (float)v.Z);
- }
- public struct DisplayVertex
- {
- // Used for rendering.
- public Vector3 pos;
- public Vector3 nrm;
- public Vector3 col;
-
- public static int Size = 4 * (3 + 3 + 3);
- }
- public class KCLModel : STGenericObject
- {
- public KCLModel()
- {
- ImageKey = "mesh";
- SelectedImageKey = "mesh";
-
- Checked = true;
- }
-
- public int[] display;
- public int Offset; // For Rendering
-
- public int strip = 0x40;
- public int displayFaceSize = 0;
-
- public class Face : TreeNode
- {
- public int MaterialFlag = 0;
-
- }
-
- public List CreateDisplayVertices()
- {
- // rearrange faces
- display = getDisplayFace().ToArray();
-
- List displayVertList = new List();
-
- if (faces.Count <= 3)
- return displayVertList;
-
- foreach (Vertex v in vertices)
- {
- DisplayVertex displayVert = new DisplayVertex()
- {
- pos = v.pos,
- nrm = v.nrm,
- col = v.col.Xyz,
- };
-
- displayVertList.Add(displayVert);
- }
-
- return displayVertList;
- }
-
- public List getDisplayFace()
- {
- if ((strip >> 4) == 4)
- {
- displayFaceSize = faces.Count;
- return faces;
- }
- else
- {
- List f = new List();
-
- int startDirection = 1;
- int p = 0;
- int f1 = faces[p++];
- int f2 = faces[p++];
- int faceDirection = startDirection;
- int f3;
- do
- {
- f3 = faces[p++];
- if (f3 == 0xFFFF)
- {
- f1 = faces[p++];
- f2 = faces[p++];
- faceDirection = startDirection;
- }
- else
- {
- faceDirection *= -1;
- if ((f1 != f2) && (f2 != f3) && (f3 != f1))
- {
- if (faceDirection > 0)
- {
- f.Add(f3);
- f.Add(f2);
- f.Add(f1);
- }
- else
- {
- f.Add(f2);
- f.Add(f3);
- f.Add(f1);
- }
- }
- f1 = f2;
- f2 = f3;
- }
- } while (p < faces.Count);
-
- displayFaceSize = f.Count;
- return f;
- }
- }
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/MSBT.cs b/Switch_FileFormatsMain/FileFormats/MSBT.cs
deleted file mode 100644
index a900ea12..00000000
--- a/Switch_FileFormatsMain/FileFormats/MSBT.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Switch_Toolbox;
-using System.Windows.Forms;
-using Switch_Toolbox.Library;
-
-namespace FirstPlugin
-{
- public class MSBT : IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "AAMP" };
- public string[] Extension { get; set; } = new string[] { "*.aamp" };
- public string Magic { get; set; } = "MsgStdBn";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public int Alignment { get; set; } = 0;
- public string FilePath { get; set; }
- public IFileInfo IFileInfo { get; set; }
- public Type[] Types
- {
- get
- {
- List types = new List();
- return types.ToArray();
- }
- }
-
- public void Load()
- {
- IsActive = true;
- }
- public void Unload()
- {
-
- }
- public byte[] Save()
- {
- return null;
- }
- }
-}
diff --git a/Switch_FileFormatsMain/FileFormats/SARC.cs b/Switch_FileFormatsMain/FileFormats/SARC.cs
deleted file mode 100644
index a882d8ac..00000000
--- a/Switch_FileFormatsMain/FileFormats/SARC.cs
+++ /dev/null
@@ -1,401 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using Switch_Toolbox;
-using System.Windows.Forms;
-using SARCExt;
-using Switch_Toolbox.Library;
-using Switch_Toolbox.Library.IO;
-using Switch_Toolbox.Library.Forms;
-
-namespace FirstPlugin
-{
- public class SARC : TreeNodeFile, IFileFormat
- {
- public bool CanSave { get; set; } = false;
- public bool FileIsEdited { get; set; } = false;
- public bool FileIsCompressed { get; set; } = false;
- public string[] Description { get; set; } = new string[] { "*SARC", "*SARC", "*SARC" };
- public string[] Extension { get; set; } = new string[] { "*.szs", "*.pack", "*.sarc" };
- public string Magic { get; set; } = "SARC";
- public CompressionType CompressionType { get; set; } = CompressionType.None;
- public byte[] Data { get; set; }
- public string FileName { get; set; }
- public bool IsActive { get; set; } = false;
- public bool UseEditMenu { get; set; } = false;
- public string FilePath { get; set; }
- public IFileInfo IFileInfo { get; set; }
- public Type[] Types
- {
- get
- {
- List types = new List();
- return types.ToArray();
- }
- }
-
- public SarcData sarcData;
- public string SarcHash;
- public void Load()
- {
- IsActive = true;
- CanSave = true;
- UseEditMenu = true;
-
- var SzsFiles = SARCExt.SARC.UnpackRamN(Data);
- sarcData = new SarcData();
- sarcData.HashOnly = false;
- sarcData.Files = SzsFiles.Files;
- sarcData.endianness = GetByteOrder(Data);
- SarcHash = Utils.GenerateUniqueHashID();
-
- IFileInfo = new IFileInfo();
- FillTreeNodes(this, SzsFiles.Files, SarcHash);
-
- Text = FileName;
-
- ContextMenu = new ContextMenu();
- MenuItem save = new MenuItem("Save");
- ContextMenu.MenuItems.Add(save);
- save.Click += Save;
-
- sarcData.Files.Clear();
- }
- public Syroot.BinaryData.ByteOrder GetByteOrder(byte[] data)
- {
- using (FileReader reader = new FileReader(data))
- {
- reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
- reader.Seek(6);
- ushort bom = reader.ReadUInt16();
- reader.Close();
- reader.Dispose();
-
- if (bom == 0xFFFE)
- return Syroot.BinaryData.ByteOrder.LittleEndian;
- else
- return Syroot.BinaryData.ByteOrder.BigEndian;
- }
- }
-
- public void Unload()
- {
- Nodes.Clear();
- }
-
- IEnumerable Collect(TreeNodeCollection nodes)
- {
- foreach (TreeNode node in nodes)
- {
- yield return node;
-
- foreach (var child in Collect(node.Nodes))
- yield return child;
- }
- }
- public byte[] Save()
- {
- Console.WriteLine("Saving sarc");
-
- sarcData.Files.Clear();
- foreach (TreeNode node in Collect(Nodes))
- {
- if (node is SarcEntry)
- {
- Console.WriteLine("Saving " + node);
- SaveFileEntryData((SarcEntry)node);
- }
- else if (node is TreeNodeFile && node != this)
- {
- IFileFormat fileFormat = (IFileFormat)node;
- if (fileFormat != null && fileFormat.IFileInfo != null && fileFormat.IFileInfo.ArchiveHash == SarcHash)
- {
- sarcData.Files.Add(SetSarcPath(node, this),
- STLibraryCompression.CompressFile(fileFormat.Save(), fileFormat));
- }
- }
- }
-
- Tuple sarc = SARCExt.SARC.PackN(sarcData);
- IFileInfo.Alignment = sarc.Item1;
- return sarc.Item2;
- }
-
- public static string SetSarcPath(TreeNode node, TreeNode sarcNode)
- {
- string nodePath = node.FullPath;
- int startIndex = nodePath.IndexOf(sarcNode.Text);
- if (startIndex > 0)
- nodePath = nodePath.Substring(startIndex);
-
- string slash = Path.DirectorySeparatorChar.ToString();
- string slashAlt = Path.AltDirectorySeparatorChar.ToString();
-
- string SetPath = nodePath.Replace(sarcNode.Text + slash, string.Empty).Replace(slash ?? "", slashAlt);
- return !(SetPath == string.Empty) ? SetPath : node.Text;
- }
-
- private void SaveFileEntryData(SarcEntry sarc)
- {
- string dir = Path.GetDirectoryName(sarc.FullName);
-
- Console.WriteLine(sarc.FullName);
-
- if (dir == string.Empty)
- sarc.FullName = sarc.Text;
- else
- sarc.FullName = dir + "/" + sarc.Text;
-
- Console.WriteLine(sarc.FullName);
-
- sarcData.Files.Add(sarc.FullName, sarc.Data);
- }
- public static void ReplaceNode(TreeNode node, TreeNode replaceNode, TreeNode NewNode)
- {
- if (NewNode == null)
- return;
-
- int index = node.Nodes.IndexOf(replaceNode);
- node.Nodes.RemoveAt(index);
- node.Nodes.Insert(index, NewNode);
- }
-
- private void Save(object sender, EventArgs args)
- {
- List formats = new List();
- formats.Add(this);
-
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = Utils.GetAllFilters(formats);
- sfd.FileName = FileName;
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- STFileSaver.SaveFileFormat(this, sfd.FileName, IFileInfo.Alignment);
- }
- }
- private void CallRecursive(TreeView treeView)
- {
- // Print each node recursively.
- TreeNodeCollection nodes = treeView.Nodes;
- foreach (TreeNode n in nodes)
- {
- PrintRecursive(n);
- }
- }
- private void PrintRecursive(TreeNode treeNode)
- {
- // Print the node.
-
- if (treeNode is SarcEntry)
- {
- ((SarcEntry)treeNode).OnClick(treeNode.TreeView);
- }
- if (treeNode is IFileFormat)
- {
-
- }
-
- // Print each node recursively.
- foreach (TreeNode tn in treeNode.Nodes)
- {
- PrintRecursive(tn);
- }
- }
- public class SarcEntry : TreeNodeCustom
- {
- public SARC sarc; //Sarc file the entry is located in
- public byte[] Data;
- public string sarcHash;
-
- public SarcEntry()
- {
- ImageKey = "fileBlank";
- SelectedImageKey = "fileBlank";
-
- ContextMenu = new ContextMenu();
- MenuItem export = new MenuItem("Export");
- ContextMenu.MenuItems.Add(export);
- export.Click += Export;
-
- MenuItem replace = new MenuItem("Replace");
- ContextMenu.MenuItems.Add(replace);
- replace.Click += Replace;
-
- MenuItem remove = new MenuItem("Remove");
- ContextMenu.MenuItems.Add(remove);
- remove.Click += Remove;
-
- MenuItem rename = new MenuItem("Rename");
- ContextMenu.MenuItems.Add(rename);
- rename.Click += Rename;
- }
- public override void OnDoubleMouseClick(TreeView treeView)
- {
- TreeNode node = STFileLoader.GetNodeFileFormat(FullName, Data, true, sarcHash, this);
-
- if (node != null)
- ReplaceNode(this.Parent, this, node);
- }
-
- private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
- {
- TreeNode node = TreeView.SelectedNode;
-
- // Determine by checking the Text property.
- MessageBox.Show(node.Text);
- }
-
- public string FullName;
- public IFileFormat FileHandle; //Load file instance to save later if possible
- private void Replace(object sender, EventArgs args)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.FileName = Text;
- ofd.DefaultExt = Path.GetExtension(Text);
- ofd.Filter = "All files(*.*)|*.*";
-
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- Data = File.ReadAllBytes(ofd.FileName);
- }
- }
- private void Export(object sender, EventArgs args)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.FileName = Text;
- sfd.DefaultExt = Path.GetExtension(Text);
- sfd.Filter = "All files(*.*)|*.*";
-
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- File.WriteAllBytes(sfd.FileName, Data);
- }
- }
- private void Remove(object sender, EventArgs args)
- {
- DialogResult result = MessageBox.Show($"Are your sure you want to remove {Text}? This cannot be undone!", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
-
- if (result == DialogResult.Yes)
- {
- Parent.Nodes.Remove(this);
- }
- }
- private void Rename(object sender, EventArgs args)
- {
- RenameDialog dialog = new RenameDialog();
- dialog.SetString(Text);
-
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- Text = dialog.textBox1.Text;
- }
- }
- }
- void FillTreeNodes(TreeNode root, Dictionary files, string SarcHash)
- {
- var rootText = root.Text;
- var rootTextLength = rootText.Length;
- var nodeStrings = files;
- foreach (var node in nodeStrings)
- {
- string nodeString = node.Key;
-
- var roots = nodeString.Split(new char[] { '/' },
- StringSplitOptions.RemoveEmptyEntries);
-
- // The initial parent is the root node
- var parentNode = root;
- var sb = new StringBuilder(rootText, nodeString.Length + rootTextLength);
- for (int rootIndex = 0; rootIndex < roots.Length; rootIndex++)
- {
- // Build the node name
- var parentName = roots[rootIndex];
- sb.Append("/");
- sb.Append(parentName);
- var nodeName = sb.ToString();
-
- // Search for the node
- var index = parentNode.Nodes.IndexOfKey(nodeName);
- if (index == -1)
- {
- // Node was not found, add it
-
- var temp = new TreeNode(parentName, 0, 0);
- if (rootIndex == roots.Length - 1)
- temp = SetupFileEntry(node.Value, parentName, node.Key, SarcHash);
-
- temp.Name = nodeName;
- parentNode.Nodes.Add(temp);
- parentNode = temp;
- }
- else
- {
- // Node was found, set that as parent and continue
- parentNode = parentNode.Nodes[index];
- }
- }
- }
- }
-
- List BuildFinalList(List