AssetStudio/AssetStudioGUI/AssetStudioGUIForm.cs

1949 lines
74 KiB
C#
Raw Normal View History

2015-10-30 02:41:37 +00:00
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Drawing.Text;
using OpenTK;
using OpenTK.Graphics.OpenGL;
2018-11-18 22:48:06 +00:00
using AssetStudio;
using static AssetStudioGUI.Studio;
2018-11-21 07:37:56 +00:00
using Object = AssetStudio.Object;
using Font = AssetStudio.Font;
2019-01-03 00:55:43 +00:00
using Vector3 = OpenTK.Vector3;
using Vector4 = OpenTK.Vector4;
2015-10-30 02:41:37 +00:00
2018-11-18 22:48:06 +00:00
namespace AssetStudioGUI
2015-10-30 02:41:37 +00:00
{
2018-11-18 22:48:06 +00:00
partial class AssetStudioGUIForm : Form
2015-10-30 02:41:37 +00:00
{
2018-11-07 21:00:53 +00:00
private AssetItem lastSelectedItem;
private AssetItem lastLoadedAsset;
2017-02-11 20:57:24 +00:00
private FMOD.System system;
private FMOD.Sound sound;
private FMOD.Channel channel;
private FMOD.SoundGroup masterSoundGroup;
2015-10-30 02:41:37 +00:00
private FMOD.MODE loopMode = FMOD.MODE.LOOP_OFF;
2017-02-11 20:57:24 +00:00
private uint FMODlenms;
2015-10-30 02:41:37 +00:00
private float FMODVolume = 0.8f;
2017-02-11 20:57:24 +00:00
private Bitmap imageTexture;
2015-10-30 02:41:37 +00:00
2018-08-15 00:40:46 +00:00
#region GLControl
2018-08-14 20:53:11 +00:00
private bool glControlLoaded;
2018-08-15 00:40:46 +00:00
private int mdx, mdy;
private bool lmdown, rmdown;
2018-04-21 13:52:15 +00:00
private int pgmID, pgmColorID, pgmBlackID;
private int attributeVertexPosition;
private int attributeNormalDirection;
private int attributeVertexColor;
private int uniformModelMatrix;
private int uniformViewMatrix;
private int uniformProjMatrix;
2018-04-21 13:52:15 +00:00
private int vao;
private Vector3[] vertexData;
private Vector3[] normalData;
private Vector3[] normal2Data;
private Vector4[] colorData;
private Matrix4 modelMatrixData;
private Matrix4 viewMatrixData;
private Matrix4 projMatrixData;
2018-04-21 13:52:15 +00:00
private int[] indiceData;
private int wireFrameMode;
private int shadeMode;
private int normalMode;
#endregion
//asset list sorting helpers
private int firstSortColumn = -1;
2017-02-11 20:57:24 +00:00
private int secondSortColumn;
private bool reverseSort;
private bool enableFiltering;
2015-10-30 02:41:37 +00:00
//tree search
2017-02-11 20:57:24 +00:00
private int nextGObject;
2018-11-20 08:47:35 +00:00
private List<TreeNode> treeSrcResults = new List<TreeNode>();
2015-10-30 02:41:37 +00:00
[DllImport("gdi32.dll")]
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);
2017-04-09 19:13:08 +00:00
private void loadFile_Click(object sender, EventArgs e)
2015-10-30 02:41:37 +00:00
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
2018-11-07 22:45:33 +00:00
ResetForm();
2017-02-11 20:57:24 +00:00
ThreadPool.QueueUserWorkItem(state =>
2015-10-30 02:41:37 +00:00
{
2018-11-18 22:48:06 +00:00
assetsManager.LoadFiles(openFileDialog1.FileNames);
BuildAssetStructures();
2017-02-11 20:57:24 +00:00
});
2015-10-30 02:41:37 +00:00
}
}
2017-04-09 19:13:08 +00:00
private void loadFolder_Click(object sender, EventArgs e)
2015-10-30 02:41:37 +00:00
{
2018-11-18 22:48:06 +00:00
var openFolderDialog = new OpenFolderDialog();
if (openFolderDialog.ShowDialog(this) == DialogResult.OK)
2015-10-30 02:41:37 +00:00
{
2018-11-07 22:45:33 +00:00
ResetForm();
ThreadPool.QueueUserWorkItem(state =>
2017-10-22 15:48:31 +00:00
{
2018-11-18 22:48:06 +00:00
assetsManager.LoadFolder(openFolderDialog.Folder);
BuildAssetStructures();
2017-10-22 15:48:31 +00:00
});
2015-10-30 02:41:37 +00:00
}
}
2018-04-18 04:04:46 +00:00
private void extractFileToolStripMenuItem_Click(object sender, EventArgs e)
2015-10-30 02:41:37 +00:00
{
2018-04-09 20:45:09 +00:00
var openBundleDialog = new OpenFileDialog
{
2018-04-18 04:04:46 +00:00
Filter = "All types|*.*",
2018-04-09 20:45:09 +00:00
FilterIndex = 1,
RestoreDirectory = true,
Multiselect = true
};
2015-10-30 02:41:37 +00:00
if (openBundleDialog.ShowDialog() == DialogResult.OK)
{
2018-04-18 04:04:46 +00:00
ExtractFile(openBundleDialog.FileNames);
2015-10-30 02:41:37 +00:00
}
}
private void extractFolderToolStripMenuItem_Click(object sender, EventArgs e)
{
2017-10-22 15:48:31 +00:00
var openFolderDialog1 = new OpenFolderDialog();
if (openFolderDialog1.ShowDialog(this) == DialogResult.OK)
2015-10-30 02:41:37 +00:00
{
2018-04-18 04:04:46 +00:00
var files = Directory.GetFiles(openFolderDialog1.Folder, "*.*", SearchOption.AllDirectories);
ExtractFile(files);
2015-10-30 02:41:37 +00:00
}
}
2018-11-18 22:48:06 +00:00
private void BuildAssetStructures()
2015-10-30 02:41:37 +00:00
{
2018-11-18 22:48:06 +00:00
if (assetsManager.assetsFileList.Count == 0)
{
StatusStripUpdate("No file was loaded.");
return;
}
2018-11-18 22:48:06 +00:00
var productName = string.Empty;
2018-11-21 07:37:56 +00:00
var tempDic = new Dictionary<Object, AssetItem>();
2019-08-11 21:50:04 +00:00
if (!dontBuildAssetListMenuItem.Checked)
2018-11-18 22:48:06 +00:00
{
BuildAssetList(tempDic, displayAll.Checked, displayOriginalName.Checked, out productName);
}
2018-11-21 07:37:56 +00:00
List<TreeNode> treeNodeCollection = null;
2018-11-18 22:48:06 +00:00
if (!dontBuildHierarchyMenuItem.Checked)
{
treeNodeCollection = BuildTreeStructure(tempDic);
}
tempDic.Clear();
2018-11-22 06:45:28 +00:00
Dictionary<string, SortedDictionary<int, TypeTreeItem>> typeMap = null;
2018-11-18 22:48:06 +00:00
if (buildClassStructuresMenuItem.Checked)
{
2018-11-22 06:45:28 +00:00
typeMap = BuildClassStructure();
2018-11-18 22:48:06 +00:00
}
2015-10-30 02:41:37 +00:00
BeginInvoke(new Action(() =>
2015-10-30 02:41:37 +00:00
{
2018-04-21 13:52:15 +00:00
if (!string.IsNullOrEmpty(productName))
2015-10-30 02:41:37 +00:00
{
2018-11-18 22:48:06 +00:00
Text = $"AssetStudioGUI - {productName} - {assetsManager.assetsFileList[0].unityVersion} - {assetsManager.assetsFileList[0].m_TargetPlatform}";
}
2018-11-07 22:45:33 +00:00
else
{
2018-11-18 22:48:06 +00:00
Text = $"AssetStudioGUI - no productName - {assetsManager.assetsFileList[0].unityVersion} - {assetsManager.assetsFileList[0].m_TargetPlatform}";
}
2019-08-11 21:50:04 +00:00
if (!dontBuildAssetListMenuItem.Checked)
{
2017-02-11 20:57:24 +00:00
assetListView.VirtualListSize = visibleAssets.Count;
resizeAssetListColumns();
}
if (!dontBuildHierarchyMenuItem.Checked)
{
sceneTreeView.BeginUpdate();
2018-09-26 17:15:37 +00:00
sceneTreeView.Nodes.AddRange(treeNodeCollection.ToArray());
2018-11-07 21:00:53 +00:00
treeNodeCollection.Clear();
2018-04-21 13:52:15 +00:00
foreach (TreeNode node in sceneTreeView.Nodes)
{
node.HideCheckBox();
}
sceneTreeView.EndUpdate();
}
if (buildClassStructuresMenuItem.Checked)
{
classesListView.BeginUpdate();
2018-11-22 06:45:28 +00:00
foreach (var version in typeMap)
{
2018-11-18 22:48:06 +00:00
var versionGroup = new ListViewGroup(version.Key);
classesListView.Groups.Add(versionGroup);
foreach (var uclass in version.Value)
{
uclass.Value.Group = versionGroup;
classesListView.Items.Add(uclass.Value);
}
2015-10-30 02:41:37 +00:00
}
2018-11-22 06:45:28 +00:00
typeMap.Clear();
classesListView.EndUpdate();
2015-10-30 02:41:37 +00:00
}
2018-04-17 21:05:17 +00:00
2018-11-07 09:15:54 +00:00
var types = exportableAssets.Select(x => x.Type).Distinct().OrderBy(x => x.ToString()).ToArray();
2018-04-17 21:05:17 +00:00
foreach (var type in types)
{
var typeItem = new ToolStripMenuItem
{
CheckOnClick = true,
Name = type.ToString(),
Size = new Size(180, 22),
Text = type.ToString()
};
typeItem.Click += typeToolStripMenuItem_Click;
2018-08-04 21:25:26 +00:00
filterTypeToolStripMenuItem.DropDownItems.Add(typeItem);
2018-04-17 21:05:17 +00:00
}
allToolStripMenuItem.Checked = true;
2018-11-18 22:48:06 +00:00
StatusStripUpdate($"Finished loading {assetsManager.assetsFileList.Count} files with {assetListView.Items.Count} exportable assets.");
treeSearch.Select();
}));
2015-10-30 02:41:37 +00:00
}
2018-04-17 21:05:17 +00:00
private void typeToolStripMenuItem_Click(object sender, EventArgs e)
{
var typeItem = (ToolStripMenuItem)sender;
if (typeItem != allToolStripMenuItem)
{
allToolStripMenuItem.Checked = false;
}
else if (allToolStripMenuItem.Checked)
{
2018-08-04 21:25:26 +00:00
for (var i = 1; i < filterTypeToolStripMenuItem.DropDownItems.Count; i++)
2018-04-17 21:05:17 +00:00
{
2018-08-04 21:25:26 +00:00
var item = (ToolStripMenuItem)filterTypeToolStripMenuItem.DropDownItems[i];
2018-04-17 21:05:17 +00:00
item.Checked = false;
}
}
2018-04-21 07:50:13 +00:00
FilterAssetList();
2018-04-17 21:05:17 +00:00
}
2018-04-02 22:51:22 +00:00
private void AssetStudioForm_KeyDown(object sender, KeyEventArgs e)
2015-11-02 08:11:26 +00:00
{
2018-01-16 22:20:06 +00:00
if (glControl1.Visible)
{
2018-08-15 00:40:46 +00:00
if (e.Control)
{
2018-08-15 00:40:46 +00:00
switch (e.KeyCode)
{
case Keys.W:
if (e.Control) //Toggle WireFrame
{
wireFrameMode = (wireFrameMode + 1) % 3;
glControl1.Invalidate();
}
break;
case Keys.S:
if (e.Control) //Toggle Shade
{
shadeMode = (shadeMode + 1) % 2;
glControl1.Invalidate();
}
break;
2018-08-31 23:07:26 +00:00
case Keys.N:
2018-08-15 00:40:46 +00:00
if (e.Control) //Normal mode
{
normalMode = (normalMode + 1) % 2;
2018-12-09 03:56:24 +00:00
CreateVAO();
2018-08-15 00:40:46 +00:00
glControl1.Invalidate();
}
break;
}
}
}
2015-11-02 08:11:26 +00:00
}
2019-08-11 21:50:04 +00:00
private void dontBuildAssetListMenuItem_CheckedChanged(object sender, EventArgs e)
2015-11-02 08:11:26 +00:00
{
2019-08-11 21:50:04 +00:00
if (dontBuildAssetListMenuItem.Checked)
2015-11-02 08:11:26 +00:00
{
dontBuildHierarchyMenuItem.Checked = true;
dontBuildHierarchyMenuItem.Enabled = false;
}
2018-11-18 22:48:06 +00:00
else
{
dontBuildHierarchyMenuItem.Enabled = true;
}
2015-11-02 08:11:26 +00:00
}
2015-11-02 08:11:26 +00:00
private void exportClassStructuresMenuItem_Click(object sender, EventArgs e)
{
2018-11-22 06:45:28 +00:00
if (classesListView.Items.Count > 0)
2015-11-02 08:11:26 +00:00
{
2018-11-18 22:48:06 +00:00
var saveFolderDialog = new OpenFolderDialog();
if (saveFolderDialog.ShowDialog(this) == DialogResult.OK)
2015-11-02 08:11:26 +00:00
{
2018-11-22 06:45:28 +00:00
var savePath = saveFolderDialog.Folder;
var count = classesListView.Items.Count;
2018-11-18 22:48:06 +00:00
int i = 0;
Progress.Reset();
2018-11-22 06:45:28 +00:00
foreach (TypeTreeItem item in classesListView.Items)
2015-11-02 08:11:26 +00:00
{
2018-11-22 06:45:28 +00:00
var versionPath = savePath + "\\" + item.Group.Header;
Directory.CreateDirectory(versionPath);
2015-11-02 08:11:26 +00:00
2018-11-22 06:45:28 +00:00
var saveFile = $"{versionPath}\\{item.SubItems[1].Text} {item.Text}.txt";
File.WriteAllText(saveFile, item.ToString());
2015-11-02 08:11:26 +00:00
2018-11-18 22:48:06 +00:00
Progress.Report(++i, count);
2015-11-02 08:11:26 +00:00
}
StatusStripUpdate("Finished exporting class structures");
}
}
}
2015-10-30 02:41:37 +00:00
private void enablePreview_Check(object sender, EventArgs e)
{
if (lastLoadedAsset != null)
{
2018-03-27 22:29:28 +00:00
switch (lastLoadedAsset.Type)
2015-10-30 02:41:37 +00:00
{
2018-10-16 16:43:34 +00:00
case ClassIDType.Texture2D:
case ClassIDType.Sprite:
2015-10-30 02:41:37 +00:00
{
if (enablePreview.Checked && imageTexture != null)
{
previewPanel.BackgroundImage = imageTexture;
}
else
{
previewPanel.BackgroundImage = Properties.Resources.preview;
previewPanel.BackgroundImageLayout = ImageLayout.Center;
2015-10-30 02:41:37 +00:00
}
}
break;
2018-10-16 16:43:34 +00:00
case ClassIDType.Shader:
case ClassIDType.TextAsset:
case ClassIDType.MonoBehaviour:
2015-10-30 02:41:37 +00:00
textPreviewBox.Visible = !textPreviewBox.Visible;
break;
2018-10-16 16:43:34 +00:00
case ClassIDType.Font:
2015-10-30 02:41:37 +00:00
fontPreviewBox.Visible = !fontPreviewBox.Visible;
break;
2018-10-16 16:43:34 +00:00
case ClassIDType.AudioClip:
2015-10-30 02:41:37 +00:00
{
FMODpanel.Visible = !FMODpanel.Visible;
if (sound != null && channel != null)
2015-10-30 02:41:37 +00:00
{
2018-01-16 22:20:06 +00:00
var result = channel.isPlaying(out var playing);
if (result == FMOD.RESULT.OK && playing)
2015-10-30 02:41:37 +00:00
{
2018-11-18 22:48:06 +00:00
channel.stop();
FMODreset();
2015-10-30 02:41:37 +00:00
}
}
else if (FMODpanel.Visible)
{
PreviewAsset(lastLoadedAsset);
2015-10-30 02:41:37 +00:00
}
break;
}
}
}
else if (lastSelectedItem != null && enablePreview.Checked)
{
lastLoadedAsset = lastSelectedItem;
PreviewAsset(lastLoadedAsset);
}
Properties.Settings.Default["enablePreview"] = enablePreview.Checked;
Properties.Settings.Default.Save();
}
private void displayAssetInfo_Check(object sender, EventArgs e)
{
2018-11-18 22:48:06 +00:00
if (displayInfo.Checked && assetInfoLabel.Text != null)
{
assetInfoLabel.Visible = true;
}
else
{
assetInfoLabel.Visible = false;
}
2015-10-30 02:41:37 +00:00
Properties.Settings.Default["displayInfo"] = displayInfo.Checked;
Properties.Settings.Default.Save();
}
private void MenuItem_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default[((ToolStripMenuItem)sender).Name] = ((ToolStripMenuItem)sender).Checked;
Properties.Settings.Default.Save();
}
private void assetGroupOptions_SelectedIndexChanged(object sender, EventArgs e)
{
Properties.Settings.Default["assetGroupOption"] = ((ToolStripComboBox)sender).SelectedIndex;
Properties.Settings.Default.Save();
}
private void showExpOpt_Click(object sender, EventArgs e)
{
ExportOptions exportOpt = new ExportOptions();
exportOpt.ShowDialog();
}
private void assetListView_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
2017-02-11 20:57:24 +00:00
e.Item = visibleAssets[e.ItemIndex];
2015-10-30 02:41:37 +00:00
}
2015-10-30 02:41:37 +00:00
private void tabPageSelected(object sender, TabControlEventArgs e)
{
2015-11-02 08:11:26 +00:00
switch (e.TabPageIndex)
{
2017-09-23 23:14:18 +00:00
case 0:
treeSearch.Select();
break;
2015-11-02 08:11:26 +00:00
case 1:
resizeAssetListColumns(); //required because the ListView is not visible on app launch
2015-11-02 08:11:26 +00:00
classPreviewPanel.Visible = false;
previewPanel.Visible = true;
listSearch.Select();
break;
case 2:
previewPanel.Visible = false;
classPreviewPanel.Visible = true;
break;
}
2015-10-30 02:41:37 +00:00
}
private void treeSearch_Enter(object sender, EventArgs e)
{
if (treeSearch.Text == " Search ")
{
treeSearch.Text = "";
2017-04-09 19:13:08 +00:00
treeSearch.ForeColor = SystemColors.WindowText;
2015-10-30 02:41:37 +00:00
}
}
private void treeSearch_Leave(object sender, EventArgs e)
{
if (treeSearch.Text == "")
{
treeSearch.Text = " Search ";
2017-04-09 19:13:08 +00:00
treeSearch.ForeColor = SystemColors.GrayText;
2015-10-30 02:41:37 +00:00
}
}
private void treeSearch_TextChanged(object sender, EventArgs e)
{
treeSrcResults.Clear();
nextGObject = 0;
}
2015-10-30 02:41:37 +00:00
private void treeSearch_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (treeSrcResults.Count == 0)
2015-10-30 02:41:37 +00:00
{
2018-11-20 08:47:35 +00:00
foreach (TreeNode node in sceneTreeView.Nodes)
2015-10-30 02:41:37 +00:00
{
2018-11-20 08:47:35 +00:00
TreeNodeSearch(node);
}
}
2018-04-21 08:36:18 +00:00
if (treeSrcResults.Count > 0)
2015-10-30 02:41:37 +00:00
{
2018-04-21 08:36:18 +00:00
if (nextGObject >= treeSrcResults.Count)
2015-10-30 02:41:37 +00:00
{
2018-04-21 08:36:18 +00:00
nextGObject = 0;
2015-10-30 02:41:37 +00:00
}
2018-04-21 08:36:18 +00:00
treeSrcResults[nextGObject].EnsureVisible();
sceneTreeView.SelectedNode = treeSrcResults[nextGObject];
nextGObject++;
2015-10-30 02:41:37 +00:00
}
}
}
2018-11-20 08:47:35 +00:00
private void TreeNodeSearch(TreeNode treeNode)
{
if (treeNode.Text.IndexOf(treeSearch.Text, StringComparison.CurrentCultureIgnoreCase) >= 0)
{
treeSrcResults.Add(treeNode);
}
foreach (TreeNode node in treeNode.Nodes)
{
TreeNodeSearch(node);
}
}
2015-10-30 02:41:37 +00:00
private void sceneTreeView_AfterCheck(object sender, TreeViewEventArgs e)
{
2018-09-26 17:15:37 +00:00
foreach (TreeNode childNode in e.Node.Nodes)
2015-10-30 02:41:37 +00:00
{
childNode.Checked = e.Node.Checked;
}
}
private void resizeAssetListColumns()
{
assetListView.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.HeaderSize);
assetListView.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent);
assetListView.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.HeaderSize);
assetListView.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent);
var vscrollwidth = SystemInformation.VerticalScrollBarWidth;
2017-02-11 20:57:24 +00:00
var hasvscroll = (visibleAssets.Count / (float)assetListView.Height) > 0.0567f;
columnHeaderName.Width = assetListView.Width - columnHeaderType.Width - columnHeaderSize.Width - (hasvscroll ? (5 + vscrollwidth) : 5);
}
private void tabPage2_Resize(object sender, EventArgs e)
2015-10-30 02:41:37 +00:00
{
resizeAssetListColumns();
}
2015-10-30 02:41:37 +00:00
private void listSearch_Enter(object sender, EventArgs e)
{
if (listSearch.Text == " Filter ")
{
listSearch.Text = "";
2017-04-09 19:13:08 +00:00
listSearch.ForeColor = SystemColors.WindowText;
enableFiltering = true;
2015-10-30 02:41:37 +00:00
}
}
private void listSearch_Leave(object sender, EventArgs e)
{
if (listSearch.Text == "")
{
enableFiltering = false;
2015-10-30 02:41:37 +00:00
listSearch.Text = " Filter ";
2017-04-09 19:13:08 +00:00
listSearch.ForeColor = SystemColors.GrayText;
2015-10-30 02:41:37 +00:00
}
}
private void ListSearchTextChanged(object sender, EventArgs e)
{
if (enableFiltering)
{
2018-04-21 07:50:13 +00:00
FilterAssetList();
}
}
2015-10-30 02:41:37 +00:00
private void assetListView_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (firstSortColumn != e.Column)
{
//sorting column has been changed
reverseSort = false;
secondSortColumn = firstSortColumn;
}
else { reverseSort = !reverseSort; }
firstSortColumn = e.Column;
2015-10-30 02:41:37 +00:00
assetListView.BeginUpdate();
assetListView.SelectedIndices.Clear();
switch (e.Column)
{
case 0:
2018-11-07 21:00:53 +00:00
visibleAssets.Sort(delegate (AssetItem a, AssetItem b)
2015-10-30 02:41:37 +00:00
{
int xdiff = reverseSort ? b.Text.CompareTo(a.Text) : a.Text.CompareTo(b.Text);
if (xdiff != 0) return xdiff;
2018-10-16 17:51:25 +00:00
return secondSortColumn == 1 ? a.TypeString.CompareTo(b.TypeString) : a.FullSize.CompareTo(b.FullSize);
});
2015-10-30 02:41:37 +00:00
break;
case 1:
2018-11-07 21:00:53 +00:00
visibleAssets.Sort(delegate (AssetItem a, AssetItem b)
2015-10-30 02:41:37 +00:00
{
int xdiff = reverseSort ? b.TypeString.CompareTo(a.TypeString) : a.TypeString.CompareTo(b.TypeString);
if (xdiff != 0) return xdiff;
2018-10-16 17:51:25 +00:00
return secondSortColumn == 2 ? a.FullSize.CompareTo(b.FullSize) : a.Text.CompareTo(b.Text);
});
2015-10-30 02:41:37 +00:00
break;
case 2:
2018-11-07 21:00:53 +00:00
visibleAssets.Sort(delegate (AssetItem a, AssetItem b)
2015-10-30 02:41:37 +00:00
{
2018-10-16 17:51:25 +00:00
int xdiff = reverseSort ? b.FullSize.CompareTo(a.FullSize) : a.FullSize.CompareTo(b.FullSize);
if (xdiff != 0) return xdiff;
2017-04-09 19:13:08 +00:00
return secondSortColumn == 1 ? a.TypeString.CompareTo(b.TypeString) : a.Text.CompareTo(b.Text);
});
2015-10-30 02:41:37 +00:00
break;
}
2015-10-30 02:41:37 +00:00
assetListView.EndUpdate();
resizeAssetListColumns();
2015-10-30 02:41:37 +00:00
}
private void selectAsset(object sender, ListViewItemSelectionChangedEventArgs e)
{
2016-11-08 12:31:07 +00:00
previewPanel.BackgroundImage = Properties.Resources.preview;
2017-04-09 19:13:08 +00:00
previewPanel.BackgroundImageLayout = ImageLayout.Center;
2015-10-30 02:41:37 +00:00
assetInfoLabel.Visible = false;
assetInfoLabel.Text = null;
textPreviewBox.Visible = false;
fontPreviewBox.Visible = false;
FMODpanel.Visible = false;
glControl1.Visible = false;
2015-10-30 02:41:37 +00:00
lastLoadedAsset = null;
StatusStripUpdate("");
2015-10-30 02:41:37 +00:00
FMODreset();
2015-10-30 02:41:37 +00:00
2018-11-07 21:00:53 +00:00
lastSelectedItem = (AssetItem)e.Item;
2015-10-30 02:41:37 +00:00
if (e.IsSelected)
{
if (enablePreview.Checked)
{
lastLoadedAsset = lastSelectedItem;
PreviewAsset(lastLoadedAsset);
}
2018-01-18 00:08:48 +00:00
if (displayInfo.Checked && assetInfoLabel.Text != null)//only display the label if asset has info text
{
assetInfoLabel.Text = lastSelectedItem.InfoText;
assetInfoLabel.Visible = true;
}
2015-10-30 02:41:37 +00:00
}
}
2015-11-02 08:11:26 +00:00
private void classesListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
if (e.IsSelected)
{
2018-10-16 16:43:34 +00:00
classTextBox.Text = ((TypeTreeItem)classesListView.SelectedItems[0]).ToString();
2015-11-02 08:11:26 +00:00
}
}
2018-11-21 07:37:56 +00:00
private void PreviewAsset(AssetItem assetItem)
2017-02-11 20:57:24 +00:00
{
2018-11-18 22:48:06 +00:00
try
2015-10-30 02:41:37 +00:00
{
2018-11-21 07:37:56 +00:00
switch (assetItem.Asset)
2018-11-18 22:48:06 +00:00
{
2018-11-21 07:37:56 +00:00
case Texture2D m_Texture2D:
PreviewTexture2D(assetItem, m_Texture2D);
break;
case AudioClip m_AudioClip:
PreviewAudioClip(assetItem, m_AudioClip);
break;
case Shader m_Shader:
PreviewShader(m_Shader);
break;
case TextAsset m_TextAsset:
PreviewTextAsset(m_TextAsset);
break;
case MonoBehaviour m_MonoBehaviour:
PreviewMonoBehaviour(m_MonoBehaviour);
break;
case Font m_Font:
PreviewFont(m_Font);
break;
case Mesh m_Mesh:
PreviewMesh(m_Mesh);
break;
case VideoClip _:
case MovieTexture _:
StatusStripUpdate("Only supported export.");
break;
case Sprite m_Sprite:
PreviewSprite(assetItem, m_Sprite);
break;
case Animator _:
StatusStripUpdate("Can be exported to FBX file.");
2019-07-29 19:34:15 +00:00
break;
2018-11-21 07:37:56 +00:00
case AnimationClip _:
StatusStripUpdate("Can be exported with Animator or Objects");
2019-07-29 19:34:15 +00:00
break;
2018-11-21 07:37:56 +00:00
default:
var str = assetItem.Asset.Dump();
if (str != null)
2018-09-26 17:15:37 +00:00
{
2018-11-21 07:37:56 +00:00
textPreviewBox.Text = str;
textPreviewBox.Visible = true;
2015-10-30 02:41:37 +00:00
}
2018-11-21 07:37:56 +00:00
break;
}
}
catch (Exception e)
{
MessageBox.Show($"Preview {assetItem.Type}:{assetItem.Text} error\r\n{e.Message}\r\n{e.StackTrace}");
}
}
2018-09-26 17:15:37 +00:00
2018-11-21 07:37:56 +00:00
private void PreviewTexture2D(AssetItem assetItem, Texture2D m_Texture2D)
{
var converter = new Texture2DConverter(m_Texture2D);
var bitmap = converter.ConvertToBitmap(true);
if (bitmap != null)
{
assetItem.InfoText = $"Width: {m_Texture2D.m_Width}\nHeight: {m_Texture2D.m_Height}\nFormat: {m_Texture2D.m_TextureFormat}";
switch (m_Texture2D.m_TextureSettings.m_FilterMode)
2018-11-21 07:37:56 +00:00
{
case 0: assetItem.InfoText += "\nFilter Mode: Point "; break;
case 1: assetItem.InfoText += "\nFilter Mode: Bilinear "; break;
case 2: assetItem.InfoText += "\nFilter Mode: Trilinear "; break;
}
assetItem.InfoText += $"\nAnisotropic level: {m_Texture2D.m_TextureSettings.m_Aniso}\nMip map bias: {m_Texture2D.m_TextureSettings.m_MipBias}";
switch (m_Texture2D.m_TextureSettings.m_WrapMode)
2018-11-21 07:37:56 +00:00
{
case 0: assetItem.InfoText += "\nWrap mode: Repeat"; break;
case 1: assetItem.InfoText += "\nWrap mode: Clamp"; break;
}
2018-09-26 17:15:37 +00:00
2018-11-21 07:37:56 +00:00
PreviewTexture(bitmap);
}
else
{
StatusStripUpdate("Unsupported image for preview");
}
}
2015-10-30 02:41:37 +00:00
2018-11-21 07:37:56 +00:00
private void PreviewAudioClip(AssetItem assetItem, AudioClip m_AudioClip)
{
//Info
assetItem.InfoText = "Compression format: ";
if (m_AudioClip.version[0] < 5)
{
switch (m_AudioClip.m_Type)
{
case AudioType.ACC:
assetItem.InfoText += "Acc";
break;
case AudioType.AIFF:
assetItem.InfoText += "AIFF";
break;
case AudioType.IT:
assetItem.InfoText += "Impulse tracker";
break;
case AudioType.MOD:
assetItem.InfoText += "Protracker / Fasttracker MOD";
break;
case AudioType.MPEG:
assetItem.InfoText += "MP2/MP3 MPEG";
break;
case AudioType.OGGVORBIS:
assetItem.InfoText += "Ogg vorbis";
break;
case AudioType.S3M:
assetItem.InfoText += "ScreamTracker 3";
break;
case AudioType.WAV:
assetItem.InfoText += "Microsoft WAV";
break;
case AudioType.XM:
assetItem.InfoText += "FastTracker 2 XM";
break;
case AudioType.XMA:
assetItem.InfoText += "Xbox360 XMA";
break;
case AudioType.VAG:
assetItem.InfoText += "PlayStation Portable ADPCM";
break;
case AudioType.AUDIOQUEUE:
assetItem.InfoText += "iPhone";
break;
default:
assetItem.InfoText += "Unknown";
break;
}
}
else
{
switch (m_AudioClip.m_CompressionFormat)
{
case AudioCompressionFormat.PCM:
assetItem.InfoText += "PCM";
break;
case AudioCompressionFormat.Vorbis:
assetItem.InfoText += "Vorbis";
break;
case AudioCompressionFormat.ADPCM:
assetItem.InfoText += "ADPCM";
break;
case AudioCompressionFormat.MP3:
assetItem.InfoText += "MP3";
break;
case AudioCompressionFormat.VAG:
assetItem.InfoText += "PlayStation Portable ADPCM";
break;
case AudioCompressionFormat.HEVAG:
assetItem.InfoText += "PSVita ADPCM";
break;
case AudioCompressionFormat.XMA:
assetItem.InfoText += "Xbox360 XMA";
break;
case AudioCompressionFormat.AAC:
assetItem.InfoText += "AAC";
break;
case AudioCompressionFormat.GCADPCM:
assetItem.InfoText += "Nintendo 3DS/Wii DSP";
break;
case AudioCompressionFormat.ATRAC9:
assetItem.InfoText += "PSVita ATRAC9";
break;
default:
assetItem.InfoText += "Unknown";
break;
}
}
2015-10-30 02:41:37 +00:00
2018-11-21 07:37:56 +00:00
var m_AudioData = m_AudioClip.m_AudioData.Value;
if (m_AudioData == null || m_AudioData.Length == 0)
return;
FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO();
2015-10-30 02:41:37 +00:00
2018-11-21 07:37:56 +00:00
exinfo.cbsize = Marshal.SizeOf(exinfo);
exinfo.length = (uint)m_AudioClip.m_Size;
2018-11-21 07:37:56 +00:00
var result = system.createSound(m_AudioData, FMOD.MODE.OPENMEMORY | loopMode, ref exinfo, out sound);
if (ERRCHECK(result)) return;
2015-10-30 02:41:37 +00:00
2018-11-21 07:37:56 +00:00
result = sound.getSubSound(0, out var subsound);
if (result == FMOD.RESULT.OK)
{
sound = subsound;
}
2015-10-30 02:41:37 +00:00
2018-11-21 07:37:56 +00:00
result = sound.getLength(out FMODlenms, FMOD.TIMEUNIT.MS);
if (ERRCHECK(result)) return;
2015-10-30 02:41:37 +00:00
2018-11-21 07:37:56 +00:00
result = system.playSound(sound, null, true, out channel);
if (ERRCHECK(result)) return;
2018-11-21 07:37:56 +00:00
FMODpanel.Visible = true;
2017-01-15 15:20:40 +00:00
2018-11-21 07:37:56 +00:00
result = channel.getFrequency(out var frequency);
if (ERRCHECK(result)) return;
2018-11-18 22:48:06 +00:00
2018-11-21 07:37:56 +00:00
FMODinfoLabel.Text = frequency + " Hz";
FMODtimerLabel.Text = $"0:0.0 / {FMODlenms / 1000 / 60}:{FMODlenms / 1000 % 60}.{FMODlenms / 10 % 100}";
}
2015-10-30 02:41:37 +00:00
2018-11-21 07:37:56 +00:00
private void PreviewShader(Shader m_Shader)
{
var str = ShaderConverter.Convert(m_Shader);
PreviewText(str == null ? "Serialized Shader can't be read" : str.Replace("\n", "\r\n"));
}
2018-11-18 22:48:06 +00:00
2018-11-21 07:37:56 +00:00
private void PreviewTextAsset(TextAsset m_TextAsset)
{
var text = Encoding.UTF8.GetString(m_TextAsset.m_Script);
PreviewText(text.Replace("\n", "\r\n"));
}
2018-11-21 07:37:56 +00:00
private void PreviewMonoBehaviour(MonoBehaviour m_MonoBehaviour)
{
PreviewText(m_MonoBehaviour.Dump() ?? GetScriptString(m_MonoBehaviour.reader));
}
private void PreviewFont(Font m_Font)
{
if (m_Font.m_FontData != null)
{
var data = Marshal.AllocCoTaskMem(m_Font.m_FontData.Length);
Marshal.Copy(m_Font.m_FontData, 0, data, m_Font.m_FontData.Length);
uint cFonts = 0;
var re = AddFontMemResourceEx(data, (uint)m_Font.m_FontData.Length, IntPtr.Zero, ref cFonts);
if (re != IntPtr.Zero)
{
using (var pfc = new PrivateFontCollection())
{
pfc.AddMemoryFont(data, m_Font.m_FontData.Length);
Marshal.FreeCoTaskMem(data);
if (pfc.Families.Length > 0)
2017-03-31 16:41:18 +00:00
{
2018-11-21 07:37:56 +00:00
fontPreviewBox.SelectionStart = 0;
fontPreviewBox.SelectionLength = 80;
fontPreviewBox.SelectionFont = new System.Drawing.Font(pfc.Families[0], 16, FontStyle.Regular);
fontPreviewBox.SelectionStart = 81;
fontPreviewBox.SelectionLength = 56;
fontPreviewBox.SelectionFont = new System.Drawing.Font(pfc.Families[0], 12, FontStyle.Regular);
fontPreviewBox.SelectionStart = 138;
fontPreviewBox.SelectionLength = 56;
fontPreviewBox.SelectionFont = new System.Drawing.Font(pfc.Families[0], 18, FontStyle.Regular);
fontPreviewBox.SelectionStart = 195;
fontPreviewBox.SelectionLength = 56;
fontPreviewBox.SelectionFont = new System.Drawing.Font(pfc.Families[0], 24, FontStyle.Regular);
fontPreviewBox.SelectionStart = 252;
fontPreviewBox.SelectionLength = 56;
fontPreviewBox.SelectionFont = new System.Drawing.Font(pfc.Families[0], 36, FontStyle.Regular);
fontPreviewBox.SelectionStart = 309;
fontPreviewBox.SelectionLength = 56;
fontPreviewBox.SelectionFont = new System.Drawing.Font(pfc.Families[0], 48, FontStyle.Regular);
fontPreviewBox.SelectionStart = 366;
fontPreviewBox.SelectionLength = 56;
fontPreviewBox.SelectionFont = new System.Drawing.Font(pfc.Families[0], 60, FontStyle.Regular);
fontPreviewBox.SelectionStart = 423;
fontPreviewBox.SelectionLength = 55;
fontPreviewBox.SelectionFont = new System.Drawing.Font(pfc.Families[0], 72, FontStyle.Regular);
fontPreviewBox.Visible = true;
2018-11-18 22:48:06 +00:00
}
2018-11-21 07:37:56 +00:00
}
return;
2018-11-18 22:48:06 +00:00
}
}
2018-11-21 07:37:56 +00:00
StatusStripUpdate("Unsupported font for preview. Try to export.");
}
private void PreviewMesh(Mesh m_Mesh)
{
if (m_Mesh.m_VertexCount > 0)
{
viewMatrixData = Matrix4.CreateRotationY(-(float)Math.PI / 4) * Matrix4.CreateRotationX(-(float)Math.PI / 6);
#region Vertices
if (m_Mesh.m_Vertices == null || m_Mesh.m_Vertices.Length == 0)
{
StatusStripUpdate("Mesh can't be previewed.");
return;
}
int count = 3;
if (m_Mesh.m_Vertices.Length == m_Mesh.m_VertexCount * 4)
{
count = 4;
}
vertexData = new Vector3[m_Mesh.m_VertexCount];
// Calculate Bounding
float[] min = new float[3];
float[] max = new float[3];
for (int i = 0; i < 3; i++)
{
min[i] = m_Mesh.m_Vertices[i];
max[i] = m_Mesh.m_Vertices[i];
}
for (int v = 0; v < m_Mesh.m_VertexCount; v++)
{
for (int i = 0; i < 3; i++)
{
min[i] = Math.Min(min[i], m_Mesh.m_Vertices[v * count + i]);
max[i] = Math.Max(max[i], m_Mesh.m_Vertices[v * count + i]);
}
vertexData[v] = new Vector3(
m_Mesh.m_Vertices[v * count],
m_Mesh.m_Vertices[v * count + 1],
m_Mesh.m_Vertices[v * count + 2]);
}
// Calculate modelMatrix
Vector3 dist = Vector3.One, offset = Vector3.Zero;
for (int i = 0; i < 3; i++)
{
dist[i] = max[i] - min[i];
offset[i] = (max[i] + min[i]) / 2;
}
float d = Math.Max(1e-5f, dist.Length);
modelMatrixData = Matrix4.CreateTranslation(-offset) * Matrix4.CreateScale(2f / d);
#endregion
#region Indicies
indiceData = new int[m_Mesh.m_Indices.Count];
for (int i = 0; i < m_Mesh.m_Indices.Count; i = i + 3)
{
indiceData[i] = (int)m_Mesh.m_Indices[i];
indiceData[i + 1] = (int)m_Mesh.m_Indices[i + 1];
indiceData[i + 2] = (int)m_Mesh.m_Indices[i + 2];
}
#endregion
#region Normals
if (m_Mesh.m_Normals != null && m_Mesh.m_Normals.Length > 0)
{
if (m_Mesh.m_Normals.Length == m_Mesh.m_VertexCount * 3)
count = 3;
else if (m_Mesh.m_Normals.Length == m_Mesh.m_VertexCount * 4)
count = 4;
normalData = new Vector3[m_Mesh.m_VertexCount];
for (int n = 0; n < m_Mesh.m_VertexCount; n++)
{
normalData[n] = new Vector3(
m_Mesh.m_Normals[n * count],
m_Mesh.m_Normals[n * count + 1],
m_Mesh.m_Normals[n * count + 2]);
}
}
else
normalData = null;
// calculate normal by ourself
normal2Data = new Vector3[m_Mesh.m_VertexCount];
int[] normalCalculatedCount = new int[m_Mesh.m_VertexCount];
for (int i = 0; i < m_Mesh.m_VertexCount; i++)
{
normal2Data[i] = Vector3.Zero;
normalCalculatedCount[i] = 0;
}
for (int i = 0; i < m_Mesh.m_Indices.Count; i = i + 3)
{
Vector3 dir1 = vertexData[indiceData[i + 1]] - vertexData[indiceData[i]];
Vector3 dir2 = vertexData[indiceData[i + 2]] - vertexData[indiceData[i]];
Vector3 normal = Vector3.Cross(dir1, dir2);
normal.Normalize();
for (int j = 0; j < 3; j++)
{
normal2Data[indiceData[i + j]] += normal;
normalCalculatedCount[indiceData[i + j]]++;
}
}
for (int i = 0; i < m_Mesh.m_VertexCount; i++)
{
if (normalCalculatedCount[i] == 0)
normal2Data[i] = new Vector3(0, 1, 0);
else
normal2Data[i] /= normalCalculatedCount[i];
}
#endregion
#region Colors
if (m_Mesh.m_Colors != null && m_Mesh.m_Colors.Length == m_Mesh.m_VertexCount * 3)
{
colorData = new Vector4[m_Mesh.m_VertexCount];
for (int c = 0; c < m_Mesh.m_VertexCount; c++)
{
colorData[c] = new Vector4(
m_Mesh.m_Colors[c * 3],
m_Mesh.m_Colors[c * 3 + 1],
m_Mesh.m_Colors[c * 3 + 2],
1.0f);
}
}
else if (m_Mesh.m_Colors != null && m_Mesh.m_Colors.Length == m_Mesh.m_VertexCount * 4)
{
colorData = new Vector4[m_Mesh.m_VertexCount];
for (int c = 0; c < m_Mesh.m_VertexCount; c++)
{
colorData[c] = new Vector4(
m_Mesh.m_Colors[c * 4],
m_Mesh.m_Colors[c * 4 + 1],
m_Mesh.m_Colors[c * 4 + 2],
m_Mesh.m_Colors[c * 4 + 3]);
}
}
else
{
colorData = new Vector4[m_Mesh.m_VertexCount];
for (int c = 0; c < m_Mesh.m_VertexCount; c++)
{
colorData[c] = new Vector4(0.5f, 0.5f, 0.5f, 1.0f);
}
}
#endregion
glControl1.Visible = true;
2018-12-09 03:56:24 +00:00
CreateVAO();
StatusStripUpdate("Using OpenGL Version: " + GL.GetString(StringName.Version) + "\n"
+ "'Mouse Left'=Rotate | 'Mouse Right'=Move | 'Mouse Wheel'=Zoom \n"
+ "'Ctrl W'=Wireframe | 'Ctrl S'=Shade | 'Ctrl N'=ReNormal ");
}
else
{
StatusStripUpdate("Unable to preview this mesh");
2018-11-21 07:37:56 +00:00
}
}
private void PreviewSprite(AssetItem assetItem, Sprite m_Sprite)
{
var bitmap = SpriteHelper.GetImageFromSprite(m_Sprite);
if (bitmap != null)
{
2018-11-23 20:42:45 +00:00
assetItem.InfoText = $"Width: {bitmap.Width}\nHeight: {bitmap.Height}\n";
2018-11-21 07:37:56 +00:00
PreviewTexture(bitmap);
}
else
2018-11-18 22:48:06 +00:00
{
2018-11-21 07:37:56 +00:00
StatusStripUpdate("Unsupported sprite for preview.");
2015-10-30 02:41:37 +00:00
}
}
2018-11-21 07:37:56 +00:00
private void PreviewTexture(Bitmap bitmap)
{
imageTexture?.Dispose();
imageTexture = bitmap;
previewPanel.BackgroundImage = imageTexture;
if (imageTexture.Width > previewPanel.Width || imageTexture.Height > previewPanel.Height)
previewPanel.BackgroundImageLayout = ImageLayout.Zoom;
else
previewPanel.BackgroundImageLayout = ImageLayout.Center;
}
private void PreviewText(string text)
{
textPreviewBox.Text = text;
textPreviewBox.Visible = true;
}
2015-10-30 02:41:37 +00:00
private void FMODinit()
{
FMODreset();
2015-10-30 02:41:37 +00:00
2018-01-16 22:20:06 +00:00
var result = FMOD.Factory.System_Create(out system);
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
2018-01-16 22:20:06 +00:00
result = system.getVersion(out var version);
2015-10-30 02:41:37 +00:00
ERRCHECK(result);
if (version < FMOD.VERSION.number)
{
2018-01-16 22:20:06 +00:00
MessageBox.Show($"Error! You are using an old version of FMOD {version:X}. This program requires {FMOD.VERSION.number:X}.");
2015-10-30 02:41:37 +00:00
Application.Exit();
}
2017-11-09 18:27:36 +00:00
result = system.init(1, FMOD.INITFLAGS.NORMAL, IntPtr.Zero);
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
result = system.getMasterSoundGroup(out masterSoundGroup);
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
result = masterSoundGroup.setVolume(FMODVolume);
if (ERRCHECK(result)) { return; }
}
private void FMODreset()
{
timer.Stop();
FMODprogressBar.Value = 0;
FMODtimerLabel.Text = "0:00.0 / 0:00.0";
FMODstatusLabel.Text = "Stopped";
FMODinfoLabel.Text = "";
2018-01-08 15:53:15 +00:00
if (sound != null && sound.isValid())
{
var result = sound.release();
2017-11-09 18:27:36 +00:00
ERRCHECK(result);
sound = null;
}
2015-10-30 02:41:37 +00:00
}
private void FMODplayButton_Click(object sender, EventArgs e)
{
if (sound != null && channel != null)
2015-10-30 02:41:37 +00:00
{
timer.Start();
2018-01-16 22:20:06 +00:00
var result = channel.isPlaying(out var playing);
2015-10-30 02:41:37 +00:00
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
}
if (playing)
{
result = channel.stop();
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
result = system.playSound(sound, null, false, out channel);
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
FMODpauseButton.Text = "Pause";
}
else
{
result = system.playSound(sound, null, false, out channel);
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
FMODstatusLabel.Text = "Playing";
if (FMODprogressBar.Value > 0)
{
uint newms = FMODlenms / 1000 * (uint)FMODprogressBar.Value;
2015-10-30 02:41:37 +00:00
result = channel.setPosition(newms, FMOD.TIMEUNIT.MS);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
if (ERRCHECK(result)) { return; }
}
2015-10-30 02:41:37 +00:00
}
}
}
}
private void FMODpauseButton_Click(object sender, EventArgs e)
{
if (sound != null && channel != null)
2015-10-30 02:41:37 +00:00
{
2018-01-16 22:20:06 +00:00
var result = channel.isPlaying(out var playing);
2015-10-30 02:41:37 +00:00
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
}
if (playing)
{
2018-01-16 22:20:06 +00:00
result = channel.getPaused(out var paused);
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
result = channel.setPaused(!paused);
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
if (paused)
{
2018-01-16 22:20:06 +00:00
FMODstatusLabel.Text = "Playing";
2015-10-30 02:41:37 +00:00
FMODpauseButton.Text = "Pause";
timer.Start();
}
else
{
FMODstatusLabel.Text = "Paused";
FMODpauseButton.Text = "Resume";
timer.Stop();
}
}
}
}
private void FMODstopButton_Click(object sender, EventArgs e)
{
if (channel != null)
{
2018-01-16 22:20:06 +00:00
var result = channel.isPlaying(out var playing);
2015-10-30 02:41:37 +00:00
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
}
if (playing)
{
result = channel.stop();
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
//channel = null;
//don't FMODreset, it will nullify the sound
2015-10-30 02:41:37 +00:00
timer.Stop();
FMODprogressBar.Value = 0;
FMODtimerLabel.Text = "0:00.0 / 0:00.0";
FMODstatusLabel.Text = "Stopped";
2015-10-30 02:41:37 +00:00
FMODpauseButton.Text = "Pause";
}
}
}
private void FMODloopButton_CheckedChanged(object sender, EventArgs e)
{
FMOD.RESULT result;
2018-01-16 22:20:06 +00:00
loopMode = FMODloopButton.Checked ? FMOD.MODE.LOOP_NORMAL : FMOD.MODE.LOOP_OFF;
2015-10-30 02:41:37 +00:00
if (sound != null)
{
result = sound.setMode(loopMode);
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
}
if (channel != null)
{
2018-01-16 22:20:06 +00:00
result = channel.isPlaying(out var playing);
2015-10-30 02:41:37 +00:00
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
}
2018-01-16 22:20:06 +00:00
result = channel.getPaused(out var paused);
2015-10-30 02:41:37 +00:00
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
}
if (playing || paused)
{
result = channel.setMode(loopMode);
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
}
}
}
private void FMODvolumeBar_ValueChanged(object sender, EventArgs e)
{
FMODVolume = Convert.ToSingle(FMODvolumeBar.Value) / 10;
2018-01-16 22:20:06 +00:00
var result = masterSoundGroup.setVolume(FMODVolume);
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
}
private void FMODprogressBar_Scroll(object sender, EventArgs e)
{
if (channel != null)
{
uint newms = FMODlenms / 1000 * (uint)FMODprogressBar.Value;
2018-01-16 22:20:06 +00:00
FMODtimerLabel.Text = $"{newms / 1000 / 60}:{newms / 1000 % 60}.{newms / 10 % 100}/{FMODlenms / 1000 / 60}:{FMODlenms / 1000 % 60}.{FMODlenms / 10 % 100}";
2015-10-30 02:41:37 +00:00
}
}
private void FMODprogressBar_MouseDown(object sender, MouseEventArgs e)
{
timer.Stop();
}
private void FMODprogressBar_MouseUp(object sender, MouseEventArgs e)
{
if (channel != null)
{
uint newms = FMODlenms / 1000 * (uint)FMODprogressBar.Value;
2015-10-30 02:41:37 +00:00
2018-01-16 22:20:06 +00:00
var result = channel.setPosition(newms, FMOD.TIMEUNIT.MS);
2015-10-30 02:41:37 +00:00
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
}
2018-01-16 22:20:06 +00:00
result = channel.isPlaying(out var playing);
2015-10-30 02:41:37 +00:00
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
if (ERRCHECK(result)) { return; }
2015-10-30 02:41:37 +00:00
}
if (playing) { timer.Start(); }
}
}
private void timer_Tick(object sender, EventArgs e)
{
uint ms = 0;
bool playing = false;
bool paused = false;
if (channel != null)
{
2018-01-16 22:20:06 +00:00
var result = channel.getPosition(out ms, FMOD.TIMEUNIT.MS);
2015-10-30 02:41:37 +00:00
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel.isPlaying(out playing);
2015-10-30 02:41:37 +00:00
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel.getPaused(out paused);
2015-10-30 02:41:37 +00:00
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
}
2018-01-16 22:20:06 +00:00
FMODtimerLabel.Text = $"{ms / 1000 / 60}:{ms / 1000 % 60}.{ms / 10 % 100} / {FMODlenms / 1000 / 60}:{FMODlenms / 1000 % 60}.{FMODlenms / 10 % 100}";
2015-10-30 02:41:37 +00:00
FMODprogressBar.Value = (int)(ms * 1000 / FMODlenms);
2018-01-16 22:20:06 +00:00
FMODstatusLabel.Text = paused ? "Paused " : playing ? "Playing" : "Stopped";
2015-10-30 02:41:37 +00:00
if (system != null && channel != null)
2015-10-30 02:41:37 +00:00
{
system.update();
}
}
private bool ERRCHECK(FMOD.RESULT result)
2015-10-30 02:41:37 +00:00
{
if (result != FMOD.RESULT.OK)
{
FMODreset();
2018-01-16 22:20:06 +00:00
StatusStripUpdate($"FMOD error! {result} - {FMOD.Error.String(result)}");
return true;
2015-10-30 02:41:37 +00:00
}
2017-04-09 19:13:08 +00:00
return false;
2015-10-30 02:41:37 +00:00
}
private void SetProgressBarValue(int value)
{
if (InvokeRequired)
{
BeginInvoke(new Action(() => { progressBar1.Value = value; }));
}
else
{
progressBar1.Value = value;
}
}
private void StatusStripUpdate(string statusText)
{
if (InvokeRequired)
{
BeginInvoke(new Action(() => { toolStripStatusLabel1.Text = statusText; }));
}
else
{
toolStripStatusLabel1.Text = statusText;
}
}
2015-10-30 02:41:37 +00:00
2018-11-18 22:48:06 +00:00
public AssetStudioGUIForm()
2015-10-30 02:41:37 +00:00
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
InitializeComponent();
displayOriginalName.Checked = (bool)Properties.Settings.Default["displayOriginalName"];
displayAll.Checked = (bool)Properties.Settings.Default["displayAll"];
2015-10-30 02:41:37 +00:00
displayInfo.Checked = (bool)Properties.Settings.Default["displayInfo"];
enablePreview.Checked = (bool)Properties.Settings.Default["enablePreview"];
openAfterExport.Checked = (bool)Properties.Settings.Default["openAfterExport"];
assetGroupOptions.SelectedIndex = (int)Properties.Settings.Default["assetGroupOption"];
FMODinit();
2018-11-18 22:48:06 +00:00
Logger.Default = new GUILogger(StatusStripUpdate);
Progress.Default = new GUIProgress(SetProgressBarValue);
2019-08-11 20:36:07 +00:00
Studio.StatusStripUpdate = StatusStripUpdate;
2015-10-30 02:41:37 +00:00
}
2018-12-09 03:56:24 +00:00
private void InitOpenTK()
{
2018-12-09 03:56:24 +00:00
ChangeGLSize(glControl1.Size);
2019-01-03 00:55:43 +00:00
GL.ClearColor(System.Drawing.Color.CadetBlue);
pgmID = GL.CreateProgram();
2018-12-09 03:56:24 +00:00
LoadShader("vs", ShaderType.VertexShader, pgmID, out int vsID);
LoadShader("fs", ShaderType.FragmentShader, pgmID, out int fsID);
GL.LinkProgram(pgmID);
pgmColorID = GL.CreateProgram();
2018-12-09 03:56:24 +00:00
LoadShader("vs", ShaderType.VertexShader, pgmColorID, out vsID);
LoadShader("fsColor", ShaderType.FragmentShader, pgmColorID, out fsID);
GL.LinkProgram(pgmColorID);
pgmBlackID = GL.CreateProgram();
2018-12-09 03:56:24 +00:00
LoadShader("vs", ShaderType.VertexShader, pgmBlackID, out vsID);
LoadShader("fsBlack", ShaderType.FragmentShader, pgmBlackID, out fsID);
GL.LinkProgram(pgmBlackID);
2017-10-22 15:48:31 +00:00
attributeVertexPosition = GL.GetAttribLocation(pgmID, "vertexPosition");
attributeNormalDirection = GL.GetAttribLocation(pgmID, "normalDirection");
attributeVertexColor = GL.GetAttribLocation(pgmColorID, "vertexColor");
uniformModelMatrix = GL.GetUniformLocation(pgmID, "modelMatrix");
uniformViewMatrix = GL.GetUniformLocation(pgmID, "viewMatrix");
uniformProjMatrix = GL.GetUniformLocation(pgmID, "projMatrix");
}
2018-12-09 03:56:24 +00:00
private static void LoadShader(string filename, ShaderType type, int program, out int address)
{
address = GL.CreateShader(type);
2018-01-18 14:08:44 +00:00
var str = (string)Properties.Resources.ResourceManager.GetObject(filename);
2017-08-21 11:51:32 +00:00
GL.ShaderSource(address, str);
GL.CompileShader(address);
GL.AttachShader(program, address);
GL.DeleteShader(address);
}
2018-12-09 03:56:24 +00:00
private static void CreateVBO(out int vboAddress, Vector3[] data, int address)
{
GL.GenBuffers(1, out vboAddress);
GL.BindBuffer(BufferTarget.ArrayBuffer, vboAddress);
2017-04-12 06:43:41 +00:00
GL.BufferData(BufferTarget.ArrayBuffer,
2017-04-09 19:13:08 +00:00
(IntPtr)(data.Length * Vector3.SizeInBytes),
data,
BufferUsageHint.StaticDraw);
GL.VertexAttribPointer(address, 3, VertexAttribPointerType.Float, false, 0, 0);
GL.EnableVertexAttribArray(address);
}
2018-12-09 03:56:24 +00:00
private static void CreateVBO(out int vboAddress, Vector4[] data, int address)
{
GL.GenBuffers(1, out vboAddress);
GL.BindBuffer(BufferTarget.ArrayBuffer, vboAddress);
2017-04-12 06:43:41 +00:00
GL.BufferData(BufferTarget.ArrayBuffer,
2017-04-09 19:13:08 +00:00
(IntPtr)(data.Length * Vector4.SizeInBytes),
data,
BufferUsageHint.StaticDraw);
GL.VertexAttribPointer(address, 4, VertexAttribPointerType.Float, false, 0, 0);
GL.EnableVertexAttribArray(address);
}
2018-12-09 03:56:24 +00:00
private static void CreateVBO(out int vboAddress, Matrix4 data, int address)
{
GL.GenBuffers(1, out vboAddress);
GL.UniformMatrix4(address, false, ref data);
}
2018-12-09 03:56:24 +00:00
private static void CreateEBO(out int address, int[] data)
{
GL.GenBuffers(1, out address);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, address);
GL.BufferData(BufferTarget.ElementArrayBuffer,
(IntPtr)(data.Length * sizeof(int)),
data,
BufferUsageHint.StaticDraw);
}
2018-12-09 03:56:24 +00:00
private void CreateVAO()
{
GL.DeleteVertexArray(vao);
GL.GenVertexArrays(1, out vao);
GL.BindVertexArray(vao);
2018-12-09 03:56:24 +00:00
CreateVBO(out var vboPositions, vertexData, attributeVertexPosition);
if (normalMode == 0)
{
2018-12-09 03:56:24 +00:00
CreateVBO(out var vboNormals, normal2Data, attributeNormalDirection);
}
else
{
if (normalData != null)
2018-12-09 03:56:24 +00:00
CreateVBO(out var vboNormals, normalData, attributeNormalDirection);
}
2018-12-09 03:56:24 +00:00
CreateVBO(out var vboColors, colorData, attributeVertexColor);
CreateVBO(out var vboModelMatrix, modelMatrixData, uniformModelMatrix);
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);
}
2018-12-09 03:56:24 +00:00
private void ChangeGLSize(Size size)
2018-08-14 20:53:11 +00:00
{
GL.Viewport(0, 0, size.Width, size.Height);
if (size.Width <= size.Height)
{
float k = 1.0f * size.Width / size.Height;
projMatrixData = Matrix4.CreateScale(1, k, 1);
}
else
{
float k = 1.0f * size.Height / size.Width;
projMatrixData = Matrix4.CreateScale(k, 1, 1);
}
}
private void preview_Resize(object sender, EventArgs e)
{
if (glControlLoaded && glControl1.Visible)
{
2018-12-09 03:56:24 +00:00
ChangeGLSize(glControl1.Size);
2018-08-14 20:53:11 +00:00
glControl1.Invalidate();
}
}
private void glControl1_Load(object sender, EventArgs e)
{
2018-12-09 03:56:24 +00:00
InitOpenTK();
2018-08-14 20:53:11 +00:00
glControlLoaded = true;
}
private void glControl1_Paint(object sender, PaintEventArgs e)
{
glControl1.MakeCurrent();
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.Enable(EnableCap.DepthTest);
GL.DepthFunc(DepthFunction.Lequal);
GL.BindVertexArray(vao);
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);
}
//Wireframe
if (wireFrameMode == 1 || wireFrameMode == 2)
{
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.Disable(EnableCap.PolygonOffsetLine);
}
GL.BindVertexArray(0);
GL.Flush();
glControl1.SwapBuffers();
}
2018-04-09 20:45:09 +00:00
private void glControl1_MouseWheel(object sender, MouseEventArgs e)
{
if (glControl1.Visible)
{
viewMatrixData *= Matrix4.CreateScale(1 + e.Delta / 1000f);
glControl1.Invalidate();
}
}
2018-04-17 21:05:17 +00:00
2018-08-15 00:40:46 +00:00
private void glControl1_MouseDown(object sender, MouseEventArgs e)
{
mdx = e.X;
mdy = e.Y;
if (e.Button == MouseButtons.Left)
{
lmdown = true;
}
if (e.Button == MouseButtons.Right)
{
rmdown = true;
}
}
private void glControl1_MouseMove(object sender, MouseEventArgs e)
{
if (lmdown || rmdown)
{
float dx = mdx - e.X;
float dy = mdy - e.Y;
mdx = e.X;
mdy = e.Y;
if (lmdown)
{
dx *= 0.01f;
dy *= 0.01f;
viewMatrixData *= Matrix4.CreateRotationX(dy);
viewMatrixData *= Matrix4.CreateRotationY(dx);
}
if (rmdown)
{
dx *= 0.003f;
dy *= 0.003f;
viewMatrixData *= Matrix4.CreateTranslation(-dx, dy, 0);
}
glControl1.Invalidate();
}
}
private void glControl1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
lmdown = false;
}
if (e.Button == MouseButtons.Right)
{
rmdown = false;
}
}
2018-11-07 22:45:33 +00:00
private void ResetForm()
2015-10-30 02:41:37 +00:00
{
2018-11-18 22:48:06 +00:00
Text = "AssetStudioGUI";
assetsManager.Clear();
2017-02-11 20:57:24 +00:00
exportableAssets.Clear();
visibleAssets.Clear();
2015-10-30 02:41:37 +00:00
sceneTreeView.Nodes.Clear();
assetListView.VirtualListSize = 0;
assetListView.Items.Clear();
2015-11-02 08:11:26 +00:00
classesListView.Items.Clear();
classesListView.Groups.Clear();
2016-11-08 12:31:07 +00:00
previewPanel.BackgroundImage = Properties.Resources.preview;
2018-11-21 07:37:56 +00:00
imageTexture?.Dispose();
2017-04-09 19:13:08 +00:00
previewPanel.BackgroundImageLayout = ImageLayout.Center;
2015-10-30 02:41:37 +00:00
assetInfoLabel.Visible = false;
assetInfoLabel.Text = null;
textPreviewBox.Visible = false;
fontPreviewBox.Visible = false;
glControl1.Visible = false;
2015-10-30 02:41:37 +00:00
lastSelectedItem = null;
lastLoadedAsset = null;
firstSortColumn = -1;
secondSortColumn = 0;
reverseSort = false;
enableFiltering = false;
2018-04-17 17:29:18 +00:00
listSearch.Text = " Filter ";
2018-04-17 21:05:17 +00:00
2018-08-04 21:25:26 +00:00
var count = filterTypeToolStripMenuItem.DropDownItems.Count;
2018-04-17 21:05:17 +00:00
for (var i = 1; i < count; i++)
{
2018-08-04 21:25:26 +00:00
filterTypeToolStripMenuItem.DropDownItems.RemoveAt(1);
2018-04-17 21:05:17 +00:00
}
FMODreset();
2018-08-04 20:46:27 +00:00
2018-12-11 07:24:49 +00:00
if (scriptDumper != null)
{
scriptDumper.Dispose();
scriptDumper = null;
}
2015-10-30 02:41:37 +00:00
}
private void assetListView_MouseClick(object sender, MouseEventArgs e)
{
2018-04-09 20:45:09 +00:00
if (e.Button == MouseButtons.Right && assetListView.SelectedIndices.Count > 0)
{
jumpToSceneHierarchyToolStripMenuItem.Visible = false;
2018-04-09 20:45:09 +00:00
showOriginalFileToolStripMenuItem.Visible = false;
2018-04-17 23:11:10 +00:00
exportAnimatorwithselectedAnimationClipMenuItem.Visible = false;
2018-04-09 20:45:09 +00:00
if (assetListView.SelectedIndices.Count == 1)
{
jumpToSceneHierarchyToolStripMenuItem.Visible = true;
2018-04-09 20:45:09 +00:00
showOriginalFileToolStripMenuItem.Visible = true;
}
2018-04-12 19:16:09 +00:00
if (assetListView.SelectedIndices.Count >= 1)
2018-04-09 20:45:09 +00:00
{
2018-04-17 23:11:10 +00:00
var selectedAssets = GetSelectedAssets();
2018-10-16 16:43:34 +00:00
if (selectedAssets.Any(x => x.Type == ClassIDType.Animator) && selectedAssets.Any(x => x.Type == ClassIDType.AnimationClip))
2018-04-09 20:45:09 +00:00
{
2018-04-17 23:11:10 +00:00
exportAnimatorwithselectedAnimationClipMenuItem.Visible = true;
2018-04-09 20:45:09 +00:00
}
}
contextMenuStrip1.Show(assetListView, e.X, e.Y);
}
}
2018-01-16 22:20:06 +00:00
2018-04-09 20:45:09 +00:00
private void exportSelectedAssetsToolStripMenuItem_Click(object sender, EventArgs e)
2018-01-16 22:20:06 +00:00
{
2019-08-06 09:43:51 +00:00
ExportAssets(2, ExportType.Convert);
2018-01-16 22:20:06 +00:00
}
2018-04-06 23:51:33 +00:00
2018-04-09 20:45:09 +00:00
private void showOriginalFileToolStripMenuItem_Click(object sender, EventArgs e)
{
2018-11-07 21:00:53 +00:00
var selectasset = (AssetItem)assetListView.Items[assetListView.SelectedIndices[0]];
2018-11-21 07:37:56 +00:00
var args = $"/select, \"{selectasset.SourceFile.originalPath ?? selectasset.SourceFile.fullName}\"";
2018-04-09 20:45:09 +00:00
var pfi = new ProcessStartInfo("explorer.exe", args);
Process.Start(pfi);
}
private void exportAnimatorwithAnimationClipMenuItem_Click(object sender, EventArgs e)
2018-04-06 23:51:33 +00:00
{
2018-11-07 21:00:53 +00:00
AssetItem animator = null;
List<AssetItem> animationList = new List<AssetItem>();
2018-04-17 23:11:10 +00:00
var selectedAssets = GetSelectedAssets();
2018-04-09 20:45:09 +00:00
foreach (var assetPreloadData in selectedAssets)
2018-04-06 23:51:33 +00:00
{
2018-10-16 16:43:34 +00:00
if (assetPreloadData.Type == ClassIDType.Animator)
2018-04-06 23:51:33 +00:00
{
2018-04-09 20:45:09 +00:00
animator = assetPreloadData;
2018-04-06 23:51:33 +00:00
}
2018-10-16 16:43:34 +00:00
else if (assetPreloadData.Type == ClassIDType.AnimationClip)
2018-04-06 23:51:33 +00:00
{
2018-04-09 20:45:09 +00:00
animationList.Add(assetPreloadData);
2018-04-06 23:51:33 +00:00
}
}
if (animator != null)
{
var saveFolderDialog1 = new OpenFolderDialog();
if (saveFolderDialog1.ShowDialog(this) == DialogResult.OK)
{
2018-04-11 07:52:37 +00:00
var exportPath = saveFolderDialog1.Folder + "\\Animator\\";
2018-11-24 15:30:04 +00:00
ExportAnimatorWithAnimationClip(animator, animationList, exportPath, openAfterExport.Checked);
2018-04-06 23:51:33 +00:00
}
}
}
2018-04-09 20:45:09 +00:00
2018-04-17 23:11:10 +00:00
private void exportSelectedObjectsToolStripMenuItem_Click(object sender, EventArgs e)
{
2019-07-27 19:47:12 +00:00
ExportObjects(false);
2018-04-17 23:11:10 +00:00
}
private void exportObjectswithAnimationClipMenuItem_Click(object sender, EventArgs e)
2019-07-27 19:47:12 +00:00
{
ExportObjects(true);
}
private void ExportObjects(bool animation)
2018-04-18 00:19:30 +00:00
{
if (sceneTreeView.Nodes.Count > 0)
{
var saveFolderDialog1 = new OpenFolderDialog();
if (saveFolderDialog1.ShowDialog(this) == DialogResult.OK)
{
var exportPath = saveFolderDialog1.Folder + "\\GameObject\\";
2019-07-27 19:47:12 +00:00
List<AssetItem> animationList = null;
if (animation)
{
animationList = GetSelectedAssets().Where(x => x.Type == ClassIDType.AnimationClip).ToList();
if (animationList.Count == 0)
{
animationList = null;
}
}
ExportObjectsWithAnimationClip(exportPath, sceneTreeView.Nodes, openAfterExport.Checked, animationList);
2018-04-18 00:19:30 +00:00
}
}
else
{
StatusStripUpdate("No Objects available for export");
}
}
2019-07-17 04:51:00 +00:00
private void exportSelectedObjectsmergeToolStripMenuItem_Click(object sender, EventArgs e)
{
2019-07-27 19:47:12 +00:00
ExportMergeObjects(false);
2019-07-17 04:51:00 +00:00
}
private void exportSelectedObjectsmergeWithAnimationClipToolStripMenuItem_Click(object sender, EventArgs e)
2019-07-27 19:47:12 +00:00
{
ExportMergeObjects(true);
}
private void ExportMergeObjects(bool animation)
2019-07-17 04:51:00 +00:00
{
if (sceneTreeView.Nodes.Count > 0)
{
var gameObjects = new List<GameObject>();
GetSelectedParentNode(sceneTreeView.Nodes, gameObjects);
var saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = gameObjects[0].m_Name + " (merge).fbx";
saveFileDialog.AddExtension = false;
saveFileDialog.Filter = "Fbx file (*.fbx)|*.fbx";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
var exportPath = saveFileDialog.FileName;
2019-07-27 19:47:12 +00:00
List<AssetItem> animationList = null;
if (animation)
{
animationList = GetSelectedAssets().Where(x => x.Type == ClassIDType.AnimationClip).ToList();
if (animationList.Count == 0)
{
animationList = null;
}
}
ExportObjectsMergeWithAnimationClip(exportPath, openAfterExport.Checked, gameObjects, animationList);
2019-07-17 04:51:00 +00:00
}
}
}
private void jumpToSceneHierarchyToolStripMenuItem_Click(object sender, EventArgs e)
2018-04-09 20:45:09 +00:00
{
2018-11-07 21:00:53 +00:00
var selectasset = (AssetItem)assetListView.Items[assetListView.SelectedIndices[0]];
2018-11-20 08:47:35 +00:00
if (selectasset.TreeNode != null)
{
2018-11-20 08:47:35 +00:00
sceneTreeView.SelectedNode = selectasset.TreeNode;
tabControl1.SelectedTab = tabPage1;
}
}
2019-07-28 11:48:06 +00:00
private void exportAllAssetsMenuItem_Click(object sender, EventArgs e)
{
2019-08-06 09:43:51 +00:00
ExportAssets(1, ExportType.Convert);
2019-07-28 11:48:06 +00:00
}
private void exportSelectedAssetsMenuItem_Click(object sender, EventArgs e)
{
2019-08-06 09:43:51 +00:00
ExportAssets(2, ExportType.Convert);
2019-07-28 11:48:06 +00:00
}
private void exportFilteredAssetsMenuItem_Click(object sender, EventArgs e)
{
2019-08-06 09:43:51 +00:00
ExportAssets(3, ExportType.Convert);
}
private void toolStripMenuItem4_Click(object sender, EventArgs e)
{
ExportAssets(1, ExportType.Raw);
}
private void toolStripMenuItem5_Click(object sender, EventArgs e)
{
ExportAssets(2, ExportType.Raw);
}
private void toolStripMenuItem6_Click(object sender, EventArgs e)
{
ExportAssets(3, ExportType.Raw);
}
private void toolStripMenuItem7_Click(object sender, EventArgs e)
{
ExportAssets(1, ExportType.Dump);
}
private void toolStripMenuItem8_Click(object sender, EventArgs e)
{
ExportAssets(2, ExportType.Dump);
}
private void toolStripMenuItem9_Click(object sender, EventArgs e)
{
ExportAssets(3, ExportType.Dump);
2019-07-28 11:48:06 +00:00
}
private void exportAllObjectssplitToolStripMenuItem1_Click(object sender, EventArgs e)
{
if (sceneTreeView.Nodes.Count > 0)
2018-04-11 07:52:37 +00:00
{
var saveFolderDialog1 = new OpenFolderDialog();
if (saveFolderDialog1.ShowDialog(this) == DialogResult.OK)
{
var savePath = saveFolderDialog1.Folder + "\\";
2018-11-24 15:30:04 +00:00
ExportSplitObjects(savePath, sceneTreeView.Nodes, openAfterExport.Checked);
}
}
else
{
StatusStripUpdate("No Objects available for export");
2018-04-11 07:52:37 +00:00
}
}
2018-11-07 21:00:53 +00:00
private List<AssetItem> GetSelectedAssets()
2018-04-11 07:52:37 +00:00
{
2019-07-28 11:48:06 +00:00
var selectedAssets = new List<AssetItem>(assetListView.SelectedIndices.Count);
2018-04-17 23:11:10 +00:00
foreach (int index in assetListView.SelectedIndices)
2018-04-11 07:52:37 +00:00
{
2018-11-07 21:00:53 +00:00
selectedAssets.Add((AssetItem)assetListView.Items[index]);
2018-04-11 07:52:37 +00:00
}
2018-04-17 23:11:10 +00:00
return selectedAssets;
2018-04-09 20:45:09 +00:00
}
2018-04-21 07:50:13 +00:00
private void FilterAssetList()
{
assetListView.BeginUpdate();
assetListView.SelectedIndices.Clear();
2018-10-16 16:43:34 +00:00
var show = new List<ClassIDType>();
2018-04-21 07:50:13 +00:00
if (!allToolStripMenuItem.Checked)
{
2018-08-04 21:25:26 +00:00
for (var i = 1; i < filterTypeToolStripMenuItem.DropDownItems.Count; i++)
2018-04-21 07:50:13 +00:00
{
2018-08-04 21:25:26 +00:00
var item = (ToolStripMenuItem)filterTypeToolStripMenuItem.DropDownItems[i];
2018-04-21 07:50:13 +00:00
if (item.Checked)
{
2018-10-16 16:43:34 +00:00
show.Add((ClassIDType)Enum.Parse(typeof(ClassIDType), item.Text));
2018-04-21 07:50:13 +00:00
}
}
visibleAssets = exportableAssets.FindAll(x => show.Contains(x.Type));
}
else
{
visibleAssets = exportableAssets;
}
if (listSearch.Text != " Filter ")
{
visibleAssets = visibleAssets.FindAll(x => x.Text.IndexOf(listSearch.Text, StringComparison.CurrentCultureIgnoreCase) >= 0);
}
assetListView.VirtualListSize = visibleAssets.Count;
assetListView.EndUpdate();
}
2019-07-28 11:48:06 +00:00
2019-08-06 09:43:51 +00:00
private void ExportAssets(int type, ExportType exportType)
2019-07-28 11:48:06 +00:00
{
if (exportableAssets.Count > 0)
{
var saveFolderDialog1 = new OpenFolderDialog();
if (saveFolderDialog1.ShowDialog(this) == DialogResult.OK)
{
timer.Stop();
List<AssetItem> toExportAssets = null;
switch (type)
{
case 1: //All Assets
toExportAssets = exportableAssets;
break;
case 2: //Selected Assets
toExportAssets = GetSelectedAssets();
break;
case 3: //Filtered Assets
toExportAssets = visibleAssets;
break;
}
2019-08-06 09:43:51 +00:00
Studio.ExportAssets(saveFolderDialog1.Folder, toExportAssets, assetGroupOptions.SelectedIndex, openAfterExport.Checked, exportType);
2019-07-28 11:48:06 +00:00
}
}
else
{
StatusStripUpdate("No exportable assets loaded");
}
}
2015-10-30 02:41:37 +00:00
}
}