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

Add model cycling if multiple models are active in an editor.

Models can be cycled in the same editor. The active one now gets properly set. You can adjust the combo box to preview multiple models in the scene.
Fixed a bug where some models would project on the top of the screen as duplicates.
This commit is contained in:
KillzXGaming 2019-06-06 15:40:32 -04:00
parent 04c43b8bd5
commit 157ff75b79
37 changed files with 620 additions and 232 deletions

Binary file not shown.

View File

@ -43,6 +43,7 @@ namespace FirstPlugin
public BcresFile BcresFile;
public BCRES_Render RenderedBcres;
public DrawableContainer DrawableContainer = new DrawableContainer();
public void Load(System.IO.Stream stream)
{
@ -50,6 +51,9 @@ namespace FirstPlugin
BcresFile = new BcresFile(stream);
RenderedBcres = new BCRES_Render();
DrawableContainer.Name = FileName;
DrawableContainer.Drawables.Add(RenderedBcres);
AddNodeGroup(BcresFile.Data.Models, new BCRESGroupNode(BCRESGroupType.Models));
AddNodeGroup(BcresFile.Data.Textures, new BCRESGroupNode(BCRESGroupType.Textures));
AddNodeGroup(BcresFile.Data.Lookups, new BCRESGroupNode(BCRESGroupType.Lookups));
@ -96,8 +100,7 @@ namespace FirstPlugin
}
}
List<AbstractGlDrawable> drawables = new List<AbstractGlDrawable>();
private bool DrawablesLoaded;
public void LoadEditors(TreeNode Wrapper, Action OnPropertyChanged)
{
BcresEditor bcresEditor = (BcresEditor)LibraryGUI.Instance.GetActiveContent(typeof(BcresEditor));
@ -109,20 +112,21 @@ namespace FirstPlugin
LibraryGUI.Instance.LoadEditor(bcresEditor);
}
if (drawables.Count <= 0)
if (!DrawablesLoaded)
{
//Add drawables
drawables.Add(RenderedBcres);
ObjectEditor.AddContainer(DrawableContainer);
for (int m = 0; m < RenderedBcres.Models.Count; m++)
{
if (RenderedBcres.Models[m].Skeleton.Renderable != null)
drawables.Add(RenderedBcres.Models[m].Skeleton.Renderable);
DrawableContainer.Drawables.Add(RenderedBcres.Models[m].Skeleton.Renderable);
}
DrawablesLoaded = true;
}
if (Runtime.UseOpenGL)
bcresEditor.LoadViewport(drawables);
bcresEditor.LoadViewport(this, DrawableContainer);
if (Wrapper is BcresTextureMapWrapper)
{
@ -166,7 +170,7 @@ namespace FirstPlugin
public void Unload()
{
ObjectEditor.RemoveContainer(DrawableContainer);
}
public byte[] Save()
{

View File

@ -10,7 +10,7 @@ using BcresLibrary;
namespace FirstPlugin
{
public class CRESSkeletonWrapper : STBone
public class CRESSkeletonWrapper : TreeNodeCustom
{
internal BCRES BcresParent;
internal Skeleton Skeleton;

View File

@ -49,10 +49,11 @@ namespace FirstPlugin
}
}
private Thread Thread;
public override string ExportFilter => Utils.GetAllFilters(new BFRES());
//Stores the skeleton and models in this
public DrawableContainer DrawableContainer = new DrawableContainer();
class MenuExt : IFileMenuExtension
{
public STToolStripItem[] NewFileMenuExtensions => newFileExt;
@ -176,29 +177,6 @@ namespace FirstPlugin
editor.Refresh();
}
//Used for adding new skeleton drawables
public void AddSkeletonDrawable(STSkeleton skeleton)
{
BfresEditor bfresEditor = (BfresEditor)LibraryGUI.Instance.GetActiveContent(typeof(BfresEditor));
if (bfresEditor != null)
{
bfresEditor.AddDrawable(skeleton);
}
drawables.Add(skeleton);
}
public void RemoveSkeletonDrawable(STSkeleton skeleton)
{
BfresEditor bfresEditor = (BfresEditor)LibraryGUI.Instance.GetActiveContent(typeof(BfresEditor));
if (bfresEditor != null)
{
bfresEditor.RemoveDrawable(skeleton);
}
drawables.Remove(skeleton);
}
public void LoadAdvancedMode()
{
foreach (var model in BFRESRender.models)
@ -300,7 +278,7 @@ namespace FirstPlugin
return "";
}
List<AbstractGlDrawable> drawables = new List<AbstractGlDrawable>();
private bool DrawablesLoaded = false;
public void LoadEditors(object SelectedSection)
{
BfresEditor bfresEditor = (BfresEditor)LibraryGUI.Instance.GetActiveContent(typeof(BfresEditor));
@ -405,18 +383,14 @@ namespace FirstPlugin
return;
}
if (drawables.Count <= 0)
if (!DrawablesLoaded)
{
//Add drawables
drawables.Add(BFRESRender);
for (int m = 0; m < BFRESRender.models.Count; m++)
drawables.Add(BFRESRender.models[m].Skeleton);
ObjectEditor.AddContainer(DrawableContainer);
DrawablesLoaded = true;
}
if (Runtime.UseOpenGL)
bfresEditor.LoadViewport(drawables, new List<ToolStripMenuItem>());
bfresEditor.LoadViewport(this, DrawableContainer);
bool IsSimpleEditor = PluginRuntime.UseSimpleBfresEditor;
@ -707,10 +681,14 @@ namespace FirstPlugin
reader.Position = 0;
}
LoadMenus(IsWiiU);
BFRESRender = new BFRESRender();
DrawableContainer.Drawables.Add(BFRESRender);
DrawableContainer.Name = FileName;
BFRESRender.ModelTransform = MarioCostumeEditor.SetTransform(FileName);
BFRESRender.ResFileNode = this;
@ -723,11 +701,20 @@ namespace FirstPlugin
{
LoadFile(new Syroot.NintenTools.NSW.Bfres.ResFile(stream));
}
var Models = GetModels();
if (Models != null)
{
foreach (FMDL mdl in Models)
DrawableContainer.Drawables.Add(mdl.Skeleton);
}
}
public void Unload()
{
BFRESRender.Destroy();
ObjectEditor.RemoveContainer(DrawableContainer);
foreach (var node in TreeViewExtensions.Collect(BFRESRender.ResFileNode.Nodes))
{
if (node is BFRESGroupNode)

View File

@ -192,7 +192,7 @@ namespace Bfres.Structs
fmdl.ModelU.Materials.Add("NewMaterial", new ResU.Material() { Name = "NewMaterial", RenderState = new ResU.RenderState(), });
BfresWiiU.ReadModel(fmdl, fmdl.ModelU);
((BFRES)Parent).AddSkeletonDrawable(fmdl.Skeleton);
((BFRES)Parent).DrawableContainer.Drawables.Add(fmdl.Skeleton);
}
else
{
@ -218,7 +218,7 @@ namespace Bfres.Structs
fmdl.Model.VertexBuffers.Add(VertexBuffer);
BfresSwitch.ReadModel(fmdl, fmdl.Model);
((BFRES)Parent).AddSkeletonDrawable(fmdl.Skeleton);
((BFRES)Parent).DrawableContainer.Drawables.Add(fmdl.Skeleton);
}
if (AddTreeNode)

View File

@ -108,7 +108,7 @@ namespace Bfres.Structs
if (dialogResult == DialogResult.Yes)
{
((BFRES)Parent.Parent).RemoveSkeletonDrawable(Skeleton);
((BFRES)Parent.Parent).DrawableContainer.Drawables.Remove(Skeleton);
shapes.Clear();
materials.Clear();
@ -469,7 +469,7 @@ namespace Bfres.Structs
public override void Unload()
{
if (Parent != null)
((BFRES)Parent.Parent).RemoveSkeletonDrawable(Skeleton);
((BFRES)Parent.Parent).DrawableContainer.Drawables.Remove(Skeleton);
shapes.Clear();
materials.Clear();

View File

@ -75,11 +75,19 @@ namespace FirstPlugin
}
}
public DrawableContainer DrawableContainer = new DrawableContainer();
public void Load(System.IO.Stream stream)
{
Text = FileName;
Renderer = new KCLRendering();
DrawableContainer = new DrawableContainer()
{
Name = FileName,
Drawables = new List<AbstractGlDrawable>() { Renderer },
};
stream.Position = 0;
data = stream.ToArray();
Read(data);
@ -123,6 +131,13 @@ namespace FirstPlugin
kcl.IFileInfo = new IFileInfo();
kcl.FileName = name;
kcl.Renderer = new KCLRendering();
kcl.DrawableContainer = new DrawableContainer()
{
Name = kcl.FileName,
Drawables = new List<AbstractGlDrawable>() { kcl.Renderer },
};
kcl.Read(f.Write(ByteOrder));
ObjectEditor editor = new ObjectEditor(kcl);
@ -133,7 +148,7 @@ namespace FirstPlugin
public void Unload()
{
ObjectEditor.RemoveContainer(DrawableContainer);
}
public byte[] Save()
{
@ -294,27 +309,27 @@ namespace FirstPlugin
}
public KCLRendering Renderer;
bool IsLoaded = false;
bool DrawablesLoaded = false;
public override void OnClick(TreeView treeView)
{
if (Runtime.UseOpenGL)
{
if (viewport == null)
{
viewport = new Viewport();
viewport = new Viewport(ObjectEditor.GetDrawableContainers());
viewport.Dock = DockStyle.Fill;
}
if (!DrawablesLoaded)
{
ObjectEditor.AddContainer(DrawableContainer);
DrawablesLoaded = true;
}
viewport.ReloadDrawables(DrawableContainer);
LibraryGUI.Instance.LoadEditor(viewport);
viewport.Text = Text;
if (!IsLoaded)
{
viewport.AddDrawable(Renderer);
viewport.LoadObjects();
}
IsLoaded = true;
}
}

View File

@ -43,7 +43,7 @@ namespace FirstPlugin.Forms
OnLoadedTab();
else
{
viewport = new Viewport();
viewport = new Viewport(ObjectEditor.GetDrawableContainers());
viewport.Dock = DockStyle.Fill;
OnLoadedTab();
}
@ -80,7 +80,7 @@ namespace FirstPlugin.Forms
//Always create an instance of the viewport unless opengl is disabled
if (viewport == null && Runtime.UseOpenGL)
{
viewport = new Viewport();
viewport = new Viewport(ObjectEditor.GetDrawableContainers());
viewport.Dock = DockStyle.Fill;
}
@ -134,16 +134,11 @@ namespace FirstPlugin.Forms
public bool IsLoaded = false;
private BCRES ActiveBcres;
//All drawables for this particular editor
List<AbstractGlDrawable> Drawables;
//Drawables removed but the viewport is toggled off to update
List<AbstractGlDrawable> RemovedDrawables = new List<AbstractGlDrawable>();
public void LoadViewport(List<AbstractGlDrawable> drawables, List<ToolStripMenuItem> customContextMenus = null)
public void LoadViewport(BCRES bcres, DrawableContainer ActiveDrawable, List<ToolStripMenuItem> customContextMenus = null)
{
Drawables = drawables;
ActiveBcres = bcres;
if (!Runtime.UseOpenGL || !DisplayViewport)
return;
@ -154,40 +149,11 @@ namespace FirstPlugin.Forms
viewport.LoadCustomMenuItem(menu);
}
viewport.ReloadDrawables(ActiveDrawable);
OnLoadedTab();
}
public void AddDrawable(AbstractGlDrawable draw)
{
Drawables.Add(draw);
if (!Runtime.UseOpenGL || !Runtime.DisplayViewport || viewport == null)
{
IsLoaded = false;
return;
}
if (!viewport.scene.staticObjects.Contains(draw) &&
!viewport.scene.objects.Contains(draw))
{
viewport.AddDrawable(draw);
}
}
public void RemoveDrawable(AbstractGlDrawable draw)
{
Drawables.Remove(draw);
if (!Runtime.UseOpenGL || !Runtime.DisplayViewport || viewport == null)
{
IsLoaded = false;
RemovedDrawables.Add(draw);
return;
}
viewport.RemoveDrawable(draw);
}
public override void OnControlClosing()
{
}
@ -195,23 +161,9 @@ namespace FirstPlugin.Forms
private void OnLoadedTab()
{
//If a model was loaded we don't need to load the drawables again
if (IsLoaded || Drawables == null || !Runtime.UseOpenGL || !Runtime.DisplayViewport)
if (IsLoaded ||!Runtime.UseOpenGL || !Runtime.DisplayViewport)
return;
Console.WriteLine("drawables count " + Drawables.Count);
foreach (var draw in Drawables)
{
if (!viewport.scene.staticObjects.Contains(draw) &&
!viewport.scene.objects.Contains(draw))
{
viewport.AddDrawable(draw);
}
}
foreach (var draw in RemovedDrawables)
viewport.RemoveDrawable(draw);
viewport.LoadObjects();
IsLoaded = true;

View File

@ -182,6 +182,7 @@
this.Controls.Add(this.stPanel2);
this.Name = "BfresEditor";
this.Size = new System.Drawing.Size(712, 543);
this.Enter += new System.EventHandler(this.BfresEditor_Enter);
this.stPanel2.ResumeLayout(false);
this.stPanel2.PerformLayout();
this.stToolStrip1.ResumeLayout(false);

View File

@ -43,7 +43,7 @@ namespace FirstPlugin.Forms
OnLoadedTab();
else
{
viewport = new Viewport();
viewport = new Viewport(ObjectEditor.GetDrawableContainers());
viewport.Dock = DockStyle.Fill;
OnLoadedTab();
}
@ -89,7 +89,7 @@ namespace FirstPlugin.Forms
//Always create an instance of the viewport unless opengl is disabled
if (viewport == null && Runtime.UseOpenGL)
{
viewport = new Viewport();
viewport = new Viewport(ObjectEditor.GetDrawableContainers());
viewport.Dock = DockStyle.Fill;
}
@ -156,15 +156,10 @@ namespace FirstPlugin.Forms
public bool IsLoaded = false;
//All drawables for this particular editor
List<AbstractGlDrawable> Drawables;
//Drawables removed but the viewport is toggled off to update
List<AbstractGlDrawable> RemovedDrawables = new List<AbstractGlDrawable>();
public void LoadViewport(List<AbstractGlDrawable> drawables, List<ToolStripMenuItem> customContextMenus = null)
private BFRES ActiveBfres;
public void LoadViewport(BFRES bfres, DrawableContainer ActiveDrawable, List<ToolStripMenuItem> customContextMenus = null)
{
Drawables = drawables;
ActiveBfres = bfres;
if (!Runtime.UseOpenGL || !DisplayViewport)
return;
@ -175,40 +170,11 @@ namespace FirstPlugin.Forms
viewport.LoadCustomMenuItem(menu);
}
viewport.ReloadDrawables(ActiveDrawable);
OnLoadedTab();
}
public void AddDrawable(AbstractGlDrawable draw)
{
Drawables.Add(draw);
if (!Runtime.UseOpenGL || !Runtime.DisplayViewport || viewport == null)
{
IsLoaded = false;
return;
}
if (!viewport.scene.staticObjects.Contains(draw) &&
!viewport.scene.objects.Contains(draw))
{
viewport.AddDrawable(draw);
}
}
public void RemoveDrawable(AbstractGlDrawable draw)
{
Drawables.Remove(draw);
if (!Runtime.UseOpenGL || !Runtime.DisplayViewport || viewport == null)
{
IsLoaded = false;
RemovedDrawables.Add(draw);
return;
}
viewport.RemoveDrawable(draw);
}
public override void OnControlClosing()
{
animationPanel.ClosePanel();
@ -217,23 +183,9 @@ namespace FirstPlugin.Forms
private void OnLoadedTab()
{
//If a model was loaded we don't need to load the drawables again
if (IsLoaded || Drawables == null || !Runtime.UseOpenGL || !Runtime.DisplayViewport)
if (IsLoaded ||!Runtime.UseOpenGL || !Runtime.DisplayViewport)
return;
Console.WriteLine("drawables count " + Drawables.Count);
foreach (var draw in Drawables)
{
if (!viewport.scene.staticObjects.Contains(draw) &&
!viewport.scene.objects.Contains(draw))
{
viewport.AddDrawable(draw);
}
}
foreach (var draw in RemovedDrawables)
viewport.RemoveDrawable(draw);
viewport.LoadObjects();
IsLoaded = true;
@ -280,5 +232,10 @@ namespace FirstPlugin.Forms
DisplayViewport = Runtime.DisplayViewport;
Config.Save();
}
private void BfresEditor_Enter(object sender, EventArgs e)
{
}
}
}

