diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/EditorProgress.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/EditorProgress.cs new file mode 100644 index 000000000..c2fdf1587 --- /dev/null +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/EditorProgress.cs @@ -0,0 +1,13 @@ +using System; +using UnityEditor; + +namespace UniGLTF +{ + public class EditorProgress : IProgress + { + public void Report(ExportProgress value) + { + EditorUtility.DisplayProgressBar(value.Title, value.Message, value.Progress); + } + } +} diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/EditorProgress.cs.meta b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/EditorProgress.cs.meta new file mode 100644 index 000000000..bec5f71bf --- /dev/null +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/EditorProgress.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 354f802e5f3f61145bafeda8e58307b6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs index c525a036b..30f85d0bf 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs @@ -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(); } } } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ProgressInfo.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ProgressInfo.cs new file mode 100644 index 000000000..12b27ed3f --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ProgressInfo.cs @@ -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 + { + public void Report(ExportProgress value) + { + } + } +} diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ProgressInfo.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/ProgressInfo.cs.meta new file mode 100644 index 000000000..7a9f4e653 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ProgressInfo.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2235603b34ed9d045b81273d88806b51 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs index 4f8707b7b..e9014d5d1 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs @@ -68,7 +68,18 @@ namespace UniGLTF GltfExportSettings m_settings; - public gltfExporter(ExportingGltfData data, GltfExportSettings settings) + IProgress 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 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>(); 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(); var animator = Copy.GetComponent();