From 69bf34b7d7b74d70557516d785180000f75f1090 Mon Sep 17 00:00:00 2001 From: Gene Tailor Date: Mon, 16 Feb 2026 20:49:05 +0000 Subject: [PATCH 1/4] Added Stopwatch timer to measure overall prefab import time. --- Packages/VRM/Editor/Format/vrmAssetPostprocessor.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Packages/VRM/Editor/Format/vrmAssetPostprocessor.cs b/Packages/VRM/Editor/Format/vrmAssetPostprocessor.cs index 1ebaaee95..75494b092 100644 --- a/Packages/VRM/Editor/Format/vrmAssetPostprocessor.cs +++ b/Packages/VRM/Editor/Format/vrmAssetPostprocessor.cs @@ -63,6 +63,9 @@ namespace VRM return; } + System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); + sw.Start(); + /// /// これは EditorApplication.delayCall により呼び出される。 /// @@ -91,6 +94,9 @@ namespace VRM editor.SaveAsAsset(loaded); } + sw.Stop(); + + Debug.Log($"Import complete [importMs={sw.ElapsedMilliseconds}]"); }; using (var data = new GlbFileParser(vrmPath).Parse()) From c1123cf543fc444c7fce98311e50859b665b4c0c Mon Sep 17 00:00:00 2001 From: Gene Tailor Date: Mon, 16 Feb 2026 21:05:57 +0000 Subject: [PATCH 2/4] Added ProfilerMarkers for more detailed profiling info without the need for Deep Profiling. --- .../UniGLTF/ScriptedImporter/TextureExtractor.cs | 16 ++++++++++++++-- .../Editor/Format/VRMEditorImporterContext.cs | 11 +++++++++++ .../VRM/Editor/Format/vrmAssetPostprocessor.cs | 8 ++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Packages/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs b/Packages/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs index 05fb2110a..40fd43d10 100644 --- a/Packages/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs +++ b/Packages/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs @@ -1,9 +1,10 @@ using System; using System.Collections.Generic; using System.IO; -using UnityEngine; -using UnityEditor; using System.Linq; +using Unity.Profiling; +using UnityEditor; +using UnityEngine; namespace UniGLTF { @@ -20,6 +21,9 @@ namespace UniGLTF private readonly IReadOnlyDictionary m_subAssets; UnityPath m_textureDirectory; + private static ProfilerMarker s_MarkerStartExtractTextures = new ProfilerMarker("Start Extract Textures"); + private static ProfilerMarker s_MarkerDelayedExtractTextures = new ProfilerMarker("Delayed Extract Textures"); + public TextureExtractor(GltfData data, UnityPath textureDirectory, IReadOnlyDictionary subAssets) { m_data = data; @@ -77,14 +81,20 @@ namespace UniGLTF Action addRemap, Action> onCompleted = null) { + s_MarkerStartExtractTextures.Begin(); + var extractor = new TextureExtractor(data, textureDirectory, subAssets); foreach (var param in textureDescriptorGenerator.Get().GetEnumerable()) { extractor.Extract(param.SubAssetKey, param); } + s_MarkerStartExtractTextures.End(); + EditorApplication.delayCall += () => { + s_MarkerDelayedExtractTextures.Begin(); + // Wait for the texture assets to be imported foreach (var (key, targetPath) in extractor.Textures) @@ -97,6 +107,8 @@ namespace UniGLTF } } + s_MarkerDelayedExtractTextures.End(); + if (onCompleted != null) { onCompleted(extractor.Textures.Values); diff --git a/Packages/VRM/Editor/Format/VRMEditorImporterContext.cs b/Packages/VRM/Editor/Format/VRMEditorImporterContext.cs index 7bfc9826d..4f4cda57e 100644 --- a/Packages/VRM/Editor/Format/VRMEditorImporterContext.cs +++ b/Packages/VRM/Editor/Format/VRMEditorImporterContext.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using UniGLTF; +using Unity.Profiling; using UnityEditor; using UnityEngine; @@ -12,6 +13,8 @@ namespace VRM UnityPath m_prefabPath; List m_paths = new List(); + private static ProfilerMarker s_MarkerConvertAndExtractImages = new ProfilerMarker("Convert and Extract Images"); + public ITextureDescriptorGenerator TextureDescriptorGenerator => m_context.TextureDescriptorGenerator; public VRMEditorImporterContext(VRMImporterContext context, UnityPath prefabPath) @@ -76,22 +79,27 @@ namespace VRM /// public void ConvertAndExtractImages(Action> onTextureReloaded) { + s_MarkerConvertAndExtractImages.Begin(); + // // convert images(metallic roughness, occlusion map) // var task = m_context.LoadMaterialsAsync(new ImmediateCaller()); if (!task.IsCompleted) { + s_MarkerConvertAndExtractImages.End(); throw new Exception(); } if (task.IsFaulted) { if (task.Exception is AggregateException ae && ae.InnerExceptions.Count == 1) { + s_MarkerConvertAndExtractImages.End(); throw ae.InnerException; } else { + s_MarkerConvertAndExtractImages.End(); throw task.Exception; } } @@ -100,6 +108,7 @@ namespace VRM var task2 = m_context.ReadMetaAsync(new ImmediateCaller()); if (!task2.IsCompleted || task2.IsCanceled || task2.IsFaulted) { + s_MarkerConvertAndExtractImages.End(); throw new Exception(); } @@ -110,6 +119,8 @@ namespace VRM var vrmTextures = new BuiltInVrmMaterialDescriptorGenerator(m_context.VRM); var dirName = $"{m_prefabPath.FileNameWithoutExtension}.Textures"; TextureExtractor.ExtractTextures(m_context.Data, m_prefabPath.Parent.Child(dirName), m_context.TextureDescriptorGenerator, subAssets, (_x, _y) => { }, onTextureReloaded); + + s_MarkerConvertAndExtractImages.End(); } void SaveAsAsset(SubAssetKey _, UnityEngine.Object o) diff --git a/Packages/VRM/Editor/Format/vrmAssetPostprocessor.cs b/Packages/VRM/Editor/Format/vrmAssetPostprocessor.cs index 75494b092..e201d871a 100644 --- a/Packages/VRM/Editor/Format/vrmAssetPostprocessor.cs +++ b/Packages/VRM/Editor/Format/vrmAssetPostprocessor.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using UniGLTF; +using Unity.Profiling; using UnityEditor; using UnityEngine; @@ -10,6 +11,8 @@ namespace VRM { public class vrmAssetPostprocessor : AssetPostprocessor { + private static ProfilerMarker s_MarkerCreatePrefab = new ProfilerMarker("Create Prefab"); + #if !VRM_STOP_ASSETPOSTPROCESSOR static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { @@ -76,6 +79,8 @@ namespace VRM /// Action> onCompleted = texturePaths => { + s_MarkerCreatePrefab.Begin(); + var map = texturePaths .Select(x => x.LoadAsset()) .ToDictionary(x => new SubAssetKey(x), x => x as UnityEngine.Object); @@ -94,6 +99,9 @@ namespace VRM editor.SaveAsAsset(loaded); } + + s_MarkerCreatePrefab.End(); + sw.Stop(); Debug.Log($"Import complete [importMs={sw.ElapsedMilliseconds}]"); From dfe2c83a26d587536db820421578822761b77a8b Mon Sep 17 00:00:00 2001 From: Gene Tailor Date: Mon, 16 Feb 2026 21:24:13 +0000 Subject: [PATCH 3/4] Added StartAssetEditing and StopAssetEditing around creation of prefab and related assets in onCompleted callback delegate inside vrmAssetPostprocessor.ImportVrmAndCreatePrefab() to batch Unity asset importing. --- .../Editor/Format/vrmAssetPostprocessor.cs | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/Packages/VRM/Editor/Format/vrmAssetPostprocessor.cs b/Packages/VRM/Editor/Format/vrmAssetPostprocessor.cs index e201d871a..282ccc374 100644 --- a/Packages/VRM/Editor/Format/vrmAssetPostprocessor.cs +++ b/Packages/VRM/Editor/Format/vrmAssetPostprocessor.cs @@ -84,21 +84,35 @@ namespace VRM var map = texturePaths .Select(x => x.LoadAsset()) .ToDictionary(x => new SubAssetKey(x), x => x as UnityEngine.Object); - var settings = new ImporterContextSettings(); - // 確実に Dispose するために敢えて再パースしている - using (var data = new GlbFileParser(vrmPath).Parse()) - using (var context = new VRMImporterContext(new VRMData(data), externalObjectMap: map, settings: settings)) + try { - var editor = new VRMEditorImporterContext(context, prefabPath); - foreach (var textureInfo in context.TextureDescriptorGenerator.Get().GetEnumerable()) - { - TextureImporterConfigurator.Configure(textureInfo, context.TextureFactory.ExternalTextures); - } - var loaded = context.Load(); - editor.SaveAsAsset(loaded); - } + AssetDatabase.StartAssetEditing(); + var settings = new ImporterContextSettings(); + + // 確実に Dispose するために敢えて再パースしている + using (var data = new GlbFileParser(vrmPath).Parse()) + using (var context = new VRMImporterContext(new VRMData(data), externalObjectMap: map, settings: settings)) + { + var editor = new VRMEditorImporterContext(context, prefabPath); + foreach (var textureInfo in context.TextureDescriptorGenerator.Get().GetEnumerable()) + { + TextureImporterConfigurator.Configure(textureInfo, context.TextureFactory.ExternalTextures); + } + var loaded = context.Load(); + editor.SaveAsAsset(loaded); + } + + } + catch (Exception e) + { + Debug.LogException(e); + } + finally + { + AssetDatabase.StopAssetEditing(); + } s_MarkerCreatePrefab.End(); From 2b4ecb5e73b359796c9001b28d521678a64fa1f1 Mon Sep 17 00:00:00 2001 From: Gene Tailor Date: Mon, 16 Feb 2026 21:37:44 +0000 Subject: [PATCH 4/4] Applied same *AssetEditing improvements to the Texture extracting section of TextureExtractor.ExtractTextures() to batch the importing of created Textures. --- .../ScriptedImporter/TextureExtractor.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Packages/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs b/Packages/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs index 40fd43d10..cac1a48c8 100644 --- a/Packages/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs +++ b/Packages/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs @@ -84,9 +84,22 @@ namespace UniGLTF s_MarkerStartExtractTextures.Begin(); var extractor = new TextureExtractor(data, textureDirectory, subAssets); - foreach (var param in textureDescriptorGenerator.Get().GetEnumerable()) + try { - extractor.Extract(param.SubAssetKey, param); + AssetDatabase.StartAssetEditing(); + + foreach (var param in textureDescriptorGenerator.Get().GetEnumerable()) + { + extractor.Extract(param.SubAssetKey, param); + } + } + catch (Exception e) + { + Debug.LogException(e); + } + finally + { + AssetDatabase.StopAssetEditing(); } s_MarkerStartExtractTextures.End();