示例#1
0
        public void MeshTest()
        {
            var model = new glTFMesh("mesh")
            {
                primitives = new List <glTFPrimitives>
                {
                    new glTFPrimitives
                    {
                        attributes = new glTFAttributes
                        {
                            POSITION = 0,
                        }
                    }
                },
            };

            var json = model.ToJson();

            Assert.AreEqual(@"{""name"":""mesh"",""primitives"":[{""mode"":0,""indices"":-1,""attributes"":{""POSITION"":0},""material"":0}]}", json);
            Debug.Log(json);

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

            Assert.AreEqual(@"{""name"":""mesh"",""primitives"":[{""mode"":0,""attributes"":{""POSITION"":0},""material"":0}]}", json2);
        }
示例#2
0
        public void PrimitiveTest()
        {
            var model = new glTFPrimitives
            {
                attributes = new glTFAttributes
                {
                    POSITION = 0,
                },
                extras = new glTFPrimitives_extras
                {
                    targetNames = new List <String>
                    {
                        "aaa",
                    }
                }
            };

            var json = model.ToJson();

            Assert.AreEqual(@"{""mode"":0,""indices"":-1,""attributes"":{""POSITION"":0},""material"":0,""extras"":{""targetNames"":[""aaa""]}}", json);
            Debug.Log(json);

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

            Assert.AreEqual(@"{""mode"":0,""attributes"":{""POSITION"":0},""material"":0,""extras"":{""targetNames"":[""aaa""]}}", json2);
        }
        public void MetaTest()
        {
            var model = new glTF_VRM_Meta()
            {
                allowedUserName      = "******",
                violentUssageName    = "Disallow",
                sexualUssageName     = "Disallow",
                commercialUssageName = "Disallow",
                licenseName          = "CC0",
            };

            var json = model.ToJson();

            Assert.AreEqual(@"{""texture"":-1,""allowedUserName"":""OnlyAuthor"",""violentUssageName"":""Disallow"",""sexualUssageName"":""Disallow"",""commercialUssageName"":""Disallow"",""licenseName"":""CC0""}", json);
            Debug.Log(json);

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

            // NOTE: New serializer outputs values which will not be used...
            Assert.AreEqual(@"{""allowedUserName"":""OnlyAuthor"",""violentUssageName"":""Disallow"",""sexualUssageName"":""Disallow"",""commercialUssageName"":""Disallow"",""licenseName"":""CC0""}", json2);
        }
示例#4
0
        public void HasDictionaryObjectValidator()
        {
            var c = new JsonSchemaValidationContext("test");

            {
                var s = JsonSchema.FromType <HasDictionary>();
                Assert.Null(s.Validator.Validate(c, new HasDictionary()));
            }

            Assert.True(c.IsEmpty());
        }
示例#5
0
        public void StringEnumValidator()
        {
            var c = new JsonSchemaValidationContext("test");

            {
                var v = JsonStringEnumValidator.Create(new string[] { "a", "b" }, EnumSerializationType.AsString);
                Assert.Null(v.Validate(c, "a"));
                Assert.NotNull(v.Validate(c, "c"));
            }

            Assert.True(c.IsEmpty());
        }
示例#6
0
        public byte[] ToGlbBytes()
        {
            var c = new JsonSchemaValidationContext(this)
            {
                EnableDiagnosisForNotRequiredFields = true,
            };
            var json = JsonSchema.FromType(GetType()).Serialize(this, c);

            RemoveUnusedExtensions(json);

            return(Glb.ToBytes(json, buffers[0].GetBytes()));
        }
示例#7
0
        public void IntEnumValidator()
        {
            var c = new JsonSchemaValidationContext("test");

            {
                var v = new JsonIntEnumValidator();
                v.Values = new int[] { 1, 2 };
                Assert.Null(v.Validate(c, 1));
                Assert.NotNull(v.Validate(c, 3));
            }

            Assert.True(c.IsEmpty());
        }
