Some improvements

This commit is contained in:
Perfare 2018-04-21 21:52:15 +08:00
parent 87d6a26232
commit 52ba354dc5
6 changed files with 212 additions and 210 deletions

View File

@ -211,6 +211,7 @@
<Compile Include="StudioClasses\AssetsFile.cs" />
<Compile Include="StudioClasses\Texture2DConverter.cs" />
<Compile Include="StudioClasses\WebFile.cs" />
<Compile Include="TreeViewExtensions.cs" />
<EmbeddedResource Include="AssetStudioForm.resx">
<DependentUpon>AssetStudioForm.cs</DependentUpon>
<SubType>Designer</SubType>

View File

@ -211,6 +211,7 @@
<Compile Include="AssetStudioForm.Designer.cs">
<DependentUpon>AssetStudioForm.cs</DependentUpon>
</Compile>
<Compile Include="TreeViewExtensions.cs" />
<EmbeddedResource Include="ExportOptions.resx">
<DependentUpon>ExportOptions.cs</DependentUpon>
</EmbeddedResource>

View File

@ -30,34 +30,27 @@ namespace AssetStudio
private FMOD.MODE loopMode = FMOD.MODE.LOOP_OFF;
private uint FMODlenms;
private float FMODVolume = 0.8f;
private float FMODfrequency;
private Bitmap imageTexture;
#region OpenTK variables
int pgmID, pgmColorID, pgmBlackID;
int attributeVertexPosition;
int attributeNormalDirection;
int attributeVertexColor;
int uniformModelMatrix;
int uniformViewMatrix;
int vao;
int vboPositions;
int vboNormals;
int vboColors;
int vboModelMatrix;
int vboViewMatrix;
int eboElements;
Vector3[] vertexData;
Vector3[] normalData;
Vector3[] normal2Data;
Vector4[] colorData;
Matrix4 modelMatrixData;
Matrix4 viewMatrixData;
int[] indiceData;
int wireFrameMode;
int shadeMode;
int normalMode;
#region OpenTK
private int pgmID, pgmColorID, pgmBlackID;
private int attributeVertexPosition;
private int attributeNormalDirection;
private int attributeVertexColor;
private int uniformModelMatrix;
private int uniformViewMatrix;
private int vao;
private Vector3[] vertexData;
private Vector3[] normalData;
private Vector3[] normal2Data;
private Vector4[] colorData;
private Matrix4 modelMatrixData;
private Matrix4 viewMatrixData;
private int[] indiceData;
private int wireFrameMode;
private int shadeMode;
private int normalMode;
#endregion
//asset list sorting helpers
@ -70,8 +63,6 @@ namespace AssetStudio
private int nextGObject;
private List<GameObject> treeSrcResults = new List<GameObject>();
private PrivateFontCollection pfc = new PrivateFontCollection();
[DllImport("gdi32.dll")]
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);
@ -176,16 +167,12 @@ namespace AssetStudio
return;
}
bool optionLoadAssetsMenuItem = !dontLoadAssetsMenuItem.Checked;
bool optionDisplayAll = displayAll.Checked;
bool optionBuildHierarchyMenuItem = !dontBuildHierarchyMenuItem.Checked;
bool optionBuildClassStructuresMenuItem = buildClassStructuresMenuItem.Checked;
BuildAssetStructures(optionLoadAssetsMenuItem, optionDisplayAll, optionBuildHierarchyMenuItem, optionBuildClassStructuresMenuItem, displayOriginalName.Checked);
BuildAssetStructures(!dontLoadAssetsMenuItem.Checked, displayAll.Checked, !dontBuildHierarchyMenuItem.Checked, buildClassStructuresMenuItem.Checked,
displayOriginalName.Checked, out var fileNodes);
BeginInvoke(new Action(() =>
{
if (productName != "")
if (!string.IsNullOrEmpty(productName))
{
Text = $"AssetStudio - {productName} - {assetsfileList[0].m_Version} - {assetsfileList[0].platformStr}";
}
@ -203,7 +190,10 @@ namespace AssetStudio
{
sceneTreeView.BeginUpdate();
sceneTreeView.Nodes.AddRange(fileNodes.ToArray());
fileNodes.Clear();
foreach (TreeNode node in sceneTreeView.Nodes)
{
node.HideCheckBox();
}
sceneTreeView.EndUpdate();
}
if (buildClassStructuresMenuItem.Checked)
@ -676,7 +666,6 @@ namespace AssetStudio
assetInfoLabel.Text = null;
textPreviewBox.Visible = false;
fontPreviewBox.Visible = false;
pfc.Dispose();
FMODpanel.Visible = false;
glControl1.Visible = false;
lastLoadedAsset = null;
@ -759,10 +748,10 @@ namespace AssetStudio
FMODpanel.Visible = true;
result = channel.getFrequency(out FMODfrequency);
result = channel.getFrequency(out var frequency);
if (ERRCHECK(result)) { break; }
FMODinfoLabel.Text = FMODfrequency + " Hz";
FMODinfoLabel.Text = frequency + " Hz";
FMODtimerLabel.Text = $"0:0.0 / {FMODlenms / 1000 / 60}:{FMODlenms / 1000 % 60}.{FMODlenms / 10 % 100}";
break;
}
@ -808,13 +797,12 @@ namespace AssetStudio
var re = AddFontMemResourceEx(data, (uint)m_Font.m_FontData.Length, IntPtr.Zero, ref cFonts);
if (re != IntPtr.Zero)
{
pfc = new PrivateFontCollection();
using (var pfc = new PrivateFontCollection())
{
pfc.AddMemoryFont(data, m_Font.m_FontData.Length);
Marshal.FreeCoTaskMem(data);
if (pfc.Families.Length > 0)
{
//textPreviewBox.Font = new Font(pfc.Families[0], 16, FontStyle.Regular);
//textPreviewBox.Text = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWYZ\r\n1234567890.:,;'\"(!?)+-*/=\r\nThe quick brown fox jumps over the lazy dog. 1234567890";
fontPreviewBox.SelectionStart = 0;
fontPreviewBox.SelectionLength = 80;
fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 16, FontStyle.Regular);
@ -841,6 +829,7 @@ namespace AssetStudio
fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 72, FontStyle.Regular);
fontPreviewBox.Visible = true;
}
}
break;
}
}
@ -1576,20 +1565,20 @@ namespace AssetStudio
GL.DeleteVertexArray(vao);
GL.GenVertexArrays(1, out vao);
GL.BindVertexArray(vao);
createVBO(out vboPositions, vertexData, attributeVertexPosition);
createVBO(out var vboPositions, vertexData, attributeVertexPosition);
if (normalMode == 0)
{
createVBO(out vboNormals, normal2Data, attributeNormalDirection);
createVBO(out var vboNormals, normal2Data, attributeNormalDirection);
}
else
{
if (normalData != null)
createVBO(out vboNormals, normalData, attributeNormalDirection);
createVBO(out var vboNormals, normalData, attributeNormalDirection);
}
createVBO(out vboColors, colorData, attributeVertexColor);
createVBO(out vboModelMatrix, modelMatrixData, uniformModelMatrix);
createVBO(out vboViewMatrix, viewMatrixData, uniformViewMatrix);
createEBO(out eboElements, indiceData);
createVBO(out var vboColors, colorData, attributeVertexColor);
createVBO(out var vboModelMatrix, modelMatrixData, uniformModelMatrix);
createVBO(out var vboViewMatrix, viewMatrixData, uniformViewMatrix);
createEBO(out var eboElements, indiceData);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
GL.BindVertexArray(0);
}
@ -1826,7 +1815,7 @@ namespace AssetStudio
var savePath = saveFolderDialog1.Folder + "\\";
progressBar1.Value = 0;
progressBar1.Maximum = sceneTreeView.Nodes.Count;
ExportSplitObjectsNew(savePath, sceneTreeView.Nodes);
ExportSplitObjects(savePath, sceneTreeView.Nodes, true);
}
}
else

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
using static AssetStudio.Studio;
using static AssetStudio.Exporter;
@ -13,6 +14,15 @@ namespace AssetStudio
public static void WriteFBX(string FBXfile, List<GameObject> gameObjects)
{
var timestamp = DateTime.Now;
Dictionary<string, Dictionary<string, string>> jsonMats = null;
if (File.Exists(mainPath + "\\materials.json"))
{
using (var reader = File.OpenText(mainPath + "\\materials.json"))
{
var matLine = reader.ReadToEnd();
jsonMats = new JavaScriptSerializer().Deserialize<Dictionary<string, Dictionary<string, string>>>(matLine);
}
}
using (StreamWriter FBXwriter = new StreamWriter(FBXfile))
{

View File

@ -5,7 +5,6 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using static AssetStudio.Exporter;
@ -19,13 +18,9 @@ namespace AssetStudio
public static List<AssetPreloadData> exportableAssets = new List<AssetPreloadData>(); //used to hold all assets while the ListView is filtered
private static HashSet<string> exportableAssetsHash = new HashSet<string>(); //avoid the same name asset
public static List<AssetPreloadData> visibleAssets = new List<AssetPreloadData>(); //used to build the ListView from all or filtered assets
public static string productName = "";
public static string mainPath = "";
public static List<GameObject> fileNodes = new List<GameObject>();
public static Dictionary<string, Dictionary<string, string>> jsonMats;
public static Dictionary<string, SortedDictionary<int, ClassStruct>> AllClassStructures = new Dictionary<string, SortedDictionary<int, ClassStruct>>();
public static string mainPath;
public static string productName = "";
//UI
public static Action<int> SetProgressBarValue;
@ -154,10 +149,12 @@ namespace AssetStudio
return extractedCount;
}
public static void BuildAssetStructures(bool loadAssetsMenuItem, bool displayAll, bool buildHierarchyMenuItem, bool buildClassStructuresMenuItem, bool displayOriginalName)
public static void BuildAssetStructures(bool loadAssets, bool displayAll, bool buildHierarchy, bool buildClassStructures, bool displayOriginalName, out List<GameObject> fileNodes)
{
fileNodes = null;
#region first loop - read asset data & create list
if (loadAssetsMenuItem)
if (loadAssets)
{
SetProgressBarValue(0);
SetProgressBarMaximum(assetsfileList.Sum(x => x.preloadTable.Values.Count));
@ -325,11 +322,14 @@ namespace AssetStudio
#endregion
#region second loop - build tree structure
if (buildHierarchy)
{
fileNodes = new List<GameObject>();
if (buildHierarchyMenuItem)
var gameObjectCount = assetsfileList.Sum(x => x.GameObjectList.Values.Count);
if (gameObjectCount > 0)
{
SetProgressBarValue(0);
SetProgressBarMaximum(assetsfileList.Sum(x => x.GameObjectList.Values.Count));
SetProgressBarMaximum(gameObjectCount);
StatusStripUpdate("Building tree structure...");
foreach (var assetsFile in assetsfileList)
@ -402,10 +402,8 @@ namespace AssetStudio
{
if (assetsfileList.TryGetTransform(m_Transform.m_Father, out var m_Father))
{
//GameObject Parent;
if (assetsfileList.TryGetGameObject(m_Father.m_GameObject, out parentNode))
{
//parentNode = Parent;
}
}
}
@ -419,21 +417,12 @@ namespace AssetStudio
fileNodes.Add(fileNode);
}
}
if (File.Exists(mainPath + "\\materials.json"))
{
string matLine;
using (StreamReader reader = File.OpenText(mainPath + "\\materials.json"))
{
matLine = reader.ReadToEnd();
}
jsonMats = new JavaScriptSerializer().Deserialize<Dictionary<string, Dictionary<string, string>>>(matLine);
}
}
#endregion
#region build list of class strucutres
if (buildClassStructuresMenuItem)
if (buildClassStructures)
{
//group class structures by versionv
foreach (var assetsFile in assetsfileList)
@ -595,7 +584,7 @@ namespace AssetStudio
});
}
public static void ExportSplitObjects(string savePath, TreeNodeCollection nodes)
public static void ExportSplitObjects(string savePath, TreeNodeCollection nodes, bool isNew = false)
{
ThreadPool.QueueUserWorkItem(state =>
{
@ -629,6 +618,9 @@ namespace AssetStudio
Directory.CreateDirectory(targetPath);
//导出FBX
StatusStripUpdate($"Exporting {filename}.fbx");
if (isNew)
ExportGameObject((GameObject)j, targetPath);
else
FBXExporter.WriteFBX($"{targetPath}{filename}.fbx", gameObjects);
StatusStripUpdate($"Finished exporting {filename}.fbx");
}
@ -637,48 +629,6 @@ namespace AssetStudio
});
}
public static void ExportSplitObjectsNew(string savePath, TreeNodeCollection nodes)
{
ThreadPool.QueueUserWorkItem(state =>
{
foreach (TreeNode node in nodes)
{
//遍历一级子节点
foreach (TreeNode j in node.Nodes)
{
//收集所有子节点
var gameObjects = new List<GameObject>();
CollectNode(j, gameObjects);
//跳过一些不需要导出的object
if (gameObjects.All(x => x.m_SkinnedMeshRenderer == null && x.m_MeshFilter == null))
continue;
//处理非法文件名
var filename = FixFileName(j.Text);
//每个文件存放在单独的文件夹
var targetPath = $"{savePath}{filename}\\";
//重名文件处理
for (int i = 1; ; i++)
{
if (Directory.Exists(targetPath))
{
targetPath = $"{savePath}{filename} ({i})\\";
}
else
{
break;
}
}
Directory.CreateDirectory(targetPath);
//导出FBX
StatusStripUpdate($"Exporting {j.Text}.fbx");
ExportGameObject((GameObject)j, targetPath);
StatusStripUpdate($"Finished exporting {j.Text}.fbx");
}
ProgressBarPerformStep();
}
});
}
private static void CollectNode(TreeNode node, List<GameObject> gameObjects)
{
gameObjects.Add((GameObject)node);

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace AssetStudio
{
public static class TreeViewExtensions
{
private const int TVIF_STATE = 0x8;
private const int TVIS_STATEIMAGEMASK = 0xF000;
private const int TV_FIRST = 0x1100;
private const int TVM_SETITEM = TV_FIRST + 63;
[StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Auto)]
private struct TVITEM
{
public int mask;
public IntPtr hItem;
public int state;
public int stateMask;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpszText;
public int cchTextMax;
public int iImage;
public int iSelectedImage;
public int cChildren;
public IntPtr lParam;
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref TVITEM lParam);
/// <summary>
/// Hides the checkbox for the specified node on a TreeView control.
/// </summary>
public static void HideCheckBox(this TreeNode node)
{
var tvi = new TVITEM
{
hItem = node.Handle,
mask = TVIF_STATE,
stateMask = TVIS_STATEIMAGEMASK,
state = 0
};
SendMessage(node.TreeView.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi);
}
}
}