mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-12 13:59:21 -05:00
add EditorProgress for GltfExportWindow
This commit is contained in:
13
Assets/UniGLTF/Editor/UniGLTF/ExportDialog/EditorProgress.cs
Normal file
13
Assets/UniGLTF/Editor/UniGLTF/ExportDialog/EditorProgress.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public class EditorProgress : IProgress<ExportProgress>
|
||||
{
|
||||
public void Report(ExportProgress value)
|
||||
{
|
||||
EditorUtility.DisplayProgressBar(value.Title, value.Message, value.Progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 354f802e5f3f61145bafeda8e58307b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -100,40 +100,51 @@ namespace UniGLTF
|
||||
default: throw new System.Exception();
|
||||
}
|
||||
|
||||
var data = new ExportingGltfData();
|
||||
using (var exporter = new gltfExporter(data, Settings))
|
||||
var progress = 0;
|
||||
EditorUtility.DisplayProgressBar("export gltf", path, progress);
|
||||
try
|
||||
{
|
||||
exporter.Prepare(State.ExportRoot);
|
||||
exporter.Export(new EditorTextureSerializer());
|
||||
}
|
||||
|
||||
if (isGlb)
|
||||
{
|
||||
var bytes = data.ToGlbBytes();
|
||||
File.WriteAllBytes(path, bytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
var (json, buffer0) = data.ToGltf(path);
|
||||
|
||||
var data = new ExportingGltfData();
|
||||
using (var exporter = new gltfExporter(data, Settings, new EditorProgress()))
|
||||
{
|
||||
// write JSON without BOM
|
||||
var encoding = new System.Text.UTF8Encoding(false);
|
||||
File.WriteAllText(path, json, encoding);
|
||||
exporter.Prepare(State.ExportRoot);
|
||||
exporter.Export(new EditorTextureSerializer());
|
||||
}
|
||||
|
||||
if (isGlb)
|
||||
{
|
||||
// write to buffer0 local folder
|
||||
var dir = Path.GetDirectoryName(path);
|
||||
var bufferPath = Path.Combine(dir, buffer0.uri);
|
||||
File.WriteAllBytes(bufferPath, data.BinBytes.ToArray());
|
||||
var bytes = data.ToGlbBytes();
|
||||
File.WriteAllBytes(path, bytes);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var (json, buffer0) = data.ToGltf(path);
|
||||
|
||||
if (path.StartsWithUnityAssetPath())
|
||||
{
|
||||
// write JSON without BOM
|
||||
var encoding = new System.Text.UTF8Encoding(false);
|
||||
File.WriteAllText(path, json, encoding);
|
||||
}
|
||||
|
||||
{
|
||||
// write to buffer0 local folder
|
||||
var dir = Path.GetDirectoryName(path);
|
||||
var bufferPath = Path.Combine(dir, buffer0.uri);
|
||||
File.WriteAllBytes(bufferPath, data.BinBytes.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
if (path.StartsWithUnityAssetPath())
|
||||
{
|
||||
AssetDatabase.ImportAsset(path.ToUnityRelativePath());
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
AssetDatabase.ImportAsset(path.ToUnityRelativePath());
|
||||
AssetDatabase.Refresh();
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
25
Assets/UniGLTF/Runtime/UniGLTF/IO/ProgressInfo.cs
Normal file
25
Assets/UniGLTF/Runtime/UniGLTF/IO/ProgressInfo.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public readonly struct ExportProgress
|
||||
{
|
||||
public readonly string Title;
|
||||
public readonly string Message;
|
||||
public readonly float Progress;
|
||||
|
||||
public ExportProgress(string title, string message, float progress)
|
||||
{
|
||||
Title = title;
|
||||
Message = message;
|
||||
Progress = progress;
|
||||
}
|
||||
}
|
||||
|
||||
public class NullProgress : IProgress<ExportProgress>
|
||||
{
|
||||
public void Report(ExportProgress value)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/UniGLTF/Runtime/UniGLTF/IO/ProgressInfo.cs.meta
Normal file
11
Assets/UniGLTF/Runtime/UniGLTF/IO/ProgressInfo.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2235603b34ed9d045b81273d88806b51
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -68,7 +68,18 @@ namespace UniGLTF
|
||||
|
||||
GltfExportSettings m_settings;
|
||||
|
||||
public gltfExporter(ExportingGltfData data, GltfExportSettings settings)
|
||||
IProgress<ExportProgress> m_progress;
|
||||
|
||||
void ReportProgress(string msg, float progress)
|
||||
{
|
||||
if (m_progress == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_progress.Report(new ExportProgress("gltfExporter", msg, progress));
|
||||
}
|
||||
|
||||
public gltfExporter(ExportingGltfData data, GltfExportSettings settings, IProgress<ExportProgress> progress = null)
|
||||
{
|
||||
_data = data;
|
||||
|
||||
@@ -113,6 +124,8 @@ namespace UniGLTF
|
||||
// should throw ?
|
||||
Debug.LogError("root mesh is not exported");
|
||||
}
|
||||
|
||||
ReportProgress("prepared", 0.1f);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -233,6 +246,7 @@ namespace UniGLTF
|
||||
uniqueUnityMeshes.GetInfo(Nodes, m_settings);
|
||||
|
||||
#region Materials and Textures
|
||||
ReportProgress("Materials and Textures", 0.2f);
|
||||
Materials = uniqueUnityMeshes.GetUniqueMaterials().ToList();
|
||||
|
||||
_textureExporter = new TextureExporter(textureSerializer);
|
||||
@@ -242,6 +256,7 @@ namespace UniGLTF
|
||||
#endregion
|
||||
|
||||
#region Meshes
|
||||
ReportProgress("Meshes", 0.4f);
|
||||
MeshBlendShapeIndexMap = new Dictionary<Mesh, Dictionary<int, int>>();
|
||||
foreach (var unityMesh in uniqueUnityMeshes)
|
||||
{
|
||||
@@ -265,6 +280,7 @@ namespace UniGLTF
|
||||
#endregion
|
||||
|
||||
#region Nodes and Skins
|
||||
ReportProgress("Nodes and Skins", 0.8f);
|
||||
var skins = uniqueUnityMeshes
|
||||
.SelectMany(x => x.Renderers)
|
||||
.Where(x => x.Item1 is SkinnedMeshRenderer && x.UniqueBones != null)
|
||||
@@ -314,6 +330,7 @@ namespace UniGLTF
|
||||
|
||||
#if UNITY_EDITOR
|
||||
#region Animations
|
||||
ReportProgress("Animations", 0.9f);
|
||||
|
||||
var clips = new List<AnimationClip>();
|
||||
var animator = Copy.GetComponent<Animator>();
|
||||
|
||||
Reference in New Issue
Block a user