示例#8
0
        public void BlendShapeBindTestError()
        {
            var model = new glTF_VRM_BlendShapeBind();

            var c = new JsonSchemaValidationContext("")
            {
                EnableDiagnosisForNotRequiredFields = true,
            };
            var ex = Assert.Throws <JsonSchemaValidationException>(
                () => JsonSchema.FromType <glTF_VRM_BlendShapeBind>().Serialize(model, c)
                );

            Assert.AreEqual("[mesh.String] minimum: ! -1>=0", ex.Message);
        }
示例#9
0
        public void TextureInfoTestError()
        {
            var model = new glTFMaterialBaseColorTextureInfo();

            var c = new JsonSchemaValidationContext("")
            {
                EnableDiagnosisForNotRequiredFields = true,
            };
            var ex = Assert.Throws <JsonSchemaValidationException>(
                () => JsonSchema.FromType <glTFMaterialBaseColorTextureInfo>().Serialize(model, c)
                );

            Assert.AreEqual("[index.String] minimum: ! -1>=0", ex.Message);
        }
示例#10
0
        public void TestHasDeps()
        {
            var obj = new HasDepsTest();

            var s = JsonSchema.FromType <HasDepsTest>();
            {
                var c = new JsonSchemaValidationContext(obj);
                Assert.Null(s.Validator.Validate(c, s));
            }
            var actual = s.Serialize(obj);

            var expected = @"{""X"":0,""Y"":0}";

            Assert.AreEqual(expected, actual);
        }
示例#11
0
        public void TestObjectNestedWithNull()
        {
            var obj = new ObjectNestedTest();

            var s = JsonSchema.FromType <ObjectNestedTest>();
            {
                var c = new JsonSchemaValidationContext(obj);
                Assert.Null(s.Validator.Validate(c, s));
            }
            var actual = s.Serialize(obj);

            var expected = @"{}";

            Assert.AreEqual(expected, actual);
        }
示例#12
0
        public void ObjectValidator()
        {
            var c = new JsonSchemaValidationContext("test");

            {
                var s = JsonSchema.FromType <Hoge>();
                Assert.Null(s.Validator.Validate(c, new Hoge {
                    Value = 1
                }));
                Assert.NotNull(s.Validator.Validate(c, new Hoge {
                    Value = 0
                }));
            }

            Assert.True(c.IsEmpty());
        }
示例#13
0
        public void MaterialTest()
        {
            var model = new glTF_VRM_Material
            {
                floatProperties = new Dictionary <string, float>
                {
                    { "float", 1.0f }
                },
                vectorProperties = new Dictionary <string, float[]>
                {
                    { "vector", new float[] { 0, 1, 2, 3 } }
                },
                textureProperties = new Dictionary <string, int>
                {
                    { "texture", 0 }
                },
                keywordMap = new Dictionary <string, bool>
                {
                    { "keyword", true }
                },
                tagMap = new Dictionary <string, string>
                {
                    { "tag", "map" }
                },
            };

            var json = model.ToJson();

            Assert.AreEqual(@"{""renderQueue"":-1,""floatProperties"":{""float"":1},""vectorProperties"":{""vector"":[0,1,2,3]},""textureProperties"":{""texture"":0},""keywordMap"":{""keyword"":true},""tagMap"":{""tag"":""map""}}", json);
            Debug.Log(json);

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

            // NOTE: New serializer outputs values which will not be used...
            Assert.AreEqual(json, json2);

            // deserialize
            var deserialized = default(glTF_VRM_Material);

            json.ParseAsJson().Deserialize(ref deserialized);
            Assert.AreEqual(1, deserialized.floatProperties.Count);
        }
