<commit_before>﻿using System;
using GLTF.Extensions;
using GLTF.Math;
using Newtonsoft.Json;

namespace GLTF.Schema
{
    /// <summary>
    /// A set of parameter values that are used to define the specular-glossiness
    /// material model from Physically-Based Rendering (PBR) methodology.
    /// </summary>
    public class PbrSpecularGlossiness : GLTFProperty
    {
        /// <summary>
        /// The RGBA components of the base color of the material.
        /// The fourth component (A) is the opacity of the material.
        /// These values are linear.
        /// </summary>
        public Color BaseColorFactor = Color.White;

        /// <summary>
        /// The base color texture.
        /// This texture contains RGB(A) components in sRGB color space.
        /// The first three components (RGB) specify the base color of the material.
        /// If the fourth component (A) is present, it represents the opacity of the
        /// material. Otherwise, an opacity of 1.0 is assumed.
        /// </summary>
        public TextureInfo BaseColorTexture;

        /// <summary>
        /// The metalness of the material.
        /// A value of 1.0 means the material is a metal.
        /// A value of 0.0 means the material is a dielectric.
        /// Values in between are for blending between metals and dielectrics such as
        /// dirty metallic surfaces.
        /// This value is linear.
        /// </summary>
        public double MetallicFactor = 1;

        /// <summary>
        /// The roughness of the material.
        /// A value of 1.0 means the material is completely rough.
        /// A value of 0.0 means the material is completely smooth.
        /// This value is linear.
        /// </summary>
        public double RoughnessFactor = 1;

        /// <summary>
        /// The metallic-roughness texture has two components.
        /// The first component (R) contains the metallic-ness of the material.
        /// The second component (G) contains the roughness of the material.
        /// These values are linear.
        /// If the third component (B) and/or the fourth component (A) are present,
        /// they are ignored.
        /// </summary>
        public TextureInfo MetallicRoughnessTexture;

        public static PbrSpecularGlossiness Deserialize(GLTFRoot root, JsonReader reader)
        {
            var specularGlossiness = new PbrSpecularGlossiness();

            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 "baseColorFactor":
                        specularGlossiness.BaseColorFactor = reader.ReadAsRGBAColor();
                        break;
                    case "baseColorTexture":
                        specularGlossiness.BaseColorTexture = TextureInfo.Deserialize(root, reader);
                        break;
                    case "metallicFactor":
                        specularGlossiness.MetallicFactor = reader.ReadAsDouble().Value;
                        break;
                    case "roughnessFactor":
                        specularGlossiness.RoughnessFactor = reader.ReadAsDouble().Value;
                        break;
                    case "metallicRoughnessTexture":
                        specularGlossiness.MetallicRoughnessTexture = TextureInfo.Deserialize(root, reader);
                        break;
                    default:
                        specularGlossiness.DefaultPropertyDeserializer(root, reader);
                        break;
                }
            }

            return specularGlossiness;
        }

        public override void Serialize(JsonWriter writer)
        {
            writer.WriteStartObject();

            if (BaseColorFactor != Color.White)
            {
                writer.WritePropertyName("baseColorFactor");
                writer.WriteStartArray();
                writer.WriteValue(BaseColorFactor.R);
                writer.WriteValue(BaseColorFactor.G);
                writer.WriteValue(BaseColorFactor.B);
                writer.WriteValue(BaseColorFactor.A);
                writer.WriteEndArray();
            }

            if (BaseColorTexture != null)
            {
                writer.WritePropertyName("baseColorTexture");
                BaseColorTexture.Serialize(writer);
            }

            if (MetallicFactor != 1.0f)
            {
                writer.WritePropertyName("metallicFactor");
                writer.WriteValue(MetallicFactor);
            }

            if (RoughnessFactor != 1.0f)
            {
                writer.WritePropertyName("roughnessFactor");
                writer.WriteValue(RoughnessFactor);
            }

            if (MetallicRoughnessTexture != null)
            {
                writer.WritePropertyName("metallicRoughnessTexture");
                MetallicRoughnessTexture.Serialize(writer);
            }

            base.Serialize(writer);

            writer.WriteEndObject();
        }
    }
}<commit_msg>Change the fields from metal/roughness to specular/gloss<commit_after>﻿using System;
using GLTF.Extensions;
using GLTF.Math;
using Newtonsoft.Json;

