JsonSchema を更新してコードを再生成した

https://github.com/vrm-c/vrm-specification/pull/296
This commit is contained in:
ousttrue
2021-07-02 19:30:00 +09:00
parent ea642495cd
commit fa460f0031
27 changed files with 8496 additions and 302 deletions

View File

@@ -26,7 +26,7 @@ namespace UniVRM10.Samples
}
}
IEnumerator RoutineNest(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset preset, float velocity, float wait)
IEnumerator RoutineNest(ExpressionPreset preset, float velocity, float wait)
{
for (var value = 0.0f; value <= 1.0f; value += velocity)
{
@@ -52,11 +52,11 @@ namespace UniVRM10.Samples
var velocity = 0.1f;
yield return RoutineNest(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.aa, velocity, m_wait);
yield return RoutineNest(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ih, velocity, m_wait);
yield return RoutineNest(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ou, velocity, m_wait);
yield return RoutineNest(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ee, velocity, m_wait);
yield return RoutineNest(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.oh, velocity, m_wait);
yield return RoutineNest(ExpressionPreset.aa, velocity, m_wait);
yield return RoutineNest(ExpressionPreset.ih, velocity, m_wait);
yield return RoutineNest(ExpressionPreset.ou, velocity, m_wait);
yield return RoutineNest(ExpressionPreset.ee, velocity, m_wait);
yield return RoutineNest(ExpressionPreset.oh, velocity, m_wait);
}
}

View File

@@ -72,10 +72,10 @@ namespace UniVRM10.Samples
break;
}
m_controller.Vrm.Expression.SetWeight(ExpressionKey.CreateFromPreset(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blink), value);
m_controller.Vrm.Expression.SetWeight(ExpressionKey.CreateFromPreset(ExpressionPreset.blink), value);
yield return null;
}
m_controller.Vrm.Expression.SetWeight(ExpressionKey.CreateFromPreset(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blink), 1.0f);
m_controller.Vrm.Expression.SetWeight(ExpressionKey.CreateFromPreset(ExpressionPreset.blink), 1.0f);
// wait...
yield return new WaitForSeconds(ClosingTime);
@@ -91,10 +91,10 @@ namespace UniVRM10.Samples
break;
}
m_controller.Vrm.Expression.SetWeight(ExpressionKey.CreateFromPreset(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blink), value);
m_controller.Vrm.Expression.SetWeight(ExpressionKey.CreateFromPreset(ExpressionPreset.blink), value);
yield return null;
}
m_controller.Vrm.Expression.SetWeight(ExpressionKey.CreateFromPreset(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blink), 0);
m_controller.Vrm.Expression.SetWeight(ExpressionKey.CreateFromPreset(ExpressionPreset.blink), 0);
}
}

View File

@@ -4,6 +4,8 @@ using UniGLTF;
using System.IO;
using UniGLTF.MeshUtility;
using System.Linq;
using System.Collections.Generic;
using VRMShaders;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
#else
@@ -24,6 +26,31 @@ namespace UniVRM10
Vrm10Parser.Result m_result;
IEnumerable<SubAssetKey> EnumerateExpressinKeys(UniGLTF.Extensions.VRMC_vrm.Expressions expressions)
{
if (expressions?.Preset?.Happy != null) yield return ExpressionKey.Happy.SubAssetKey;
if (expressions?.Preset?.Angry != null) yield return ExpressionKey.Angry.SubAssetKey;
if (expressions?.Preset?.Sad != null) yield return ExpressionKey.Sad.SubAssetKey;
if (expressions?.Preset?.Relaxed != null) yield return ExpressionKey.Relaxed.SubAssetKey;
if (expressions?.Preset?.Surprised != null) yield return ExpressionKey.Surprised.SubAssetKey;
if (expressions?.Preset?.Aa != null) yield return ExpressionKey.Aa.SubAssetKey;
if (expressions?.Preset?.Ih != null) yield return ExpressionKey.Ih.SubAssetKey;
if (expressions?.Preset?.Ou != null) yield return ExpressionKey.Ou.SubAssetKey;
if (expressions?.Preset?.Ee != null) yield return ExpressionKey.Ee.SubAssetKey;
if (expressions?.Preset?.Oh != null) yield return ExpressionKey.Oh.SubAssetKey;
if (expressions?.Preset?.Blink != null) yield return ExpressionKey.Blink.SubAssetKey;
if (expressions?.Preset?.BlinkLeft != null) yield return ExpressionKey.BlinkLeft.SubAssetKey;
if (expressions?.Preset?.BlinkRight != null) yield return ExpressionKey.BlinkRight.SubAssetKey;
if (expressions?.Preset?.LookUp != null) yield return ExpressionKey.LookUp.SubAssetKey;
if (expressions?.Preset?.LookDown != null) yield return ExpressionKey.LookDown.SubAssetKey;
if (expressions?.Preset?.LookLeft != null) yield return ExpressionKey.LookLeft.SubAssetKey;
if (expressions?.Preset?.LookRight != null) yield return ExpressionKey.LookRight.SubAssetKey;
foreach (var kv in expressions.Custom)
{
yield return ExpressionKey.CreateCustom(kv.Key).SubAssetKey;
}
}
public override void OnEnable()
{
base.OnEnable();
@@ -42,8 +69,7 @@ namespace UniVRM10
var materialKeys = m_result.Data.GLTF.materials.Select((x, i) => generator.Get(m_result.Data, i).SubAssetKey);
var textureKeys = new GltfTextureDescriptorGenerator(m_result.Data).Get().GetEnumerable().Select(x => x.SubAssetKey);
m_materialEditor = new RemapEditorMaterial(materialKeys.Concat(textureKeys), GetEditorMap, SetEditorMap);
var expressionSubAssetKeys = m_result.Vrm.Expressions.Select(x => ExpressionKey.CreateFromVrm10(x).SubAssetKey);
m_vrmEditor = new RemapEditorVrm(new[] { VRM10Object.SubAssetKey }.Concat(expressionSubAssetKeys), GetEditorMap, SetEditorMap);
m_vrmEditor = new RemapEditorVrm(new[] { VRM10Object.SubAssetKey }.Concat(EnumerateExpressinKeys(m_result.Vrm.Expressions)), GetEditorMap, SetEditorMap);
}
enum Tabs

