Update generic archive class with node wrapper and conversion
This commit is contained in:
parent
aba65a7a10
commit
059b406128
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -72,7 +72,7 @@ namespace FirstPlugin
|
|||||||
var info = new FileInfo(reader);
|
var info = new FileInfo(reader);
|
||||||
|
|
||||||
APAKFileInfo archive = new APAKFileInfo();
|
APAKFileInfo archive = new APAKFileInfo();
|
||||||
archive.FileData = new System.IO.MemoryStream(info.Data);
|
archive.FileData = info.Data;
|
||||||
archive.Name = info.Text;
|
archive.Name = info.Text;
|
||||||
|
|
||||||
Nodes.Add(info);
|
Nodes.Add(info);
|
||||||
|
@ -132,7 +132,7 @@ namespace FirstPlugin
|
|||||||
{
|
{
|
||||||
SetAlignment(writer, files[i].FileName);
|
SetAlignment(writer, files[i].FileName);
|
||||||
writer.WriteUint32Offset(files[i]._posHeader + 4);
|
writer.WriteUint32Offset(files[i]._posHeader + 4);
|
||||||
writer.Write(files[i].FileData.ToArray());
|
writer.Write(files[i].FileData);
|
||||||
}
|
}
|
||||||
writer.Close();
|
writer.Close();
|
||||||
writer.Dispose();
|
writer.Dispose();
|
||||||
@ -157,7 +157,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Export(object sender, EventArgs args)
|
public override void Export()
|
||||||
{
|
{
|
||||||
SaveFileDialog sfd = new SaveFileDialog();
|
SaveFileDialog sfd = new SaveFileDialog();
|
||||||
sfd.FileName = FileName;
|
sfd.FileName = FileName;
|
||||||
@ -166,7 +166,20 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
if (sfd.ShowDialog() == DialogResult.OK)
|
if (sfd.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
File.WriteAllBytes(sfd.FileName, FileData.ToArray());
|
File.WriteAllBytes(sfd.FileName, FileData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Replace()
|
||||||
|
{
|
||||||
|
OpenFileDialog ofd = new OpenFileDialog();
|
||||||
|
ofd.FileName = FileName;
|
||||||
|
ofd.DefaultExt = Path.GetExtension(FileName);
|
||||||
|
ofd.Filter = "Raw Data (*.*)|*.*";
|
||||||
|
|
||||||
|
if (ofd.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
FileData = File.ReadAllBytes(ofd.FileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +206,7 @@ namespace FirstPlugin
|
|||||||
FileName = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
|
FileName = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
|
||||||
|
|
||||||
reader.Seek(FileOffset, System.IO.SeekOrigin.Begin);
|
reader.Seek(FileOffset, System.IO.SeekOrigin.Begin);
|
||||||
FileData = new MemoryStream(reader.ReadBytes((int)FileSize));
|
FileData = reader.ReadBytes((int)FileSize);
|
||||||
State = ArchiveFileState.Archived;
|
State = ArchiveFileState.Archived;
|
||||||
|
|
||||||
reader.Seek(pos + 16, System.IO.SeekOrigin.Begin);
|
reader.Seek(pos + 16, System.IO.SeekOrigin.Begin);
|
||||||
|
@ -131,7 +131,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
public override void Draw(GL_ControlModern control, Pass pass)
|
public override void Draw(GL_ControlModern control, Pass pass)
|
||||||
{
|
{
|
||||||
if (!Runtime.OpenTKInitialized)
|
if (!Runtime.OpenTKInitialized || pass == Pass.TRANSPARENT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool buffersWereInitialized = ibo_elements != 0 && vbo_position != 0;
|
bool buffersWereInitialized = ibo_elements != 0 && vbo_position != 0;
|
||||||
@ -152,9 +152,34 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
shader.SetVector3("difLightDirection", Vector3.TransformNormal(lightDirection, invertedCamera).Normalized());
|
shader.SetVector3("difLightDirection", Vector3.TransformNormal(lightDirection, invertedCamera).Normalized());
|
||||||
|
|
||||||
|
// GL.Enable(EnableCap.AlphaTest);
|
||||||
|
// GL.AlphaFunc(AlphaFunction.Gequal, 0.1f);
|
||||||
|
|
||||||
SetRenderSettings(shader);
|
SetRenderSettings(shader);
|
||||||
|
|
||||||
DrawModels(shader, control);
|
DrawModels(shader, control);
|
||||||
|
|
||||||
|
|
||||||
|
GL.UseProgram(0);
|
||||||
|
GL.Disable(EnableCap.DepthTest);
|
||||||
|
GL.Enable(EnableCap.DepthTest);
|
||||||
|
GL.Enable(EnableCap.CullFace);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SetBoneUniforms(ShaderProgram shader, CMDLWrapper fmdl, SOBJWrapper fshp)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < fmdl.Skeleton.Renderable.bones.Count; i++)
|
||||||
|
{
|
||||||
|
GL.Uniform1(GL.GetUniformLocation(shader.program, String.Format("boneIds[{0}]", i)), i);
|
||||||
|
|
||||||
|
Matrix4 transform = fmdl.Skeleton.Renderable.bones[i].invert * fmdl.Skeleton.Renderable.bones[i].Transform;
|
||||||
|
GL.UniformMatrix4(GL.GetUniformLocation(shader.program, String.Format("bones[{0}]", i)), false, ref transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SetUniforms(MTOBWrapper mat, ShaderProgram shader, SOBJWrapper m, int id)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetTextureUniforms(MTOBWrapper mat, SOBJWrapper m, ShaderProgram shader)
|
private static void SetTextureUniforms(MTOBWrapper mat, SOBJWrapper m, ShaderProgram shader)
|
||||||
@ -164,6 +189,21 @@ namespace FirstPlugin
|
|||||||
GL.ActiveTexture(TextureUnit.Texture0 + 1);
|
GL.ActiveTexture(TextureUnit.Texture0 + 1);
|
||||||
GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.Id);
|
GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.Id);
|
||||||
|
|
||||||
|
GL.Uniform1(shader["debugOption"], 2);
|
||||||
|
|
||||||
|
GL.ActiveTexture(TextureUnit.Texture11);
|
||||||
|
GL.Uniform1(shader["weightRamp1"], 11);
|
||||||
|
GL.BindTexture(TextureTarget.Texture2D, RenderTools.BoneWeightGradient.Id);
|
||||||
|
|
||||||
|
GL.ActiveTexture(TextureUnit.Texture12);
|
||||||
|
GL.Uniform1(shader["weightRamp2"], 12);
|
||||||
|
GL.BindTexture(TextureTarget.Texture2D, RenderTools.BoneWeightGradient2.Id);
|
||||||
|
|
||||||
|
|
||||||
|
GL.ActiveTexture(TextureUnit.Texture10);
|
||||||
|
GL.Uniform1(shader["UVTestPattern"], 10);
|
||||||
|
GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.Id);
|
||||||
|
|
||||||
foreach (STGenericMatTexture matex in mat.TextureMaps)
|
foreach (STGenericMatTexture matex in mat.TextureMaps)
|
||||||
{
|
{
|
||||||
if (matex.Type == STGenericMatTexture.TextureType.Diffuse)
|
if (matex.Type == STGenericMatTexture.TextureType.Diffuse)
|
||||||
@ -223,6 +263,7 @@ namespace FirstPlugin
|
|||||||
private void SetRenderSettings(ShaderProgram shader)
|
private void SetRenderSettings(ShaderProgram shader)
|
||||||
{
|
{
|
||||||
shader.SetInt("renderType", (int)Runtime.viewportShading);
|
shader.SetInt("renderType", (int)Runtime.viewportShading);
|
||||||
|
shader.SetInt("selectedBoneIndex", Runtime.SelectedBoneIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawModels(ShaderProgram shader, GL_ControlModern control)
|
private void DrawModels(ShaderProgram shader, GL_ControlModern control)
|
||||||
@ -261,8 +302,10 @@ namespace FirstPlugin
|
|||||||
if (m.lodMeshes[m.DisplayLODIndex].faces.Count <= 3)
|
if (m.lodMeshes[m.DisplayLODIndex].faces.Count <= 3)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
SetBoneUniforms(shader, mdl, m);
|
||||||
SetVertexAttributes(m, shader);
|
SetVertexAttributes(m, shader);
|
||||||
SetTextureUniforms(m.MaterialWrapper, m, shader);
|
SetTextureUniforms(m.MaterialWrapper, m, shader);
|
||||||
|
SetUniforms(m.MaterialWrapper, shader,m, m.DisplayId);
|
||||||
|
|
||||||
if ((m.IsSelected))
|
if ((m.IsSelected))
|
||||||
{
|
{
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -75,10 +75,24 @@ namespace Switch_Toolbox.Library.Forms
|
|||||||
|
|
||||||
if (UseListView && FileFormat is IArchiveFile)
|
if (UseListView && FileFormat is IArchiveFile)
|
||||||
{
|
{
|
||||||
ObjectList = new ObjectEditorList();
|
/* ObjectList = new ObjectEditorList();
|
||||||
ObjectList.Dock = DockStyle.Fill;
|
ObjectList.Dock = DockStyle.Fill;
|
||||||
stPanel1.Controls.Add(ObjectList);
|
stPanel1.Controls.Add(ObjectList);
|
||||||
ObjectList.FillList((IArchiveFile)FileFormat);
|
ObjectList.FillList((IArchiveFile)FileFormat);*/
|
||||||
|
|
||||||
|
ObjectTree = new ObjectEditorTree();
|
||||||
|
ObjectTree.Dock = DockStyle.Fill;
|
||||||
|
stPanel1.Controls.Add(ObjectTree);
|
||||||
|
|
||||||
|
TreeNode FileRoot = new TreeNode(FileFormat.FileName);
|
||||||
|
foreach (var archive in ((IArchiveFile)FileFormat).Files)
|
||||||
|
{
|
||||||
|
ArchiveNodeWrapper node = new ArchiveNodeWrapper(archive.FileName);
|
||||||
|
node.ArchiveFileInfo = archive;
|
||||||
|
FileRoot.Nodes.Add(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
AddNode(FileRoot);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -89,6 +103,7 @@ namespace Switch_Toolbox.Library.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Viewport GetViewport() => viewport;
|
public Viewport GetViewport() => viewport;
|
||||||
|
|
||||||
//Attatch a viewport instance here if created.
|
//Attatch a viewport instance here if created.
|
||||||
|
@ -4,6 +4,8 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Switch_Toolbox.Library.Forms;
|
||||||
|
using Switch_Toolbox.Library.IO;
|
||||||
|
|
||||||
namespace Switch_Toolbox.Library
|
namespace Switch_Toolbox.Library
|
||||||
{
|
{
|
||||||
@ -31,8 +33,13 @@ namespace Switch_Toolbox.Library
|
|||||||
}
|
}
|
||||||
public class ArchiveFileInfo
|
public class ArchiveFileInfo
|
||||||
{
|
{
|
||||||
|
public virtual STToolStripItem[] Menus { get; set; }
|
||||||
|
|
||||||
public FileType FileDataType = FileType.Default;
|
public FileType FileDataType = FileType.Default;
|
||||||
|
|
||||||
|
public virtual void Replace() { }
|
||||||
|
public virtual void Export() { }
|
||||||
|
|
||||||
public string GetSize()
|
public string GetSize()
|
||||||
{
|
{
|
||||||
return STMath.GetFileSize(FileData.Length, 4);
|
return STMath.GetFileSize(FileData.Length, 4);
|
||||||
@ -40,15 +47,14 @@ namespace Switch_Toolbox.Library
|
|||||||
|
|
||||||
IFileFormat FileFormat = null; //Format attached for saving
|
IFileFormat FileFormat = null; //Format attached for saving
|
||||||
|
|
||||||
protected Stream _fileData = null;
|
protected byte[] _fileData = null;
|
||||||
|
|
||||||
public string FileName { get; set; } = string.Empty; //Full File Name
|
public string FileName { get; set; } = string.Empty; //Full File Name
|
||||||
public string Name { get; set; } = string.Empty; //File Name (No Path)
|
public string Name { get; set; } = string.Empty; //File Name (No Path)
|
||||||
public virtual Stream FileData
|
public virtual byte[] FileData
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
_fileData.Position = 0;
|
|
||||||
return _fileData;
|
return _fileData;
|
||||||
}
|
}
|
||||||
set { _fileData = value; }
|
set { _fileData = value; }
|
||||||
@ -56,4 +62,45 @@ namespace Switch_Toolbox.Library
|
|||||||
|
|
||||||
public ArchiveFileState State { get; set; } = ArchiveFileState.Empty;
|
public ArchiveFileState State { get; set; } = ArchiveFileState.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ArchiveNodeWrapper : TreeNodeCustom
|
||||||
|
{
|
||||||
|
public ArchiveNodeWrapper(string text)
|
||||||
|
{
|
||||||
|
Text = text;
|
||||||
|
|
||||||
|
ContextMenuStrip = new STContextMenuStrip();
|
||||||
|
ContextMenuStrip.Items.Add(new STToolStripItem("Extract", ExtractAction));
|
||||||
|
ContextMenuStrip.Items.Add(new STToolStripItem("Replace", ReplaceAction));
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual ArchiveFileInfo ArchiveFileInfo { get; set; }
|
||||||
|
|
||||||
|
private void ExtractAction(object sender, EventArgs args)
|
||||||
|
{
|
||||||
|
ArchiveFileInfo.Export();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReplaceAction(object sender, EventArgs args)
|
||||||
|
{
|
||||||
|
ArchiveFileInfo.Replace();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnDoubleMouseClick(TreeView treeview)
|
||||||
|
{
|
||||||
|
TreeNode node = STFileLoader.GetNodeFileFormat(Text, ArchiveFileInfo.FileData, true, this);
|
||||||
|
if (node != null)
|
||||||
|
ReplaceNode(this.Parent, this, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ in vec2 f_texcoord1;
|
|||||||
in vec2 f_texcoord2;
|
in vec2 f_texcoord2;
|
||||||
in vec2 f_texcoord3;
|
in vec2 f_texcoord3;
|
||||||
|
|
||||||
|
in vec3 boneWeightsColored;
|
||||||
|
|
||||||
uniform vec3 difLightDirection;
|
uniform vec3 difLightDirection;
|
||||||
uniform vec3 difLightColor;
|
uniform vec3 difLightColor;
|
||||||
uniform vec3 ambLightColor;
|
uniform vec3 ambLightColor;
|
||||||
@ -55,7 +57,10 @@ void main()
|
|||||||
if (renderVertColor == 1)
|
if (renderVertColor == 1)
|
||||||
FragColor *= min(color, vec4(1));
|
FragColor *= min(color, vec4(1));
|
||||||
|
|
||||||
|
FragColor.rgb *= min(boneWeightsColored, vec3(1));
|
||||||
|
|
||||||
vec3 displayNormal = (normal.xyz * 0.5) + 0.5;
|
vec3 displayNormal = (normal.xyz * 0.5) + 0.5;
|
||||||
if (renderType == 1) // normals color
|
if (renderType == 1) // normals color
|
||||||
FragColor = vec4(displayNormal.rgb,1);
|
FragColor = vec4(displayNormal.rgb,1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@ out vec3 normal;
|
|||||||
out vec4 color;
|
out vec4 color;
|
||||||
out vec3 position;
|
out vec3 position;
|
||||||
|
|
||||||
|
out vec3 boneWeightsColored;
|
||||||
|
|
||||||
// Skinning uniforms
|
// Skinning uniforms
|
||||||
uniform mat4 bones[190];
|
uniform mat4 bones[190];
|
||||||
|
|
||||||
@ -28,6 +30,16 @@ uniform mat4 mtxCam;
|
|||||||
uniform mat4 mtxMdl;
|
uniform mat4 mtxMdl;
|
||||||
uniform mat4 previewScale;
|
uniform mat4 previewScale;
|
||||||
|
|
||||||
|
// Bone Weight Display
|
||||||
|
uniform sampler2D weightRamp1;
|
||||||
|
uniform sampler2D weightRamp2;
|
||||||
|
uniform int selectedBoneIndex;
|
||||||
|
uniform int debugOption;
|
||||||
|
|
||||||
|
uniform int NoSkinning;
|
||||||
|
uniform int RigidSkinning;
|
||||||
|
uniform int SingleBoneIndex;
|
||||||
|
|
||||||
vec4 skin(vec3 pos, ivec4 index)
|
vec4 skin(vec3 pos, ivec4 index)
|
||||||
{
|
{
|
||||||
vec4 newPosition = vec4(pos.xyz, 1.0);
|
vec4 newPosition = vec4(pos.xyz, 1.0);
|
||||||
@ -53,11 +65,47 @@ vec3 skinNRM(vec3 nr, ivec4 index)
|
|||||||
return newNormal;
|
return newNormal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vec3 BoneWeightColor(float weights)
|
||||||
|
{
|
||||||
|
float rampInputLuminance = weights;
|
||||||
|
rampInputLuminance = clamp((rampInputLuminance), 0.001, 0.999);
|
||||||
|
if (debugOption == 1) // Greyscale
|
||||||
|
return vec3(weights);
|
||||||
|
else if (debugOption == 2) // Color 1
|
||||||
|
return texture(weightRamp1, vec2(1 - rampInputLuminance, 0.50)).rgb;
|
||||||
|
else // Color 2
|
||||||
|
return texture(weightRamp2, vec2(1 - rampInputLuminance, 0.50)).rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
float BoneWeightDisplay(ivec4 index)
|
||||||
|
{
|
||||||
|
float weight = 0;
|
||||||
|
if (selectedBoneIndex == index.x)
|
||||||
|
weight += vWeight.x;
|
||||||
|
if (selectedBoneIndex == index.y)
|
||||||
|
weight += vWeight.y;
|
||||||
|
if (selectedBoneIndex == index.z)
|
||||||
|
weight += vWeight.z;
|
||||||
|
if (selectedBoneIndex == index.w)
|
||||||
|
weight += vWeight.w;
|
||||||
|
|
||||||
|
if (selectedBoneIndex == index.x && RigidSkinning == 1)
|
||||||
|
weight = 1;
|
||||||
|
if (selectedBoneIndex == SingleBoneIndex && NoSkinning == 1)
|
||||||
|
weight = 1;
|
||||||
|
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
ivec4 index = ivec4(vBone);
|
ivec4 index = ivec4(vBone);
|
||||||
|
|
||||||
vec4 objPos = vec4(vPosition.xyz, 1.0);
|
vec4 objPos = vec4(vPosition.xyz, 1.0);
|
||||||
|
if (vBone.x != -1.0)
|
||||||
|
objPos = skin(vPosition, index);
|
||||||
|
if(vBone.x != -1.0)
|
||||||
|
normal = normalize((skinNRM(vNormal.xyz, index)).xyz);
|
||||||
|
|
||||||
vec4 position = mtxCam * mtxMdl * vec4(objPos.xyz, 1.0);
|
vec4 position = mtxCam * mtxMdl * vec4(objPos.xyz, 1.0);
|
||||||
|
|
||||||
@ -70,6 +118,7 @@ void main()
|
|||||||
|
|
||||||
gl_Position = mtxCam * mtxMdl * vec4(vPosition.xyz, 1.0);
|
gl_Position = mtxCam * mtxMdl * vec4(vPosition.xyz, 1.0);
|
||||||
|
|
||||||
vec3 distance = (vPosition.xyz + vec3(5, 5, 5))/2;
|
float totalWeight = BoneWeightDisplay(index);
|
||||||
|
boneWeightsColored = BoneWeightColor(totalWeight).rgb;
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user