mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-07-18 16:21:50 -05:00
meta, expressionAvatar, expression の extract を復旧
This commit is contained in:
parent
b0d9b5f54c
commit
b62c123b66
|
|
@ -14,30 +14,29 @@ using UnityEditor.Experimental.AssetImporters;
|
|||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public static class EditorMaterial
|
||||
public class TmpGuiEnable : IDisposable
|
||||
{
|
||||
class TmpGuiEnable : IDisposable
|
||||
bool m_backup;
|
||||
public TmpGuiEnable(bool enable)
|
||||
{
|
||||
bool m_backup;
|
||||
public TmpGuiEnable(bool enable)
|
||||
{
|
||||
m_backup = GUI.enabled;
|
||||
GUI.enabled = enable;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GUI.enabled = m_backup;
|
||||
}
|
||||
m_backup = GUI.enabled;
|
||||
GUI.enabled = enable;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GUI.enabled = m_backup;
|
||||
}
|
||||
}
|
||||
public static class EditorMaterial
|
||||
{
|
||||
static bool s_foldMaterials = true;
|
||||
static bool s_foldTextures = true;
|
||||
|
||||
public static void OnGUIMaterial(ScriptedImporter importer, GltfParser parser, EnumerateAllTexturesDistinctFunc enumTextures)
|
||||
public static void OnGUI(ScriptedImporter importer, GltfParser parser, EnumerateAllTexturesDistinctFunc enumTextures)
|
||||
{
|
||||
var canExtract = !importer.GetExternalObjectMap().Any(x => x.Value is Material || x.Value is Texture2D);
|
||||
using (new TmpGuiEnable(canExtract))
|
||||
var hasExternal = importer.GetExternalObjectMap().Any(x => x.Value is Material || x.Value is Texture2D);
|
||||
using (new TmpGuiEnable(!hasExternal))
|
||||
{
|
||||
if (GUILayout.Button("Extract Materials And Textures ..."))
|
||||
{
|
||||
|
|
@ -51,7 +50,7 @@ namespace UniGLTF
|
|||
s_foldMaterials = EditorGUILayout.Foldout(s_foldMaterials, "Remapped Materials");
|
||||
if (s_foldMaterials)
|
||||
{
|
||||
DrawRemapGUI<UnityEngine.Material>(importer, parser.GLTF.materials.Select(x => x.name));
|
||||
importer.DrawRemapGUI<UnityEngine.Material>(parser.GLTF.materials.Select(x => x.name));
|
||||
}
|
||||
|
||||
s_foldTextures = EditorGUILayout.Foldout(s_foldTextures, "Remapped Textures");
|
||||
|
|
@ -77,7 +76,7 @@ namespace UniGLTF
|
|||
})
|
||||
.Where(x => !string.IsNullOrEmpty(x))
|
||||
;
|
||||
DrawRemapGUI<UnityEngine.Texture2D>(importer, names);
|
||||
importer.DrawRemapGUI<UnityEngine.Texture2D>(names);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Clear"))
|
||||
|
|
@ -87,34 +86,6 @@ namespace UniGLTF
|
|||
}
|
||||
}
|
||||
|
||||
static void DrawRemapGUI<T>(ScriptedImporter importer, IEnumerable<string> names) where T : UnityEngine.Object
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
var map = importer.GetExternalObjectMap()
|
||||
.Select(x => (x.Key.name, x.Value as T))
|
||||
.Where(x => x.Item2 != null)
|
||||
.ToDictionary(x => x.Item1, x => x.Item2)
|
||||
;
|
||||
foreach (var name in names)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new System.ArgumentNullException();
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.PrefixLabel(name);
|
||||
map.TryGetValue(name, out T value);
|
||||
var asset = EditorGUILayout.ObjectField(value, typeof(T), true) as T;
|
||||
if (asset != value)
|
||||
{
|
||||
importer.SetExternalUnityObject(new AssetImporter.SourceAssetIdentifier(value), asset);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
public static void SetExternalUnityObject<T>(this ScriptedImporter self, UnityEditor.AssetImporter.SourceAssetIdentifier sourceAssetIdentifier, T obj) where T : UnityEngine.Object
|
||||
{
|
||||
self.AddRemap(sourceAssetIdentifier, obj);
|
||||
|
|
@ -157,28 +128,14 @@ namespace UniGLTF
|
|||
return;
|
||||
}
|
||||
var path = $"{Path.GetDirectoryName(importer.assetPath)}/{Path.GetFileNameWithoutExtension(importer.assetPath)}.Materials";
|
||||
var info = TextureExtractor.SafeCreateDirectory(path);
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
foreach (var asset in importer.GetSubAssets<Material>(importer.assetPath))
|
||||
{
|
||||
ExtractSubAsset(asset, $"{path}/{asset.name}.mat", false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ExtractSubAsset(UnityEngine.Object subAsset, string destinationPath, bool isForceUpdate)
|
||||
{
|
||||
string assetPath = AssetDatabase.GetAssetPath(subAsset);
|
||||
|
||||
var clone = UnityEngine.Object.Instantiate(subAsset);
|
||||
AssetDatabase.CreateAsset(clone, destinationPath);
|
||||
|
||||
var assetImporter = AssetImporter.GetAtPath(assetPath);
|
||||
assetImporter.AddRemap(new AssetImporter.SourceAssetIdentifier(clone), clone);
|
||||
|
||||
if (isForceUpdate)
|
||||
{
|
||||
AssetDatabase.WriteImportSettingsIfDirty(assetPath);
|
||||
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
|
||||
asset.ExtractSubAsset($"{path}/{asset.name}.mat", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ namespace UniGLTF
|
|||
break;
|
||||
|
||||
case Tabs.Materials:
|
||||
EditorMaterial.OnGUIMaterial(m_importer, m_parser, GltfTextureEnumerator.EnumerateAllTexturesDistinct);
|
||||
EditorMaterial.OnGUI(m_importer, m_parser, GltfTextureEnumerator.EnumerateAllTexturesDistinct);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ namespace UniGLTF
|
|||
break;
|
||||
|
||||
case Tabs.Materials:
|
||||
EditorMaterial.OnGUIMaterial(m_importer, m_parser, GltfTextureEnumerator.EnumerateAllTexturesDistinct);
|
||||
EditorMaterial.OnGUI(m_importer, m_parser, GltfTextureEnumerator.EnumerateAllTexturesDistinct);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,5 +31,60 @@ namespace UniGLTF
|
|||
.Where(x => x is T)
|
||||
.Select(x => x as T);
|
||||
}
|
||||
|
||||
public static void DrawRemapGUI<T>(this ScriptedImporter importer, IEnumerable<string> names) where T : UnityEngine.Object
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
{
|
||||
var map = importer.GetExternalObjectMap()
|
||||
.Select(x => (x.Key.name, x.Value as T))
|
||||
.Where(x => x.Item2 != null)
|
||||
.ToDictionary(x => x.Item1, x => x.Item2)
|
||||
;
|
||||
foreach (var name in names)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new System.ArgumentNullException();
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.PrefixLabel(name);
|
||||
map.TryGetValue(name, out T value);
|
||||
var asset = EditorGUILayout.ObjectField(value, typeof(T), true) as T;
|
||||
if (asset != value)
|
||||
{
|
||||
importer.SetExternalUnityObject(new AssetImporter.SourceAssetIdentifier(value), asset);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// subAsset を 指定された path に extract する
|
||||
/// </summary>
|
||||
/// <param name="subAsset"></param>
|
||||
/// <param name="destinationPath"></param>
|
||||
/// <param name="isForceUpdate"></param>
|
||||
public static void ExtractSubAsset(this UnityEngine.Object subAsset, string destinationPath, bool isForceUpdate)
|
||||
{
|
||||
string assetPath = AssetDatabase.GetAssetPath(subAsset);
|
||||
|
||||
// clone を path に出力
|
||||
var clone = UnityEngine.Object.Instantiate(subAsset);
|
||||
AssetDatabase.CreateAsset(clone, destinationPath);
|
||||
|
||||
// subAsset を clone に対して remap する
|
||||
var assetImporter = AssetImporter.GetAtPath(assetPath);
|
||||
assetImporter.AddRemap(new AssetImporter.SourceAssetIdentifier(clone), clone);
|
||||
|
||||
if (isForceUpdate)
|
||||
{
|
||||
AssetDatabase.WriteImportSettingsIfDirty(assetPath);
|
||||
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,15 +82,6 @@ namespace UniGLTF
|
|||
Textures.Add(targetPath, param);
|
||||
}
|
||||
|
||||
public static DirectoryInfo SafeCreateDirectory(string path)
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// * Texture(.png etc...)をディスクに書き出す
|
||||
|
|
|
|||
110
Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs
Normal file
110
Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using VRMShaders;
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
using UnityEditor.AssetImporters;
|
||||
#else
|
||||
using UnityEditor.Experimental.AssetImporters;
|
||||
#endif
|
||||
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static class EditorVrm
|
||||
{
|
||||
static ExpressionKey CreateKey(UniGLTF.Extensions.VRMC_vrm.Expression expression)
|
||||
{
|
||||
if (expression.Preset == UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.custom)
|
||||
{
|
||||
return ExpressionKey.CreateCustom(expression.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ExpressionKey.CreateFromPreset(expression.Preset);
|
||||
}
|
||||
}
|
||||
|
||||
public static void OnGUI(ScriptedImporter importer, GltfParser parser, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm)
|
||||
{
|
||||
var hasExternal = importer.GetExternalObjectMap().Any(x => x.Value is VRM10MetaObject || x.Value is VRM10ExpressionAvatar || x.Value is VRM10Expression);
|
||||
using (new TmpGuiEnable(!hasExternal))
|
||||
{
|
||||
if (GUILayout.Button("Extract Meta And Expressions ..."))
|
||||
{
|
||||
Extract(importer, parser);
|
||||
}
|
||||
}
|
||||
|
||||
// meta
|
||||
importer.DrawRemapGUI<VRM10MetaObject>(new string[] { VRM10MetaObject.ExtractKey });
|
||||
|
||||
// expression avatar
|
||||
importer.DrawRemapGUI<VRM10ExpressionAvatar>(new string[] { VRM10ExpressionAvatar.ExtractKey });
|
||||
|
||||
// expressions
|
||||
importer.DrawRemapGUI<VRM10Expression>(vrm.Expressions.Select(x => CreateKey(x).ExtractKey));
|
||||
|
||||
if (GUILayout.Button("Clear"))
|
||||
{
|
||||
importer.ClearExternalObjects<VRM10MetaObject>();
|
||||
importer.ClearExternalObjects<VRM10ExpressionAvatar>();
|
||||
importer.ClearExternalObjects<VRM10Expression>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SubAssetを外部ファイルに展開する
|
||||
/// </summary>
|
||||
public static void Extract(ScriptedImporter importer, GltfParser parser)
|
||||
{
|
||||
if (string.IsNullOrEmpty(importer.assetPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var path = $"{Path.GetDirectoryName(importer.assetPath)}/{Path.GetFileNameWithoutExtension(importer.assetPath)}.Extracted";
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
// meta
|
||||
{
|
||||
foreach (var asset in importer.GetSubAssets<VRM10MetaObject>(importer.assetPath))
|
||||
{
|
||||
asset.ExtractSubAsset($"{path}/{asset.name}.asset", false);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// expressions
|
||||
foreach (var asset in importer.GetSubAssets<VRM10Expression>(importer.assetPath))
|
||||
{
|
||||
asset.ExtractSubAsset($"{path}/{asset.name}.asset", false);
|
||||
}
|
||||
|
||||
// expressions
|
||||
foreach (var asset in importer.GetSubAssets<VRM10ExpressionAvatar>(importer.assetPath))
|
||||
{
|
||||
asset.ExtractSubAsset($"{path}/{asset.name}.asset", false);
|
||||
}
|
||||
|
||||
// external な expressionAvatar.Clips に 再代入する
|
||||
var expressionAvatar = importer.GetExternalObjectMap().Select(x => x.Value as VRM10ExpressionAvatar).FirstOrDefault(x => x != null);
|
||||
var expressions = importer.GetExternalObjectMap().Select(x => x.Value as VRM10Expression).Where(x => x != null).ToList();
|
||||
expressionAvatar.Clips = expressions;
|
||||
var avatarPath = AssetDatabase.GetAssetPath(expressionAvatar);
|
||||
if (!string.IsNullOrEmpty(avatarPath))
|
||||
{
|
||||
EditorUtility.SetDirty(expressionAvatar);
|
||||
AssetDatabase.WriteImportSettingsIfDirty(avatarPath);
|
||||
}
|
||||
}
|
||||
|
||||
AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs.meta
Normal file
11
Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a15559f8a5ba86841a1ef6e08d37569a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UniGLTF;
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
|
|
@ -14,14 +13,10 @@ namespace UniVRM10
|
|||
[CustomEditor(typeof(VrmScriptedImporter))]
|
||||
public class VrmScriptedImporterEditorGUI : ScriptedImporterEditor
|
||||
{
|
||||
// const string TextureDirName = "Textures";
|
||||
// const string MaterialDirName = "Materials";
|
||||
// const string MetaDirName = "MetaObjects";
|
||||
// const string ExpressionDirName = "Expressions";
|
||||
|
||||
VrmScriptedImporter m_importer;
|
||||
GltfParser m_parser;
|
||||
VrmLib.Model m_model;
|
||||
UniGLTF.Extensions.VRMC_vrm.VRMC_vrm m_vrm;
|
||||
|
||||
public override void OnEnable()
|
||||
{
|
||||
|
|
@ -33,7 +28,10 @@ namespace UniVRM10
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(m_parser.GLTF.extensions, out m_vrm))
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_model = VrmLoader.CreateVrmModel(m_parser);
|
||||
}
|
||||
|
||||
|
|
@ -59,95 +57,17 @@ namespace UniVRM10
|
|||
case Tabs.Materials:
|
||||
if (m_parser != null)
|
||||
{
|
||||
EditorMaterial.OnGUIMaterial(m_importer, m_parser, Vrm10MToonMaterialImporter.EnumerateAllTexturesDistinct);
|
||||
EditorMaterial.OnGUI(m_importer, m_parser, Vrm10MToonMaterialImporter.EnumerateAllTexturesDistinct);
|
||||
}
|
||||
break;
|
||||
|
||||
case Tabs.Vrm:
|
||||
if (m_parser != null)
|
||||
{
|
||||
EditorVrm.OnGUI(m_importer, m_parser, m_vrm);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// var importer = target as VrmScriptedImporter;
|
||||
|
||||
// EditorGUILayout.LabelField("Extract settings");
|
||||
|
||||
// EditorGUILayout.BeginHorizontal();
|
||||
// EditorGUILayout.PrefixLabel("Materials And Textures");
|
||||
// GUI.enabled = !(importer.GetExternalUnityObjects<UnityEngine.Material>().Any()
|
||||
// && importer.GetExternalUnityObjects<UnityEngine.Texture2D>().Any());
|
||||
// if (GUILayout.Button("Extract"))
|
||||
// {
|
||||
// importer.ExtractMaterialsAndTextures();
|
||||
// }
|
||||
// GUI.enabled = !GUI.enabled;
|
||||
// if (GUILayout.Button("Clear"))
|
||||
// {
|
||||
// importer.ClearExternalObjects<UnityEngine.Material>();
|
||||
// importer.ClearExternalObjects<UnityEngine.Texture2D>();
|
||||
// }
|
||||
// GUI.enabled = true;
|
||||
// EditorGUILayout.EndHorizontal();
|
||||
|
||||
// EditorGUILayout.BeginHorizontal();
|
||||
// EditorGUILayout.PrefixLabel("Meta");
|
||||
// GUI.enabled = !importer.GetExternalUnityObjects<UniVRM10.VRM10MetaObject>().Any();
|
||||
// if (GUILayout.Button("Extract"))
|
||||
// {
|
||||
// importer.ExtractMeta();
|
||||
// }
|
||||
// GUI.enabled = !GUI.enabled;
|
||||
// if (GUILayout.Button("Clear"))
|
||||
// {
|
||||
// importer.ClearExternalObjects<UniVRM10.VRM10MetaObject>();
|
||||
// }
|
||||
// GUI.enabled = true;
|
||||
// EditorGUILayout.EndHorizontal();
|
||||
|
||||
// EditorGUILayout.BeginHorizontal();
|
||||
// EditorGUILayout.PrefixLabel("Expressions");
|
||||
// GUI.enabled = !(importer.GetExternalUnityObjects<UniVRM10.VRM10ExpressionAvatar>().Any()
|
||||
// && importer.GetExternalUnityObjects<UniVRM10.VRM10Expression>().Any());
|
||||
// if (GUILayout.Button("Extract"))
|
||||
// {
|
||||
// importer.ExtractExpressions();
|
||||
// }
|
||||
// GUI.enabled = !GUI.enabled;
|
||||
// if (GUILayout.Button("Clear"))
|
||||
// {
|
||||
// importer.ClearExternalObjects<UniVRM10.VRM10ExpressionAvatar>();
|
||||
// importer.ClearExternalObjects<UniVRM10.VRM10Expression>();
|
||||
// }
|
||||
// GUI.enabled = true;
|
||||
// EditorGUILayout.EndHorizontal();
|
||||
|
||||
// // ObjectMap
|
||||
// DrawRemapGUI<UnityEngine.Material>("Material Remap", importer);
|
||||
// DrawRemapGUI<UnityEngine.Texture2D>("Texture Remap", importer);
|
||||
// DrawRemapGUI<UniVRM10.VRM10MetaObject>("Meta Remap", importer);
|
||||
// DrawRemapGUI<UniVRM10.VRM10ExpressionAvatar>("ExpressionAvatar Remap", importer);
|
||||
// DrawRemapGUI<UniVRM10.VRM10Expression>("Expression Remap", importer);
|
||||
|
||||
// base.OnInspectorGUI();
|
||||
// }
|
||||
|
||||
// private void DrawRemapGUI<T>(string title, VrmScriptedImporter importer) where T : UnityEngine.Object
|
||||
// {
|
||||
// EditorGUILayout.Foldout(_isOpen, title);
|
||||
// EditorGUI.indentLevel++;
|
||||
// var objects = importer.GetExternalObjectMap().Where(x => x.Key.type == typeof(T));
|
||||
// foreach (var obj in objects)
|
||||
// {
|
||||
// EditorGUILayout.BeginHorizontal();
|
||||
// EditorGUILayout.PrefixLabel(obj.Key.name);
|
||||
// var asset = EditorGUILayout.ObjectField(obj.Value, obj.Key.type, true) as T;
|
||||
// if (asset != obj.Value)
|
||||
// {
|
||||
// importer.SetExternalUnityObject(obj.Key, asset);
|
||||
// }
|
||||
// EditorGUILayout.EndHorizontal();
|
||||
// }
|
||||
// EditorGUI.indentLevel--;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,124 +85,5 @@ namespace UniVRM10
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
// public void ExtractMeta()
|
||||
// {
|
||||
// this.ExtractAssets<UniVRM10.VRM10MetaObject>(MetaDirName, ".asset");
|
||||
// var metaObject = this.GetExternalUnityObjects<UniVRM10.VRM10MetaObject>().FirstOrDefault();
|
||||
// var metaObjectPath = AssetDatabase.GetAssetPath(metaObject.Value);
|
||||
// if (!string.IsNullOrEmpty(metaObjectPath))
|
||||
// {
|
||||
// EditorUtility.SetDirty(metaObject.Value);
|
||||
// AssetDatabase.WriteImportSettingsIfDirty(metaObjectPath);
|
||||
// }
|
||||
// AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
|
||||
// }
|
||||
|
||||
// public void ExtractExpressions()
|
||||
// {
|
||||
// this.ExtractAssets<UniVRM10.VRM10ExpressionAvatar>(ExpressionDirName, ".asset");
|
||||
// this.ExtractAssets<UniVRM10.VRM10Expression>(ExpressionDirName, ".asset");
|
||||
|
||||
// var expressionAvatar = this.GetExternalUnityObjects<UniVRM10.VRM10ExpressionAvatar>().FirstOrDefault();
|
||||
// var expressions = this.GetExternalUnityObjects<UniVRM10.VRM10Expression>();
|
||||
|
||||
// expressionAvatar.Value.Clips = expressions.Select(x => x.Value).ToList();
|
||||
// var avatarPath = AssetDatabase.GetAssetPath(expressionAvatar.Value);
|
||||
// if (!string.IsNullOrEmpty(avatarPath))
|
||||
// {
|
||||
// EditorUtility.SetDirty(expressionAvatar.Value);
|
||||
// AssetDatabase.WriteImportSettingsIfDirty(avatarPath);
|
||||
// }
|
||||
|
||||
// AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
|
||||
// }
|
||||
|
||||
// public Dictionary<string, T> GetExternalUnityObjects<T>() where T : UnityEngine.Object
|
||||
// {
|
||||
// return this.GetExternalObjectMap().Where(x => x.Key.type == typeof(T)).ToDictionary(x => x.Key.name, x => (T)x.Value);
|
||||
// }
|
||||
|
||||
// public void SetExternalUnityObject<T>(UnityEditor.AssetImporter.SourceAssetIdentifier sourceAssetIdentifier, T obj) where T : UnityEngine.Object
|
||||
// {
|
||||
// this.AddRemap(sourceAssetIdentifier, obj);
|
||||
// AssetDatabase.WriteImportSettingsIfDirty(this.assetPath);
|
||||
// AssetDatabase.ImportAsset(this.assetPath, ImportAssetOptions.ForceUpdate);
|
||||
// }
|
||||
|
||||
// public static void ClearExternalObjects<T>(this ScriptedImporter importer) where T : UnityEngine.Object
|
||||
// {
|
||||
// foreach (var extarnalObject in importer.GetExternalObjectMap().Where(x => x.Key.type == typeof(T)))
|
||||
// {
|
||||
// importer.RemoveRemap(extarnalObject.Key);
|
||||
// }
|
||||
|
||||
// AssetDatabase.WriteImportSettingsIfDirty(importer.assetPath);
|
||||
// AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate);
|
||||
// }
|
||||
|
||||
// public static void ClearExtarnalObjects(this ScriptedImporter importer)
|
||||
// {
|
||||
// foreach (var extarnalObject in importer.GetExternalObjectMap())
|
||||
// {
|
||||
// importer.RemoveRemap(extarnalObject.Key);
|
||||
// }
|
||||
|
||||
// AssetDatabase.WriteImportSettingsIfDirty(importer.assetPath);
|
||||
// AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate);
|
||||
// }
|
||||
|
||||
// private static T GetSubAsset<T>(this ScriptedImporter importer, string assetPath) where T : UnityEngine.Object
|
||||
// {
|
||||
// return importer.GetSubAssets<T>(assetPath)
|
||||
// .FirstOrDefault();
|
||||
// }
|
||||
|
||||
// public static IEnumerable<T> GetSubAssets<T>(this ScriptedImporter importer, string assetPath) where T : UnityEngine.Object
|
||||
// {
|
||||
// return AssetDatabase
|
||||
// .LoadAllAssetsAtPath(assetPath)
|
||||
// .Where(x => AssetDatabase.IsSubAsset(x))
|
||||
// .Where(x => x is T)
|
||||
// .Select(x => x as T);
|
||||
// }
|
||||
|
||||
// private static void ExtractFromAsset(UnityEngine.Object subAsset, string destinationPath, bool isForceUpdate)
|
||||
// {
|
||||
// string assetPath = AssetDatabase.GetAssetPath(subAsset);
|
||||
|
||||
// var clone = UnityEngine.Object.Instantiate(subAsset);
|
||||
// AssetDatabase.CreateAsset(clone, destinationPath);
|
||||
|
||||
// var assetImporter = AssetImporter.GetAtPath(assetPath);
|
||||
// assetImporter.AddRemap(new AssetImporter.SourceAssetIdentifier(subAsset), clone);
|
||||
|
||||
// if (isForceUpdate)
|
||||
// {
|
||||
// AssetDatabase.WriteImportSettingsIfDirty(assetPath);
|
||||
// AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public static void ExtractAssets<T>(this ScriptedImporter importer, string dirName, string extension) where T : UnityEngine.Object
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(importer.assetPath))
|
||||
// return;
|
||||
|
||||
// var subAssets = importer.GetSubAssets<T>(importer.assetPath);
|
||||
|
||||
// var path = string.Format("{0}/{1}.{2}",
|
||||
// Path.GetDirectoryName(importer.assetPath),
|
||||
// Path.GetFileNameWithoutExtension(importer.assetPath),
|
||||
// dirName
|
||||
// );
|
||||
|
||||
// var info = importer.SafeCreateDirectory(path);
|
||||
|
||||
// foreach (var asset in subAssets)
|
||||
// {
|
||||
// ExtractFromAsset(asset, string.Format("{0}/{1}{2}", path, asset.name, extension), false);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,6 +193,11 @@ namespace UniVRM10
|
|||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
if (VRMVersion.IsNewer(m_exporterVersion.stringValue))
|
||||
|
|
|
|||
|
|
@ -21,13 +21,13 @@ namespace UniVRM10
|
|||
/// Preset of this ExpressionKey.
|
||||
/// </summary>
|
||||
public readonly UniGLTF.Extensions.VRMC_vrm.ExpressionPreset Preset;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Custom Name of this ExpressionKey.
|
||||
/// This works if Preset was Custom.
|
||||
/// </summary>
|
||||
public readonly string Name;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Id for comparison of ExpressionKey.
|
||||
/// </summary>
|
||||
|
|
@ -172,6 +172,13 @@ namespace UniVRM10
|
|||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public string ExtractKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"Expression.{this}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace UniVRM10
|
|||
[CreateAssetMenu(menuName = "VRM10/ExpressionAvatar")]
|
||||
public sealed class VRM10ExpressionAvatar : ScriptableObject
|
||||
{
|
||||
public const string ExtractKey = ".ExpressionAvatar";
|
||||
public const string ExtractKey = "ExpressionAvatar";
|
||||
|
||||
[SerializeField]
|
||||
public List<VRM10Expression> Clips = new List<VRM10Expression>();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace UniVRM10
|
|||
[CreateAssetMenu(menuName = "VRM10/MetaObject")]
|
||||
public class VRM10MetaObject : ScriptableObject
|
||||
{
|
||||
public const string ExtractKey = ".Meta";
|
||||
public const string ExtractKey = "Meta";
|
||||
|
||||
[SerializeField]
|
||||
public string ExporterVersion;
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@ namespace UniVRM10
|
|||
/// for SubAssetName
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string ExtractName(this Expression expression)
|
||||
public static string ExtractKey(this Expression expression)
|
||||
{
|
||||
ExpressionKey key =
|
||||
(expression.Preset == ExpressionPreset.custom)
|
||||
? ExpressionKey.CreateCustom(expression.Name)
|
||||
: ExpressionKey.CreateFromPreset(expression.Preset)
|
||||
;
|
||||
return $"Expression.{key}";
|
||||
return key.ExtractKey;
|
||||
}
|
||||
|
||||
public static UniVRM10.MorphTargetBinding Build10(this MorphTargetBind bind, GameObject root, RuntimeUnityBuilder.ModelMap loader, VrmLib.Model model)
|
||||
|
|
|
|||
|
|
@ -18,10 +18,17 @@ namespace UniVRM10
|
|||
|
||||
UniGLTF.Extensions.VRMC_vrm.VRMC_vrm m_vrm;
|
||||
|
||||
List<(string, UnityEngine.Object)> m_external = new List<(string, UnityEngine.Object)>();
|
||||
|
||||
public RuntimeUnityBuilder(UniGLTF.GltfParser parser, IEnumerable<(string, UnityEngine.Object)> externalObjectMap = null) : base(parser, externalObjectMap)
|
||||
{
|
||||
m_model = VrmLoader.CreateVrmModel(parser);
|
||||
|
||||
if (externalObjectMap != null)
|
||||
{
|
||||
m_external.AddRange(externalObjectMap);
|
||||
}
|
||||
|
||||
// for `VRMC_materials_mtoon`
|
||||
this.GltfMaterialImporter.GltfMaterialParamProcessors.Insert(0, Vrm10MToonMaterialImporter.TryCreateParam);
|
||||
|
||||
|
|
@ -229,7 +236,17 @@ namespace UniVRM10
|
|||
async Task LoadVrmAsync(IAwaitCaller awaitCaller, VRM10Controller controller, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm)
|
||||
{
|
||||
// meta
|
||||
if (vrm.Meta != null)
|
||||
controller.Meta = m_external.Select(x => x.Item2 as VRM10MetaObject).FirstOrDefault(x => x != null);
|
||||
// external meta != null のとき m_meta は null になる
|
||||
if (controller.Meta != null)
|
||||
{
|
||||
// texture の 取得
|
||||
if (Vrm10MToonMaterialImporter.TryGetMetaThumbnailTextureImportParam(Parser, vrm, out VRMShaders.TextureImportParam param))
|
||||
{
|
||||
var texture = await TextureFactory.GetTextureAsync(param);
|
||||
}
|
||||
}
|
||||
else if (vrm.Meta != null)
|
||||
{
|
||||
var src = vrm.Meta;
|
||||
m_meta = ScriptableObject.CreateInstance<VRM10MetaObject>();
|
||||
|
|
@ -269,7 +286,8 @@ namespace UniVRM10
|
|||
}
|
||||
|
||||
// expression
|
||||
if (vrm.Expressions != null)
|
||||
controller.Expression.ExpressionAvatar = m_external.Select(x => x.Item2 as VRM10ExpressionAvatar).FirstOrDefault(x => x != null);
|
||||
if (controller.Expression.ExpressionAvatar == null && vrm.Expressions != null)
|
||||
{
|
||||
controller.Expression.ExpressionAvatar = ScriptableObject.CreateInstance<VRM10ExpressionAvatar>();
|
||||
|
||||
|
|
@ -281,7 +299,7 @@ namespace UniVRM10
|
|||
var clip = ScriptableObject.CreateInstance<UniVRM10.VRM10Expression>();
|
||||
clip.Preset = expression.Preset;
|
||||
clip.ExpressionName = expression.Name;
|
||||
clip.name = expression.ExtractName();
|
||||
clip.name = expression.ExtractKey();
|
||||
clip.IsBinary = expression.IsBinary.GetValueOrDefault();
|
||||
clip.OverrideBlink = expression.OverrideBlink;
|
||||
clip.OverrideLookAt = expression.OverrideLookAt;
|
||||
|
|
@ -555,22 +573,28 @@ namespace UniVRM10
|
|||
m_humanoid = null;
|
||||
}
|
||||
|
||||
if (take(m_meta))
|
||||
if (m_meta != null)
|
||||
{
|
||||
m_meta = null;
|
||||
}
|
||||
|
||||
foreach (var x in m_exressionAvatar.Clips)
|
||||
{
|
||||
if (take(x))
|
||||
if (take(m_meta))
|
||||
{
|
||||
// do nothing
|
||||
m_meta = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (take(m_exressionAvatar))
|
||||
if (m_exressionAvatar != null)
|
||||
{
|
||||
m_exressionAvatar = null;
|
||||
foreach (var x in m_exressionAvatar.Clips)
|
||||
{
|
||||
if (take(x))
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
if (take(m_exressionAvatar))
|
||||
{
|
||||
m_exressionAvatar = null;
|
||||
}
|
||||
}
|
||||
|
||||
// GLTF のリソース
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user