From a4af90c978dd92b2a690775ecdc04aeeeb009079 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 23 Oct 2024 15:38:44 +0900 Subject: [PATCH] if IsAssetImport, Prevent runtime resource allocation. Or temporary object when export. --- Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs | 5 ++++- .../ScriptedImporter/VrmScriptedImporterImpl.cs | 5 ++++- Assets/VRM10/Editor/Vrm10ExportDialog.cs | 1 + Assets/VRM10/Runtime/IO/Vrm10Importer.cs | 11 ++++++++--- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs index 68f5bdec66..2b4e5a83ba 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -12,6 +12,7 @@ namespace UniGLTF /// public class ImporterContext : IResponsibilityForDestroyObjects { + public readonly bool IsAssetImport; private readonly ImporterContextSettings _settings; public ITextureDescriptorGenerator TextureDescriptorGenerator { get; protected set; } @@ -37,8 +38,10 @@ public ImporterContext( IReadOnlyDictionary externalObjectMap = null, ITextureDeserializer textureDeserializer = null, IMaterialDescriptorGenerator materialGenerator = null, - ImporterContextSettings settings = null) + ImporterContextSettings settings = null, + bool isAssetImport = false) { + IsAssetImport = isAssetImport; _settings = settings ?? new ImporterContextSettings(); Data = data; TextureDescriptorGenerator = new GltfTextureDescriptorGenerator(Data); diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs index c748a94510..a3c5d71b26 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs @@ -48,7 +48,10 @@ static void Process(Vrm10Data result, ScriptedImporter scriptedImporter, AssetIm var materialGenerator = GetMaterialDescriptorGenerator(renderPipeline); - using (var loader = new Vrm10Importer(result, externalObjectMap: extractedObjects, materialGenerator: materialGenerator)) + using (var loader = new Vrm10Importer(result, + externalObjectMap: extractedObjects, + materialGenerator: materialGenerator, + isAssetImport: true)) { // settings TextureImporters foreach (var textureInfo in loader.TextureDescriptorGenerator.Get().GetEnumerable()) diff --git a/Assets/VRM10/Editor/Vrm10ExportDialog.cs b/Assets/VRM10/Editor/Vrm10ExportDialog.cs index 41e71f8ed2..eb805d3586 100644 --- a/Assets/VRM10/Editor/Vrm10ExportDialog.cs +++ b/Assets/VRM10/Editor/Vrm10ExportDialog.cs @@ -290,6 +290,7 @@ protected override void ExportPath(string path) { Debug.Log("vrm-1.0 FreezeMesh"); var copy = GameObject.Instantiate(root); + copy.GetComponent().UpdateType = Vrm10Instance.UpdateTypes.None; disposer.Push(copy); root = copy; diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index dacfdedf7b..220a0ceaaf 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -33,9 +33,10 @@ public Vrm10Importer( IMaterialDescriptorGenerator materialGenerator = null, bool useControlRig = false, ImporterContextSettings settings = null, - IVrm10SpringBoneRuntime springboneRuntime = null + IVrm10SpringBoneRuntime springboneRuntime = null, + bool isAssetImport = false ) - : base(vrm.Data, externalObjectMap, textureDeserializer, settings: settings) + : base(vrm.Data, externalObjectMap, textureDeserializer, settings: settings, isAssetImport: isAssetImport) { if (vrm == null) { @@ -288,7 +289,11 @@ protected override async Task FinalizeAsync(IAwaitCaller awaitCaller) await LoadSpringBoneAsync(awaitCaller, controller, springBone); } - if (Application.isPlaying) + if (IsAssetImport) + { + controller.UpdateType = Vrm10Instance.UpdateTypes.None; + } + else { // EditorImport では呼ばない // Vrm10Runtime で初期化していたが、 async にするためこちらに移動 v0.127