Browse Source

redesigning access to material parameters in schema to prevent ambiguities. (WIP)

Vicente Penades 3 years ago
parent
commit
fed5dcf56a

+ 4 - 4
examples/SharpGLTF.Runtime.MonoGame/LoaderContext.BasicEffect.cs

@@ -126,7 +126,7 @@ namespace SharpGLTF.Runtime
 
             if (baseColor == null) return 1;
 
-            return baseColor.Value.Parameter.W;
+            return baseColor.Value.Color.W;
         }
 
         private static Vector3 GetDiffuseColor(GLTFMATERIAL srcMaterial)
@@ -136,8 +136,8 @@ namespace SharpGLTF.Runtime
             if (diffuse == null) diffuse = srcMaterial.FindChannel("BaseColor");
 
             if (diffuse == null) return Vector3.One;
-
-            return new Vector3(diffuse.Value.Parameter.X, diffuse.Value.Parameter.Y, diffuse.Value.Parameter.Z);
+            
+            return new Vector3(diffuse.Value.Color.X, diffuse.Value.Color.Y, diffuse.Value.Color.Z);
         }
 
         private static Vector3 GetSpecularColor(GLTFMATERIAL srcMaterial)
@@ -176,7 +176,7 @@ namespace SharpGLTF.Runtime
 
             if (emissive == null) return Vector3.Zero;
 
-            return new Vector3(emissive.Value.Parameter.X, emissive.Value.Parameter.Y, emissive.Value.Parameter.Z);
+            return new Vector3(emissive.Value.Color.X, emissive.Value.Color.Y, emissive.Value.Color.Z);
         }
 
         private Texture2D UseDiffuseTexture(GLTFMATERIAL srcMaterial)

+ 37 - 143
src/SharpGLTF.Core/Schema2/gltf.MaterialChannel.cs