namespace GLTF.Schema
{
    /// <summary>
    /// A set of parameter values that are used to define the specular-glossiness
    /// material model from Physically-Based Rendering (PBR) methodology.
    /// 
    /// Supports the KHR_materials_pbrSpecularGlossiness material extension.
    /// </summary>
    public class PbrSpecularGlossiness : GLTFProperty
    {
        /// <summary>
        /// The RGBA components of the base color of the material.
        /// The fourth component (A) is the opacity of the material.
        /// These values are linear.
        /// </summary>
        public Color BaseColorFactor = Color.White;

        /// <summary>
        /// The base color texture.
        /// This texture contains RGB(A) components in sRGB color space.
        /// The first three components (RGB) specify the base color of the material.
        /// If the fourth component (A) is present, it represents the opacity of the
        /// material. Otherwise, an opacity of 1.0 is assumed.
        /// </summary>
        public TextureInfo BaseColorTexture;

        /// <summary>
        /// The specularity of the material.
        /// A value of 1.0 means the material is shiny and mirror-like.
        /// A value of 0.0 means the material is completely diffuse.
        /// Values in between are for blending between metals and dielectrics such as
        /// plastics.
        /// This value is linear.
        /// </summary>
        public double SpecularFactor = 1;

        /// <summary>
        /// The glossiness of the material.
        /// A value of 1.0 means the material is completely rough.
        /// A value of 0.0 means the material is completely smooth.
        /// This value is linear.
        /// </summary>
        public double GlossinessFactor = 1;

        /// <summary>
        /// The specular-glossiness texture has two components.
        /// The first component (R) contains the specularity of the material.
        /// The second component (G) contains the glossiness of the material.
        /// These values are linear.
        /// If the third component (B) and/or the fourth component (A) are present,
        /// they are ignored.
        /// </summary>
        public TextureInfo SpecularGlossinessTexture;

        public static PbrSpecularGlossiness Deserialize(GLTFRoot root, JsonReader reader)
        {
            var specularGlossiness = new PbrSpecularGlossiness();

            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 "diffuseFactor":
                        specularGlossiness.BaseColorFactor = reader.ReadAsRGBAColor();
                        break;
                    case "diffuseTexture":
                        specularGlossiness.BaseColorTexture = TextureInfo.Deserialize(root, reader);
                        break;
                    case "specularFactor":
                        specularGlossiness.SpecularFactor = reader.ReadAsDouble().Value;
                        break;
                    case "glossinessFactor":
                        specularGlossiness.GlossinessFactor = reader.ReadAsDouble().Value;
                        break;
                    case "specularGlossinessTexture":
                        specularGlossiness.SpecularGlossinessTexture = TextureInfo.Deserialize(root, reader);
                        break;
                    default:
                        specularGlossiness.DefaultPropertyDeserializer(root, reader);
                        break;
                }
            }

            return specularGlossiness;
        }

        public override void Serialize(JsonWriter writer)
        {
            writer.WriteStartObject();

            if (BaseColorFactor != Color.White)
            {
                writer.WritePropertyName("diffuseFactor");
                writer.WriteStartArray();
                writer.WriteValue(BaseColorFactor.R);
                writer.WriteValue(BaseColorFactor.G);
                writer.WriteValue(BaseColorFactor.B);
                writer.WriteValue(BaseColorFactor.A);
                writer.WriteEndArray();
            }

            if (BaseColorTexture != null)
            {
                writer.WritePropertyName("diffuseTexture");
                BaseColorTexture.Serialize(writer);
            }

            if (SpecularFactor != 1.0f)
            {
                writer.WritePropertyName("specularFactor");
                writer.WriteValue(SpecularFactor);
            }

            if (GlossinessFactor != 1.0f)
            {
                writer.WritePropertyName("glossinessFactor");
                writer.WriteValue(GlossinessFactor);
            }

            if (SpecularGlossinessTexture != null)
            {
                writer.WritePropertyName("specularGlossinessTexture");
                SpecularGlossinessTexture.Serialize(writer);
            }

            base.Serialize(writer);

            writer.WriteEndObject();
        }
    }
}
{'fraction_non_alphanumeric': 0.08671707271539252, 'fraction_numerical': 0.002987025109679828, 'mean_word_length': 1.5503451559152583, 'pattern_counts': {'":': 10, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5630982', 'n_tokens_mistral': 2634, 'n_tokens_neox': 2469, 'n_words': 716}