View File

@@ -11,8 +11,8 @@ namespace UniVRM10
/// <summary>
/// Enum.ToString() のGC回避用キャッシュ
/// </summary>
private static readonly Dictionary<UniGLTF.Extensions.VRMC_vrm.ExpressionPreset, string> PresetNameDictionary =
new Dictionary<UniGLTF.Extensions.VRMC_vrm.ExpressionPreset, string>();
private static readonly Dictionary<ExpressionPreset, string> PresetNameDictionary =
new Dictionary<ExpressionPreset, string>();
/// <summary>
/// ExpressionPreset と同名の名前を持つ独自に追加した Expression を区別するための prefix
@@ -22,7 +22,7 @@ namespace UniVRM10
/// <summary>
/// Preset of this ExpressionKey.
/// </summary>
public readonly UniGLTF.Extensions.VRMC_vrm.ExpressionPreset Preset;
public readonly ExpressionPreset Preset;
/// <summary>
/// Custom Name of this ExpressionKey.
@@ -41,9 +41,9 @@ namespace UniVRM10
{
switch (Preset)
{
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blink:
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blinkLeft:
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blinkRight:
case ExpressionPreset.blink:
case ExpressionPreset.blinkLeft:
case ExpressionPreset.blinkRight:
return true;
}
return false;
@@ -56,10 +56,10 @@ namespace UniVRM10
{
switch (Preset)
{
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookUp:
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookDown:
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookLeft:
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookRight:
case ExpressionPreset.lookUp:
case ExpressionPreset.lookDown:
case ExpressionPreset.lookLeft:
case ExpressionPreset.lookRight:
return true;
}
return false;
@@ -72,11 +72,11 @@ namespace UniVRM10
{
switch (Preset)
{
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.aa:
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ih:
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ou:
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ee:
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.oh:
case ExpressionPreset.aa:
case ExpressionPreset.ih:
case ExpressionPreset.ou:
case ExpressionPreset.ee:
case ExpressionPreset.oh:
return true;
}
return false;
@@ -85,11 +85,11 @@ namespace UniVRM10
public bool IsProcedual => IsBlink || IsLookAt || IsMouth;
public ExpressionKey(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset preset, string customName = null)
public ExpressionKey(ExpressionPreset preset, string customName = null)
{
Preset = preset;
if (Preset != UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.custom)
if (Preset != ExpressionPreset.custom)
{
if (PresetNameDictionary.ContainsKey((Preset)))
{
@@ -105,7 +105,7 @@ namespace UniVRM10
{
if (string.IsNullOrEmpty(customName))
{
throw new ArgumentException("name is required for UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.Custom");
throw new ArgumentException("name is required for ExpressionPreset.Custom");
}
_id = $"{UnknownPresetPrefix}{customName}";
@@ -115,10 +115,10 @@ namespace UniVRM10
public static ExpressionKey CreateCustom(String key)
{
return new ExpressionKey(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.custom, key);
return new ExpressionKey(ExpressionPreset.custom, key);
}
public static ExpressionKey CreateFromPreset(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset preset)
public static ExpressionKey CreateFromPreset(ExpressionPreset preset)
{
return new ExpressionKey(preset);
}
@@ -133,17 +133,25 @@ namespace UniVRM10
return new ExpressionKey(clip.Preset, clip.ExpressionName);
}
public static ExpressionKey CreateFromVrm10(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 ExpressionKey Happy => CreateFromPreset(ExpressionPreset.happy);
public static ExpressionKey Angry => CreateFromPreset(ExpressionPreset.angry);
public static ExpressionKey Sad => CreateFromPreset(ExpressionPreset.sad);
public static ExpressionKey Relaxed => CreateFromPreset(ExpressionPreset.relaxed);
public static ExpressionKey Surprised => CreateFromPreset(ExpressionPreset.surprised);
public static ExpressionKey Aa => CreateFromPreset(ExpressionPreset.aa);
public static ExpressionKey Ih => CreateFromPreset(ExpressionPreset.ih);
public static ExpressionKey Ou => CreateFromPreset(ExpressionPreset.ou);
public static ExpressionKey Ee => CreateFromPreset(ExpressionPreset.ee);
public static ExpressionKey Oh => CreateFromPreset(ExpressionPreset.oh);
public static ExpressionKey Blink => CreateFromPreset(ExpressionPreset.blink);
public static ExpressionKey BlinkLeft => CreateFromPreset(ExpressionPreset.blinkLeft);
public static ExpressionKey BlinkRight => CreateFromPreset(ExpressionPreset.blinkRight);
public static ExpressionKey LookUp => CreateFromPreset(ExpressionPreset.lookUp);
public static ExpressionKey LookDown => CreateFromPreset(ExpressionPreset.lookDown);
public static ExpressionKey LookLeft => CreateFromPreset(ExpressionPreset.lookLeft);
public static ExpressionKey LookRight => CreateFromPreset(ExpressionPreset.lookRight);
public static ExpressionKey Neutral => CreateFromPreset(ExpressionPreset.neutral);
public override string ToString()
{

View File

@@ -0,0 +1,25 @@
namespace UniVRM10
{
public enum ExpressionPreset
{
custom,
happy,
angry,
sad,
relaxed,
surprised,
aa,
ih,
ou,
ee,
oh,
blink,
blinkLeft,
blinkRight,
lookUp,
lookDown,
lookLeft,
lookRight,
neutral,
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 959cd7efa29185648bb7996d11eb2a14
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -16,7 +16,7 @@ namespace UniVRM10
/// ExpressionPreset を識別する。 Unknown の場合は、 ExpressionName で識別する
/// </summary>
[SerializeField]
public UniGLTF.Extensions.VRMC_vrm.ExpressionPreset Preset;
public ExpressionPreset Preset;
/// <summary>
/// 対象メッシュの Expression を操作する
@@ -67,7 +67,7 @@ namespace UniVRM10
void OnValidate()
{
if (Preset == UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.custom)
if (Preset == ExpressionPreset.custom)
{
if (string.IsNullOrEmpty(ExpressionName))
{

View File

@@ -104,24 +104,24 @@ namespace UniVRM10
{
switch (clip.Preset)
{
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.happy: Happy = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.angry: Angry = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.sad: Sad = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.relaxed: Relaxed = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.surprised: Surprised = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.aa: Aa = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ih: Ih = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ou: Ou = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ee: Ee = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.oh: Oh = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blink: Blink = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blinkLeft: BlinkLeft = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blinkRight: BlinkRight = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookUp: LookUp = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookDown: LookDown = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookLeft: LookLeft = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookRight: LookRight = clip; break;
case UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.neutral: Neutral = clip; break;
case ExpressionPreset.happy: Happy = clip; break;
case ExpressionPreset.angry: Angry = clip; break;
case ExpressionPreset.sad: Sad = clip; break;
case ExpressionPreset.relaxed: Relaxed = clip; break;
case ExpressionPreset.surprised: Surprised = clip; break;
case ExpressionPreset.aa: Aa = clip; break;
case ExpressionPreset.ih: Ih = clip; break;
case ExpressionPreset.ou: Ou = clip; break;
case ExpressionPreset.ee: Ee = clip; break;
case ExpressionPreset.oh: Oh = clip; break;
case ExpressionPreset.blink: Blink = clip; break;
case ExpressionPreset.blinkLeft: BlinkLeft = clip; break;
case ExpressionPreset.blinkRight: BlinkRight = clip; break;
case ExpressionPreset.lookUp: LookUp = clip; break;
case ExpressionPreset.lookDown: LookDown = clip; break;
case ExpressionPreset.lookLeft: LookLeft = clip; break;
case ExpressionPreset.lookRight: LookRight = clip; break;
case ExpressionPreset.neutral: Neutral = clip; break;
default: CustomClips.Add(clip); break;
}
}
@@ -242,8 +242,8 @@ namespace UniVRM10
// /// </summary>
// public void CreateDefaultPreset()
// {
// foreach (var preset in ((UniGLTF.Extensions.VRMC_vrm.ExpressionPreset[])Enum.GetValues(typeof(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset)))
// .Where(x => x != UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.custom)
// foreach (var preset in ((ExpressionPreset[])Enum.GetValues(typeof(ExpressionPreset)))
// .Where(x => x != ExpressionPreset.custom)
// )
// {
// CreateDefaultPreset(preset);

View File

@@ -47,6 +47,11 @@ public static VRMC_node_constraint Deserialize(JsonNode parsed)
continue;
}
if(key=="specVersion"){
value.SpecVersion = kv.Value.GetString();
continue;
}
if(key=="constraint"){
value.Constraint = Deserialize_Constraint(kv.Value);
continue;

View File

@@ -128,6 +128,9 @@ namespace UniGLTF.Extensions.VRMC_node_constraint
// Application-specific data.
public object Extras;
// Specification version of VRMC_node_constraint
public string SpecVersion;
// Contains position, rotation, or aim
public Constraint Constraint;
}

View File

@@ -43,6 +43,11 @@ public static void Serialize(JsonFormatter f, VRMC_node_constraint value)
(value.Extras as glTFExtension).Serialize(f);
}
if(!string.IsNullOrEmpty(value.SpecVersion)){
f.Key("specVersion");
f.Value(value.SpecVersion);
}
if(value.Constraint!=null){
f.Key("constraint");
Serialize_Constraint(f, value.Constraint);

View File

@@ -47,8 +47,8 @@ public static VRMC_materials_mtoon Deserialize(JsonNode parsed)
continue;
}
if(key=="version"){
value.Version = kv.Value.GetString();
if(key=="specVersion"){
value.SpecVersion = kv.Value.GetString();
continue;
}

View File

@@ -43,9 +43,9 @@ public static void Serialize(JsonFormatter f, VRMC_materials_mtoon value)
(value.Extras as glTFExtension).Serialize(f);
}
if(!string.IsNullOrEmpty(value.Version)){
f.Key("version");
f.Value(value.Version);
if(!string.IsNullOrEmpty(value.SpecVersion)){
f.Key("specVersion");
f.Value(value.SpecVersion);
}
if(value.TransparentWithZWrite.HasValue){

View File

@@ -47,6 +47,11 @@ public static VRMC_springBone Deserialize(JsonNode parsed)
continue;
}
if(key=="specVersion"){
value.SpecVersion = kv.Value.GetString();
continue;
}
if(key=="colliders"){
value.Colliders = Deserialize_Colliders(kv.Value);
continue;

View File

@@ -124,6 +124,9 @@ namespace UniGLTF.Extensions.VRMC_springBone
// Application-specific data.
public object Extras;
// Specification version of VRMC_springBone
public string SpecVersion;
// An array of colliders.
public List<Collider> Colliders;

View File

@@ -43,17 +43,22 @@ public static void Serialize(JsonFormatter f, VRMC_springBone value)
(value.Extras as glTFExtension).Serialize(f);
}
if(value.Colliders!=null&&value.Colliders.Count()>=0){
if(!string.IsNullOrEmpty(value.SpecVersion)){
f.Key("specVersion");
f.Value(value.SpecVersion);
}
if(value.Colliders!=null&&value.Colliders.Count()>=1){
f.Key("colliders");
Serialize_Colliders(f, value.Colliders);
}
if(value.ColliderGroups!=null&&value.ColliderGroups.Count()>=0){
if(value.ColliderGroups!=null&&value.ColliderGroups.Count()>=1){
f.Key("colliderGroups");
Serialize_ColliderGroups(f, value.ColliderGroups);
}
if(value.Springs!=null&&value.Springs.Count()>=0){
if(value.Springs!=null&&value.Springs.Count()>=1){
f.Key("springs");
Serialize_Springs(f, value.Springs);
}
@@ -290,12 +295,12 @@ public static void Serialize_Springs_ITEM(JsonFormatter f, Spring value)
f.Value(value.Name);
}
if(value.Joints!=null&&value.Joints.Count()>=0){
if(value.Joints!=null&&value.Joints.Count()>=1){
f.Key("joints");
__springs_ITEM_Serialize_Joints(f, value.Joints);
}
if(value.ColliderGroups!=null&&value.ColliderGroups.Count()>=0){
if(value.ColliderGroups!=null&&value.ColliderGroups.Count()>=1){
f.Key("colliderGroups");
__springs_ITEM_Serialize_ColliderGroups(f, value.ColliderGroups);
}

File diff suppressed because it is too large Load Diff

View File

@@ -69,6 +69,9 @@ namespace UniGLTF.Extensions.VRMC_vrm
// The index to the thumbnail image of the model in gltf.images
public int? ThumbnailImage;
// A URL towards the license document this model refers to
public string LicenseUrl;
// A person who can perform as an avatar with this model
public AvatarPermissionType AvatarPermission;
@@ -346,7 +349,7 @@ namespace UniGLTF.Extensions.VRMC_vrm
// Yaw and pitch angles ( degrees ) between the head bone forward vector and the eye gaze LookAt vector
public float? InputMaxValue;
// Degree for LookAtType.bone , Weight for LookAtType.blendShape
// Degree for type.bone, Weight for type.expressions
public float? OutputScale;
}
@@ -376,30 +379,6 @@ namespace UniGLTF.Extensions.VRMC_vrm
public LookAtRangeMap RangeMapVerticalUp;
}
public enum ExpressionPreset
{
custom,
happy,
angry,
sad,
relaxed,
surprised,
aa,
ih,
ou,
ee,
oh,
blink,
blinkLeft,
blinkRight,
lookUp,
lookDown,
lookLeft,
lookRight,
neutral,
}
public class MorphTargetBind
{
// Dictionary object with extension-specific objects.
@@ -479,12 +458,6 @@ namespace UniGLTF.Extensions.VRMC_vrm
// Application-specific data.
public object Extras;
// Use only if the preset is custom. Unique within the model
public string Name;
// Functions of Expression
public ExpressionPreset Preset;
// Specify a morph target
public List<MorphTargetBind> MorphTargetBinds;
@@ -507,6 +480,75 @@ namespace UniGLTF.Extensions.VRMC_vrm
public ExpressionOverrideType OverrideMouth;
}
public class Preset
{
// Definition of expression by weighted animation
public Expression Happy;
// Definition of expression by weighted animation
public Expression Angry;
// Definition of expression by weighted animation
public Expression Sad;
// Definition of expression by weighted animation
public Expression Relaxed;
// Definition of expression by weighted animation
public Expression Surprised;
// Definition of expression by weighted animation
public Expression Aa;
// Definition of expression by weighted animation
public Expression Ih;
// Definition of expression by weighted animation
public Expression Ou;
// Definition of expression by weighted animation
public Expression Ee;
// Definition of expression by weighted animation
public Expression Oh;
// Definition of expression by weighted animation
public Expression Blink;
// Definition of expression by weighted animation
public Expression BlinkLeft;
// Definition of expression by weighted animation
public Expression BlinkRight;
// Definition of expression by weighted animation
public Expression LookUp;
// Definition of expression by weighted animation
public Expression LookDown;
// Definition of expression by weighted animation
public Expression LookLeft;
// Definition of expression by weighted animation
public Expression LookRight;
}
public class Expressions
{
// Dictionary object with extension-specific objects.
public object Extensions;
// Application-specific data.
public object Extras;
// Preset expressions
public Preset Preset;
// Custom expressions
public Dictionary<string, Expression> Custom;
}
public class VRMC_vrm
{
public const string ExtensionName = "VRMC_vrm";
@@ -517,7 +559,7 @@ namespace UniGLTF.Extensions.VRMC_vrm
// Application-specific data.
public object Extras;
// Specification version of the VRM
// Specification version of VRMC_vrm
public string SpecVersion;
// Meta informations of the VRM model
@@ -532,7 +574,7 @@ namespace UniGLTF.Extensions.VRMC_vrm
// Eye gaze control
public LookAt LookAt;
// Definitions of expressions
public List<Expression> Expressions;
// Definition of expressions
public Expressions Expressions;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -10,6 +10,8 @@ namespace UniVRM10
{
public static class Vrm10MToonMaterialExporter
{
const string MTOON_SPEC_VERSION = "1.0-draft";
public static bool TryExportMaterialAsMToon(Material src, ITextureExporter textureExporter, out glTFMaterial dst)
{
try
@@ -30,7 +32,7 @@ namespace UniVRM10
// vrmc_materials_mtoon ext
var mtoon = new UniGLTF.Extensions.VRMC_materials_mtoon.VRMC_materials_mtoon();
mtoon.Version = "";
mtoon.SpecVersion = MTOON_SPEC_VERSION;
// Rendering
dst.alphaMode = ExportAlphaMode(context.AlphaMode);

View File

@@ -558,11 +558,11 @@ namespace UniVRM10
};
}
void ExportExpression(UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm, VRM10Controller vrmController, Model model, ModelExporter converter)
UniGLTF.Extensions.VRMC_vrm.Expression ExportExpression(VRM10Expression e, VRM10Controller vrmController, Model model, ModelExporter converter)
{
if (vrmController?.Vrm?.Expression?.Clips == null)
if (e == null)
{
return;
return null;
}
Func<string, int> getIndexFromRelativePath = relativePath =>
@@ -571,6 +571,19 @@ namespace UniVRM10
var node = converter.Nodes[rendererNode.gameObject];
return model.Nodes.IndexOf(node);
};
var vrmExpression = new UniGLTF.Extensions.VRMC_vrm.Expression
{
// Preset = e.Preset,
// Name = e.ExpressionName,
IsBinary = e.IsBinary,
OverrideBlink = e.OverrideBlink,
OverrideLookAt = e.OverrideLookAt,
OverrideMouth = e.OverrideMouth,
MorphTargetBinds = new List<UniGLTF.Extensions.VRMC_vrm.MorphTargetBind>(),
MaterialColorBinds = new List<UniGLTF.Extensions.VRMC_vrm.MaterialColorBind>(),
TextureTransformBinds = new List<UniGLTF.Extensions.VRMC_vrm.TextureTransformBind>(),
};
Func<string, int> getIndexFromMaterialName = materialName =>
{
for (int i = 0; i < model.Materials.Count; ++i)
@@ -584,56 +597,73 @@ namespace UniVRM10
throw new KeyNotFoundException();
};
vrm.Expressions = new List<UniGLTF.Extensions.VRMC_vrm.Expression>();
foreach (var e in vrmController.Vrm.Expression.Clips)
foreach (var b in e.MorphTargetBindings)
{
var vrmExpression = new UniGLTF.Extensions.VRMC_vrm.Expression
try
{
Preset = e.Preset,
Name = e.ExpressionName,
IsBinary = e.IsBinary,
OverrideBlink = e.OverrideBlink,
OverrideLookAt = e.OverrideLookAt,
OverrideMouth = e.OverrideMouth,
MorphTargetBinds = new List<UniGLTF.Extensions.VRMC_vrm.MorphTargetBind>(),
MaterialColorBinds = new List<UniGLTF.Extensions.VRMC_vrm.MaterialColorBind>(),
TextureTransformBinds = new List<UniGLTF.Extensions.VRMC_vrm.TextureTransformBind>(),
};
foreach (var b in e.MorphTargetBindings)
{
try
{
vrmExpression.MorphTargetBinds.Add(ExportMorphTargetBinding(b, getIndexFromRelativePath));
}
catch (Exception ex)
{
Debug.LogWarning(ex);
}
vrmExpression.MorphTargetBinds.Add(ExportMorphTargetBinding(b, getIndexFromRelativePath));
}
foreach (var b in e.MaterialColorBindings)
catch (Exception ex)
{
try
{
vrmExpression.MaterialColorBinds.Add(ExportMaterialColorBinding(b, getIndexFromMaterialName));
}
catch (Exception ex)
{
Debug.LogWarning(ex);
}
Debug.LogWarning(ex);
}
foreach (var b in e.MaterialUVBindings)
{
try
{
vrmExpression.TextureTransformBinds.Add(ExportTextureTransformBinding(b, getIndexFromMaterialName));
}
catch (Exception ex)
{
Debug.LogWarning(ex);
}
}
vrm.Expressions.Add(vrmExpression);
}
foreach (var b in e.MaterialColorBindings)
{
try
{
vrmExpression.MaterialColorBinds.Add(ExportMaterialColorBinding(b, getIndexFromMaterialName));
}
catch (Exception ex)
{
Debug.LogWarning(ex);
}
}
foreach (var b in e.MaterialUVBindings)
{
try
{
vrmExpression.TextureTransformBinds.Add(ExportTextureTransformBinding(b, getIndexFromMaterialName));
}
catch (Exception ex)
{
Debug.LogWarning(ex);
}
}
return vrmExpression;
}
void ExportExpression(UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm, VRM10Controller vrmController, Model model, ModelExporter converter)
{
if (vrmController?.Vrm?.Expression?.Clips == null)
{
return;
}
vrm.Expressions = new UniGLTF.Extensions.VRMC_vrm.Expressions
{
Preset = new UniGLTF.Extensions.VRMC_vrm.Preset
{
Happy = ExportExpression(vrmController.Vrm.Expression.Happy, vrmController, model, converter),
Angry = ExportExpression(vrmController.Vrm.Expression.Angry, vrmController, model, converter),
Sad = ExportExpression(vrmController.Vrm.Expression.Sad, vrmController, model, converter),
Relaxed = ExportExpression(vrmController.Vrm.Expression.Relaxed, vrmController, model, converter),
Surprised = ExportExpression(vrmController.Vrm.Expression.Surprised, vrmController, model, converter),
Aa = ExportExpression(vrmController.Vrm.Expression.Aa, vrmController, model, converter),
Ih = ExportExpression(vrmController.Vrm.Expression.Ih, vrmController, model, converter),
Ou = ExportExpression(vrmController.Vrm.Expression.Ou, vrmController, model, converter),
Ee = ExportExpression(vrmController.Vrm.Expression.Ee, vrmController, model, converter),
Oh = ExportExpression(vrmController.Vrm.Expression.Oh, vrmController, model, converter),
Blink = ExportExpression(vrmController.Vrm.Expression.Blink, vrmController, model, converter),
BlinkLeft = ExportExpression(vrmController.Vrm.Expression.BlinkLeft, vrmController, model, converter),
BlinkRight = ExportExpression(vrmController.Vrm.Expression.BlinkRight, vrmController, model, converter),
LookUp = ExportExpression(vrmController.Vrm.Expression.LookUp, vrmController, model, converter),
LookDown = ExportExpression(vrmController.Vrm.Expression.LookDown, vrmController, model, converter),
LookLeft = ExportExpression(vrmController.Vrm.Expression.LookLeft, vrmController, model, converter),
LookRight = ExportExpression(vrmController.Vrm.Expression.LookRight, vrmController, model, converter),
},
Custom = vrmController.Vrm.Expression.CustomClips.ToDictionary(c => c.ExpressionName, c => ExportExpression(c, vrmController, model, converter)),
};
}
int? ExportMeta(UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm, VRM10ObjectMeta meta)

View File

@@ -244,16 +244,42 @@ namespace UniVRM10
await LoadConstraintAsync(awaitCaller, controller);
}
static ExpressionKey Key(UniGLTF.Extensions.VRMC_vrm.Expression e)
VRM10Expression GetOrLoadExpression(in SubAssetKey key, UniGLTF.Extensions.VRMC_vrm.Expression expression)
{
if (e.Preset == UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.custom)
if (expression == null)
{
return ExpressionKey.CreateCustom(e.Name);
return null;
}
VRM10Expression clip = default;
if (m_externalMap.TryGetValue(key, out UnityEngine.Object expressionObj))
{
clip = expressionObj as VRM10Expression;
}
else
{
return ExpressionKey.CreateFromPreset(e.Preset);
clip = ScriptableObject.CreateInstance<UniVRM10.VRM10Expression>();
clip.Preset = ExpressionPreset.custom;
clip.ExpressionName = key.Name;
clip.name = key.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();
m_expressions.Add(clip);
}
return clip;
}
async Task<VRM10Object> LoadVrmAsync(IAwaitCaller awaitCaller, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrmExtension)
@@ -310,38 +336,31 @@ namespace UniVRM10
// expression
if (vrmExtension.Expressions != null)
{
foreach (var expression in vrmExtension.Expressions)
vrm.Expression.Happy = GetOrLoadExpression(ExpressionKey.Happy.SubAssetKey, vrmExtension.Expressions.Preset.Happy);
vrm.Expression.Angry = GetOrLoadExpression(ExpressionKey.Angry.SubAssetKey, vrmExtension.Expressions.Preset.Angry);
vrm.Expression.Sad = GetOrLoadExpression(ExpressionKey.Sad.SubAssetKey, vrmExtension.Expressions.Preset.Sad);
vrm.Expression.Relaxed = GetOrLoadExpression(ExpressionKey.Relaxed.SubAssetKey, vrmExtension.Expressions.Preset.Relaxed);
vrm.Expression.Surprised = GetOrLoadExpression(ExpressionKey.Surprised.SubAssetKey, vrmExtension.Expressions.Preset.Surprised);
vrm.Expression.Aa = GetOrLoadExpression(ExpressionKey.Aa.SubAssetKey, vrmExtension.Expressions.Preset.Aa);
vrm.Expression.Ih = GetOrLoadExpression(ExpressionKey.Ih.SubAssetKey, vrmExtension.Expressions.Preset.Ih);
vrm.Expression.Ou = GetOrLoadExpression(ExpressionKey.Ou.SubAssetKey, vrmExtension.Expressions.Preset.Ou);
vrm.Expression.Ee = GetOrLoadExpression(ExpressionKey.Ee.SubAssetKey, vrmExtension.Expressions.Preset.Ee);
vrm.Expression.Oh = GetOrLoadExpression(ExpressionKey.Oh.SubAssetKey, vrmExtension.Expressions.Preset.Oh);
vrm.Expression.Blink = GetOrLoadExpression(ExpressionKey.Blink.SubAssetKey, vrmExtension.Expressions.Preset.Blink);
vrm.Expression.BlinkLeft = GetOrLoadExpression(ExpressionKey.BlinkLeft.SubAssetKey, vrmExtension.Expressions.Preset.BlinkLeft);
vrm.Expression.BlinkRight = GetOrLoadExpression(ExpressionKey.BlinkRight.SubAssetKey, vrmExtension.Expressions.Preset.BlinkRight);
vrm.Expression.LookUp = GetOrLoadExpression(ExpressionKey.LookUp.SubAssetKey, vrmExtension.Expressions.Preset.LookUp);
vrm.Expression.LookDown = GetOrLoadExpression(ExpressionKey.LookDown.SubAssetKey, vrmExtension.Expressions.Preset.LookDown);
vrm.Expression.LookLeft = GetOrLoadExpression(ExpressionKey.LookLeft.SubAssetKey, vrmExtension.Expressions.Preset.LookLeft);
vrm.Expression.LookRight = GetOrLoadExpression(ExpressionKey.LookRight.SubAssetKey, vrmExtension.Expressions.Preset.LookRight);
foreach (var (name, expression) in vrmExtension.Expressions.Custom)
{
VRM10Expression clip = default;
if (m_externalMap.TryGetValue(Key(expression).SubAssetKey, out UnityEngine.Object expressionObj))
var key = ExpressionKey.CreateCustom(name);
var clip = GetOrLoadExpression(key.SubAssetKey, expression);
if (clip != null)
{
clip = expressionObj as VRM10Expression;
vrm.Expression.AddClip(clip);
}
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();
m_expressions.Add(clip);
}
vrm.Expression.AddClip(clip);
}
}

View File

@@ -45,7 +45,37 @@ namespace UniVRM10
// blendshape (optional)
if (vrm0.TryGet("blendShapeMaster", out JsonNode vrm0BlendShape))
{
vrm1.Expressions = MigrationVrmExpression.Migrate(gltf, vrm0BlendShape).ToList();
vrm1.Expressions = new UniGLTF.Extensions.VRMC_vrm.Expressions
{
Preset = new UniGLTF.Extensions.VRMC_vrm.Preset(),
Custom = new Dictionary<string, UniGLTF.Extensions.VRMC_vrm.Expression>(),
};
foreach (var (preset, customName, expression) in MigrationVrmExpression.Migrate(gltf, vrm0BlendShape))
{
switch (preset)
{
case ExpressionPreset.happy: vrm1.Expressions.Preset.Happy = expression; break;
case ExpressionPreset.angry: vrm1.Expressions.Preset.Angry = expression; break;
case ExpressionPreset.sad: vrm1.Expressions.Preset.Sad = expression; break;
case ExpressionPreset.relaxed: vrm1.Expressions.Preset.Relaxed = expression; break;
case ExpressionPreset.surprised: vrm1.Expressions.Preset.Surprised = expression; break;
case ExpressionPreset.aa: vrm1.Expressions.Preset.Aa = expression; break;
case ExpressionPreset.ih: vrm1.Expressions.Preset.Ih = expression; break;
case ExpressionPreset.ou: vrm1.Expressions.Preset.Ou = expression; break;
case ExpressionPreset.ee: vrm1.Expressions.Preset.Ee = expression; break;
case ExpressionPreset.oh: vrm1.Expressions.Preset.Oh = expression; break;
case ExpressionPreset.blink: vrm1.Expressions.Preset.Blink = expression; break;
case ExpressionPreset.blinkLeft: vrm1.Expressions.Preset.BlinkLeft = expression; break;
case ExpressionPreset.blinkRight: vrm1.Expressions.Preset.BlinkRight = expression; break;
case ExpressionPreset.lookUp: vrm1.Expressions.Preset.LookUp = expression; break;
case ExpressionPreset.lookDown: vrm1.Expressions.Preset.LookDown = expression; break;
case ExpressionPreset.lookLeft: vrm1.Expressions.Preset.LookLeft = expression; break;
case ExpressionPreset.lookRight: vrm1.Expressions.Preset.LookRight = expression; break;
case ExpressionPreset.neutral: vrm1.Expressions.Custom[customName] = expression; break;
case ExpressionPreset.custom: vrm1.Expressions.Custom[customName] = expression; break;
default: throw new NotImplementedException();
}
}
}
// lookat & firstperson (optional)

View File

@@ -7,35 +7,35 @@ namespace UniVRM10
{
public static class MigrationVrmExpression
{
static UniGLTF.Extensions.VRMC_vrm.ExpressionPreset ToPreset(JsonNode json)
static ExpressionPreset ToPreset(JsonNode json)
{
switch (json.GetString().ToLower())
{
case "unknown": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.custom;
case "unknown": return ExpressionPreset.custom;
// https://github.com/vrm-c/vrm-specification/issues/185
case "neutral": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.neutral;
case "neutral": return ExpressionPreset.neutral;
case "a": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.aa;
case "i": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ih;
case "u": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ou;
case "e": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.ee;
case "o": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.oh;
case "a": return ExpressionPreset.aa;
case "i": return ExpressionPreset.ih;
case "u": return ExpressionPreset.ou;
case "e": return ExpressionPreset.ee;
case "o": return ExpressionPreset.oh;
case "blink": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blink;
case "blink_l": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blinkLeft;
case "blink_r": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.blinkRight;
case "blink": return ExpressionPreset.blink;
case "blink_l": return ExpressionPreset.blinkLeft;
case "blink_r": return ExpressionPreset.blinkRight;
// https://github.com/vrm-c/vrm-specification/issues/163
case "joy": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.happy;
case "angry": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.angry;
case "sorrow": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.sad;
case "fun": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.relaxed;
case "joy": return ExpressionPreset.happy;
case "angry": return ExpressionPreset.angry;
case "sorrow": return ExpressionPreset.sad;
case "fun": return ExpressionPreset.relaxed;
case "lookup": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookUp;
case "lookdown": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookDown;
case "lookleft": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookLeft;
case "lookright": return UniGLTF.Extensions.VRMC_vrm.ExpressionPreset.lookRight;
case "lookup": return ExpressionPreset.lookUp;
case "lookdown": return ExpressionPreset.lookDown;
case "lookleft": return ExpressionPreset.lookLeft;
case "lookright": return ExpressionPreset.lookRight;
}
throw new NotImplementedException();
@@ -152,7 +152,7 @@ namespace UniVRM10
}
}
public static IEnumerable<UniGLTF.Extensions.VRMC_vrm.Expression> Migrate(UniGLTF.glTF gltf, JsonNode json)
public static IEnumerable<(ExpressionPreset, string, UniGLTF.Extensions.VRMC_vrm.Expression)> Migrate(UniGLTF.glTF gltf, JsonNode json)
{
foreach (var blendShapeClip in json["blendShapeGroups"].ArrayItems())
{
@@ -162,10 +162,9 @@ namespace UniVRM10
{
isBinary = isBinaryNode.GetBoolean();
}
var preset = ToPreset(blendShapeClip["presetName"]);
var expression = new UniGLTF.Extensions.VRMC_vrm.Expression
{
Name = name,
Preset = ToPreset(blendShapeClip["presetName"]),
IsBinary = isBinary,
MorphTargetBinds = new List<UniGLTF.Extensions.VRMC_vrm.MorphTargetBind>(),
MaterialColorBinds = new List<UniGLTF.Extensions.VRMC_vrm.MaterialColorBind>(),
@@ -178,7 +177,7 @@ namespace UniVRM10
ToMaterialColorBinds(gltf, materialValues, expression);
}
yield return expression;
yield return (preset, name, expression);
}
}
}

View File

@@ -211,7 +211,7 @@ namespace UniVRM10
var data = new UniGLTF.Extensions.VRMC_vrm.Expression();
data.OverrideBlink = UniGLTF.Extensions.VRMC_vrm.ExpressionOverrideType.block;
var json = Serialize(data, UniGLTF.Extensions.VRMC_vrm.GltfSerializer.Serialize_Expressions_ITEM);
var json = Serialize(data, UniGLTF.Extensions.VRMC_vrm.GltfSerializer.__expressions_Serialize_Custom_ITEM);
Assert.AreEqual($"{{{q}preset{q}:{q}custom{q},{q}overrideBlink{q}:{q}block{q},{q}overrideLookAt{q}:{q}none{q},{q}overrideMouth{q}:{q}none{q}}}", json);
}
@@ -241,14 +241,14 @@ namespace UniVRM10
// foreach (var preset in Enum.GetValues(typeof(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset)) as UniGLTF.Extensions.VRMC_vrm.ExpressionPreset[])
// {
// var expression = new UniGLTF.Extensions.VRMC_vrm.Expression(preset, "", false);
// // expect no exception
// var gltf = ExpressionAdapter.ToGltf(
// expression,
// new List<UniGLTF.Extensions.VRMC_vrm.Node>(),
// new List<UniGLTF.Extensions.VRMC_vrm.Material>());
// }
// // import
// foreach (var preset in Enum.GetValues(typeof(UniGLTF.Extensions.VRMC_vrm.ExpressionPreset)) as UniGLTF.Extensions.VRMC_vrm.ExpressionPreset[])
// {

View File

@@ -57,8 +57,8 @@ namespace UniGLTF.Extensions.VRMC_materials_mtoon
// Application-specific data.
public object Extras;
// Meta
public string Version;
// Specification version of VRMC_materials_mtoon
public string SpecVersion;
// enable depth buffer when `alphaMode` is `BLEND`
public bool? TransparentWithZWrite;