This commit is contained in:
Razmoth
2022-11-03 19:32:12 +04:00
parent c257f5669c
commit 3be27949f8
34 changed files with 390 additions and 421 deletions

View File

@@ -2,12 +2,12 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net472;net5.0-windows;net6.0-windows</TargetFrameworks>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>Resources\as.ico</ApplicationIcon>
<Version>0.18.30</Version>
<AssemblyVersion>0.18.30</AssemblyVersion>
<FileVersion>0.18.30</FileVersion>
<Version>0.18.60</Version>
<AssemblyVersion>0.18.60</AssemblyVersion>
<FileVersion>0.18.60</FileVersion>
<Copyright>Copyright © Razmoth 2022; Copyright © Perfare 2018-2022</Copyright>
<DebugType>embedded</DebugType>
</PropertyGroup>
@@ -74,22 +74,13 @@
</ContentWithTargetPath>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net472' ">
<PackageReference Include="OpenTK" Version="4.6.7" />
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta2" />
<PackageReference Include="OpenTK" Version="5.0.0-pre.8" />
<Reference Include="OpenTK.WinForms">
<HintPath>Libraries\OpenTK.WinForms.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<PackageReference Include="OpenTK" Version="3.1.0" />
<PackageReference Include="OpenTK.GLControl" Version="3.1.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<Target Name="CopyExtraFiles" AfterTargets="AfterBuild">
<Copy SourceFiles="$(SolutionDir)AssetStudioFBXNative\bin\Win32\$(Configuration)\AssetStudioFBXNative.dll" DestinationFolder="$(TargetDir)x86" ContinueOnError="true" />

View File

@@ -120,7 +120,7 @@
this.FMODpauseButton = new System.Windows.Forms.Button();
this.FMODplayButton = new System.Windows.Forms.Button();
this.fontPreviewBox = new System.Windows.Forms.RichTextBox();
this.glControl1 = new OpenTK.GLControl();
this.glControl = new OpenTK.WinForms.GLControl();
this.textPreviewBox = new System.Windows.Forms.TextBox();
this.classTextBox = new System.Windows.Forms.TextBox();
this.tabPage5 = new System.Windows.Forms.TabPage();
@@ -849,7 +849,7 @@
this.previewPanel.Controls.Add(this.assetInfoLabel);
this.previewPanel.Controls.Add(this.FMODpanel);
this.previewPanel.Controls.Add(this.fontPreviewBox);
this.previewPanel.Controls.Add(this.glControl1);
this.previewPanel.Controls.Add(this.glControl);
this.previewPanel.Controls.Add(this.textPreviewBox);
this.previewPanel.Controls.Add(this.classTextBox);
this.previewPanel.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -1008,21 +1008,24 @@
this.fontPreviewBox.WordWrap = false;
//
// glControl1
//
this.glControl1.BackColor = System.Drawing.SystemColors.ControlDarkDark;
this.glControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.glControl1.Location = new System.Drawing.Point(0, 0);
this.glControl1.Name = "glControl1";
this.glControl1.Size = new System.Drawing.Size(768, 607);
this.glControl1.TabIndex = 4;
this.glControl1.Visible = false;
this.glControl1.VSync = false;
this.glControl1.Load += new System.EventHandler(this.glControl1_Load);
this.glControl1.Paint += new System.Windows.Forms.PaintEventHandler(this.glControl1_Paint);
this.glControl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseDown);
this.glControl1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseMove);
this.glControl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseUp);
this.glControl1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseWheel);
//
this.glControl.API = OpenTK.Windowing.Common.ContextAPI.OpenGL;
this.glControl.APIVersion = new System.Version(4, 6, 0, 0);
this.glControl.BackColor = System.Drawing.SystemColors.ControlDarkDark;
this.glControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.glControl.Flags = OpenTK.Windowing.Common.ContextFlags.Default;
this.glControl.IsEventDriven = true;
this.glControl.Location = new System.Drawing.Point(0, 0);
this.glControl.Name = "glControl1";
this.glControl.Size = new System.Drawing.Size(768, 607);
this.glControl.TabIndex = 4;
this.glControl.Visible = false;
this.glControl.Load += new System.EventHandler(this.glControl1_Load);
this.glControl.Paint += new System.Windows.Forms.PaintEventHandler(this.glControl1_Paint);
this.glControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseDown);
this.glControl.MouseMove += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseMove);
this.glControl.MouseUp += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseUp);
this.glControl.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseWheel);
//
// textPreviewBox
//
@@ -1260,7 +1263,7 @@
private System.Windows.Forms.TextBox classTextBox;
private System.Windows.Forms.ToolStripMenuItem exportClassStructuresMenuItem;
private System.Windows.Forms.Label FMODcopyright;
private OpenTK.GLControl glControl1;
private OpenTK.WinForms.GLControl glControl;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem showOriginalFileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exportAnimatorwithselectedAnimationClipMenuItem;