View File

@ -34,7 +34,7 @@ namespace FirstPlugin.Forms
treeView1.BackColor = FormThemes.BaseTheme.FormBackColor;
treeView1.ForeColor = FormThemes.BaseTheme.FormForeColor;
viewport = new Viewport();
viewport = new Viewport(ObjectEditor.GetDrawableContainers());
viewport.Dock = DockStyle.Fill;
viewport.scene.SelectionChanged += Scene_SelectionChanged;
stPanel4.Controls.Add(viewport);

View File

@ -286,11 +286,11 @@
<DependentUpon>SmoothNormalsMultiMeshForm.cs</DependentUpon>
</Compile>
<Compile Include="YAML\YamlAamp.cs" />
<Compile Include="GUI\BCRES\BfresEditor.cs">
<Compile Include="GUI\BCRES\BcresEditor.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="GUI\BCRES\BfresEditor.Designer.cs">
<DependentUpon>BfresEditor.cs</DependentUpon>
<Compile Include="GUI\BCRES\BcresEditor.Designer.cs">
<DependentUpon>BcresEditor.cs</DependentUpon>
</Compile>
<Compile Include="GUI\BCRES\Material\SamplerEditorSimple.cs">
<SubType>UserControl</SubType>
@ -928,8 +928,8 @@
<EmbeddedResource Include="GUI\AttributeEditor.resx">
<DependentUpon>AttributeEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="GUI\BCRES\BfresEditor.resx">
<DependentUpon>BfresEditor.cs</DependentUpon>
<EmbeddedResource Include="GUI\BCRES\BcresEditor.resx">
<DependentUpon>BcresEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="GUI\BCRES\Material\SamplerEditorSimple.resx">
<DependentUpon>SamplerEditorSimple.cs</DependentUpon>

