Update preview scale for kcl

This commit is contained in:
KillzXGaming 2019-06-20 17:20:06 -04:00
parent 9fe7f254ff
commit 0fbb18ac85
11 changed files with 166 additions and 11 deletions

Binary file not shown.

View file

@ -648,9 +648,8 @@ namespace FirstPlugin
control.CurrentShader = defaultShaderProgram;
// control.UpdateModelMatrix(
// Matrix4.CreateScale(Runtime.previewScale) *
// Matrix4.CreateTranslation(Selected ? editorScene.CurrentAction.NewPos(position) : position));
control.UpdateModelMatrix(
Matrix4.CreateScale(Runtime.previewScale));
SetRenderSettings(defaultShaderProgram);

View file

@ -7,6 +7,7 @@ using Switch_Toolbox;
using System.Windows.Forms;
using Switch_Toolbox.Library;
using Switch_Toolbox.Library.IO;
using Switch_Toolbox.Library.Forms;
namespace FirstPlugin
{
@ -43,12 +44,55 @@ namespace FirstPlugin
}
}
Viewport viewport
{
get
{
var editor = LibraryGUI.Instance.GetObjectEditor();
return editor.GetViewport();
}
set
{
var editor = LibraryGUI.Instance.GetObjectEditor();
editor.LoadViewport(value);
}
}
bool DrawablesLoaded = false;
public override void OnClick(TreeView treeView)
{
if (Runtime.UseOpenGL)
{
if (viewport == null)
{
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;
}
}
public Header header;
public DrawableContainer DrawableContainer = new DrawableContainer();
public void Load(System.IO.Stream stream)
{
DrawableContainer.Name = FileName;
header = new Header();
header.Read(new FileReader(stream));
DrawableContainer.Drawables.Add(header.Skeleton);
}
public void Unload()
{
@ -63,6 +107,8 @@ namespace FirstPlugin
public class Header
{
public STSkeleton Skeleton { get; set; }
public uint Version { get; set; }
public float[] Boundings { get; set; }
public List<string> TextureMaps = new List<string>();
@ -70,6 +116,8 @@ namespace FirstPlugin
public void Read(FileReader reader)
{
Skeleton = new STSkeleton();
reader.SetByteOrder(false);
Version = reader.ReadUInt32();
@ -80,6 +128,7 @@ namespace FirstPlugin
long Unknown2Offset = reader.ReadOffset(true, typeof(uint));
long ShaderOffset = reader.ReadOffset(true, typeof(uint));
long VisGroupOffset = reader.ReadOffset(true, typeof(uint));
long VertexDataOffset = reader.ReadOffset(true, typeof(uint));
long BoneDataOffset = reader.ReadOffset(true, typeof(uint));
if (TextureOffset != 0)
@ -89,15 +138,26 @@ namespace FirstPlugin
TextureMaps = reader.ReadNameOffsets(Count, true, typeof(uint), true);
}
foreach (var tex in TextureMaps)
Console.WriteLine("TEXNAME " + tex);
if (MaterialOffset != 0)
{
reader.Seek(MaterialOffset, SeekOrigin.Begin);
uint Count = reader.ReadUInt32();
Materials = reader.ReadNameOffsets(Count, true, typeof(uint));
}
if (BoneDataOffset != 0)
{
reader.Seek(BoneDataOffset, SeekOrigin.Begin);
uint Count = reader.ReadUInt32();
Console.WriteLine($"BoneCount {Count}");
for (int i = 0; i < Count; i++)
{
var bone = new Bone(Skeleton);
bone.Read(reader);
Skeleton.bones.Add(bone);
}
}
}
public void Write(FileWriter writer)
@ -106,9 +166,106 @@ namespace FirstPlugin
}
}
public class Bone
public class Bone : STBone
{
internal BoneInfo BoneInfo { get; set; }
public Bone(STSkeleton skeleton) : base(skeleton) { }
public void Read(FileReader reader)
{
long DataPosition = reader.Position;
var BoneDataOffset = reader.ReadOffset(true, typeof(uint));
reader.SeekBegin(BoneDataOffset);
long InfoPosition = reader.Position;
uint BoneInfoOffset = reader.ReadUInt32();
//Read the info section for position data
reader.SeekBegin(InfoPosition - BoneInfoOffset);
BoneInfo = new BoneInfo();
BoneInfo.Read(reader);
if (BoneInfo.NamePosition != 0)
{
reader.SeekBegin(DataPosition + BoneInfo.NamePosition);
uint NameLength = reader.ReadUInt32();
Text = reader.ReadString((int)NameLength);
}
if (BoneInfo.RotationPosition != 0)
{
reader.SeekBegin(DataPosition + BoneInfo.RotationPosition);
float RotationX = reader.ReadSingle();
float RotationY = reader.ReadSingle();
float RotationZ = reader.ReadSingle();
rotation = new float[] { RotationX,RotationY, RotationZ };
}
if (BoneInfo.TranslationPosition != 0)
{
reader.SeekBegin(DataPosition + BoneInfo.RotationPosition);
float TranslateX = reader.ReadSingle();
float TranslateY = reader.ReadSingle();
float TranslateZ = reader.ReadSingle();
position = new float[] { TranslateX, TranslateY, TranslateZ };
}
if (BoneInfo.ScalePosition != 0)
{
reader.SeekBegin(DataPosition + BoneInfo.ScalePosition);
float ScaleX = reader.ReadSingle();
float ScaleY = reader.ReadSingle();
float ScaleZ = reader.ReadSingle();
scale = new float[] { ScaleX, ScaleY, ScaleZ };
}
if (BoneInfo.ParentPosition != 0)
{
reader.SeekBegin(DataPosition + BoneInfo.ParentPosition);
parentIndex = reader.ReadInt32();
}
Console.WriteLine("BONE " + Text);
//Seek back to next bone in array
reader.SeekBegin(DataPosition + sizeof(uint));
}
}
//A section that stores position info for bone data
public class BoneInfo
{
internal ushort SectionSize { get; set; }
internal ushort NamePosition { get; set; }
internal ushort UnknownPosition { get; set; }
internal ushort Unknown2Position { get; set; }
internal ushort ParentPosition { get; set; }
internal ushort Unknown3Position { get; set; }
internal ushort IsVisablePosition { get; set; }
internal ushort ScalePosition { get; set; }
internal ushort RotationPosition { get; set; }
internal ushort TranslationPosition { get; set; }
internal ushort Unknown4Position { get; set; }
internal ushort Unknown5Position { get; set; }
public void Read(FileReader reader)
{
SectionSize = reader.ReadUInt16();
NamePosition = reader.ReadUInt16();
UnknownPosition = reader.ReadUInt16();
Unknown2Position = reader.ReadUInt16();
ParentPosition = reader.ReadUInt16();
Unknown3Position = reader.ReadUInt16(); //Padding
IsVisablePosition = reader.ReadUInt16(); //Points to byte. 0 or 1 for visibilty
ScalePosition = reader.ReadUInt16();
RotationPosition = reader.ReadUInt16();
TranslationPosition = reader.ReadUInt16();
Unknown4Position = reader.ReadUInt16(); //Padding
Unknown5Position = reader.ReadUInt16(); //Padding
}
}
public class Material