View File

@@ -1,6 +1,6 @@
using AssetStudio;
using Newtonsoft.Json;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using System;
using System.Collections.Generic;
@@ -20,14 +20,11 @@ using System.Timers;
using System.Windows.Forms;
using static AssetStudioGUI.Studio;
using Font = AssetStudio.Font;
#if NET472
using Vector3 = OpenTK.Vector3;
using Vector4 = OpenTK.Vector4;
#else
using Vector3 = OpenTK.Mathematics.Vector3;
using Vector4 = OpenTK.Mathematics.Vector4;
using Matrix4 = OpenTK.Mathematics.Matrix4;
#endif
using OpenTK.Mathematics;
using SpirV;
namespace AssetStudioGUI
{
@@ -54,14 +51,14 @@ namespace AssetStudioGUI
private bool glControlLoaded;
private int mdx, mdy;
private bool lmdown, rmdown;
private int pgmID, pgmColorID, pgmBlackID;
private ProgramHandle pgmID, pgmColorID, pgmBlackID;
private int attributeVertexPosition;
private int attributeNormalDirection;
private int attributeVertexColor;
private int uniformModelMatrix;
private int uniformViewMatrix;
private int uniformProjMatrix;
private int vao;
private VertexArrayHandle vao;
private Vector3[] vertexData;
private Vector3[] normalData;
private Vector3[] normal2Data;
@@ -137,7 +134,7 @@ namespace AssetStudioGUI
Studio.Game = GameManager.GetGame(Properties.Settings.Default.selectedGame);
specifyGame.SelectedIndex = Properties.Settings.Default.selectedGame;
specifyGame.SelectedIndexChanged += new EventHandler(toolStripComboBox2_SelectedIndexChanged);
Logger.Info($"Target Game is {Studio.Game.DisplayName}");
Logger.Info($"Target Game is {Studio.Game.Name}");
CABManager.LoadMap(Studio.Game);
}
@@ -248,7 +245,7 @@ namespace AssetStudioGUI
}
else
{
Text = $"Studio v{Application.ProductVersion} - {Studio.Game.DisplayName} - {Path.GetFileName(assetsManager.assetsFileList[0].originalPath)} - {assetsManager.assetsFileList[0].unityVersion} - {assetsManager.assetsFileList[0].m_TargetPlatform}";
Text = $"Studio v{Application.ProductVersion} - {Studio.Game.Name} - {Path.GetFileName(assetsManager.assetsFileList[0].originalPath)} - {assetsManager.assetsFileList[0].unityVersion} - {assetsManager.assetsFileList[0].m_TargetPlatform}";
}
assetListView.VirtualListSize = visibleAssets.Count;
@@ -317,7 +314,7 @@ namespace AssetStudioGUI
private void AssetStudioForm_KeyDown(object sender, KeyEventArgs e)
{
if (glControl1.Visible)
if (glControl.Visible)
{
if (e.Control)
{
@@ -326,18 +323,18 @@ namespace AssetStudioGUI
case Keys.W:
//Toggle WireFrame
wireFrameMode = (wireFrameMode + 1) % 3;
glControl1.Invalidate();
glControl.Invalidate();
break;
case Keys.S:
//Toggle Shade
shadeMode = (shadeMode + 1) % 2;
glControl1.Invalidate();
glControl.Invalidate();
break;
case Keys.N:
//Normal mode
normalMode = (normalMode + 1) % 2;
CreateVAO();
glControl1.Invalidate();
glControl.Invalidate();
break;
}
}
@@ -701,7 +698,7 @@ namespace AssetStudioGUI
textPreviewBox.Visible = false;
fontPreviewBox.Visible = false;
FMODpanel.Visible = false;
glControl1.Visible = false;
glControl.Visible = false;
StatusStripUpdate("");
FMODreset();
@@ -734,7 +731,7 @@ namespace AssetStudioGUI
textPreviewBox.Visible = false;
fontPreviewBox.Visible = false;
FMODpanel.Visible = false;
glControl1.Visible = false;
glControl.Visible = false;
StatusStripUpdate("");
if (e.IsSelected)
{
@@ -744,10 +741,10 @@ namespace AssetStudioGUI
private void preview_Resize(object sender, EventArgs e)
{
if (glControlLoaded && glControl1.Visible)
if (glControlLoaded && glControl.Visible)
{
ChangeGLSize(glControl1.Size);
glControl1.Invalidate();
ChangeGLSize(glControl.Size);
glControl.Invalidate();
}
}
@@ -1219,7 +1216,7 @@ namespace AssetStudioGUI
}
}
#endregion
glControl1.Visible = true;
glControl.Visible = true;
CreateVAO();
StatusStripUpdate("Using OpenGL Version: " + GL.GetString(StringName.Version) + "\n"
+ "'Mouse Left'=Rotate | 'Mouse Right'=Move | 'Mouse Wheel'=Zoom \n"
@@ -1308,7 +1305,7 @@ namespace AssetStudioGUI
assetInfoLabel.Text = null;
textPreviewBox.Visible = false;
fontPreviewBox.Visible = false;
glControl1.Visible = false;
glControl.Visible = false;
lastSelectedItem = null;
sortColumn = -1;
reverseSort = false;
@@ -1954,11 +1951,11 @@ namespace AssetStudioGUI
#region GLControl
private void InitOpenTK()
{
ChangeGLSize(glControl1.Size);
GL.ClearColor(System.Drawing.Color.CadetBlue);
ChangeGLSize(glControl.Size);
GL.ClearColor(Color4.Dimgray);
pgmID = GL.CreateProgram();
LoadShader("vs", ShaderType.VertexShader, pgmID, out int vsID);
LoadShader("fs", ShaderType.FragmentShader, pgmID, out int fsID);
LoadShader("vs", ShaderType.VertexShader, pgmID, out var vsID);
LoadShader("fs", ShaderType.FragmentShader, pgmID, out var fsID);
GL.LinkProgram(pgmID);
pgmColorID = GL.CreateProgram();
@@ -1979,7 +1976,7 @@ namespace AssetStudioGUI
uniformProjMatrix = GL.GetUniformLocation(pgmID, "projMatrix");
}
private static void LoadShader(string filename, ShaderType type, int program, out int address)
private static void LoadShader(string filename, ShaderType type, ProgramHandle program, out ShaderHandle address)
{
address = GL.CreateShader(type);
var str = (string)Properties.Resources.ResourceManager.GetObject(filename);
@@ -1989,50 +1986,47 @@ namespace AssetStudioGUI
GL.DeleteShader(address);
}
private static void CreateVBO(out int vboAddress, Vector3[] data, int address)
private static void CreateVBO(out BufferHandle vboAddress, Vector3[] data, int address)
{
GL.GenBuffers(1, out vboAddress);
GL.BindBuffer(BufferTarget.ArrayBuffer, vboAddress);
GL.BufferData(BufferTarget.ArrayBuffer,
(IntPtr)(data.Length * Vector3.SizeInBytes),
GL.CreateBuffer(out vboAddress);
GL.BindBuffer(BufferTargetARB.ArrayBuffer, vboAddress);
GL.BufferData(BufferTargetARB.ArrayBuffer,
data,
BufferUsageHint.StaticDraw);
GL.VertexAttribPointer(address, 3, VertexAttribPointerType.Float, false, 0, 0);
GL.EnableVertexAttribArray(address);
BufferUsageARB.StaticDraw);
GL.VertexAttribPointer((uint)address, 3, VertexAttribPointerType.Float, false, 0, 0);
GL.EnableVertexAttribArray((uint)address);
}
private static void CreateVBO(out int vboAddress, Vector4[] data, int address)
private static void CreateVBO(out BufferHandle vboAddress, Vector4[] data, int address)
{
GL.GenBuffers(1, out vboAddress);
GL.BindBuffer(BufferTarget.ArrayBuffer, vboAddress);
GL.BufferData(BufferTarget.ArrayBuffer,
(IntPtr)(data.Length * Vector4.SizeInBytes),
GL.CreateBuffer(out vboAddress);
GL.BindBuffer(BufferTargetARB.ArrayBuffer, vboAddress);
GL.BufferData(BufferTargetARB.ArrayBuffer,
data,
BufferUsageHint.StaticDraw);
GL.VertexAttribPointer(address, 4, VertexAttribPointerType.Float, false, 0, 0);
GL.EnableVertexAttribArray(address);
BufferUsageARB.StaticDraw);
GL.VertexAttribPointer((uint)address, 4, VertexAttribPointerType.Float, false, 0, 0);
GL.EnableVertexAttribArray((uint)address);
}
private static void CreateVBO(out int vboAddress, Matrix4 data, int address)
private static void CreateVBO(out BufferHandle vboAddress, Matrix4 data, int address)
{
GL.GenBuffers(1, out vboAddress);
GL.UniformMatrix4(address, false, ref data);
GL.CreateBuffer(out vboAddress);
GL.UniformMatrix4f(address, false, data);
}
private static void CreateEBO(out int address, int[] data)
private static void CreateEBO(out BufferHandle address, int[] data)
{
GL.GenBuffers(1, out address);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, address);
GL.BufferData(BufferTarget.ElementArrayBuffer,
(IntPtr)(data.Length * sizeof(int)),
GL.CreateBuffer(out address);
GL.BindBuffer(BufferTargetARB.ElementArrayBuffer, address);
GL.BufferData(BufferTargetARB.ElementArrayBuffer,
data,
BufferUsageHint.StaticDraw);
BufferUsageARB.StaticDraw);
}
private void CreateVAO()
{
GL.DeleteVertexArray(vao);
GL.GenVertexArrays(1, out vao);
GL.CreateVertexArray(out vao);
GL.BindVertexArray(vao);
CreateVBO(out var vboPositions, vertexData, attributeVertexPosition);
if (normalMode == 0)
@@ -2049,8 +2043,8 @@ namespace AssetStudioGUI
CreateVBO(out var vboViewMatrix, viewMatrixData, uniformViewMatrix);
CreateVBO(out var vboProjMatrix, projMatrixData, uniformProjMatrix);
CreateEBO(out var eboElements, indiceData);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
GL.BindVertexArray(0);
GL.BindBuffer(BufferTargetARB.ArrayBuffer, BufferHandle.Zero);
GL.BindVertexArray(VertexArrayHandle.Zero);
}
private void ChangeGLSize(Size size)
@@ -2077,7 +2071,7 @@ namespace AssetStudioGUI
private void glControl1_Paint(object sender, PaintEventArgs e)
{
glControl1.MakeCurrent();
glControl.MakeCurrent();
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.Enable(EnableCap.DepthTest);
GL.DepthFunc(DepthFunction.Lequal);
@@ -2085,11 +2079,11 @@ namespace AssetStudioGUI
if (wireFrameMode == 0 || wireFrameMode == 2)
{
GL.UseProgram(shadeMode == 0 ? pgmID : pgmColorID);
GL.UniformMatrix4(uniformModelMatrix, false, ref modelMatrixData);
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData);
GL.UniformMatrix4(uniformProjMatrix, false, ref projMatrixData);
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
GL.DrawElements(BeginMode.Triangles, indiceData.Length, DrawElementsType.UnsignedInt, 0);
GL.UniformMatrix4f(uniformModelMatrix, false, modelMatrixData);
GL.UniformMatrix4f(uniformViewMatrix, false, viewMatrixData);
GL.UniformMatrix4f(uniformProjMatrix, false, projMatrixData);
GL.PolygonMode(TriangleFace.FrontAndBack, PolygonMode.Fill);
GL.DrawElements(PrimitiveType.Triangles, indiceData.Length, DrawElementsType.UnsignedInt, 0);
}
//Wireframe
if (wireFrameMode == 1 || wireFrameMode == 2)
@@ -2097,16 +2091,16 @@ namespace AssetStudioGUI
GL.Enable(EnableCap.PolygonOffsetLine);
GL.PolygonOffset(-1, -1);
GL.UseProgram(pgmBlackID);
GL.UniformMatrix4(uniformModelMatrix, false, ref modelMatrixData);
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData);
GL.UniformMatrix4(uniformProjMatrix, false, ref projMatrixData);
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
GL.DrawElements(BeginMode.Triangles, indiceData.Length, DrawElementsType.UnsignedInt, 0);
GL.UniformMatrix4f(uniformModelMatrix, false, modelMatrixData);
GL.UniformMatrix4f(uniformViewMatrix, false, viewMatrixData);
GL.UniformMatrix4f(uniformProjMatrix, false, projMatrixData);
GL.PolygonMode(TriangleFace.FrontAndBack, PolygonMode.Line);
GL.DrawElements(PrimitiveType.Triangles, indiceData.Length, DrawElementsType.UnsignedInt, 0);
GL.Disable(EnableCap.PolygonOffsetLine);
}
GL.BindVertexArray(0);
GL.BindVertexArray(VertexArrayHandle.Zero);
GL.Flush();
glControl1.SwapBuffers();
glControl.SwapBuffers();
}
private void tabControl2_SelectedIndexChanged(object sender, EventArgs e)
@@ -2212,7 +2206,7 @@ namespace AssetStudioGUI
Properties.Settings.Default.Save();
Studio.Game = GameManager.GetGame(Properties.Settings.Default.selectedGame);
Logger.Info($"Target Game is {Studio.Game.DisplayName}");
Logger.Info($"Target Game is {Studio.Game.Name}");
ResetForm();
assetsManager.SpecifyUnityVersion = specifyUnityVersion.Text;
@@ -2234,10 +2228,10 @@ namespace AssetStudioGUI
private void glControl1_MouseWheel(object sender, MouseEventArgs e)
{
if (glControl1.Visible)
if (glControl.Visible)
{
viewMatrixData *= Matrix4.CreateScale(1 + e.Delta / 1000f);
glControl1.Invalidate();
glControl.Invalidate();
}
}
@@ -2276,7 +2270,7 @@ namespace AssetStudioGUI
dy *= 0.003f;
viewMatrixData *= Matrix4.CreateTranslation(-dx, dy, 0);
}
glControl1.Invalidate();
glControl.Invalidate();
}
}