@@ -21,7 +21,7 @@ namespace SharpGLTF.Schema2
     {
         #region lifecycle
 
-        internal MaterialChannel(Material m, String key, Func<Boolean, TextureInfo> texInfo, params MaterialParameter[] parameters)
+        internal MaterialChannel(Material m, String key, Func<Boolean, TextureInfo> texInfo, params IMaterialParameter[] parameters)
         {
             Guard.NotNull(m, nameof(m));
             Guard.NotNullOrEmpty(key, nameof(key));
@@ -49,7 +49,7 @@ namespace SharpGLTF.Schema2
         private readonly Func<Boolean, TextureInfo> _TextureInfo;
 
         [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
-        private readonly IReadOnlyList<MaterialParameter> _Parameters;
+        private readonly IReadOnlyList<IMaterialParameter> _Parameters;
 
         public override int GetHashCode()
         {
@@ -77,11 +77,11 @@ namespace SharpGLTF.Schema2
         [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         public Vector4 Parameter
         {
-            get => MaterialParameter.Combine(_Parameters);
-            set => MaterialParameter.Apply(_Parameters, value);
+            get => _MaterialParameter<float>.Combine(_Parameters);
+            set => _MaterialParameter<float>.Apply(_Parameters, value);
         }
 
-        public IReadOnlyList<MaterialParameter> Parameters => _Parameters;
+        public IReadOnlyList<IMaterialParameter> Parameters => _Parameters;
 
         /// <summary>
         /// Gets the <see cref="Texture"/> instance used by this Material, or null.
@@ -97,10 +97,41 @@ namespace SharpGLTF.Schema2
 
         public TextureSampler TextureSampler => Texture?.Sampler;
 
+        public Vector4 Color
+        {
+            get
+            {
+                foreach (var p in _Parameters.OfType<_MaterialParameter<Vector4>>())
+                {
+                    if (p.Name == "RGBA") return p.Value;
+                }
+
+                foreach (var p in _Parameters.OfType<_MaterialParameter<Vector3>>())
+                {
+                    if (p.Name == "RGB") return new Vector4(p.Value, 1);
+                }
+
+                throw new InvalidOperationException("RGB or RGBA not found.");
+            }
+            set
+            {
+                foreach (var p in _Parameters.OfType<_MaterialParameter<Vector4>>())
+                {
+                    if (p.Name == "RGBA") { p.Value = value; return; }
+                }
+
+                foreach (var p in _Parameters.OfType<_MaterialParameter<Vector3>>())
+                {
+                    if (p.Name == "RGB") { p.Value = new Vector3(value.X, value.Y, value.Z); return; }
+                }
+
+                throw new InvalidOperationException("RGB or RGBA not found.");
+            }
+        }
+
         #endregion
 
         #region API
-
         private Texture _GetTexture()
         {
             var texInfo = _TextureInfo?.Invoke(false);
@@ -163,141 +194,4 @@ namespace SharpGLTF.Schema2
 
         #endregion
     }
-
-    [System.Diagnostics.DebuggerDisplay("[{Name}, {Value}]")]
-    public readonly struct MaterialParameter
-    {
-        #region constants
-
-        internal enum Key
-        {
-            RGB,
-            RGBA,
-
-            NormalScale,
-            OcclusionStrength,
-
-            MetallicFactor,
-            RoughnessFactor,
-            SpecularFactor,
-            GlossinessFactor,
-            ClearCoatFactor,
-            ThicknessFactor,
-            TransmissionFactor,
-            AttenuationDistance,
-        }
-
-        #endregion
-
-        #region constructors
-
-        internal MaterialParameter(Key key, double defval, Func<double?> getter, Action<double?> setter, double min = double.MinValue, double max = double.MaxValue)
-        {
-            _Key = key;
-            _ValueDefault = defval;
-            _ValueGetter = () => (PARAMETER)(float)getter().AsValue(defval);
-            _ValueSetter = value => { double v = (float)value; setter(v.AsNullable(defval, min, max)); };
-        }
-
-        internal MaterialParameter(Key key, float defval, Func<float> getter, Action<float> setter)
-        {
-            _Key = key;
-            _ValueDefault = defval;
-            _ValueGetter = () => (PARAMETER)getter();
-            _ValueSetter = value => setter((float)value);
-        }
-
-        internal MaterialParameter(Key key, Vector2 defval, Func<Vector2> getter, Action<Vector2> setter)
-        {
-            _Key = key;
-            _ValueDefault = defval;
-            _ValueGetter = () => (PARAMETER)getter();
-            _ValueSetter = value => setter((Vector2)value);
-        }
-
-        internal MaterialParameter(Key key, Vector3 defval, Func<Vector3> getter, Action<Vector3> setter)
-        {
-            _Key = key;
-            _ValueDefault = defval;
-            _ValueGetter = () => (PARAMETER)getter();
-            _ValueSetter = value => setter((Vector3)value);
-        }
-
-        internal MaterialParameter(Key key, Vector4 defval, Func<Vector4> getter, Action<Vector4> setter)
-        {
-            _Key = key;
-            _ValueDefault = defval;
-            _ValueGetter = () => (PARAMETER)getter();
-            _ValueSetter = value => setter((Vector4)value);
-        }
-
-        #endregion
-
-        #region data
-
-        private readonly Key _Key;
-        private readonly Object _ValueDefault;
-        private readonly Func<PARAMETER> _ValueGetter;
-        private readonly Action<PARAMETER> _ValueSetter;
-
-        #endregion
-
-        #region properties
-
-        public string Name => _Key.ToString();
-
-        public bool IsDefault => Object.Equals(Value, _ValueDefault);
-
-        public Type ValueType => _ValueDefault.GetType();
-
-        /// <summary>
-        /// Gets or sets the value of this parameter. <br/>
-        /// Valid types are <see cref="float"/> <see cref="Vector3"/> and <see cref="Vector4"/>
-        /// </summary>
-        public PARAMETER Value
-        {
-            get => _ValueGetter();
-            set => _ValueSetter(value);
-        }
-
-        #endregion
-
-        #region helpers
-        internal static Vector4 Combine(IReadOnlyList<MaterialParameter> parameters)
-        {
-            Span<float> tmp = stackalloc float[4];
-            int idx = 0;
-
-            foreach (var p in parameters)
-            {
-                if (p.Value is Single v1) { tmp[idx++] = v1; }
-                if (p.Value is Vector2 v2) { tmp[idx++] = v2.X; tmp[idx++] = v2.Y; }
-                if (p.Value is Vector3 v3) { tmp[idx++] = v3.X; tmp[idx++] = v3.Y; tmp[idx++] = v3.Z; }
-                if (p.Value is Vector4 v4) { tmp[idx++] = v4.X; tmp[idx++] = v4.Y; tmp[idx++] = v4.Z; tmp[idx++] = v4.W; }
-            }
-
-            return new Vector4(tmp[0], tmp[1], tmp[2], tmp[3]);
-        }
-
-        internal static void Apply(IReadOnlyList<MaterialParameter> parameters, Vector4 value)
-        {
-            Span<float> tmp = stackalloc float[4];
-            tmp[0] = value.X;
-            tmp[1] = value.Y;
-            tmp[2] = value.Z;
-            tmp[3] = value.W;
-
-            int idx = 0;
-
-            foreach (var p in parameters)
-            {
-                if (p.Value is Single) { p.Value = tmp[idx++]; }
-                if (p.Value is Vector2) { p.Value = new Vector2(tmp[idx + 0], tmp[idx + 1]); idx += 2; }
-                if (p.Value is Vector3) { p.Value = new Vector3(tmp[idx + 0], tmp[idx + 1], tmp[idx + 2]); idx += 3; }
-                if (p.Value is Vector4) { p.Value = new Vector4(tmp[idx + 0], tmp[idx + 1], tmp[idx + 2], tmp[idx + 3]); idx += 4; }
-            }
-        }
-
-        #endregion
-    }
 }

+ 130 - 0
src/SharpGLTF.Core/Schema2/gltf.MaterialParameter.cs

@@ -0,0 +1,130 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Numerics;
+
+namespace SharpGLTF.Schema2
+{
+    public interface IMaterialParameter
+    {
+        string Name { get; }
+
+        bool IsDefault { get; }
+
+        Type ValueType { get; }
+
+        /// <summary>
+        /// Gets or sets the value of this parameter. <br/>
+        /// Valid types are <see cref="float"/> <see cref="Vector3"/> and <see cref="Vector4"/>
+        /// </summary>
+        Object Value { get; set; }
+    }
+
+    [System.Diagnostics.DebuggerDisplay("[{_Key}, {Value}]")]
+    readonly struct _MaterialParameter<T> : IMaterialParameter
+        where T : unmanaged, IEquatable<T>
+    {
+        #region constants
+
+        internal enum Key
+        {
+            RGB,
+            RGBA,
+
+            NormalScale,
+            OcclusionStrength,
+
+            MetallicFactor,
+            RoughnessFactor,
+            SpecularFactor,
+            GlossinessFactor,
+            ClearCoatFactor,
+            ThicknessFactor,
+            TransmissionFactor,
+            AttenuationDistance,
+        }
+
+        #endregion
+
+        #region constructors
+
+        internal _MaterialParameter(Key key, T defval, Func<T> getter, Action<T> setter)
+        {
+            _Key = key;
+            _ValueDefault = defval;
+            _ValueGetter = () => getter();
+            _ValueSetter = value => setter(value);
+        }
+
+        #endregion
+
+        #region data
+
+        private readonly Key _Key;
+        private readonly T _ValueDefault;
+        private readonly Func<T> _ValueGetter;
+        private readonly Action<T> _ValueSetter;
+
+        #endregion
+
+        #region properties
+
+        public string Name => _Key.ToString();
+
+        public bool IsDefault => Value.Equals(_ValueDefault);
+
+        public Type ValueType => _ValueDefault.GetType();
+
+        public T Value
+        {
+            get => _ValueGetter();
+            set => _ValueSetter(value);
+        }
+
+        object IMaterialParameter.Value
+        {
+            get => _ValueGetter();
+            set => _ValueSetter((T)value);
+        }
+
+        #endregion
+
+        #region helpers
+        internal static Vector4 Combine(IReadOnlyList<IMaterialParameter> parameters)
+        {
+            Span<float> tmp = stackalloc float[4];
+            int idx = 0;
+
+            foreach (var p in parameters)
+            {
+                if (p is _MaterialParameter<Single> v1) { tmp[idx++] = v1.Value; }
+                if (p is _MaterialParameter<Vector2> v2) { tmp[idx++] = v2.Value.X; tmp[idx++] = v2.Value.Y; }
+                if (p is _MaterialParameter<Vector3> v3) { tmp[idx++] = v3.Value.X; tmp[idx++] = v3.Value.Y; tmp[idx++] = v3.Value.Z; }
+                if (p is _MaterialParameter<Vector4> v4) { tmp[idx++] = v4.Value.X; tmp[idx++] = v4.Value.Y; tmp[idx++] = v4.Value.Z; tmp[idx++] = v4.Value.W; }
+            }
+
+            return new Vector4(tmp[0], tmp[1], tmp[2], tmp[3]);
+        }
+
+        internal static void Apply(IReadOnlyList<IMaterialParameter> parameters, Vector4 value)
+        {
+            Span<float> tmp = stackalloc float[4];
+            tmp[0] = value.X;
+            tmp[1] = value.Y;
+            tmp[2] = value.Z;
+            tmp[3] = value.W;
+
+            int idx = 0;
+
+            foreach (var p in parameters)
+            {
+                if (p is _MaterialParameter<Single> v1) { v1.Value = tmp[idx++]; }
+                if (p is _MaterialParameter<Vector2> v2) { v2.Value = new Vector2(tmp[idx + 0], tmp[idx + 1]); idx += 2; }
+                if (p is _MaterialParameter<Vector3> v3) { v3.Value = new Vector3(tmp[idx + 0], tmp[idx + 1], tmp[idx + 2]); idx += 3; }
+                if (p is _MaterialParameter<Vector4> v4) { v4.Value = new Vector4(tmp[idx + 0], tmp[idx + 1], tmp[idx + 2], tmp[idx + 3]); idx += 4; }
+            }
+        }
+
+        #endregion
+    }
+}

+ 23 - 23
src/SharpGLTF.Core/Schema2/gltf.MaterialsFactory.cs

@@ -105,20 +105,20 @@ namespace SharpGLTF.Schema2
             channels = this.GetExtension<MaterialVolume>()?.GetChannels(this);
             if (channels != null) { foreach (var c in channels) yield return c; }
 
-            var normalParam = new MaterialParameter(
-                MaterialParameter.Key.NormalScale,
+            var normalParam = new _MaterialParameter<float>(
+                _MaterialParameter<float>.Key.NormalScale,
                 MaterialNormalTextureInfo.ScaleDefault,
                 () => _GetNormalTexture(false)?.Scale ?? MaterialNormalTextureInfo.ScaleDefault,
                 value => _GetNormalTexture(true).Scale = value);
 
-            var occlusionParam = new MaterialParameter(
-                MaterialParameter.Key.OcclusionStrength,
+            var occlusionParam = new _MaterialParameter<float>(
+                _MaterialParameter<float>.Key.OcclusionStrength,
                 MaterialOcclusionTextureInfo.StrengthDefault,
                 () => _GetOcclusionTexture(false)?.Strength ?? MaterialOcclusionTextureInfo.StrengthDefault,
                 value => _GetOcclusionTexture(true).Strength = value);
 
-            var emissiveParam = new MaterialParameter(
-                MaterialParameter.Key.RGB,
+            var emissiveParam = new _MaterialParameter<Vector3>(
+                _MaterialParameter<Vector3>.Key.RGB,
                 _emissiveFactorDefault,
                 () => this._emissiveFactor.AsValue(_emissiveFactorDefault),
                 value => this._emissiveFactor = value.AsNullable(_emissiveFactorDefault, Vector3.Zero, Vector3.One));
@@ -206,9 +206,9 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
-            var colorParam = new MaterialParameter(MaterialParameter.Key.RGBA, _baseColorFactorDefault, () => Color, v => Color = v);
-            var metallicParam = new MaterialParameter(MaterialParameter.Key.MetallicFactor, (float)_metallicFactorDefault, () => MetallicFactor, v => MetallicFactor = v);
-            var roughnessParam = new MaterialParameter(MaterialParameter.Key.RoughnessFactor, (float)_roughnessFactorDefault, () => RoughnessFactor, v => RoughnessFactor = v);
+            var colorParam = new _MaterialParameter<Vector4>(_MaterialParameter<Vector4>.Key.RGBA, _baseColorFactorDefault, () => Color, v => Color = v);
+            var metallicParam = new _MaterialParameter<float>(_MaterialParameter<float>.Key.MetallicFactor, (float)_metallicFactorDefault, () => MetallicFactor, v => MetallicFactor = v);
+            var roughnessParam = new _MaterialParameter<float>(_MaterialParameter<float>.Key.RoughnessFactor, (float)_roughnessFactorDefault, () => RoughnessFactor, v => RoughnessFactor = v);
 
             yield return new MaterialChannel(material, "BaseColor", _GetBaseTexture, colorParam);
             yield return new MaterialChannel(material, "MetallicRoughness", _GetMetallicTexture, metallicParam, roughnessParam);
@@ -275,9 +275,9 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
-            var diffuseParam = new MaterialParameter(MaterialParameter.Key.RGBA, _diffuseFactorDefault, () => DiffuseFactor, v => DiffuseFactor = v);
-            var specularParam = new MaterialParameter(MaterialParameter.Key.SpecularFactor, _specularFactorDefault, () => SpecularFactor, v => SpecularFactor = v);
-            var glossinessParam = new MaterialParameter(MaterialParameter.Key.GlossinessFactor, (float)_glossinessFactorDefault, () => GlossinessFactor, v => GlossinessFactor = v);
+            var diffuseParam = new _MaterialParameter<Vector4>(_MaterialParameter<Vector4>.Key.RGBA, _diffuseFactorDefault, () => DiffuseFactor, v => DiffuseFactor = v);
+            var specularParam = new _MaterialParameter<Vector3>(_MaterialParameter<Vector3>.Key.SpecularFactor, _specularFactorDefault, () => SpecularFactor, v => SpecularFactor = v);
+            var glossinessParam = new _MaterialParameter<float>(_MaterialParameter<float>.Key.GlossinessFactor, (float)_glossinessFactorDefault, () => GlossinessFactor, v => GlossinessFactor = v);
 
             yield return new MaterialChannel(material, "Diffuse", _GetDiffuseTexture, diffuseParam);
             yield return new MaterialChannel(material, "SpecularGlossiness", _GetGlossinessTexture, specularParam, glossinessParam);
@@ -349,9 +349,9 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
-            var clearCoatParam = new MaterialParameter(MaterialParameter.Key.ClearCoatFactor, (float)_clearcoatFactorDefault, () => ClearCoatFactor, v => ClearCoatFactor = v);
-            var roughnessParam = new MaterialParameter(MaterialParameter.Key.RoughnessFactor, (float)_clearcoatRoughnessFactorDefault, () => RoughnessFactor, v => RoughnessFactor = v);
-            var normScaleParam = new MaterialParameter(MaterialParameter.Key.NormalScale,
+            var clearCoatParam = new _MaterialParameter<float>(_MaterialParameter<float>.Key.ClearCoatFactor, (float)_clearcoatFactorDefault, () => ClearCoatFactor, v => ClearCoatFactor = v);
+            var roughnessParam = new _MaterialParameter<float>(_MaterialParameter<float>.Key.RoughnessFactor, (float)_clearcoatRoughnessFactorDefault, () => RoughnessFactor, v => RoughnessFactor = v);
+            var normScaleParam = new _MaterialParameter<float>(_MaterialParameter<float>.Key.NormalScale,
                 MaterialNormalTextureInfo.ScaleDefault,
                 () => _GetClearCoatNormalTexture(false)?.Scale ?? MaterialNormalTextureInfo.ScaleDefault,
                 v => _GetClearCoatNormalTexture(true).Scale = v);
@@ -391,7 +391,7 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
-            var transmissionParam = new MaterialParameter(MaterialParameter.Key.TransmissionFactor, (float)_transmissionFactorDefault, () => TransmissionFactor, v => TransmissionFactor = v);
+            var transmissionParam = new _MaterialParameter<float>(_MaterialParameter<float>.Key.TransmissionFactor, (float)_transmissionFactorDefault, () => TransmissionFactor, v => TransmissionFactor = v);
 
             yield return new MaterialChannel(material, "Transmission", _GetTransmissionTexture, transmissionParam);
         }
@@ -445,8 +445,8 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
-            var colorParam = new MaterialParameter(MaterialParameter.Key.RGB, _sheenColorFactorDefault, () => ColorFactor, v => ColorFactor = v);
-            var roughnessParam = new MaterialParameter(MaterialParameter.Key.RoughnessFactor, _sheenRoughnessFactorDefault, () => RoughnessFactor, v => RoughnessFactor = v);
+            var colorParam = new _MaterialParameter<Vector3>(_MaterialParameter<Vector3>.Key.RGB, _sheenColorFactorDefault, () => ColorFactor, v => ColorFactor = v);
+            var roughnessParam = new _MaterialParameter<float>(_MaterialParameter<float>.Key.RoughnessFactor, _sheenRoughnessFactorDefault, () => RoughnessFactor, v => RoughnessFactor = v);
 
             yield return new MaterialChannel(material, "SheenColor", _GetSheenColorTexture, colorParam);
             yield return new MaterialChannel(material, "SheenRoughness", _GetSheenRoughnessTexture, roughnessParam);
@@ -542,8 +542,8 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
-            var colorParam = new MaterialParameter(MaterialParameter.Key.RGB, _specularColorFactorDefault, () => SpecularColor, v => SpecularColor = v);
-            var factorParam = new MaterialParameter(MaterialParameter.Key.SpecularFactor, (float)_specularFactorDefault, () => SpecularFactor, v => SpecularFactor = v);
+            var colorParam = new _MaterialParameter<Vector3>(_MaterialParameter<Vector3>.Key.RGB, _specularColorFactorDefault, () => SpecularColor, v => SpecularColor = v);
+            var factorParam = new _MaterialParameter<float>(_MaterialParameter<float>.Key.SpecularFactor, (float)_specularFactorDefault, () => SpecularFactor, v => SpecularFactor = v);
 
             yield return new MaterialChannel(material, "SpecularColor", _GetSpecularColorTexture, colorParam);
             yield return new MaterialChannel(material, "SpecularFactor", _GetSpecularFactorTexture, factorParam);
@@ -604,9 +604,9 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
-            var thicknessParam = new MaterialParameter(MaterialParameter.Key.ThicknessFactor, (float)_thicknessFactorDefault, () => ThicknessFactor, v => ThicknessFactor = v);
-            var attColorParam = new MaterialParameter(MaterialParameter.Key.RGB, _attenuationColorDefault, () => AttenuationColor, v => AttenuationColor = v);
-            var attDistParam = new MaterialParameter(MaterialParameter.Key.AttenuationDistance, 0, () => AttenuationDistance, v => AttenuationDistance = v);
+            var thicknessParam = new _MaterialParameter<float>(_MaterialParameter<float>.Key.ThicknessFactor, (float)_thicknessFactorDefault, () => ThicknessFactor, v => ThicknessFactor = v);
+            var attColorParam = new _MaterialParameter<Vector3>(_MaterialParameter<Vector3>.Key.RGB, _attenuationColorDefault, () => AttenuationColor, v => AttenuationColor = v);
+            var attDistParam = new _MaterialParameter<float>(_MaterialParameter<float>.Key.AttenuationDistance, 0, () => AttenuationDistance, v => AttenuationDistance = v);
 
             yield return new MaterialChannel(material, "VolumeThickness", _GetThicknessTexture, thicknessParam);
             yield return new MaterialChannel(material, "VolumeAttenuation", onCreate => null, attColorParam, attDistParam);

+ 3 - 3
src/SharpGLTF.Toolkit/Schema2/MaterialExtensions.cs

@@ -39,7 +39,7 @@ namespace SharpGLTF.Schema2
 
             var ch = material.WithPBRMetallicRoughness().FindChannel("BaseColor").Value;
 
-            ch.Parameter = diffuseColor;
+            ch.Color = diffuseColor;
 
             return material;
         }
@@ -499,10 +499,10 @@ namespace SharpGLTF.Schema2
             if (material == null) return defaultColor;
 
             var channel = material.FindChannel("Diffuse");
-            if (channel.HasValue) return channel.Value.Parameter;
+            if (channel.HasValue) return channel.Value.Color;
 
             channel = material.FindChannel("BaseColor");
-            if (channel.HasValue) return channel.Value.Parameter;
+            if (channel.HasValue) return channel.Value.Color;
 
             return defaultColor;
         }

+ 2 - 2
tests/SharpGLTF.Core.Tests/Schema2/Authoring/ExtensionsCreationTests.cs

@@ -194,8 +194,8 @@ namespace SharpGLTF.Schema2.Authoring
             scene.AddRigidMesh(mesh, Matrix4x4.Identity);
 
             var gltf2 = scene.ToGltf2();
-            var sheenColorFactor = gltf2.LogicalMaterials[0].FindChannel("SheenColor").Value.Parameter;
-            Assert.AreEqual(new Vector4(1, 1, 1, 0), sheenColorFactor);
+            var sheenColorFactor = gltf2.LogicalMaterials[0].FindChannel("SheenColor").Value.Color;
+            Assert.AreEqual(Vector4.One, sheenColorFactor);
 
             var sheenRoughnessFactor = gltf2.LogicalMaterials[0].FindChannel("SheenRoughness").Value.Parameter;
             Assert.AreEqual(new Vector4(0.5f, 0, 0, 0), sheenRoughnessFactor);