Improve model export
This commit is contained in:
@@ -149,7 +149,6 @@ namespace AssetStudio
|
||||
#endregion
|
||||
|
||||
#region write Materials, collect Texture objects
|
||||
//StatusStripUpdate("Writing Materials");
|
||||
foreach (var MaterialPD in Materials)
|
||||
{
|
||||
Material m_Material = new Material(MaterialPD);
|
||||
@@ -381,7 +380,6 @@ namespace AssetStudio
|
||||
#endregion
|
||||
|
||||
#region write Model nodes and connections
|
||||
//StatusStripUpdate("Writing Nodes and hierarchy");
|
||||
foreach (var m_GameObject in GameObjects)
|
||||
{
|
||||
if (m_GameObject.m_MeshFilter == null && m_GameObject.m_SkinnedMeshRenderer == null)
|
||||
@@ -451,7 +449,6 @@ namespace AssetStudio
|
||||
#endregion
|
||||
|
||||
#region write non-skinnned Geometry
|
||||
//StatusStripUpdate("Writing Geometry");
|
||||
foreach (var MeshPD in Meshes)
|
||||
{
|
||||
Mesh m_Mesh = new Mesh(MeshPD, true);
|
||||
@@ -681,8 +678,6 @@ namespace AssetStudio
|
||||
cb.Append("\n}");//Connections end
|
||||
FBXwriter.Write(cb);
|
||||
cb.Clear();
|
||||
|
||||
StatusStripUpdate("Finished exporting " + Path.GetFileName(FBXfile));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -690,8 +685,6 @@ namespace AssetStudio
|
||||
{
|
||||
if (m_Mesh.m_VertexCount > 0)//general failsafe
|
||||
{
|
||||
//StatusStripUpdate("Writing Geometry: " + m_Mesh.m_Name);
|
||||
|
||||
ob.AppendFormat("\n\tGeometry: 3{0}, \"Geometry::\", \"Mesh\" {{", MeshID);
|
||||
ob.Append("\n\t\tProperties70: {");
|
||||
var randomColor = RandomColorGenerator(m_Mesh.m_Name);
|
||||
|
||||
@@ -25,7 +25,15 @@ namespace AssetStudio
|
||||
|
||||
public ModelConverter(GameObject m_GameObject)
|
||||
{
|
||||
InitWithGameObject(m_GameObject);
|
||||
if (assetsfileList.TryGetPD(m_GameObject.m_Animator, out var m_Animator))
|
||||
{
|
||||
var animator = new Animator(m_Animator);
|
||||
InitWithAnimator(animator);
|
||||
CollectAnimationClip(animator);
|
||||
ConvertAnimations();
|
||||
}
|
||||
else
|
||||
InitWithGameObject(m_GameObject);
|
||||
}
|
||||
|
||||
public ModelConverter(Animator m_Animator)
|
||||
@@ -65,7 +73,6 @@ namespace AssetStudio
|
||||
InitWithGameObject(m_GameObject);
|
||||
}
|
||||
|
||||
|
||||
private void InitWithGameObject(GameObject m_GameObject)
|
||||
{
|
||||
assetsfileList.TryGetTransform(m_GameObject.m_Transform, out var m_Transform);
|
||||
|
||||
@@ -85,12 +85,13 @@ namespace AssetStudio
|
||||
{
|
||||
SetProgressBarValue(0);
|
||||
SetProgressBarMaximum(assetsfileList.Sum(x => x.preloadTable.Values.Count));
|
||||
StatusStripUpdate("Building asset list...");
|
||||
|
||||
string fileIDfmt = "D" + assetsfileList.Count.ToString().Length;
|
||||
|
||||
for (var i = 0; i < assetsfileList.Count; i++)
|
||||
{
|
||||
var assetsFile = assetsfileList[i];
|
||||
StatusStripUpdate("Building asset list from " + Path.GetFileName(assetsFile.filePath));
|
||||
|
||||
string fileID = i.ToString(fileIDfmt);
|
||||
AssetBundle ab = null;
|
||||
@@ -254,9 +255,10 @@ namespace AssetStudio
|
||||
SetProgressBarMaximum(1);
|
||||
SetProgressBarValue(1);
|
||||
SetProgressBarMaximum(assetsfileList.Sum(x => x.GameObjectList.Values.Count) + 1);
|
||||
StatusStripUpdate("Building tree structure...");
|
||||
|
||||
foreach (var assetsFile in assetsfileList)
|
||||
{
|
||||
StatusStripUpdate("Building tree structure from " + Path.GetFileName(assetsFile.filePath));
|
||||
GameObject fileNode = new GameObject(null);
|
||||
fileNode.Text = Path.GetFileName(assetsFile.filePath);
|
||||
fileNode.m_Name = "RootNode";
|
||||
@@ -295,7 +297,8 @@ namespace AssetStudio
|
||||
}
|
||||
case ClassIDReference.Animator:
|
||||
{
|
||||
asset.Text = m_GameObject.asset.Text;//TODO
|
||||
m_GameObject.m_Animator = m_Component;
|
||||
asset.Text = m_GameObject.asset.Text;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -520,23 +523,64 @@ namespace AssetStudio
|
||||
continue;
|
||||
//处理非法文件名
|
||||
var filename = FixFileName(j.Text);
|
||||
//每个文件单独文件夹
|
||||
var saveName = $"{savePath}{filename}\\{filename}.fbx";
|
||||
//每个文件存放在单独的文件夹
|
||||
var targetPath = $"{savePath}{filename}\\";
|
||||
//重名文件处理
|
||||
for (int i = 1; ; i++)
|
||||
{
|
||||
if (File.Exists(saveName))
|
||||
if (Directory.Exists(targetPath))
|
||||
{
|
||||
saveName = $"{savePath}{filename} ({i})\\{filename}.fbx";
|
||||
targetPath = $"{savePath}{filename} ({i})\\";
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(saveName));
|
||||
Directory.CreateDirectory(targetPath);
|
||||
//导出FBX
|
||||
FBXExporter.WriteFBX(saveName, gameObjects);
|
||||
StatusStripUpdate($"Exporting {filename}.fbx");
|
||||
FBXExporter.WriteFBX($"{targetPath}{filename}.fbx", gameObjects);
|
||||
StatusStripUpdate($"Finished exporting {filename}.fbx");
|
||||
}
|
||||
ProgressBarPerformStep();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExportSplitObjectsNew(string savePath, TreeNodeCollection nodes)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user