View File

@@ -209,7 +209,7 @@ namespace AssetStudioGUI
var preloadEnd = preloadIndex + preloadSize;
for (int k = preloadIndex; k < preloadEnd; k++)
{
if (Game.Name == "GI" || Game.Name == "CB2" || Game.Name == "CB3")
if (Game.Name == "GI" || Game.Name == "GI_CB2" || Game.Name == "GI_CB3")
{
if (long.TryParse(m_Container.Key, out var containerValue))
{
@@ -392,7 +392,7 @@ namespace AssetStudioGUI
var preloadEnd = preloadIndex + preloadSize;
for (int k = preloadIndex; k < preloadEnd; k++)
{
if (Game.Name == "GI" || Game.Name == "CB2" || Game.Name == "CB3")
if (Game.Name == "GI" || Game.Name == "GI_CB2" || Game.Name == "GI_CB3")
{
if (long.TryParse(m_Container.Key, out var containerValue))
{
@@ -617,7 +617,7 @@ namespace AssetStudioGUI
case AssetGroupOption.ByContainer: //container path
if (!string.IsNullOrEmpty(asset.Container))
{
exportPath = Game.Name == "GI" || Game.Name == "CB2" || Game.Name == "CB3" ? Path.Combine(savePath, Path.GetDirectoryName(asset.Container)) : Path.Combine(savePath, asset.Container);
exportPath = Path.HasExtension(asset.Container) ? Path.Combine(savePath, Path.GetFileNameWithoutExtension(asset.Container)) : Path.Combine(savePath, asset.Container);
}
else
{