View File

@ -1 +1 @@
3779dc3a197c1f391b60c356a4d2114a1d71e61a
5e2bb78fbebca632406427d80546922252d8f7ff

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GL_EditorFramework.Interfaces;
using Switch_Toolbox.Library.Forms;
namespace Switch_Toolbox.Library
{
//Represents a container that stores multiple drawables
//These can be switched between the viewport
public class DrawableContainer
{
private string _name;
public string Name
{
set
{
List<string> Names = ObjectEditor.GetDrawableContainers().Select(o => o.Name).ToList();
foreach (string str in Names)
Console.WriteLine("STR NAME " + str);
_name = Utils.RenameDuplicateString(Names, value);
}
get
{
return _name;
}
}
public ContainerState ContainerState { get; set; }
public List<AbstractGlDrawable> Drawables = new List<AbstractGlDrawable>();
}
public enum ContainerState
{
Active,
Inactive,
Disposed,
}
}

View File

@ -6,6 +6,7 @@ using Switch_Toolbox.Library;
using Switch_Toolbox.Library.Animations;
using Switch_Toolbox.Library.Rendering;
using System.Windows.Forms;
using System.Linq;
namespace Switch_Toolbox.Library
{
@ -42,14 +43,14 @@ namespace Switch_Toolbox.Library
progressBar.Task = "Saving File...";
progressBar.Value = 80;
SaveScene(FileName, scene);
SaveScene(FileName, scene, model);
progressBar.Value = 100;
progressBar.Close();
progressBar.Dispose();
}
private void SaveScene(string FileName, Scene scene)
private void SaveScene(string FileName, Scene scene, STGenericModel model)
{
using (var v = new AssimpContext())
{
@ -65,11 +66,16 @@ namespace Switch_Toolbox.Library
if (ext == ".ply")
formatID = "ply";
if (v.ExportFile(scene, FileName, formatID, PostProcessSteps.FlipUVs))
bool ExportSuccessScene = v.ExportFile(scene, FileName, formatID, PostProcessSteps.FlipUVs);
if (ExportSuccessScene)
{
// WriteExtraSkinningInfo(FileName, scene, model);
MessageBox.Show($"Exported {FileName} Successfuly!");
}
else
MessageBox.Show($"Failed to export {FileName}!");
}
}
private void SaveMeshes(Scene scene, STGenericModel model, STSkeleton skeleton, string FileName, List<int> NodeArray)
@ -171,6 +177,295 @@ namespace Switch_Toolbox.Library
return mesh;
}
//Extra skin data based on https://github.com/Sage-of-Mirrors/SuperBMD/blob/ce1061e9b5f57de112f1d12f6459b938594664a0/SuperBMDLib/source/Model.cs#L193
//Todo this doesn't quite work yet
//Need to adjust all mesh name IDs so they are correct
private void WriteExtraSkinningInfo(string FileName, Scene outScene, STGenericModel Model)
{
StreamWriter test = new StreamWriter(FileName + ".tmp");
StreamReader dae = File.OpenText(FileName);
while (!dae.EndOfStream)
{
string line = dae.ReadLine();
if (line == " <library_visual_scenes>")
{
AddControllerLibrary(outScene, test);
test.WriteLine(line);
test.Flush();
}
else if (line.Contains("<node"))
{
string[] testLn = line.Split('\"');
string name = testLn[3];
string jointLine = line.Replace(">", $" sid=\"{ name }\" type=\"JOINT\">");
test.WriteLine(jointLine);
test.Flush();
}
if (line.Contains("</visual_scene>"))
{
int index = 0;
foreach (Mesh mesh in outScene.Meshes)
{
test.WriteLine($" <node id=\"{ mesh.Name }\" name=\"{ mesh.Name }\" type=\"NODE\">");
test.WriteLine($" <instance_controller url=\"#{ mesh.Name }-skin\">");
test.WriteLine(" <skeleton>#skeleton_root</skeleton>");
test.WriteLine(" <bind_material>");
test.WriteLine(" <technique_common>");
test.WriteLine($" <instance_material symbol=\"theresonlyone\" target=\"#m{ mesh.MaterialIndex }mat\" />");
test.WriteLine(" </technique_common>");
test.WriteLine(" </bind_material>");
test.WriteLine(" </instance_controller>");
test.WriteLine(" </node>");
test.Flush();
index++;
}
test.WriteLine(line);
test.Flush();
}
else if (line.Contains("<matrix"))
{
string matLine = line.Replace("<matrix>", "<matrix sid=\"matrix\">");
test.WriteLine(matLine);
test.Flush();
}
else
{
test.WriteLine(line);
test.Flush();
}
}
test.Close();
dae.Close();
File.Copy(FileName + ".tmp", FileName, true);
File.Delete(FileName + ".tmp");
}
private void AddControllerLibrary(Scene scene, StreamWriter writer)
{
writer.WriteLine(" <library_controllers>");
for (int i = 0; i < scene.MeshCount; i++)
{
Mesh curMesh = scene.Meshes[i];
curMesh.Name = curMesh.Name.Replace('_', '-');
writer.WriteLine($" <controller id=\"{ curMesh.Name }-skin\" name=\"{ curMesh.Name }Skin\">");
writer.WriteLine($" <skin source=\"#meshId{ i }\">");
WriteBindShapeMatrixToStream(writer);
WriteJointNameArrayToStream(curMesh, writer);
WriteInverseBindMatricesToStream(curMesh, writer);
WriteSkinWeightsToStream(curMesh, writer);
writer.WriteLine(" <joints>");
writer.WriteLine($" <input semantic=\"JOINT\" source=\"#{ curMesh.Name }-skin-joints-array\"></input>");
writer.WriteLine($" <input semantic=\"INV_BIND_MATRIX\" source=\"#{ curMesh.Name }-skin-bind_poses-array\"></input>");
writer.WriteLine(" </joints>");
writer.Flush();
WriteVertexWeightsToStream(curMesh, writer);
writer.WriteLine(" </skin>");
writer.WriteLine(" </controller>");
writer.Flush();
}
writer.WriteLine(" </library_controllers>");
writer.Flush();
}
private void WriteJointNameArrayToStream(Mesh mesh, StreamWriter writer)
{
writer.WriteLine($" <source id =\"{ mesh.Name }-skin-joints-array\">");
writer.WriteLine($" <Name_array id=\"{ mesh.Name }-skin-joints-array\" count=\"{ mesh.Bones.Count }\">");
writer.Write(" ");
foreach (Bone bone in mesh.Bones)
{
writer.Write($"{ bone.Name }");
if (bone != mesh.Bones.Last())
writer.Write(' ');
else
writer.Write('\n');
writer.Flush();
}
writer.WriteLine(" </Name_array>");
writer.Flush();
writer.WriteLine(" <technique_common>");
writer.WriteLine($" <accessor source=\"#{ mesh.Name }-skin-joints-array\" count=\"{ mesh.Bones.Count }\" stride=\"1\">");
writer.WriteLine(" <param name=\"JOINT\" type=\"Name\"></param>");
writer.WriteLine(" </accessor>");
writer.WriteLine(" </technique_common>");
writer.WriteLine(" </source>");
writer.Flush();
}
private void WriteInverseBindMatricesToStream(Mesh mesh, StreamWriter writer)
{
writer.WriteLine($" <source id =\"{ mesh.Name }-skin-bind_poses-array\">");
writer.WriteLine($" <float_array id=\"{ mesh.Name }-skin-bind_poses-array\" count=\"{ mesh.Bones.Count * 16 }\">");
foreach (Bone bone in mesh.Bones)
{
Matrix4x4 ibm = bone.OffsetMatrix;
ibm.Transpose();
writer.WriteLine($" {ibm.A1.ToString("F")} {ibm.A2.ToString("F")} {ibm.A3.ToString("F")} {ibm.A4.ToString("F")}");
writer.WriteLine($" {ibm.B1.ToString("F")} {ibm.B2.ToString("F")} {ibm.B3.ToString("F")} {ibm.B4.ToString("F")}");
writer.WriteLine($" {ibm.C1.ToString("F")} {ibm.C2.ToString("F")} {ibm.C3.ToString("F")} {ibm.C4.ToString("F")}");
writer.WriteLine($" {ibm.D1.ToString("F")} {ibm.D2.ToString("F")} {ibm.D3.ToString("F")} {ibm.D4.ToString("F")}");
if (bone != mesh.Bones.Last())
writer.WriteLine("");
}
writer.WriteLine(" </float_array>");
writer.Flush();
writer.WriteLine(" <technique_common>");
writer.WriteLine($" <accessor source=\"#{ mesh.Name }-skin-bind_poses-array\" count=\"{ mesh.Bones.Count }\" stride=\"16\">");
writer.WriteLine(" <param name=\"TRANSFORM\" type=\"float4x4\"></param>");
writer.WriteLine(" </accessor>");
writer.WriteLine(" </technique_common>");
writer.WriteLine(" </source>");
writer.Flush();
}
private void WriteSkinWeightsToStream(Mesh mesh, StreamWriter writer)
{
int totalWeightCount = 0;
foreach (Bone bone in mesh.Bones)
{
totalWeightCount += bone.VertexWeightCount;
}
writer.WriteLine($" <source id =\"{ mesh.Name }-skin-weights-array\">");
writer.WriteLine($" <float_array id=\"{ mesh.Name }-skin-weights-array\" count=\"{ totalWeightCount }\">");
writer.Write(" ");
foreach (Bone bone in mesh.Bones)
{
foreach (VertexWeight weight in bone.VertexWeights)
{
writer.Write($"{ weight.Weight } ");
}
if (bone == mesh.Bones.Last())
writer.WriteLine();
}
writer.WriteLine(" </float_array>");
writer.Flush();
writer.WriteLine(" <technique_common>");
writer.WriteLine($" <accessor source=\"#{ mesh.Name }-skin-weights-array\" count=\"{ totalWeightCount }\" stride=\"1\">");
writer.WriteLine(" <param name=\"WEIGHT\" type=\"float\"></param>");
writer.WriteLine(" </accessor>");
writer.WriteLine(" </technique_common>");
writer.WriteLine(" </source>");
writer.Flush();
}
private class RiggedWeight
{
public List<float> Weights { get; private set; }
public List<int> BoneIndices { get; private set; }
public int WeightCount { get; private set; }
public RiggedWeight()
{
Weights = new List<float>();
BoneIndices = new List<int>();
}
public void AddWeight(float weight, int boneIndex)
{
Weights.Add(weight);
BoneIndices.Add(boneIndex);
WeightCount++;
}
}
private void WriteVertexWeightsToStream(Mesh mesh, StreamWriter writer)
{
List<float> weights = new List<float>();
Dictionary<int, RiggedWeight> vertIDWeights = new Dictionary<int, RiggedWeight>();
foreach (Bone bone in mesh.Bones)
{
foreach (VertexWeight weight in bone.VertexWeights)
{
weights.Add(weight.Weight);
if (!vertIDWeights.ContainsKey(weight.VertexID))
vertIDWeights.Add(weight.VertexID, new RiggedWeight());
vertIDWeights[weight.VertexID].AddWeight(weight.Weight, mesh.Bones.IndexOf(bone));
}
}
writer.WriteLine($" <vertex_weights count=\"{ vertIDWeights.Count }\">");
writer.WriteLine($" <input semantic=\"JOINT\" source=\"#{ mesh.Name }-skin-joints-array\" offset=\"0\"></input>");
writer.WriteLine($" <input semantic=\"WEIGHT\" source=\"#{ mesh.Name }-skin-weights-array\" offset=\"1\"></input>");
writer.WriteLine(" <vcount>");
writer.Write(" ");
for (int i = 0; i < vertIDWeights.Count; i++)
writer.Write($"{ vertIDWeights[i].WeightCount } ");
writer.WriteLine("\n </vcount>");
writer.WriteLine(" <v>");
writer.Write(" ");
for (int i = 0; i < vertIDWeights.Count; i++)
{
RiggedWeight curWeight = vertIDWeights[i];
for (int j = 0; j < curWeight.WeightCount; j++)
{
writer.Write($"{ curWeight.BoneIndices[j] } { weights.IndexOf(curWeight.Weights[j]) } ");
}
}
writer.WriteLine("\n </v>");
writer.WriteLine($" </vertex_weights>");
}
private void WriteBindShapeMatrixToStream(StreamWriter writer)
{
writer.WriteLine(" <bind_shape_matrix>");
writer.WriteLine(" 1 0 0 0");
writer.WriteLine(" 0 1 0 0");
writer.WriteLine(" 0 0 1 0");
writer.WriteLine(" 0 0 0 1");
writer.WriteLine(" </bind_shape_matrix>");
writer.Flush();
}
private void SaveMaterials(Scene scene, STGenericModel model, string FileName, List<STGenericTexture> Textures)
{
string TextureExtension = ".png";
@ -280,7 +575,7 @@ namespace Switch_Toolbox.Library
material.Name = "NewMaterial";
scene.Materials.Add(material);
SaveScene(FileName, scene);
SaveScene(FileName, scene, new STGenericModel());
}
private void SaveSkeleton(STSkeleton skeleton, Node parentNode)

