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/Components/Vrm10Runtime/Vrm10NopSpringboneRuntime.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10NopSpringboneRuntime.cs new file mode 100644 index 0000000000..30f26068d0 --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10NopSpringboneRuntime.cs @@ -0,0 +1,44 @@ +using System.Threading.Tasks; +using UniGLTF; +using UniGLTF.SpringBoneJobs.Blittables; +using UnityEngine; + +namespace UniVRM10 +{ + /// + /// SpcriptedImporter 経由の import 向け。 + /// NativeArray の確保や DontDestroyOnLoad を回避。 + /// + public class Vrm10NopSpringboneRuntime : IVrm10SpringBoneRuntime + { + public void Dispose() + { + } + + public Task InitializeAsync(Vrm10Instance instance, IAwaitCaller awaitCaller) + { + return Task.CompletedTask; + } + + public void Process() + { + } + + public bool ReconstructSpringBone() + { + return false; + } + + public void RestoreInitialTransform() + { + } + + public void SetJointLevel(Transform joint, BlittableJointMutable jointSettings) + { + } + + public void SetModelLevel(Transform modelRoot, BlittableModelLevel modelSettings) + { + } + } +} \ No newline at end of file diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10NopSpringboneRuntime.cs.meta b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10NopSpringboneRuntime.cs.meta new file mode 100644 index 0000000000..cb64688e30 --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10NopSpringboneRuntime.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b58249c702cd4054480f69562b43b0b7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index dacfdedf7b..c3c05ff387 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) { @@ -53,7 +54,24 @@ public Vrm10Importer( m_externalMap = new Dictionary(); } - m_springboneRuntime = springboneRuntime ?? new Vrm10FastSpringboneRuntime(); + m_springboneRuntime = MakeDefaultRuntime(springboneRuntime, isAssetImport); + } + + static IVrm10SpringBoneRuntime MakeDefaultRuntime(IVrm10SpringBoneRuntime runtime, bool isAssetImport) + { + if (runtime != null) + { + return runtime; + } + + if (isAssetImport) + { + // 何もしない dummy + return new Vrm10NopSpringboneRuntime(); + } + + // Vrm10Instance.MakeRuntime に移譲 + return null; } static void AssignHumanoid(List nodes, UniGLTF.Extensions.VRMC_vrm.HumanBone humanBone, VrmLib.HumanoidBones key) @@ -288,9 +306,15 @@ protected override async Task FinalizeAsync(IAwaitCaller awaitCaller) await LoadSpringBoneAsync(awaitCaller, controller, springBone); } - if (Application.isPlaying) + if (IsAssetImport) + { + // ScriptedImpoter から発動された。 + // SpringBone のリソース確保を回避する。 + // Application.isPlaying == true がありえる。 + } + else { - // EditorImport では呼ばない + // ScriptedImpoter 経由でない。 // Vrm10Runtime で初期化していたが、 async にするためこちらに移動 v0.127 // RuntimeGltfInstance にアクセスしたいのだが OnLoadHierarchy ではまだ attach されてなかった v0.128 // VRMC_springBone が無くても初期化する v0.127.2 diff --git a/ProjectSettings/QualitySettings.asset b/ProjectSettings/QualitySettings.asset index 785dd573c3..dc07d28e48 100644 --- a/ProjectSettings/QualitySettings.asset +++ b/ProjectSettings/QualitySettings.asset @@ -230,6 +230,7 @@ QualitySettings: PSM: 5 PSP2: 2 Samsung TV: 2 + Server: 0 Standalone: 5 Switch: 5 Tizen: 2