示例#14
0
        public void DegreeMapTest()
        {
            var model = new glTF_VRM_DegreeMap();

            var json = model.ToJson();

            Assert.AreEqual(@"{""xRange"":90,""yRange"":10}", json);
            Debug.Log(json);

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

            Assert.AreEqual(json, json2);
        }
        public void SecondaryAnimationGroupTestErrorColliderGroups()
        {
            var model = new glTF_VRM_SecondaryAnimationGroup()
            {
                colliderGroups = new int[] { -1 }
            };

            var c = new JsonSchemaValidationContext("")
            {
                EnableDiagnosisForNotRequiredFields = true,
            };
            var ex = Assert.Throws <JsonSchemaValidationException>(
                () => JsonSchema.FromType <glTF_VRM_SecondaryAnimationGroup>().Serialize(model, c)
                );

            Assert.AreEqual("[colliderGroups.String] minimum: ! -1>=0", ex.Message);
        }
        public void HumanoidBoneTestError()
        {
            var model = new glTF_VRM_HumanoidBone()
            {
                bone = "hips", // NOTE: This field must not be null?
            };

            var c = new JsonSchemaValidationContext("")
            {
                EnableDiagnosisForNotRequiredFields = true,
            };
            var ex = Assert.Throws <JsonSchemaValidationException>(
                () => JsonSchema.FromType <glTF_VRM_HumanoidBone>().Serialize(model, c)
                );

            Assert.AreEqual("[node.String] minimum: ! -1>=0", ex.Message);
        }
示例#17
0
        public void ObjectValidatorForNotRequiredWithIgnorable()
        {
            {
                var c = new JsonSchemaValidationContext("test")
                {
                    EnableDiagnosisForNotRequiredFields = false, // Default behaviour
                };

                var s = JsonSchema.FromType <NotRequiredWithIgnorable>();
                // An error is not returned because Value is not 'Required' and the diagnosis is not enabled
                Assert.Null(s.Validator.Validate(c, new NotRequiredWithIgnorable {
                    Value = 0
                }));

                Assert.True(c.IsEmpty());
            }

            {
                var c = new JsonSchemaValidationContext("test")
                {
                    EnableDiagnosisForNotRequiredFields = true,
                };

                var s = JsonSchema.FromType <NotRequiredWithIgnorable>();
                Assert.NotNull(s.Validator.Validate(c, new NotRequiredWithIgnorable {
                    Value = 0
                }));

                Assert.True(c.IsEmpty());
            }

            {
                var c = new JsonSchemaValidationContext("test")
                {
                    EnableDiagnosisForNotRequiredFields = true,
                };

                var s = JsonSchema.FromType <NotRequiredWithIgnorable>();
                // An error is NOT returned even though diagnosis is enabled because of an ignorable value is matched
                Assert.Null(s.Validator.Validate(c, new NotRequiredWithIgnorable {
                    Value = -1
                }));

                Assert.True(c.IsEmpty());
            }
        }
示例#18
0
        public void MeshAnnotationTest()
        {
            var model = new glTF_VRM_MeshAnnotation();

            var json = model.ToJson();

            Assert.AreEqual(@"{""mesh"":0}", json);
            Debug.Log(json);

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

            Assert.AreEqual(json, json2);
        }
示例#19
0
        public void BlendShapeGroupTestError()
        {
            var model = new glTF_VRM_BlendShapeGroup()
            {
                presetName = "aaaaaaaaaaaa_not_exists_",
            };

            var c = new JsonSchemaValidationContext("")
            {
                EnableDiagnosisForNotRequiredFields = true,
            };
            var ex = Assert.Throws <JsonSchemaValidationException>(
                () => JsonSchema.FromType <glTF_VRM_BlendShapeGroup>().Serialize(model, c)
                );

            Assert.AreEqual("[presetName.String] aaaaaaaaaaaa_not_exists_ is not valid enum", ex.Message);
        }
示例#20
0
        public void MaterialAlphaTest()
        {
            var model = new glTFMaterial()
            {
                name           = "a",
                emissiveFactor = new float[] { 0.5f, 0.5f, 0.5f },
                alphaMode      = "MASK",
            };

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

            Assert.AreEqual(@"{""name"":""a"",""emissiveFactor"":[0.5,0.5,0.5],""alphaMode"":""MASK"",""alphaCutoff"":0.5,""doubleSided"":false}", json);
        }
示例#21
0
        public void NodeTestError()
        {
            var model = new glTFNode()
            {
                name   = "a",
                camera = -2,
            };

            var c = new JsonSchemaValidationContext("")
            {
                EnableDiagnosisForNotRequiredFields = true,
            };
            var ex = Assert.Throws <JsonSchemaValidationException>(
                () => JsonSchema.FromType <glTFNode>().Serialize(model, c)
                );

            Assert.AreEqual("[camera.String] minimum: ! -2>=0", ex.Message);
        }