View File

@ -76,6 +76,11 @@ namespace Switch_Toolbox.Library.Forms
return GetItemText(SelectedItem);
}
public void SelectItemByText(string text)
{
SelectedIndex = FindStringExact(text);
}
public void Bind(Type EnumType, object Object, string PropertyName, bool IsReset = true)
{
if (IsReset)

View File

@ -175,16 +175,33 @@ namespace Switch_Toolbox.Library.Forms
IsLoaded = true;
}
public List<EditableObject> editableGlDrawables = new List<EditableObject>();
public List<AbstractGlDrawable> staticGlDrawables = new List<AbstractGlDrawable>();
public List<DrawableContainer> DrawableContainers = new List<DrawableContainer>();
public static void AddObject(EditableObject drawable)
public static List<DrawableContainer> GetDrawableContainers()
{
var editor = LibraryGUI.Instance.GetObjectEditor();
if (editor == null)
return new List<DrawableContainer>();
return editor.DrawableContainers;
}
public static void AddContainer(DrawableContainer drawable)
{
var editor = LibraryGUI.Instance.GetObjectEditor();
if (editor == null)
return;
editor.editableGlDrawables.Add(drawable);
editor.DrawableContainers.Add(drawable);
}
public static void RemoveContainer(DrawableContainer drawable)
{
var editor = LibraryGUI.Instance.GetObjectEditor();
if (editor == null)
return;
editor.DrawableContainers.Remove(drawable);
}
public List<Control> GetEditors()

