示例#1
0
        public static new NormalTextureInfo Deserialize(GLTFRoot root, JsonReader reader)
        {
            var textureInfo = new NormalTextureInfo();

            if (reader.Read() && reader.TokenType != JsonToken.StartObject)
            {
                throw new Exception("Asset must be an object.");
            }

            while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
            {
                var curProp = reader.Value.ToString();

                switch (curProp)
                {
                case "index":
                    textureInfo.Index = TextureId.Deserialize(root, reader);
                    break;

                case "texCoord":
                    textureInfo.TexCoord = reader.ReadAsInt32().Value;
                    break;

                case "scale":
                    textureInfo.Scale = reader.ReadAsDouble().Value;
                    break;

                default:
                    textureInfo.DefaultPropertyDeserializer(root, reader);
                    break;
                }
            }

            return(textureInfo);
        }
示例#2
0
        public static Material Deserialize(GLTFRoot root, JsonReader reader)
        {
            var material = new Material();

            while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
            {
                var curProp = reader.Value.ToString();

                switch (curProp)
                {
                case "pbrMetallicRoughness":
                    material.PbrMetallicRoughness = PbrMetallicRoughness.Deserialize(root, reader);
                    break;

                case "commonConstant":
                    material.CommonConstant = MaterialCommonConstant.Deserialize(root, reader);
                    break;

                case "normalTexture":
                    material.NormalTexture = NormalTextureInfo.Deserialize(root, reader);
                    break;

                case "occlusionTexture":
                    material.OcclusionTexture = OcclusionTextureInfo.Deserialize(root, reader);
                    break;

                case "emissiveTexture":
                    material.EmissiveTexture = TextureInfo.Deserialize(root, reader);
                    break;

                case "emissiveFactor":
                    material.EmissiveFactor = reader.ReadAsRGBColor();
                    break;

                case "alphaMode":
                    material.AlphaMode = reader.ReadStringEnum <AlphaMode>();
                    break;

                case "alphaCutoff":
                    material.AlphaCutoff = reader.ReadAsDouble().Value;
                    break;

                case "doubleSided":
                    material.DoubleSided = reader.ReadAsBoolean().Value;
                    break;

                default:
                    material.DefaultPropertyDeserializer(root, reader);
                    break;
                }
            }

            return(material);
        }
示例#3
0
        private NormalTextureInfo ExportNormalTextureInfo(UnityEngine.Texture texture, UnityEngine.Material material)
        {
            var info = new NormalTextureInfo();

            info.Index = ExportTexture(texture);

            if (material.HasProperty("_BumpScale"))
            {
                info.Scale = material.GetFloat("_BumpScale");
            }

            return(info);
        }