mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-04-22 23:18:01 -05:00
ExpressionAvatar は 独立した ScriptableObject をやめる (#916)
* ExpressionAvatar is MonoBehaviour * fix controller editor
This commit is contained in:
parent
06559cf188
commit
22871e992d
|
|
@ -39,15 +39,13 @@ namespace UniVRM10
|
|||
void OnEnable()
|
||||
{
|
||||
m_target = (VRM10Controller)target;
|
||||
if (m_target.Expression.ExpressionAvatar != null && m_target.Expression.ExpressionAvatar.Clips != null)
|
||||
{
|
||||
m_expressionKeyWeights = m_target.Expression.ExpressionAvatar.Clips.ToDictionary(x => ExpressionKey.CreateFromClip(x), x => 0.0f);
|
||||
m_sliders = m_target.Expression.ExpressionAvatar.Clips
|
||||
.Where(x => x != null)
|
||||
.Select(x => new ExpressionSlider(m_expressionKeyWeights, ExpressionKey.CreateFromClip(x)))
|
||||
.ToList()
|
||||
;
|
||||
}
|
||||
|
||||
m_expressionKeyWeights = m_target.Expression.Clips.ToDictionary(x => ExpressionKey.CreateFromClip(x), x => 0.0f);
|
||||
m_sliders = m_target.Expression.Clips
|
||||
.Where(x => x != null)
|
||||
.Select(x => new ExpressionSlider(m_expressionKeyWeights, ExpressionKey.CreateFromClip(x)))
|
||||
.ToList()
|
||||
;
|
||||
|
||||
if (m_target?.Meta.Meta != null)
|
||||
{
|
||||
|
|
@ -150,7 +148,7 @@ namespace UniVRM10
|
|||
break;
|
||||
|
||||
case Tabs.Expression:
|
||||
m_expression.RecursiveProperty();
|
||||
// m_expression.RecursiveProperty();
|
||||
ExpressionGUI();
|
||||
break;
|
||||
|
||||
|
|
@ -175,11 +173,6 @@ namespace UniVRM10
|
|||
EditorGUILayout.HelpBox("Enable when playing", MessageType.Info);
|
||||
}
|
||||
|
||||
if (m_target.Expression.ExpressionAvatar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_sliders != null)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
|
|
|
|||
|
|
@ -40,9 +40,6 @@ namespace UniVRM10
|
|||
// meta
|
||||
importer.DrawRemapGUI<VRM10MetaObject>(new SubAssetKey[] { VRM10MetaObject.SubAssetKey });
|
||||
|
||||
// expression avatar
|
||||
importer.DrawRemapGUI<VRM10ExpressionAvatar>(new SubAssetKey[] { VRM10ExpressionAvatar.SubAssetKey });
|
||||
|
||||
// expressions
|
||||
importer.DrawRemapGUI<VRM10Expression>(vrm.Expressions.Select(x => CreateKey(x).SubAssetKey));
|
||||
|
||||
|
|
|
|||
|
|
@ -10,11 +10,8 @@ using UnityEditor;
|
|||
|
||||
namespace UniVRM10
|
||||
{
|
||||
[CreateAssetMenu(menuName = "VRM10/ExpressionAvatar")]
|
||||
public sealed class VRM10ExpressionAvatar : ScriptableObject
|
||||
public sealed class VRM10ExpressionAvatar : MonoBehaviour
|
||||
{
|
||||
public static UniGLTF.SubAssetKey SubAssetKey => new UniGLTF.SubAssetKey(typeof(VRM10ExpressionAvatar), "ExpressionAvatar");
|
||||
|
||||
[SerializeField]
|
||||
public List<VRM10Expression> Clips = new List<VRM10Expression>();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,18 @@ namespace UniVRM10
|
|||
{
|
||||
public static IExpressionValidatorFactory ExpressionValidatorFactory = new DefaultExpressionValidator.Factory();
|
||||
|
||||
[SerializeField]
|
||||
public VRM10ExpressionAvatar ExpressionAvatar;
|
||||
VRM10ExpressionAvatar m_expressionAvatar;
|
||||
public IEnumerable<VRM10Expression> Clips
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_expressionAvatar == null || m_expressionAvatar.Clips == null)
|
||||
{
|
||||
return Enumerable.Empty<VRM10Expression>();
|
||||
}
|
||||
return m_expressionAvatar.Clips;
|
||||
}
|
||||
}
|
||||
|
||||
private List<ExpressionKey> _keys = new List<ExpressionKey>();
|
||||
private Dictionary<ExpressionKey, float> _inputWeights = new Dictionary<ExpressionKey, float>();
|
||||
|
|
@ -35,12 +45,13 @@ namespace UniVRM10
|
|||
|
||||
internal void Setup(Transform transform, ILookAtEyeDirectionProvider eyeDirectionProvider, ILookAtEyeDirectionApplicable eyeDirectionApplicable)
|
||||
{
|
||||
if (ExpressionAvatar == null)
|
||||
m_expressionAvatar = transform.GetComponent<VRM10ExpressionAvatar>();
|
||||
if (m_expressionAvatar == null)
|
||||
{
|
||||
#if VRM_DEVELOP
|
||||
if (m_debugCount++ == 0)
|
||||
{
|
||||
Debug.LogWarning($"{nameof(VRM10ControllerExpression)}.{nameof(ExpressionAvatar)} is null.");
|
||||
Debug.LogWarning($"{nameof(VRM10ControllerExpression)}.{nameof(m_expressionAvatar)} is null.");
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
|
|
@ -48,8 +59,8 @@ namespace UniVRM10
|
|||
|
||||
Restore();
|
||||
|
||||
_merger = new ExpressionMerger(ExpressionAvatar.Clips, transform);
|
||||
_keys = ExpressionAvatar.Clips.Select(ExpressionKey.CreateFromClip).ToList();
|
||||
_merger = new ExpressionMerger(m_expressionAvatar.Clips, transform);
|
||||
_keys = m_expressionAvatar.Clips.Select(ExpressionKey.CreateFromClip).ToList();
|
||||
var oldInputWeights = _inputWeights;
|
||||
_inputWeights = _keys.ToDictionary(x => x, x => 0f);
|
||||
foreach (var key in _keys)
|
||||
|
|
@ -58,7 +69,7 @@ namespace UniVRM10
|
|||
if (oldInputWeights.ContainsKey(key)) _inputWeights[key] = oldInputWeights[key];
|
||||
}
|
||||
_actualWeights = _keys.ToDictionary(x => x, x => 0f);
|
||||
_validator = ExpressionValidatorFactory.Create(ExpressionAvatar);
|
||||
_validator = ExpressionValidatorFactory.Create(m_expressionAvatar);
|
||||
_eyeDirectionProvider = eyeDirectionProvider;
|
||||
_eyeDirectionApplicable = eyeDirectionApplicable;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -542,7 +542,8 @@ namespace UniVRM10
|
|||
|
||||
void ExportExpression(UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm, VRM10Controller vrmController, Model model, ModelExporter converter)
|
||||
{
|
||||
if (vrmController?.Expression?.ExpressionAvatar?.Clips == null)
|
||||
var expressionAvatar = vrmController.GetComponent<VRM10ExpressionAvatar>();
|
||||
if (expressionAvatar?.Clips == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -567,7 +568,7 @@ namespace UniVRM10
|
|||
};
|
||||
|
||||
vrm.Expressions = new List<UniGLTF.Extensions.VRMC_vrm.Expression>();
|
||||
foreach (var e in vrmController.Expression.ExpressionAvatar.Clips)
|
||||
foreach (var e in expressionAvatar.Clips)
|
||||
{
|
||||
var vrmExpression = new UniGLTF.Extensions.VRMC_vrm.Expression
|
||||
{
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ namespace UniVRM10
|
|||
|
||||
UnityEngine.Avatar m_humanoid;
|
||||
VRM10MetaObject m_meta;
|
||||
VRM10ExpressionAvatar m_exressionAvatar;
|
||||
List<VRM10Expression> m_expressions = new List<VRM10Expression>();
|
||||
|
||||
protected override async Task OnLoadHierarchy(IAwaitCaller awaitCaller, Func<string, IDisposable> MeasureTime)
|
||||
{
|
||||
|
|
@ -291,40 +291,42 @@ namespace UniVRM10
|
|||
}
|
||||
|
||||
// expression
|
||||
if (m_externalMap.TryGetValue(VRM10ExpressionAvatar.SubAssetKey, out UnityEngine.Object expressionAvatar))
|
||||
if (vrm.Expressions != null)
|
||||
{
|
||||
controller.Expression.ExpressionAvatar = expressionAvatar as VRM10ExpressionAvatar;
|
||||
}
|
||||
else if (vrm.Expressions != null)
|
||||
{
|
||||
controller.Expression.ExpressionAvatar = ScriptableObject.CreateInstance<VRM10ExpressionAvatar>();
|
||||
|
||||
m_exressionAvatar = controller.Expression.ExpressionAvatar;
|
||||
m_exressionAvatar.name = VRM10ExpressionAvatar.SubAssetKey.Name;
|
||||
var expressionAvatar = Root.AddComponent<VRM10ExpressionAvatar>();
|
||||
|
||||
foreach (var expression in vrm.Expressions)
|
||||
{
|
||||
var clip = ScriptableObject.CreateInstance<UniVRM10.VRM10Expression>();
|
||||
clip.Preset = expression.Preset;
|
||||
clip.ExpressionName = expression.Name;
|
||||
clip.name = Key(expression).SubAssetKey.Name;
|
||||
clip.IsBinary = expression.IsBinary.GetValueOrDefault();
|
||||
clip.OverrideBlink = expression.OverrideBlink;
|
||||
clip.OverrideLookAt = expression.OverrideLookAt;
|
||||
clip.OverrideMouth = expression.OverrideMouth;
|
||||
VRM10Expression clip = default;
|
||||
if (m_externalMap.TryGetValue(Key(expression).SubAssetKey, out UnityEngine.Object expressionObj))
|
||||
{
|
||||
clip = expressionObj as VRM10Expression;
|
||||
}
|
||||
else
|
||||
{
|
||||
clip = ScriptableObject.CreateInstance<UniVRM10.VRM10Expression>();
|
||||
clip.Preset = expression.Preset;
|
||||
clip.ExpressionName = expression.Name;
|
||||
clip.name = Key(expression).SubAssetKey.Name;
|
||||
clip.IsBinary = expression.IsBinary.GetValueOrDefault();
|
||||
clip.OverrideBlink = expression.OverrideBlink;
|
||||
clip.OverrideLookAt = expression.OverrideLookAt;
|
||||
clip.OverrideMouth = expression.OverrideMouth;
|
||||
|
||||
clip.MorphTargetBindings = expression.MorphTargetBinds.Select(x => x.Build10(Root, m_map, m_model))
|
||||
.ToArray();
|
||||
clip.MaterialColorBindings = expression.MaterialColorBinds.Select(x => x.Build10(MaterialFactory.Materials))
|
||||
.Where(x => x.HasValue)
|
||||
.Select(x => x.Value)
|
||||
.ToArray();
|
||||
clip.MaterialUVBindings = expression.TextureTransformBinds.Select(x => x.Build10(MaterialFactory.Materials))
|
||||
.Where(x => x.HasValue)
|
||||
.Select(x => x.Value)
|
||||
.ToArray();
|
||||
clip.MorphTargetBindings = expression.MorphTargetBinds.Select(x => x.Build10(Root, m_map, m_model))
|
||||
.ToArray();
|
||||
clip.MaterialColorBindings = expression.MaterialColorBinds.Select(x => x.Build10(MaterialFactory.Materials))
|
||||
.Where(x => x.HasValue)
|
||||
.Select(x => x.Value)
|
||||
.ToArray();
|
||||
clip.MaterialUVBindings = expression.TextureTransformBinds.Select(x => x.Build10(MaterialFactory.Materials))
|
||||
.Where(x => x.HasValue)
|
||||
.Select(x => x.Value)
|
||||
.ToArray();
|
||||
m_expressions.Add(clip);
|
||||
}
|
||||
|
||||
m_exressionAvatar.Clips.Add(clip);
|
||||
expressionAvatar.Clips.Add(clip);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -606,21 +608,14 @@ namespace UniVRM10
|
|||
}
|
||||
}
|
||||
|
||||
if (m_exressionAvatar != null && m_exressionAvatar.Clips != null)
|
||||
foreach (var x in m_expressions)
|
||||
{
|
||||
foreach (var x in m_exressionAvatar.Clips)
|
||||
if (take(x))
|
||||
{
|
||||
if (take(x))
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
if (take(m_exressionAvatar))
|
||||
{
|
||||
m_exressionAvatar = null;
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
m_expressions.Clear();
|
||||
|
||||
// GLTF のリソース
|
||||
base.TransferOwnership(take);
|
||||
|
|
@ -639,13 +634,10 @@ namespace UniVRM10
|
|||
{
|
||||
destroy(m_meta);
|
||||
}
|
||||
if (m_exressionAvatar != null)
|
||||
|
||||
foreach (var clip in m_expressions)
|
||||
{
|
||||
foreach (var clip in m_exressionAvatar.Clips)
|
||||
{
|
||||
destroy(clip);
|
||||
}
|
||||
destroy(m_exressionAvatar);
|
||||
destroy(clip);
|
||||
}
|
||||
|
||||
base.Dispose();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user