View File

@ -107,18 +107,6 @@ namespace Switch_Toolbox.Library.Forms
IsLoaded = true;
}
public List<EditableObject> editableGlDrawables = new List<EditableObject>();
public List<AbstractGlDrawable> staticGlDrawables = new List<AbstractGlDrawable>();
public static void AddObject(EditableObject drawable)
{
var editor = LibraryGUI.Instance.GetObjectEditor();
if (editor == null)
return;
editor.editableGlDrawables.Add(drawable);
}
public IFileFormat GetActiveFile()
{
if (treeViewCustom1.Nodes.Count == 0)

View File

@ -92,7 +92,6 @@
//
// treeViewCustom1
//
this.treeViewCustom1.AllowDrop = true;
this.treeViewCustom1.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)));

View File

@ -120,18 +120,6 @@ namespace Switch_Toolbox.Library.Forms
IsLoaded = true;
}
public List<EditableObject> editableGlDrawables = new List<EditableObject>();
public List<AbstractGlDrawable> staticGlDrawables = new List<AbstractGlDrawable>();
public static void AddObject(EditableObject drawable)
{
var editor = LibraryGUI.Instance.GetObjectEditor();
if (editor == null)
return;
editor.editableGlDrawables.Add(drawable);
}
public IFileFormat GetActiveFile()
{
if (treeViewCustom1.Nodes.Count == 0)
@ -523,8 +511,8 @@ namespace Switch_Toolbox.Library.Forms
if (IsFolder || IsRoot || IsFile)
e.Effect = DragDropEffects.Link;
else
e.Effect = DragDropEffects.None;
// else
// e.Effect = DragDropEffects.None;
}
private IArchiveFile GetActiveArchive()