View file

@ -109,7 +109,6 @@ namespace FirstPlugin
public void BatchExport(object sender, EventArgs args)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
ofd.Filter = "Supported Formats|*.bin";
if (ofd.ShowDialog() != DialogResult.OK) return;

View file

@ -304,6 +304,7 @@ namespace FirstPlugin
Formats.Add(typeof(LZARC));
Formats.Add(typeof(IGA_PAK));
Formats.Add(typeof(MKAGPDX_Model));
Formats.Add(typeof(GFBMDL));
Formats.Add(typeof(Turbo.Course_MapCamera_bin));
Formats.Add(typeof(Turbo.PartsBIN));
@ -312,7 +313,6 @@ namespace FirstPlugin
//Unfinished wip formats not ready for use
if (Runtime.DEVELOPER_DEBUG_MODE)
{
Formats.Add(typeof(GFBMDL));
Formats.Add(typeof(NCA));
Formats.Add(typeof(XCI));
Formats.Add(typeof(BFLAN));

View file

@ -241,7 +241,7 @@
<Compile Include="FileFormats\Audio\Archives\BFGRP.cs" />
<Compile Include="FileFormats\GFBMDL\GFBMDL.cs" />
<Compile Include="FileFormats\Hashes\SAHT.cs" />
<Compile Include="FileFormats\MKAGPDX\Model\MKAGPDX_Model.cs" />
<Compile Include="FileFormats\MKAGPDX\MKAGPDX_Model.cs" />
<Compile Include="FileFormats\Rom\RomfsNodeWrapper.cs" />
<Compile Include="FileFormats\Shader\NSWShaderDecompile.cs" />
<Compile Include="FileFormats\Shader\NUSHDB.cs" />

View file

@ -11,6 +11,6 @@ void main()
envColor = envColor / (envColor + vec3(1.0));
envColor = pow(envColor, vec3(1.0/2.2));
FragColor = vec4(envColor, 1.0);
}