示例#22
0
        public void NodeMeshTest()
        {
            var model = new glTFNode()
            {
                name   = "a",
                mesh   = 2,
                skin   = 0,
                camera = -1,
            };

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

            Assert.AreEqual(@"{""name"":""a"",""mesh"":2,""skin"":0,""extras"":{}}", json);
        }
示例#23
0
        public void MaterialTestError()
        {
            var model = new glTFMaterial()
            {
                name           = "b",
                emissiveFactor = new float[] { 1.5f, 0.5f, 0.5f },
            };

            var c = new JsonSchemaValidationContext("")
            {
                EnableDiagnosisForNotRequiredFields = true,
            };
            var ex = Assert.Throws <JsonSchemaValidationException>(
                () => JsonSchema.FromType <glTFMaterial>().Serialize(model, c)
                );

            Assert.AreEqual("[emissiveFactor.String] maximum: ! 1.5<=1", ex.Message);
        }
示例#24
0
        public void SkinTestError()
        {
            var model = new glTFSkin()
            {
                name   = "b",
                joints = new int[] { },
            };

            var c = new JsonSchemaValidationContext("")
            {
                EnableDiagnosisForNotRequiredFields = true,
            };
            var ex = Assert.Throws <JsonSchemaValidationException>(
                () => JsonSchema.FromType <glTFSkin>().Serialize(model, c)
                );

            Assert.AreEqual("[joints.String] minItems", ex.Message);
        }
示例#25
0
        public void MaterialTest()
        {
            var model = new glTF_VRM_Material();

            var json = model.ToJson();

            Assert.AreEqual(@"{""renderQueue"":-1,""floatProperties"":{},""vectorProperties"":{},""textureProperties"":{},""keywordMap"":{},""tagMap"":{}}", json);
            Debug.Log(json);

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

            // NOTE: New serializer outputs values which will not be used...
            Assert.AreEqual(json, json2);
        }
示例#26
0
        public void MetaTest()
        {
            var model = new glTF_VRM_Meta();

            var json = model.ToJson();

            Assert.AreEqual(@"{""texture"":-1}", json);
            Debug.Log(json);

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

            // NOTE: New serializer outputs values which will not be used...
            Assert.AreEqual(json, json2);
        }
示例#27
0
        public void SecondaryAnimationTest()
        {
            var model = new glTF_VRM_SecondaryAnimation();

            var json = model.ToJson();

            Assert.AreEqual(@"{""boneGroups"":[],""colliderGroups"":[]}", json);
            Debug.Log(json);

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

            // NOTE: New serializer outputs values which will not be used...
            Assert.AreEqual(json, json2);
        }
示例#28
0
        public void SecondaryAnimationGroupTest()
        {
            var model = new glTF_VRM_SecondaryAnimationGroup();

            var json = model.ToJson();

            Assert.AreEqual(@"{""stiffiness"":0,""gravityPower"":0,""gravityDir"":{""x"":0,""y"":0,""z"":0},""dragForce"":0,""center"":0,""hitRadius"":0,""bones"":[],""colliderGroups"":[]}", json);
            Debug.Log(json);

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

            // NOTE: New serializer outputs values which will not be used...
            Assert.AreEqual(json, json2);
        }
示例#29
0
        public void AssetsTestError()
        {
            var model = new glTFAssets();

            //var json = model.ToJson();
            //Assert.AreEqual(@"{""inverseBindMatrices"":-1,""joints"":[1]}", json);
            //Debug.Log(json);

            var c = new JsonSchemaValidationContext("")
            {
                EnableDiagnosisForNotRequiredFields = true,
            };
            var ex = Assert.Throws <JsonSchemaValidationException>(
                () => JsonSchema.FromType <glTFAssets>().Serialize(model, c)
                );

            Assert.AreEqual("[version.String] null", ex.Message);
        }
示例#30
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);
        }