View File

@ -120,7 +120,4 @@
<metadata name="stContextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="stContextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -29,6 +29,7 @@
private void InitializeComponent()
{
this.normalsShadingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.drawContainersCB = new Switch_Toolbox.Library.Forms.STComboBox();
this.panelViewport = new Switch_Toolbox.Library.Forms.STPanel();
this.stContextMenuStrip1 = new Switch_Toolbox.Library.Forms.STMenuStrip();
this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -45,12 +46,15 @@
this.leftToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.shadingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.resetCameraToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toOriginToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toActiveModelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.resetPoseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reloadShadersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toOriginToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toActiveModelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.stPanel1 = new Switch_Toolbox.Library.Forms.STPanel();
this.stLabel1 = new Switch_Toolbox.Library.Forms.STLabel();
this.stContextMenuStrip1.SuspendLayout();
this.stPanel1.SuspendLayout();
this.SuspendLayout();
//
// normalsShadingToolStripMenuItem
@ -63,12 +67,28 @@
this.normalsShadingToolStripMenuItem.Text = "Normals Shading";
this.normalsShadingToolStripMenuItem.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
//
// drawContainersCB
//
this.drawContainersCB.BorderColor = System.Drawing.Color.Empty;
this.drawContainersCB.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid;
this.drawContainersCB.ButtonColor = System.Drawing.Color.Empty;
this.drawContainersCB.FormattingEnabled = true;
this.drawContainersCB.Location = new System.Drawing.Point(93, 0);
this.drawContainersCB.Name = "drawContainersCB";
this.drawContainersCB.ReadOnly = true;
this.drawContainersCB.Size = new System.Drawing.Size(183, 21);
this.drawContainersCB.TabIndex = 0;
this.drawContainersCB.SelectedIndexChanged += new System.EventHandler(this.drawContainersCB_SelectedIndexChanged);
this.drawContainersCB.MouseDown += new System.Windows.Forms.MouseEventHandler(this.drawContainersCB_MouseDown);
//
// panelViewport
//
this.panelViewport.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelViewport.Location = new System.Drawing.Point(0, 24);
this.panelViewport.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.panelViewport.Location = new System.Drawing.Point(0, 48);
this.panelViewport.Name = "panelViewport";
this.panelViewport.Size = new System.Drawing.Size(781, 498);
this.panelViewport.Size = new System.Drawing.Size(781, 474);
this.panelViewport.TabIndex = 3;
//
// stContextMenuStrip1
@ -196,6 +216,20 @@
this.resetCameraToolStripMenuItem.Size = new System.Drawing.Size(91, 20);
this.resetCameraToolStripMenuItem.Text = "Reset Camera";
//
// toOriginToolStripMenuItem
//
this.toOriginToolStripMenuItem.Name = "toOriginToolStripMenuItem";
this.toOriginToolStripMenuItem.Size = new System.Drawing.Size(160, 22);
this.toOriginToolStripMenuItem.Text = "To Origin";
this.toOriginToolStripMenuItem.Click += new System.EventHandler(this.toOriginToolStripMenuItem_Click);
//
// toActiveModelToolStripMenuItem
//
this.toActiveModelToolStripMenuItem.Name = "toActiveModelToolStripMenuItem";
this.toActiveModelToolStripMenuItem.Size = new System.Drawing.Size(160, 22);
this.toActiveModelToolStripMenuItem.Text = "To Active Model";
this.toActiveModelToolStripMenuItem.Click += new System.EventHandler(this.toActiveModelToolStripMenuItem_Click);
//
// resetPoseToolStripMenuItem
//
this.resetPoseToolStripMenuItem.Name = "resetPoseToolStripMenuItem";
@ -218,31 +252,40 @@
this.reloadShadersToolStripMenuItem.Text = "Reload Shaders";
this.reloadShadersToolStripMenuItem.Click += new System.EventHandler(this.reloadShadersToolStripMenuItem_Click);
//
// toOriginToolStripMenuItem
// stPanel1
//
this.toOriginToolStripMenuItem.Name = "toOriginToolStripMenuItem";
this.toOriginToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.toOriginToolStripMenuItem.Text = "To Origin";
this.toOriginToolStripMenuItem.Click += new System.EventHandler(this.toOriginToolStripMenuItem_Click);
this.stPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.stPanel1.Controls.Add(this.stLabel1);
this.stPanel1.Controls.Add(this.drawContainersCB);
this.stPanel1.Location = new System.Drawing.Point(0, 26);
this.stPanel1.Name = "stPanel1";
this.stPanel1.Size = new System.Drawing.Size(778, 24);
this.stPanel1.TabIndex = 5;
//
// toActiveModelToolStripMenuItem
// stLabel1
//
this.toActiveModelToolStripMenuItem.Name = "toActiveModelToolStripMenuItem";
this.toActiveModelToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.toActiveModelToolStripMenuItem.Text = "To Active Model";
this.toActiveModelToolStripMenuItem.Click += new System.EventHandler(this.toActiveModelToolStripMenuItem_Click);
this.stLabel1.AutoSize = true;
this.stLabel1.Location = new System.Drawing.Point(3, 3);
this.stLabel1.Name = "stLabel1";
this.stLabel1.Size = new System.Drawing.Size(83, 13);
this.stLabel1.TabIndex = 1;
this.stLabel1.Text = "Active Model(s):";
//
// Viewport
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.Controls.Add(this.stPanel1);
this.Controls.Add(this.panelViewport);
this.Controls.Add(this.stContextMenuStrip1);
this.Name = "Viewport";
this.Size = new System.Drawing.Size(781, 522);
this.stContextMenuStrip1.ResumeLayout(false);
this.stContextMenuStrip1.PerformLayout();
this.stPanel1.ResumeLayout(false);
this.stPanel1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@ -271,5 +314,8 @@
private System.Windows.Forms.ToolStripMenuItem leftToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem toOriginToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem toActiveModelToolStripMenuItem;
private Forms.STComboBox drawContainersCB;
private Forms.STPanel stPanel1;
private Forms.STLabel stLabel1;
}
}

