From 21d0ce714e5472e2c8dc9d33fcce802a80472bb2 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 21 Jun 2021 14:15:48 +0900 Subject: [PATCH] =?UTF-8?q?RemapEditorBase=20=E3=81=AB=20externalObjectMap?= =?UTF-8?q?=20=E3=82=92=E4=BF=9D=E6=8C=81=E3=81=97=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GlbScriptedImporterEditorGUI.cs | 5 ++- .../GltfScriptedImporterEditorGUI.cs | 5 ++- .../ScriptedImporter/RemapEditorAnimation.cs | 6 ++-- .../ScriptedImporter/RemapEditorBase.cs | 31 +++++-------------- .../ScriptedImporter/RemapEditorMaterial.cs | 11 ++++--- .../ScriptedImporter/TextureExtractor.cs | 4 ++- .../Editor/ScriptedImporter/RemapEditorVrm.cs | 7 ++--- .../VrmScriptedImporterEditorGUI.cs | 6 ++-- .../IO/Editor/TextureImporterConfigurator.cs | 6 ---- 9 files changed, 28 insertions(+), 53 deletions(-) diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs index 320814304..13ab4911c 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs @@ -28,12 +28,11 @@ namespace UniGLTF m_parser = new GltfParser(); m_parser.ParsePath(m_importer.assetPath); - var externalObjectMap = m_importer.GetExternalObjectMap(); var materialGenerator = new GltfMaterialDescriptorGenerator(); var materialKeys = m_parser.GLTF.materials.Select((_, i) => materialGenerator.Get(m_parser, i).SubAssetKey); var textureKeys = new GltfTextureDescriptorGenerator(m_parser).Get().GetEnumerable().Select(x => x.SubAssetKey); - m_materialEditor = new RemapEditorMaterial(materialKeys.Concat(textureKeys), externalObjectMap); - m_animationEditor = new RemapEditorAnimation(AnimationImporterUtil.EnumerateSubAssetKeys(m_parser.GLTF), externalObjectMap); + m_materialEditor = new RemapEditorMaterial(materialKeys.Concat(textureKeys)); + m_animationEditor = new RemapEditorAnimation(AnimationImporterUtil.EnumerateSubAssetKeys(m_parser.GLTF)); } enum Tabs diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs index 5224d478b..049446279 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs @@ -28,12 +28,11 @@ namespace UniGLTF m_parser = new GltfParser(); m_parser.ParsePath(m_importer.assetPath); - var externalObjectMap = m_importer.GetExternalObjectMap(); var materialGenerator = new GltfMaterialDescriptorGenerator(); var materialKeys = m_parser.GLTF.materials.Select((_, i) => materialGenerator.Get(m_parser, i).SubAssetKey); var textureKeys = new GltfTextureDescriptorGenerator(m_parser).Get().GetEnumerable().Select(x => x.SubAssetKey); - m_materialEditor = new RemapEditorMaterial(materialKeys.Concat(textureKeys), externalObjectMap); - m_animationEditor = new RemapEditorAnimation(AnimationImporterUtil.EnumerateSubAssetKeys(m_parser.GLTF), externalObjectMap); + m_materialEditor = new RemapEditorMaterial(materialKeys.Concat(textureKeys)); + m_animationEditor = new RemapEditorAnimation(AnimationImporterUtil.EnumerateSubAssetKeys(m_parser.GLTF)); } enum Tabs diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs index 0a6808cdf..8290656bf 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs @@ -12,9 +12,7 @@ namespace UniGLTF { public class RemapEditorAnimation : RemapEditorBase { - public RemapEditorAnimation( - IEnumerable keys, - Dictionary externalObjectMap) : base(keys, externalObjectMap) + public RemapEditorAnimation(IEnumerable keys) : base(keys) { } public void OnGUI(ScriptedImporter importer, GltfParser parser) @@ -28,7 +26,7 @@ namespace UniGLTF } } - DrawRemapGUI(); + DrawRemapGUI(importer.GetExternalObjectMap()); if (GUILayout.Button("Clear")) { diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs index 5bb35d6ae..511ea804e 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs @@ -30,30 +30,14 @@ namespace UniGLTF /// /// Remap 対象は、このエディタのライフサイクル中に不変 - /// - /// apply, clear 時には ScriptedImporter は reimport され、新しい引数で new される - /// + /// + /// ExternalObjectMap は都度変わりうるのに注意。 /// - SubAssetPair[] m_keyValues; + SubAssetKey[] m_keys; - protected RemapEditorBase( - IEnumerable keys, - Dictionary externalObjectMap) + protected RemapEditorBase(IEnumerable keys) { - m_keyValues = keys.Select(x => - { - var id = new ScriptedImporter.SourceAssetIdentifier(x.Type, x.Name); - if (externalObjectMap.TryGetValue(id, out UnityEngine.Object value)) - { - return new SubAssetPair(x, value); - } - else - { - return new SubAssetPair(x, null); - } - }).ToArray(); - - Debug.Log($"RemapEditorBase: {m_keyValues}"); + m_keys = keys.ToArray(); } void RemapAndReload(ScriptedImporter self, UnityEditor.AssetImporter.SourceAssetIdentifier sourceAssetIdentifier, T obj) where T : UnityEngine.Object @@ -63,11 +47,11 @@ namespace UniGLTF AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); } - protected void DrawRemapGUI() where T : UnityEngine.Object + protected void DrawRemapGUI(Dictionary externalObjectMap) where T : UnityEngine.Object { EditorGUI.indentLevel++; { - foreach (var (key, value) in m_keyValues) + foreach (var key in m_keys) { if (!typeof(T).IsAssignableFrom(key.Type)) { @@ -81,6 +65,7 @@ namespace UniGLTF EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(key.Name); + externalObjectMap.TryGetValue(new AssetImporter.SourceAssetIdentifier(key.Type, key.Name), out UnityEngine.Object value); var asset = EditorGUILayout.ObjectField(value, typeof(T), true) as T; if (asset != value) { diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs index 54192dcda..36b3c13ab 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs @@ -22,9 +22,7 @@ namespace UniGLTF static bool s_foldMaterials = true; static bool s_foldTextures = true; - public RemapEditorMaterial( - IEnumerable keys, - Dictionary externalObjectMap) : base(keys, externalObjectMap) + public RemapEditorMaterial(IEnumerable keys) : base(keys) { } public void OnGUI(ScriptedImporter importer, GltfParser parser, ITextureDescriptorGenerator textureDescriptorGenerator, Func textureDir, Func materialDir) @@ -44,13 +42,13 @@ namespace UniGLTF s_foldMaterials = EditorGUILayout.Foldout(s_foldMaterials, "Remapped Materials"); if (s_foldMaterials) { - DrawRemapGUI(); + DrawRemapGUI(importer.GetExternalObjectMap()); } s_foldTextures = EditorGUILayout.Foldout(s_foldTextures, "Remapped Textures"); if (s_foldTextures) { - DrawRemapGUI(); + DrawRemapGUI(importer.GetExternalObjectMap()); } if (GUILayout.Button("Clear")) @@ -74,8 +72,11 @@ namespace UniGLTF }; Action> onCompleted = _ => { + // texture extract 後に importer 発動 AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); + ExtractMaterials(self, materialDir); + // material extract 後に importer 発動 AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); }; diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs index f633ab624..94de02f90 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs @@ -92,8 +92,10 @@ namespace UniGLTF foreach (var (key, targetPath) in extractor.Textures) { // remap - Debug.Log(targetPath); var externalObject = targetPath.LoadAsset(); +#if VRM_DEVELOP + // Debug.Log($"remap: {targetPath} => {externalObject}"); +#endif if (externalObject != null) { addRemap(key, externalObject); diff --git a/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs b/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs index 97fd573af..28a7e5d53 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs @@ -17,8 +17,7 @@ namespace UniVRM10 public class RemapEditorVrm : RemapEditorBase { public RemapEditorVrm( - IEnumerable keys, - Dictionary externalObjectMap) : base(keys, externalObjectMap) + IEnumerable keys) : base(keys) { } public void OnGUI(ScriptedImporter importer, GltfParser parser, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm) @@ -33,10 +32,10 @@ namespace UniVRM10 } // meta - DrawRemapGUI(); + DrawRemapGUI(importer.GetExternalObjectMap()); // expressions - DrawRemapGUI(); + DrawRemapGUI(importer.GetExternalObjectMap()); if (GUILayout.Button("Clear")) { diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs index 9c1603fa1..01a51bbed 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs @@ -43,16 +43,14 @@ namespace UniVRM10 m_parser = result.Parser; m_model = ModelReader.Read(result.Parser); - var externalObjectMap = m_importer.GetExternalObjectMap(); - var tmp = m_importer.GetExternalObjectMap(); var generator = new Vrm10MaterialDescriptorGenerator(); var materialKeys = m_parser.GLTF.materials.Select((x, i) => generator.Get(m_parser, i).SubAssetKey); var textureKeys = new GltfTextureDescriptorGenerator(m_parser).Get().GetEnumerable().Select(x => x.SubAssetKey); - m_materialEditor = new RemapEditorMaterial(materialKeys.Concat(textureKeys), externalObjectMap); + m_materialEditor = new RemapEditorMaterial(materialKeys.Concat(textureKeys)); var expressionSubAssetKeys = m_vrm.Expressions.Select(x => ExpressionKey.CreateFromVrm10(x).SubAssetKey); - m_vrmEditor = new RemapEditorVrm(new[] { VRM10Object.SubAssetKey }.Concat(expressionSubAssetKeys), externalObjectMap); + m_vrmEditor = new RemapEditorVrm(new[] { VRM10Object.SubAssetKey }.Concat(expressionSubAssetKeys)); } enum Tabs diff --git a/Assets/VRMShaders/GLTF/IO/Editor/TextureImporterConfigurator.cs b/Assets/VRMShaders/GLTF/IO/Editor/TextureImporterConfigurator.cs index 3ec6ad6cf..c6266f698 100644 --- a/Assets/VRMShaders/GLTF/IO/Editor/TextureImporterConfigurator.cs +++ b/Assets/VRMShaders/GLTF/IO/Editor/TextureImporterConfigurator.cs @@ -22,18 +22,12 @@ namespace VRMShaders public static void ConfigureNormalMap(Texture texture, TextureImporter textureImporter) { -#if VRM_DEVELOP - Debug.Log($"{texture} => normalmap"); -#endif textureImporter.textureType = TextureImporterType.NormalMap; textureImporter.SaveAndReimport(); } public static void ConfigureLinear(Texture texture, TextureImporter textureImporter) { -#if VRM_DEVELOP - Debug.Log($"{texture} => linear"); -#endif textureImporter.sRGBTexture = false; textureImporter.SaveAndReimport(); }