mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-14 06:50:19 -05:00
RemapEditorBase constructor
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
using UnityEditor.AssetImporters;
|
||||
#else
|
||||
@@ -16,8 +17,8 @@ namespace UniGLTF
|
||||
GlbScriptedImporter m_importer;
|
||||
GltfParser m_parser;
|
||||
|
||||
RemapEditorMaterial m_materialEditor = new RemapEditorMaterial();
|
||||
RemapEditorAnimation m_animationEditor = new RemapEditorAnimation();
|
||||
RemapEditorMaterial m_materialEditor;
|
||||
RemapEditorAnimation m_animationEditor;
|
||||
|
||||
public override void OnEnable()
|
||||
{
|
||||
@@ -26,6 +27,13 @@ namespace UniGLTF
|
||||
m_importer = target as GlbScriptedImporter;
|
||||
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);
|
||||
}
|
||||
|
||||
enum Tabs
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
using UnityEditor.AssetImporters;
|
||||
#else
|
||||
@@ -16,8 +17,8 @@ namespace UniGLTF
|
||||
GltfScriptedImporter m_importer;
|
||||
GltfParser m_parser;
|
||||
|
||||
RemapEditorMaterial m_materialEditor = new RemapEditorMaterial();
|
||||
RemapEditorAnimation m_animationEditor = new RemapEditorAnimation();
|
||||
RemapEditorMaterial m_materialEditor;
|
||||
RemapEditorAnimation m_animationEditor;
|
||||
|
||||
public override void OnEnable()
|
||||
{
|
||||
@@ -26,6 +27,13 @@ namespace UniGLTF
|
||||
m_importer = target as GltfScriptedImporter;
|
||||
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);
|
||||
}
|
||||
|
||||
enum Tabs
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
@@ -8,8 +10,13 @@ using VRMShaders;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public class RemapEditorAnimation: RemapEditorBase
|
||||
public class RemapEditorAnimation : RemapEditorBase
|
||||
{
|
||||
public RemapEditorAnimation(
|
||||
IEnumerable<SubAssetKey> keys,
|
||||
Dictionary<ScriptedImporter.SourceAssetIdentifier, UnityEngine.Object> externalObjectMap) : base(keys, externalObjectMap)
|
||||
{ }
|
||||
|
||||
public void OnGUI(ScriptedImporter importer, GltfParser parser)
|
||||
{
|
||||
var hasExternal = importer.GetExternalObjectMap().Any(x => x.Value is AnimationClip);
|
||||
@@ -21,7 +28,7 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
|
||||
DrawRemapGUI<AnimationClip>(importer, AnimationImporterUtil.EnumerateSubAssetKeys(parser.GLTF));
|
||||
DrawRemapGUI<AnimationClip>();
|
||||
|
||||
if (GUILayout.Button("Clear"))
|
||||
{
|
||||
@@ -58,6 +65,6 @@ namespace UniGLTF
|
||||
}
|
||||
|
||||
AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Experimental.AssetImporters;
|
||||
using VRMShaders;
|
||||
@@ -7,6 +9,50 @@ namespace UniGLTF
|
||||
{
|
||||
public abstract class RemapEditorBase
|
||||
{
|
||||
public struct SubAssetPair
|
||||
{
|
||||
public readonly SubAssetKey Key;
|
||||
public readonly UnityEngine.Object Object;
|
||||
|
||||
public SubAssetPair(SubAssetKey key, UnityEngine.Object o)
|
||||
{
|
||||
Key = key;
|
||||
Object = o;
|
||||
}
|
||||
|
||||
public void Deconstruct(out SubAssetKey key, out UnityEngine.Object value)
|
||||
{
|
||||
key = Key;
|
||||
value = Object;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remap 対象は、このエディタのライフサイクル中に不変
|
||||
///
|
||||
/// apply, clear 時には ScriptedImporter は reimport され、新しい引数で new される
|
||||
///
|
||||
/// </summary>
|
||||
SubAssetPair[] m_keyValues;
|
||||
|
||||
protected RemapEditorBase(
|
||||
IEnumerable<SubAssetKey> keys,
|
||||
Dictionary<ScriptedImporter.SourceAssetIdentifier, UnityEngine.Object> externalObjectMap)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
void RemapAndReload<T>(ScriptedImporter self, UnityEditor.AssetImporter.SourceAssetIdentifier sourceAssetIdentifier, T obj) where T : UnityEngine.Object
|
||||
{
|
||||
self.AddRemap(sourceAssetIdentifier, obj);
|
||||
@@ -14,13 +60,17 @@ namespace UniGLTF
|
||||
AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate);
|
||||
}
|
||||
|
||||
protected void DrawRemapGUI<T>(ScriptedImporter importer, IEnumerable<SubAssetKey> keys) where T : UnityEngine.Object
|
||||
protected void DrawRemapGUI<T>() where T : UnityEngine.Object
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
{
|
||||
var map = importer.GetExternalObjectMap();
|
||||
foreach (var key in keys)
|
||||
foreach (var (key, value) in m_keyValues)
|
||||
{
|
||||
if (!typeof(T).IsAssignableFrom(key.Type))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(key.Name))
|
||||
{
|
||||
continue;
|
||||
@@ -28,12 +78,11 @@ namespace UniGLTF
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.PrefixLabel(key.Name);
|
||||
map.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)
|
||||
{
|
||||
// update
|
||||
RemapAndReload(importer, new AssetImporter.SourceAssetIdentifier(key.Type, key.Name), asset);
|
||||
// RemapAndReload(importer, new AssetImporter.SourceAssetIdentifier(key.Type, key.Name), asset);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
@@ -17,11 +17,16 @@ namespace UniGLTF
|
||||
/// <summary>
|
||||
/// Material, Texture の Remap, Extract
|
||||
/// </summary>
|
||||
public class RemapEditorMaterial: RemapEditorBase
|
||||
public class RemapEditorMaterial : RemapEditorBase
|
||||
{
|
||||
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 void OnGUI(ScriptedImporter importer, GltfParser parser, ITextureDescriptorGenerator textureDescriptorGenerator, Func<string, string> textureDir, Func<string, string> materialDir)
|
||||
{
|
||||
var hasExternal = importer.GetExternalObjectMap().Any(x => x.Value is Material || x.Value is Texture2D);
|
||||
@@ -39,13 +44,13 @@ namespace UniGLTF
|
||||
s_foldMaterials = EditorGUILayout.Foldout(s_foldMaterials, "Remapped Materials");
|
||||
if (s_foldMaterials)
|
||||
{
|
||||
DrawRemapGUI<UnityEngine.Material>(importer, parser.GLTF.materials.Select(x => new SubAssetKey(typeof(Material), x.name)));
|
||||
DrawRemapGUI<UnityEngine.Material>();
|
||||
}
|
||||
|
||||
s_foldTextures = EditorGUILayout.Foldout(s_foldTextures, "Remapped Textures");
|
||||
if (s_foldTextures)
|
||||
{
|
||||
DrawRemapGUI<UnityEngine.Texture>(importer, textureDescriptorGenerator.Get().GetEnumerable().Select(x => x.SubAssetKey));
|
||||
DrawRemapGUI<UnityEngine.Texture>();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Clear"))
|
||||
|
||||
@@ -14,8 +14,13 @@ using UnityEditor.Experimental.AssetImporters;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public class RemapEditorVrm: RemapEditorBase
|
||||
public class RemapEditorVrm : RemapEditorBase
|
||||
{
|
||||
public RemapEditorVrm(
|
||||
IEnumerable<SubAssetKey> keys,
|
||||
Dictionary<ScriptedImporter.SourceAssetIdentifier, UnityEngine.Object> externalObjectMap) : base(keys, externalObjectMap)
|
||||
{ }
|
||||
|
||||
public void OnGUI(ScriptedImporter importer, GltfParser parser, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm)
|
||||
{
|
||||
var hasExternal = importer.GetExternalObjectMap().Any(x => x.Value is VRM10Object || x.Value is VRM10Expression);
|
||||
@@ -28,10 +33,10 @@ namespace UniVRM10
|
||||
}
|
||||
|
||||
// meta
|
||||
DrawRemapGUI<VRM10Object>(importer, new SubAssetKey[] { VRM10Object.SubAssetKey });
|
||||
DrawRemapGUI<VRM10Object>();
|
||||
|
||||
// expressions
|
||||
DrawRemapGUI<VRM10Expression>(importer, vrm.Expressions.Select(x => ExpressionKey.CreateFromVrm10(x).SubAssetKey));
|
||||
DrawRemapGUI<VRM10Expression>();
|
||||
|
||||
if (GUILayout.Button("Clear"))
|
||||
{
|
||||
|
||||
@@ -3,6 +3,8 @@ using UnityEngine;
|
||||
using UniGLTF;
|
||||
using System.IO;
|
||||
using UniGLTF.MeshUtility;
|
||||
using System.Linq;
|
||||
using VRMShaders;
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
using UnityEditor.AssetImporters;
|
||||
#else
|
||||
@@ -20,8 +22,8 @@ namespace UniVRM10
|
||||
VrmLib.Model m_model;
|
||||
UniGLTF.Extensions.VRMC_vrm.VRMC_vrm m_vrm;
|
||||
|
||||
RemapEditorMaterial m_materialEditor = new RemapEditorMaterial();
|
||||
RemapEditorVrm m_vrmEditor = new RemapEditorVrm();
|
||||
RemapEditorMaterial m_materialEditor;
|
||||
RemapEditorVrm m_vrmEditor;
|
||||
|
||||
string m_message;
|
||||
|
||||
@@ -40,6 +42,14 @@ namespace UniVRM10
|
||||
m_vrm = result.Vrm;
|
||||
m_parser = result.Parser;
|
||||
m_model = ModelReader.Read(result.Parser);
|
||||
|
||||
var externalObjectMap = 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);
|
||||
var expressionSubAssetKeys = m_vrm.Expressions.Select(x => ExpressionKey.CreateFromVrm10(x).SubAssetKey);
|
||||
m_vrmEditor = new RemapEditorVrm(new[] { VRM10Object.SubAssetKey }.Concat(expressionSubAssetKeys), externalObjectMap);
|
||||
}
|
||||
|
||||
enum Tabs
|
||||
|
||||
Reference in New Issue
Block a user