View File

@ -18,14 +18,20 @@ namespace Switch_Toolbox.Library
{
public partial class Viewport : UserControl
{
public List<DrawableContainer> DrawableContainers;
public EditorScene scene = new EditorScene();
public GL_ControlLegacy GL_ControlLegacy;
public GL_ControlModern GL_ControlModern;
Runtime.ViewportEditor editor;
public Viewport(bool LoadDrawables = true)
public Viewport(List<DrawableContainer> container, bool LoadDrawables = true)
{
DrawableContainers = container;
if (DrawableContainers == null)
DrawableContainers = new List<DrawableContainer>();
this.DoubleBuffered = true;
InitializeComponent();
@ -47,10 +53,59 @@ namespace Switch_Toolbox.Library
shadingToolStripMenuItem.Text = $"Shading: [{Runtime.viewportShading.ToString()}]";
if (LoadDrawables)
LoadBaseDrawables();
}
//Reloads drawable containers without an active object being selected
public void ReloadDrawables()
{
drawContainersCB.Items.Clear();
drawContainersCB.Items.Add("All Active Drawables");
for (int i = 0; i < DrawableContainers.Count; i++)
{
drawContainersCB.Items.Add(DrawableContainers[i].Name);
for (int a = 0; a < DrawableContainers[i].Drawables.Count; a++)
{
if (!ContainsDrawable(DrawableContainers[i].Drawables[a]))
AddDrawable((DrawableContainers[i].Drawables[a]));
}
}
}
//Reloads drawable containers with the active container selected
public void ReloadDrawables(DrawableContainer ActiveContainer)
{
drawContainersCB.Items.Clear();
drawContainersCB.Items.Add("All Active Drawables");
for (int i = 0; i < DrawableContainers.Count;i++)
{
drawContainersCB.Items.Add(DrawableContainers[i].Name);
for (int a = 0; a < DrawableContainers[i].Drawables.Count; a++)
{
if (DrawableContainers[i] != ActiveContainer)
DrawableContainers[i].Drawables[a].Visible = false;
else
DrawableContainers[i].Drawables[a].Visible = true;
if (!ContainsDrawable(DrawableContainers[i].Drawables[a]))
AddDrawable((DrawableContainers[i].Drawables[a]));
}
}
drawContainersCB.SelectItemByText(ActiveContainer.Name);
}
public bool ContainsDrawable(AbstractGlDrawable Drawable)
{
return scene.staticObjects.Contains(Drawable) || scene.objects.Contains(Drawable);
}
private void shadingToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
int i = 0;
@ -422,5 +477,44 @@ namespace Switch_Toolbox.Library
GL_ControlModern.Refresh();
}
}
private void drawContainersCB_SelectedIndexChanged(object sender, EventArgs e)
{
if (drawContainersCB.SelectedIndex == 0)
DrawAllActive();
else if (drawContainersCB.SelectedIndex > 0)
{
int index = drawContainersCB.SelectedIndex - 1;
for (int i = 0; i < DrawableContainers.Count; i++)
{
for (int a = 0; a < DrawableContainers[i].Drawables.Count; a++)
{
if (i == index)
DrawableContainers[i].Drawables[a].Visible = true;
else
DrawableContainers[i].Drawables[a].Visible = false;
}
}
}
UpdateViewport();
}
private void DrawAllActive()
{
for (int i = 0; i < DrawableContainers.Count; i++)
{
for (int a = 0; a < DrawableContainers[i].Drawables.Count; a++)
{
DrawableContainers[i].Drawables[a].Visible = true;
}
}
}
private void drawContainersCB_MouseDown(object sender, MouseEventArgs e)
{
ReloadDrawables();
}
}
}

View File

@ -203,6 +203,7 @@
<Compile Include="Audio\AudioFileRipper.cs" />
<Compile Include="Audio\VGAudioFile.cs" />
<Compile Include="Config.cs" />
<Compile Include="DrawableContainer.cs" />
<Compile Include="FileFormats\3DS\ETC1.cs" />
<Compile Include="FileFormats\Animation\SMD.cs" />
<Compile Include="FileFormats\APNG\APNG.cs" />

Binary file not shown.

Binary file not shown.

View File

@ -98,7 +98,7 @@ namespace Toolbox
if (Runtime.UseOpenGL)
{
//Create an instance of this to help load open gl data easier and quicker after boot
var viewport = new Viewport(false);
var viewport = new Viewport(ObjectEditor.GetDrawableContainers(), false);
ShaderTools.executableDir = Runtime.ExecutableDir;
if (OpenTK.Graphics.GraphicsContext.CurrentContext != null)