RemapEditorBase に externalObjectMap を保持しない

This commit is contained in:
ousttrue 2021-06-21 14:15:48 +09:00
parent e04ac65bf5
commit 21d0ce714e
9 changed files with 28 additions and 53 deletions

View File

@ -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

View File

@ -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

View File

@ -12,9 +12,7 @@ namespace UniGLTF
{
public class RemapEditorAnimation : RemapEditorBase
{
public RemapEditorAnimation(
IEnumerable<SubAssetKey> keys,
Dictionary<ScriptedImporter.SourceAssetIdentifier, UnityEngine.Object> externalObjectMap) : base(keys, externalObjectMap)
public RemapEditorAnimation(IEnumerable<SubAssetKey> keys) : base(keys)
{ }
public void OnGUI(ScriptedImporter importer, GltfParser parser)
@ -28,7 +26,7 @@ namespace UniGLTF
}
}
DrawRemapGUI<AnimationClip>();
DrawRemapGUI<AnimationClip>(importer.GetExternalObjectMap());
if (GUILayout.Button("Clear"))
{

View File

@ -30,30 +30,14 @@ namespace UniGLTF
/// <summary>
/// Remap 対象は、このエディタのライフサイクル中に不変
///
/// apply, clear 時には ScriptedImporter は reimport され、新しい引数で new される
///
///
/// ExternalObjectMap は都度変わりうるのに注意。
/// </summary>
SubAssetPair[] m_keyValues;
SubAssetKey[] m_keys;
protected RemapEditorBase(
IEnumerable<SubAssetKey> keys,
Dictionary<ScriptedImporter.SourceAssetIdentifier, UnityEngine.Object> externalObjectMap)
protected RemapEditorBase(IEnumerable<SubAssetKey> 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<T>(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<T>() where T : UnityEngine.Object
protected void DrawRemapGUI<T>(Dictionary<ScriptedImporter.SourceAssetIdentifier, UnityEngine.Object> 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)
{

View File

@ -22,9 +22,7 @@ namespace UniGLTF
static bool s_foldMaterials = true;
static bool s_foldTextures = true;
public RemapEditorMaterial(
IEnumerable<SubAssetKey> keys,
Dictionary<ScriptedImporter.SourceAssetIdentifier, UnityEngine.Object> externalObjectMap) : base(keys, externalObjectMap)
public RemapEditorMaterial(IEnumerable<SubAssetKey> keys) : base(keys)
{ }
public void OnGUI(ScriptedImporter importer, GltfParser parser, ITextureDescriptorGenerator textureDescriptorGenerator, Func<string, string> textureDir, Func<string, string> materialDir)
@ -44,13 +42,13 @@ namespace UniGLTF
s_foldMaterials = EditorGUILayout.Foldout(s_foldMaterials, "Remapped Materials");
if (s_foldMaterials)
{
DrawRemapGUI<UnityEngine.Material>();
DrawRemapGUI<UnityEngine.Material>(importer.GetExternalObjectMap());
}
s_foldTextures = EditorGUILayout.Foldout(s_foldTextures, "Remapped Textures");
if (s_foldTextures)
{
DrawRemapGUI<UnityEngine.Texture>();
DrawRemapGUI<UnityEngine.Texture>(importer.GetExternalObjectMap());
}
if (GUILayout.Button("Clear"))
@ -74,8 +72,11 @@ namespace UniGLTF
};
Action<IEnumerable<UnityPath>> onCompleted = _ =>
{
// texture extract 後に importer 発動
AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate);
ExtractMaterials(self, materialDir);
// material extract 後に importer 発動
AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate);
};

View File

@ -92,8 +92,10 @@ namespace UniGLTF
foreach (var (key, targetPath) in extractor.Textures)
{
// remap
Debug.Log(targetPath);
var externalObject = targetPath.LoadAsset<Texture2D>();
#if VRM_DEVELOP
// Debug.Log($"remap: {targetPath} => {externalObject}");
#endif
if (externalObject != null)
{
addRemap(key, externalObject);

View File

@ -17,8 +17,7 @@ namespace UniVRM10
public class RemapEditorVrm : RemapEditorBase
{
public RemapEditorVrm(
IEnumerable<SubAssetKey> keys,
Dictionary<ScriptedImporter.SourceAssetIdentifier, UnityEngine.Object> externalObjectMap) : base(keys, externalObjectMap)
IEnumerable<SubAssetKey> 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<VRM10Object>();
DrawRemapGUI<VRM10Object>(importer.GetExternalObjectMap());
// expressions
DrawRemapGUI<VRM10Expression>();
DrawRemapGUI<VRM10Expression>(importer.GetExternalObjectMap());
if (GUILayout.Button("Clear"))
{

View File

@ -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

View File

@ -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();
}