From 54998b3a3e9b47dfa6c4213ac175fb0537ee1aeb Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 8 Apr 2022 14:58:41 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BB=95=E6=A7=98=E3=82=92=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E3=80=81=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E5=86=8D=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Format/Constraints/Deserializer.g.cs | 110 +++++++++++++++--- .../Runtime/Format/Constraints/Format.g.cs | 72 +++++++++++- .../Format/Constraints/Serializer.g.cs | 103 +++++++++++++--- Assets/VRM10/Runtime/IO/Vrm10Exporter.cs | 2 +- Assets/VRM10/Runtime/IO/Vrm10Importer.cs | 2 +- vrm-specification | 2 +- 6 files changed, 251 insertions(+), 40 deletions(-) diff --git a/Assets/VRM10/Runtime/Format/Constraints/Deserializer.g.cs b/Assets/VRM10/Runtime/Format/Constraints/Deserializer.g.cs index 0788569ea..c68ee4494 100644 --- a/Assets/VRM10/Runtime/Format/Constraints/Deserializer.g.cs +++ b/Assets/VRM10/Runtime/Format/Constraints/Deserializer.g.cs @@ -79,6 +79,16 @@ public static Constraint Deserialize_Constraint(JsonNode parsed) continue; } + if(key=="roll"){ + value.Roll = __constraint_Deserialize_Roll(kv.Value); + continue; + } + + if(key=="aim"){ + value.Aim = __constraint_Deserialize_Aim(kv.Value); + continue; + } + if(key=="rotation"){ value.Rotation = __constraint_Deserialize_Rotation(kv.Value); continue; @@ -88,6 +98,90 @@ public static Constraint Deserialize_Constraint(JsonNode parsed) return value; } +public static RollConstraint __constraint_Deserialize_Roll(JsonNode parsed) +{ + var value = new RollConstraint(); + + foreach(var kv in parsed.ObjectItems()) + { + var key = kv.Key.GetString(); + + if(key=="extensions"){ + value.Extensions = new glTFExtensionImport(kv.Value); + continue; + } + + if(key=="extras"){ + value.Extras = new glTFExtensionImport(kv.Value); + continue; + } + + if(key=="name"){ + value.Name = kv.Value.GetString(); + continue; + } + + if(key=="source"){ + value.Source = kv.Value.GetInt32(); + continue; + } + + if(key=="rollAxis"){ + value.RollAxis = (RollAxis)Enum.Parse(typeof(RollAxis), kv.Value.GetString(), true); + continue; + } + + if(key=="weight"){ + value.Weight = kv.Value.GetSingle(); + continue; + } + + } + return value; +} + +public static AimConstraint __constraint_Deserialize_Aim(JsonNode parsed) +{ + var value = new AimConstraint(); + + foreach(var kv in parsed.ObjectItems()) + { + var key = kv.Key.GetString(); + + if(key=="extensions"){ + value.Extensions = new glTFExtensionImport(kv.Value); + continue; + } + + if(key=="extras"){ + value.Extras = new glTFExtensionImport(kv.Value); + continue; + } + + if(key=="name"){ + value.Name = kv.Value.GetString(); + continue; + } + + if(key=="source"){ + value.Source = kv.Value.GetInt32(); + continue; + } + + if(key=="aimAxis"){ + value.AimAxis = (AimAxis)Enum.Parse(typeof(AimAxis), kv.Value.GetString(), true); + continue; + } + + if(key=="weight"){ + value.Weight = kv.Value.GetSingle(); + continue; + } + + } + return value; +} + public static RotationConstraint __constraint_Deserialize_Rotation(JsonNode parsed) { var value = new RotationConstraint(); @@ -116,11 +210,6 @@ public static RotationConstraint __constraint_Deserialize_Rotation(JsonNode pars continue; } - if(key=="axes"){ - value.Axes = __constraint__rotation_Deserialize_Axes(kv.Value); - continue; - } - if(key=="weight"){ value.Weight = kv.Value.GetSingle(); continue; @@ -130,16 +219,5 @@ public static RotationConstraint __constraint_Deserialize_Rotation(JsonNode pars return value; } -public static bool[] __constraint__rotation_Deserialize_Axes(JsonNode parsed) -{ - var value = new bool[parsed.GetArrayCount()]; - int i=0; - foreach(var x in parsed.ArrayItems()) - { - value[i++] = x.GetBoolean(); - } - return value; -} - } // GltfDeserializer } // UniGLTF diff --git a/Assets/VRM10/Runtime/Format/Constraints/Format.g.cs b/Assets/VRM10/Runtime/Format/Constraints/Format.g.cs index 3f54d5ead..d9981025f 100644 --- a/Assets/VRM10/Runtime/Format/Constraints/Format.g.cs +++ b/Assets/VRM10/Runtime/Format/Constraints/Format.g.cs @@ -6,6 +6,67 @@ using System.Collections.Generic; namespace UniGLTF.Extensions.VRMC_node_constraint { + public enum RollAxis + { + X, + Y, + Z, + + } + + public class RollConstraint + { + // Dictionary object with extension-specific objects. + public object Extensions; + + // Application-specific data. + public object Extras; + + // The user-defined name of this object. + public string Name; + + // The index of the node constrains the node. + public int? Source; + + // The roll axis of the constraint. + public RollAxis RollAxis; + + // The weight of the constraint. + public float? Weight; + } + + public enum AimAxis + { + PositiveX, + NegativeX, + PositiveY, + NegativeY, + PositiveZ, + NegativeZ, + + } + + public class AimConstraint + { + // Dictionary object with extension-specific objects. + public object Extensions; + + // Application-specific data. + public object Extras; + + // The user-defined name of this object. + public string Name; + + // The index of the node constrains the node. + public int? Source; + + // The aim axis of the constraint. + public AimAxis AimAxis; + + // The weight of the constraint. + public float? Weight; + } + public class RotationConstraint { // Dictionary object with extension-specific objects. @@ -20,9 +81,6 @@ namespace UniGLTF.Extensions.VRMC_node_constraint // The index of the node constrains the node. public int? Source; - // Axes be constrained by this constraint, in X-Y-Z order. - public bool[] Axes; - // The weight of the constraint. public float? Weight; } @@ -35,6 +93,12 @@ namespace UniGLTF.Extensions.VRMC_node_constraint // Application-specific data. public object Extras; + // A constraint that transfers a rotation around one axis of a source. + public RollConstraint Roll; + + // A constraint that makes it look at a source object. + public AimConstraint Aim; + // A constraint that links the rotation with a source. public RotationConstraint Rotation; } @@ -52,7 +116,7 @@ namespace UniGLTF.Extensions.VRMC_node_constraint // Specification version of VRMC_node_constraint public string SpecVersion; - // Contains position, rotation, or aim + // Contains roll, aim, or rotation public Constraint Constraint; } } diff --git a/Assets/VRM10/Runtime/Format/Constraints/Serializer.g.cs b/Assets/VRM10/Runtime/Format/Constraints/Serializer.g.cs index 4a88b27fb..0828fd008 100644 --- a/Assets/VRM10/Runtime/Format/Constraints/Serializer.g.cs +++ b/Assets/VRM10/Runtime/Format/Constraints/Serializer.g.cs @@ -71,6 +71,16 @@ public static void Serialize_Constraint(JsonFormatter f, Constraint value) (value.Extras as glTFExtension).Serialize(f); } + if(value.Roll!=null){ + f.Key("roll"); + __constraint_Serialize_Roll(f, value.Roll); + } + + if(value.Aim!=null){ + f.Key("aim"); + __constraint_Serialize_Aim(f, value.Aim); + } + if(value.Rotation!=null){ f.Key("rotation"); __constraint_Serialize_Rotation(f, value.Rotation); @@ -79,6 +89,82 @@ public static void Serialize_Constraint(JsonFormatter f, Constraint value) f.EndMap(); } +public static void __constraint_Serialize_Roll(JsonFormatter f, RollConstraint value) +{ + f.BeginMap(); + + + if(value.Extensions!=null){ + f.Key("extensions"); + (value.Extensions as glTFExtension).Serialize(f); + } + + if(value.Extras!=null){ + f.Key("extras"); + (value.Extras as glTFExtension).Serialize(f); + } + + if(!string.IsNullOrEmpty(value.Name)){ + f.Key("name"); + f.Value(value.Name); + } + + if(value.Source.HasValue){ + f.Key("source"); + f.Value(value.Source.GetValueOrDefault()); + } + + if(true){ + f.Key("rollAxis"); + f.Value(value.RollAxis.ToString()); + } + + if(value.Weight.HasValue){ + f.Key("weight"); + f.Value(value.Weight.GetValueOrDefault()); + } + + f.EndMap(); +} + +public static void __constraint_Serialize_Aim(JsonFormatter f, AimConstraint value) +{ + f.BeginMap(); + + + if(value.Extensions!=null){ + f.Key("extensions"); + (value.Extensions as glTFExtension).Serialize(f); + } + + if(value.Extras!=null){ + f.Key("extras"); + (value.Extras as glTFExtension).Serialize(f); + } + + if(!string.IsNullOrEmpty(value.Name)){ + f.Key("name"); + f.Value(value.Name); + } + + if(value.Source.HasValue){ + f.Key("source"); + f.Value(value.Source.GetValueOrDefault()); + } + + if(true){ + f.Key("aimAxis"); + f.Value(value.AimAxis.ToString()); + } + + if(value.Weight.HasValue){ + f.Key("weight"); + f.Value(value.Weight.GetValueOrDefault()); + } + + f.EndMap(); +} + public static void __constraint_Serialize_Rotation(JsonFormatter f, RotationConstraint value) { f.BeginMap(); @@ -104,11 +190,6 @@ public static void __constraint_Serialize_Rotation(JsonFormatter f, RotationCons f.Value(value.Source.GetValueOrDefault()); } - if(value.Axes!=null&&value.Axes.Count()>=3){ - f.Key("axes"); - __constraint__rotation_Serialize_Axes(f, value.Axes); - } - if(value.Weight.HasValue){ f.Key("weight"); f.Value(value.Weight.GetValueOrDefault()); @@ -117,17 +198,5 @@ public static void __constraint_Serialize_Rotation(JsonFormatter f, RotationCons f.EndMap(); } -public static void __constraint__rotation_Serialize_Axes(JsonFormatter f, bool[] value) -{ - f.BeginList(); - - foreach(var item in value) - { - f.Value(item); - - } - f.EndList(); -} - } // class } // namespace diff --git a/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs b/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs index fb47fc8a7..6e98d2308 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs @@ -443,7 +443,7 @@ namespace UniVRM10 Rotation = new UniGLTF.Extensions.VRMC_node_constraint.RotationConstraint { Source = model.Nodes.IndexOf(converter.Nodes[c.Source.gameObject]), - Axes = ToArray(c.Axes), + // Axes = ToArray(c.Axes), Weight = c.Weight, }, }, diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index aa78c595e..50b510a91 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -666,7 +666,7 @@ namespace UniVRM10 var r = constraint.Rotation; var rotationConstraint = node.gameObject.AddComponent(); rotationConstraint.Source = Nodes[r.Source.Value]; - rotationConstraint.Axes = ConstraintAxes(r.Axes); + // rotationConstraint.Axes = ConstraintAxes(r.Axes); rotationConstraint.Weight = r.Weight.Value; rotationConstraint.ModelRoot = Root.transform; } diff --git a/vrm-specification b/vrm-specification index 084c4fd3a..e93a3a077 160000 --- a/vrm-specification +++ b/vrm-specification @@ -1 +1 @@ -Subproject commit 084c4fd3a19f4a94b854c35661151c23d526d26a +Subproject commit e93a3a0776660e38bbced4c8219217c21f743628