public static string ToJson(this glTF_VRM_Humanoid self)
        {
            var f = new JsonFormatter();

            VRMSerializer.Serialize_vrm_humanoid(f, self);
            return(f.ToString());
        }
Ejemplo n.º 2
0
        public static void Apply(this glTF_VRM_Humanoid self, UniHumanoid.AvatarDescription desc, List <Transform> nodes)
        {
            self.armStretch        = desc.armStretch;
            self.legStretch        = desc.legStretch;
            self.upperArmTwist     = desc.upperArmTwist;
            self.lowerArmTwist     = desc.lowerArmTwist;
            self.upperLegTwist     = desc.upperLegTwist;
            self.lowerLegTwist     = desc.lowerArmTwist;
            self.feetSpacing       = desc.feetSpacing;
            self.hasTranslationDoF = desc.hasTranslationDoF;

            foreach (var x in desc.human)
            {
                var key   = x.humanBone.FromHumanBodyBone();
                var found = self.humanBones.FirstOrDefault(y => y.vrmBone == key);
                if (found == null)
                {
                    found = new glTF_VRM_HumanoidBone
                    {
                        vrmBone = key
                    };
                    self.humanBones.Add(found);
                }

                found.node = nodes.FindIndex(y => y.name == x.boneName);

                found.useDefaultValues = x.useDefaultValues;
                found.axisLength       = x.axisLength;
                found.center           = x.center;
                found.max = x.max;
                found.min = x.min;
            }
        }
        public void HumanoidTest()
        {
            var model = new glTF_VRM_Humanoid();

            var json = model.ToJson();

            Assert.AreEqual(@"{""humanBones"":[],""armStretch"":0.05,""legStretch"":0.05,""upperArmTwist"":0.5,""lowerArmTwist"":0.5,""upperLegTwist"":0.5,""lowerLegTwist"":0.5,""feetSpacing"":0,""hasTranslationDoF"":false}", json);
            Debug.Log(json);
        }
Ejemplo n.º 4
0
        public void HumanoidTest()
        {
            var model = new glTF_VRM_Humanoid();

            var json = model.ToJson();

            Assert.AreEqual(@"{""humanBones"":[],""armStretch"":0.05,""legStretch"":0.05,""upperArmTwist"":0.5,""lowerArmTwist"":0.5,""upperLegTwist"":0.5,""lowerLegTwist"":0.5,""feetSpacing"":0,""hasTranslationDoF"":false}", json);
            Debug.Log(json);

            var c = new JsonSchemaValidationContext("")
            {
                EnableDiagnosisForNotRequiredFields = true,
            };
            var json2 = JsonSchema.FromType <glTF_VRM_Humanoid>().Serialize(model, c);

            // NOTE: New serializer outputs values which will not be used...
            Assert.AreEqual(json, json2);
        }
Ejemplo n.º 5
0
        public static void SetNodeIndex(this glTF_VRM_Humanoid self, HumanBodyBones _key, int node)
        {
            var key   = _key.FromHumanBodyBone();
            var index = self.humanBones.FindIndex(x => x.vrmBone == key);

            if (index == -1 || self.humanBones[index] == null)
            {
                // not found
                self.humanBones.Add(new glTF_VRM_HumanoidBone
                {
                    vrmBone = key,
                    node    = node
                });
            }
            else
            {
                self.humanBones[index].node = node;
            }
        }
Ejemplo n.º 6
0
        public static UniHumanoid.AvatarDescription ToDescription(this glTF_VRM_Humanoid self, List <Transform> nodes)
        {
            var description = ScriptableObject.CreateInstance <UniHumanoid.AvatarDescription>();

            description.upperLegTwist     = self.upperLegTwist;
            description.lowerLegTwist     = self.lowerLegTwist;
            description.upperArmTwist     = self.upperArmTwist;
            description.lowerArmTwist     = self.lowerArmTwist;
            description.armStretch        = self.armStretch;
            description.legStretch        = self.legStretch;
            description.hasTranslationDoF = self.hasTranslationDoF;

            var boneLimits = new UniHumanoid.BoneLimit[self.humanBones.Count];
            int index      = 0;

            foreach (var x in self.humanBones)
            {
                if (x.node < 0 || x.node >= nodes.Count)
                {
                    continue;
                }
                boneLimits[index] = new UniHumanoid.BoneLimit
                {
                    boneName         = nodes[x.node].name,
                    useDefaultValues = x.useDefaultValues,
                    axisLength       = x.axisLength,
                    center           = x.center,
                    min       = x.min,
                    max       = x.max,
                    humanBone = x.vrmBone.ToHumanBodyBone(),
                };
                index++;
            }

            description.human = boneLimits;

            return(description);
        }
Ejemplo n.º 7
0
        public static void Serialize_vrm_humanoid(JsonFormatter f, glTF_VRM_Humanoid value)
        {
            f.BeginMap();


            if (value.humanBones != null && value.humanBones.Count >= 0)
            {
                f.Key("humanBones");
                Serialize_vrm_humanoid_humanBones(f, value.humanBones);
            }

            if (true)
            {
                f.Key("armStretch");
                f.Value(value.armStretch);
            }

            if (true)
            {
                f.Key("legStretch");
                f.Value(value.legStretch);
            }

            if (true)
            {
                f.Key("upperArmTwist");
                f.Value(value.upperArmTwist);
            }

            if (true)
            {
                f.Key("lowerArmTwist");
                f.Value(value.lowerArmTwist);
            }

            if (true)
            {
                f.Key("upperLegTwist");
                f.Value(value.upperLegTwist);
            }

            if (true)
            {
                f.Key("lowerLegTwist");
                f.Value(value.lowerLegTwist);
            }

            if (true)
            {
                f.Key("feetSpacing");
                f.Value(value.feetSpacing);
            }

            if (true)
            {
                f.Key("hasTranslationDoF");
                f.Value(value.hasTranslationDoF);
            }

            f.EndMap();
        }
Ejemplo n.º 8
0
        public static glTF_VRM_Humanoid Deserialize_vrm_humanoid(ListTreeNode <JsonValue> parsed)
        {
            var value = new glTF_VRM_Humanoid();

            foreach (var kv in parsed.ObjectItems())
            {
                var key = kv.Key.GetString();

                if (key == "humanBones")
                {
                    value.humanBones = Deserialize_vrm_humanoid_humanBones(kv.Value);
                    continue;
                }

                if (key == "armStretch")
                {
                    value.armStretch = kv.Value.GetSingle();
                    continue;
                }

                if (key == "legStretch")
                {
                    value.legStretch = kv.Value.GetSingle();
                    continue;
                }

                if (key == "upperArmTwist")
                {
                    value.upperArmTwist = kv.Value.GetSingle();
                    continue;
                }

                if (key == "lowerArmTwist")
                {
                    value.lowerArmTwist = kv.Value.GetSingle();
                    continue;
                }

                if (key == "upperLegTwist")
                {
                    value.upperLegTwist = kv.Value.GetSingle();
                    continue;
                }

                if (key == "lowerLegTwist")
                {
                    value.lowerLegTwist = kv.Value.GetSingle();
                    continue;
                }

                if (key == "feetSpacing")
                {
                    value.feetSpacing = kv.Value.GetSingle();
                    continue;
                }

                if (key == "hasTranslationDoF")
                {
                    value.hasTranslationDoF = kv.Value.GetBoolean();
                    continue;
                }
            }
            return(value);
        }