Browse Source

materials API cleanup

vpenades 9 months ago
parent
commit
757ed79acc

+ 1 - 6
src/SharpGLTF.Core/Schema2/gltf.Material.cs

@@ -123,12 +123,7 @@ namespace SharpGLTF.Schema2
             }
 
             return null;
-        }
-
-        public string GetAnimationPointer()
-        {
-            return $"/materials/{LogicalIndex}/pbrMetallicRoughness";
-        }
+        }        
 
         #endregion
 

+ 54 - 20
src/SharpGLTF.Core/Schema2/gltf.MaterialChannel.cs

@@ -19,7 +19,7 @@ namespace SharpGLTF.Schema2
     {
         #region lifecycle
 
-        internal MaterialChannel(Material m, String key, Func<Boolean, TextureInfo> texInfo, params IMaterialParameter[] parameters)
+        internal MaterialChannel(Material m, String key, _MaterialTexture texInfo, params IMaterialParameter[] parameters)
         {
             Guard.NotNull(m, nameof(m));
             Guard.NotNullOrEmpty(key, nameof(key));
@@ -45,7 +45,7 @@ namespace SharpGLTF.Schema2
         private readonly String _Key;
 
         [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
-        private readonly Func<Boolean, TextureInfo> _TextureInfo;
+        private readonly _MaterialTexture _TextureInfo;
 
         [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
         private readonly IReadOnlyList<IMaterialParameter> _Parameters;
@@ -100,14 +100,14 @@ namespace SharpGLTF.Schema2
         /// </summary>
         public Texture Texture => _GetTexture();
 
+        public TextureSampler TextureSampler => Texture?.Sampler;
+
         /// <summary>
         /// Gets the index of texture's TEXCOORD_[index] attribute used for texture coordinate mapping.
         /// </summary>
-        public int TextureCoordinate => _TextureInfo?.Invoke(false)?.TextureCoordinate ?? 0;
+        public int TextureCoordinate => _TextureInfo.TextureCoordinate;
 
-        public TextureTransform TextureTransform => _TextureInfo?.Invoke(false)?.Transform;
-
-        public TextureSampler TextureSampler => Texture?.Sampler;
+        public TextureTransform TextureTransform => _TextureInfo.TextureTransform;        
 
         public Vector4 Color
         {
@@ -136,14 +136,7 @@ namespace SharpGLTF.Schema2
         #endregion
 
         #region API
-
-        public String GetAnimationPointer()
-        {
-            var ptr = _Material.GetAnimationPointer();
-
-            return ptr + "/" + Key;
-        }
-
+        
         public float GetFactor(string key)
         {
             return _Parameters
@@ -162,7 +155,7 @@ namespace SharpGLTF.Schema2
 
         private Texture _GetTexture()
         {
-            var texInfo = _TextureInfo?.Invoke(false);
+            var texInfo = _TextureInfo.Info;
             if (texInfo == null) return null;
 
             return _Material.LogicalParent.LogicalTextures[texInfo.LogicalTextureIndex];
@@ -181,7 +174,7 @@ namespace SharpGLTF.Schema2
 
             Guard.NotNull(_Material, nameof(_Material));
 
-            if (_TextureInfo == null) throw new InvalidOperationException();
+            if (_TextureInfo.IsEmpty) throw new InvalidOperationException();
 
             var sampler = _Material.LogicalParent.UseTextureSampler(ws, wt, min, mag);
             var texture = _Material.LogicalParent.UseTexture(primaryImg, fallbackImg, sampler);
@@ -196,9 +189,9 @@ namespace SharpGLTF.Schema2
             Guard.NotNull(tex, nameof(tex));
             Guard.MustShareLogicalParent(_Material, tex, nameof(tex));
 
-            if (_TextureInfo == null) throw new InvalidOperationException();
+            if (_TextureInfo.IsEmpty) throw new InvalidOperationException();
 
-            var texInfo = _TextureInfo(true);
+            var texInfo = _TextureInfo.Use();
 
             texInfo.TextureCoordinate = texSet;
             texInfo.LogicalTextureIndex = tex.LogicalIndex;
@@ -206,9 +199,9 @@ namespace SharpGLTF.Schema2
 
         public void SetTransform(Vector2 offset, Vector2 scale, float rotation = 0, int? texCoordOverride = null)
         {
-            if (_TextureInfo == null) throw new InvalidOperationException();
+            if (_TextureInfo.IsEmpty) throw new InvalidOperationException();
 
-            var texInfo = _TextureInfo(true);
+            var texInfo = _TextureInfo.Use();
 
             texInfo.SetTransform(offset, scale, rotation, texCoordOverride);
         }
@@ -222,4 +215,45 @@ namespace SharpGLTF.Schema2
 
         #endregion
     }
+
+    readonly struct _MaterialTexture
+    {
+        public static implicit operator _MaterialTexture(Func<Boolean, TextureInfo> getOrUse)
+        {
+            return new _MaterialTexture(getOrUse);
+        }
+
+        public _MaterialTexture(Func<TextureInfo> getter, Action initialize)
+        {
+            _Getter = getter;
+            _Using = () =>
+            {
+                if (getter == null) return null;
+                var value = getter.Invoke();
+                if (value != null) return value;
+                initialize?.Invoke();
+                return getter.Invoke();
+            };
+        }
+
+        public _MaterialTexture(Func<Boolean,TextureInfo> getOrUse)
+        {
+            _Getter = ()=> getOrUse(false);
+            _Using = () => getOrUse(true);
+        }
+
+        private readonly Func<TextureInfo> _Getter;
+        private readonly Func<TextureInfo> _Using;
+        public bool IsEmpty => _Getter == null;
+        public TextureInfo Info => _Getter?.Invoke();
+
+        /// <summary>
+        /// Gets the index of texture's TEXCOORD_[index] attribute used for texture coordinate mapping.
+        /// </summary>
+        public int TextureCoordinate => _Getter?.Invoke()?.TextureCoordinate ?? 0;
+
+        public TextureTransform TextureTransform => _Getter?.Invoke()?.Transform;
+
+        public TextureInfo Use() => _Using?.Invoke();
+    }
 }

+ 49 - 110
src/SharpGLTF.Core/Schema2/gltf.MaterialsFactory.cs

@@ -129,9 +129,9 @@ namespace SharpGLTF.Schema2
                 () => this._emissiveFactor.AsValue(_emissiveFactorDefault),
                 value => this._emissiveFactor = value.AsNullable(_emissiveFactorDefault, Vector3.Zero, Vector3.One));
 
-            yield return new MaterialChannel(this, "Normal", _GetNormalTexture, normalParam);
-            yield return new MaterialChannel(this, "Occlusion", _GetOcclusionTexture, occlusionParam);
-            yield return new MaterialChannel(this, "Emissive", _GetEmissiveTexture, emissiveFactorParam, MaterialEmissiveStrength.GetParameter(this));
+            yield return new MaterialChannel(this, "Normal", new _MaterialTexture(_GetNormalTexture), normalParam);
+            yield return new MaterialChannel(this, "Occlusion", new _MaterialTexture(_GetOcclusionTexture), occlusionParam);
+            yield return new MaterialChannel(this, "Emissive", new _MaterialTexture(_GetEmissiveTexture), emissiveFactorParam, MaterialEmissiveStrength.GetParameter(this));
         }
 
         private MaterialNormalTextureInfo _GetNormalTexture(bool create)
@@ -219,24 +219,14 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
+            var baseTexture = new _MaterialTexture(() => _baseColorTexture, () => SetProperty(this, ref _baseColorTexture, new TextureInfo()));
             var colorParam = new _MaterialParameter<Vector4>(_MaterialParameterKey.RGBA, _baseColorFactorDefault, () => Color, v => Color = v);
+            yield return new MaterialChannel(material, "BaseColor", baseTexture, colorParam);
+
+            var metallicRoighnessTexture = new _MaterialTexture(() => _metallicRoughnessTexture, () => SetProperty(this, ref _metallicRoughnessTexture, new TextureInfo()));
             var metallicParam = new _MaterialParameter<float>(_MaterialParameterKey.MetallicFactor, (float)_metallicFactorDefault, () => MetallicFactor, v => MetallicFactor = v);
             var roughnessParam = new _MaterialParameter<float>(_MaterialParameterKey.RoughnessFactor, (float)_roughnessFactorDefault, () => RoughnessFactor, v => RoughnessFactor = v);
-
-            yield return new MaterialChannel(material, "BaseColor", _GetBaseTexture, colorParam);
-            yield return new MaterialChannel(material, "MetallicRoughness", _GetMetallicTexture, metallicParam, roughnessParam);
-        }
-
-        private TextureInfo _GetBaseTexture(bool create)
-        {
-            if (create && _baseColorTexture == null) SetProperty(this, ref _baseColorTexture, new TextureInfo());
-            return _baseColorTexture;
-        }
-
-        private TextureInfo _GetMetallicTexture(bool create)
-        {
-            if (create && _metallicRoughnessTexture == null) SetProperty(this, ref _metallicRoughnessTexture, new TextureInfo());
-            return _metallicRoughnessTexture;
+            yield return new MaterialChannel(material, "MetallicRoughness", metallicRoighnessTexture, metallicParam, roughnessParam);
         }        
 
         #endregion
@@ -271,19 +261,7 @@ namespace SharpGLTF.Schema2
             {
                 Guard.MustBeBetweenOrEqualTo(_glossinessFactor.Value, _glossinessFactorMinimum, _glossinessFactorMaximum, nameof(_glossinessFactor));
             }
-        }
-
-        private TextureInfo _GetDiffuseTexture(bool create)
-        {
-            if (create && _diffuseTexture == null) SetProperty(this, ref _diffuseTexture, new TextureInfo());
-            return _diffuseTexture;
-        }
-
-        private TextureInfo _GetGlossinessTexture(bool create)
-        {
-            if (create && _specularGlossinessTexture == null) SetProperty(this, ref _specularGlossinessTexture, new TextureInfo());
-            return _specularGlossinessTexture;
-        }
+        }        
 
         public Vector4 DiffuseFactor
         {
@@ -305,12 +283,14 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
+            var diffuseTexture = new _MaterialTexture(() => _diffuseTexture, () => SetProperty(this, ref _diffuseTexture, new TextureInfo()));
             var diffuseParam = new _MaterialParameter<Vector4>(_MaterialParameterKey.RGBA, _diffuseFactorDefault, () => DiffuseFactor, v => DiffuseFactor = v);
-            var specularParam = new _MaterialParameter<Vector3>(_MaterialParameterKey.SpecularFactor, _specularFactorDefault, () => SpecularFactor, v => SpecularFactor = v);
-            var glossinessParam = new _MaterialParameter<float>(_MaterialParameterKey.GlossinessFactor, (float)_glossinessFactorDefault, () => GlossinessFactor, v => GlossinessFactor = v);
+            yield return new MaterialChannel(material, "Diffuse", diffuseTexture, diffuseParam);
 
-            yield return new MaterialChannel(material, "Diffuse", _GetDiffuseTexture, diffuseParam);
-            yield return new MaterialChannel(material, "SpecularGlossiness", _GetGlossinessTexture, specularParam, glossinessParam);
+            var glossinessTexture = new _MaterialTexture(() => _specularGlossinessTexture, () => SetProperty(this, ref _specularGlossinessTexture, new TextureInfo()));            
+            var specularParam = new _MaterialParameter<Vector3>(_MaterialParameterKey.SpecularFactor, _specularFactorDefault, () => SpecularFactor, v => SpecularFactor = v);
+            var glossinessParam = new _MaterialParameter<float>(_MaterialParameterKey.GlossinessFactor, (float)_glossinessFactorDefault, () => GlossinessFactor, v => GlossinessFactor = v);            
+            yield return new MaterialChannel(material, "SpecularGlossiness", glossinessTexture, specularParam, glossinessParam);
         }
     }
 
@@ -379,16 +359,19 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
+            var clearCoatTexture = new _MaterialTexture(() => _clearcoatTexture, () => SetProperty(this, ref _clearcoatTexture, new TextureInfo()));
             var clearCoatParam = new _MaterialParameter<float>(_MaterialParameterKey.ClearCoatFactor, (float)_clearcoatFactorDefault, () => ClearCoatFactor, v => ClearCoatFactor = v);
+            yield return new MaterialChannel(material, "ClearCoat", clearCoatTexture, clearCoatParam);
+
+            var roughnessTexture = new _MaterialTexture(() => _clearcoatRoughnessTexture, () => SetProperty(this, ref _clearcoatRoughnessTexture, new TextureInfo()));
             var roughnessParam = new _MaterialParameter<float>(_MaterialParameterKey.RoughnessFactor, (float)_clearcoatRoughnessFactorDefault, () => RoughnessFactor, v => RoughnessFactor = v);
+            yield return new MaterialChannel(material, "ClearCoatRoughness", roughnessTexture, roughnessParam);
+
             var normScaleParam = new _MaterialParameter<float>(_MaterialParameterKey.NormalScale,
                 MaterialNormalTextureInfo.ScaleDefault,
                 () => _GetClearCoatNormalTexture(false)?.Scale ?? MaterialNormalTextureInfo.ScaleDefault,
-                v => _GetClearCoatNormalTexture(true).Scale = v);
-
-            yield return new MaterialChannel(material, "ClearCoat", _GetClearCoatTexture, clearCoatParam);
-            yield return new MaterialChannel(material, "ClearCoatRoughness", _GetClearCoatRoughnessTexture, roughnessParam);
-            yield return new MaterialChannel(material, "ClearCoatNormal", _GetClearCoatNormalTexture, normScaleParam);
+                v => _GetClearCoatNormalTexture(true).Scale = v);            
+            yield return new MaterialChannel(material, "ClearCoatNormal", new _MaterialTexture(_GetClearCoatNormalTexture), normScaleParam);
         }
     }
 
@@ -421,18 +404,13 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
+            var transmissionTexture = new _MaterialTexture(() => _transmissionTexture, () => SetProperty(this, ref _transmissionTexture, new TextureInfo()));
             var transmissionParam = new _MaterialParameter<float>(_MaterialParameterKey.TransmissionFactor, (float)_transmissionFactorDefault, () => TransmissionFactor, v => TransmissionFactor = v);
 
-            yield return new MaterialChannel(material, "Transmission", _GetTransmissionTexture, transmissionParam);
-        }
-
-        private TextureInfo _GetTransmissionTexture(bool create)
-        {
-            if (create && _transmissionTexture == null) SetProperty(this, ref _transmissionTexture, new TextureInfo());
-            return _transmissionTexture;
+            yield return new MaterialChannel(material, "Transmission", transmissionTexture, transmissionParam);
         }
     }
-
+    
     internal sealed partial class MaterialSheen
     {
         #pragma warning disable CA1801 // Review unused parameters
@@ -475,23 +453,13 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
+            var colorTexture = new _MaterialTexture(() => _sheenColorTexture, () => SetProperty(this, ref _sheenColorTexture, new TextureInfo()));
             var colorParam = new _MaterialParameter<Vector3>(_MaterialParameterKey.RGB, _sheenColorFactorDefault, () => ColorFactor, v => ColorFactor = v);
-            var roughnessParam = new _MaterialParameter<float>(_MaterialParameterKey.RoughnessFactor, _sheenRoughnessFactorDefault, () => RoughnessFactor, v => RoughnessFactor = v);
-
-            yield return new MaterialChannel(material, "SheenColor", _GetSheenColorTexture, colorParam);
-            yield return new MaterialChannel(material, "SheenRoughness", _GetSheenRoughnessTexture, roughnessParam);
-        }
-
-        private TextureInfo _GetSheenColorTexture(bool create)
-        {
-            if (create && _sheenColorTexture == null) SetProperty(this, ref _sheenColorTexture, new TextureInfo());
-            return _sheenColorTexture;
-        }
+            yield return new MaterialChannel(material, "SheenColor", colorTexture, colorParam);
 
-        private TextureInfo _GetSheenRoughnessTexture(bool create)
-        {
-            if (create && _sheenRoughnessTexture == null) SetProperty(this, ref _sheenRoughnessTexture, new TextureInfo());
-            return _sheenRoughnessTexture;
+            var roughnessTexture = new _MaterialTexture(() => _sheenRoughnessTexture, () => SetProperty(this, ref _sheenRoughnessTexture, new TextureInfo()));
+            var roughnessParam = new _MaterialParameter<float>(_MaterialParameterKey.RoughnessFactor, _sheenRoughnessFactorDefault, () => RoughnessFactor, v => RoughnessFactor = v);            
+            yield return new MaterialChannel(material, "SheenRoughness", roughnessTexture, roughnessParam);
         }
     }
 
@@ -544,19 +512,7 @@ namespace SharpGLTF.Schema2
             {
                 Guard.MustBeBetweenOrEqualTo(_specularFactor.Value, _specularFactorMinimum, _specularFactorMaximum, nameof(_specularFactor));
             }
-        }
-
-        private TextureInfo _GetSpecularColorTexture(bool create)
-        {
-            if (create && _specularColorTexture == null) SetProperty(this, ref _specularColorTexture, new TextureInfo());
-            return _specularColorTexture;
-        }
-
-        private TextureInfo _GetSpecularFactorTexture(bool create)
-        {
-            if (create && _specularTexture == null) SetProperty(this, ref _specularTexture, new TextureInfo());
-            return _specularTexture;
-        }
+        }        
 
         public Vector3 SpecularColor
         {
@@ -572,11 +528,13 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
+            var colorTexture = new _MaterialTexture(() => _specularColorTexture, () => SetProperty(this, ref _specularColorTexture, new TextureInfo()));
             var colorParam = new _MaterialParameter<Vector3>(_MaterialParameterKey.RGB, _specularColorFactorDefault, () => SpecularColor, v => SpecularColor = v);
-            var factorParam = new _MaterialParameter<float>(_MaterialParameterKey.SpecularFactor, (float)_specularFactorDefault, () => SpecularFactor, v => SpecularFactor = v);
+            yield return new MaterialChannel(material, "SpecularColor", colorTexture, colorParam);
 
-            yield return new MaterialChannel(material, "SpecularColor", _GetSpecularColorTexture, colorParam);
-            yield return new MaterialChannel(material, "SpecularFactor", _GetSpecularFactorTexture, factorParam);
+            var factorTexture = new _MaterialTexture(() => _specularTexture, () => SetProperty(this, ref _specularTexture, new TextureInfo()));
+            var factorParam = new _MaterialParameter<float>(_MaterialParameterKey.SpecularFactor, (float)_specularFactorDefault, () => SpecularFactor, v => SpecularFactor = v);            
+            yield return new MaterialChannel(material, "SpecularFactor", factorTexture, factorParam);
         }
     }
 
@@ -606,13 +564,7 @@ namespace SharpGLTF.Schema2
             {
                 Guard.MustBeBetweenOrEqualTo(_thicknessFactor.Value, _thicknessFactorMinimum, float.MaxValue, nameof(_thicknessFactor));
             }
-        }
-
-        private TextureInfo _GetThicknessTexture(bool create)
-        {
-            if (create && _thicknessTexture == null) SetProperty(this, ref _thicknessTexture, new TextureInfo());
-            return _thicknessTexture;
-        }
+        }        
 
         public float ThicknessFactor
         {
@@ -634,12 +586,13 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
+            var thicknessTexture = new _MaterialTexture(() => _thicknessTexture, () => SetProperty(this, ref _thicknessTexture, new TextureInfo()));
             var thicknessParam = new _MaterialParameter<float>(_MaterialParameterKey.ThicknessFactor, (float)_thicknessFactorDefault, () => ThicknessFactor, v => ThicknessFactor = v);
-            var attColorParam = new _MaterialParameter<Vector3>(_MaterialParameterKey.RGB, _attenuationColorDefault, () => AttenuationColor, v => AttenuationColor = v);
-            var attDistParam = new _MaterialParameter<float>(_MaterialParameterKey.AttenuationDistance, 0, () => AttenuationDistance, v => AttenuationDistance = v);
+            yield return new MaterialChannel(material, "VolumeThickness", thicknessTexture, thicknessParam);
 
-            yield return new MaterialChannel(material, "VolumeThickness", _GetThicknessTexture, thicknessParam);
-            yield return new MaterialChannel(material, "VolumeAttenuation", onCreate => null, attColorParam, attDistParam);
+            var attColorParam = new _MaterialParameter<Vector3>(_MaterialParameterKey.RGB, _attenuationColorDefault, () => AttenuationColor, v => AttenuationColor = v);
+            var attDistParam = new _MaterialParameter<float>(_MaterialParameterKey.AttenuationDistance, 0, () => AttenuationDistance, v => AttenuationDistance = v);            
+            yield return new MaterialChannel(material, "VolumeAttenuation", default, attColorParam, attDistParam);
         }
     }
 
@@ -710,22 +663,8 @@ namespace SharpGLTF.Schema2
             var thickMax = _iridescenceThicknessMaximum ?? _iridescenceThicknessMaximumDefault;
 
             Guard.MustBeBetweenOrEqualTo(thickMin, _iridescenceThicknessMinimumMinimum, thickMax, nameof(_iridescenceThicknessMinimum));
-            Guard.MustBeBetweenOrEqualTo(thickMax, thickMin, double.MaxValue, nameof(_iridescenceThicknessMaximum));
-
-            
-        }
-
-        private TextureInfo _GetIridescenceTexture(bool create)
-        {
-            if (create && _iridescenceTexture == null) SetProperty(this, ref _iridescenceTexture, new TextureInfo());
-            return _iridescenceTexture;
-        }
-
-        private TextureInfo _GetIridescenceThicknessTexture(bool create)
-        {
-            if (create && _iridescenceThicknessTexture == null) SetProperty(this, ref _iridescenceThicknessTexture, new TextureInfo());
-            return _iridescenceThicknessTexture;
-        }
+            Guard.MustBeBetweenOrEqualTo(thickMax, thickMin, double.MaxValue, nameof(_iridescenceThicknessMaximum));            
+        }        
 
         public float IridescenceFactor
         {
@@ -753,15 +692,15 @@ namespace SharpGLTF.Schema2
 
         public IEnumerable<MaterialChannel> GetChannels(Material material)
         {
+            var iridisTexture = new _MaterialTexture(() => _iridescenceTexture, () => SetProperty(this, ref _iridescenceTexture, new TextureInfo()));
             var factor = new _MaterialParameter<float>(_MaterialParameterKey.IridescenceFactor, (float)_iridescenceFactorDefault, () => IridescenceFactor, v => IridescenceFactor = v);
             var idxRef = new _MaterialParameter<float>(_MaterialParameterKey.IndexOfRefraction, (float)_iridescenceIorDefault, () => IridescenceIndexOfRefraction, v => IridescenceIndexOfRefraction = v);
+            yield return new MaterialChannel(material, "Iridescence", iridisTexture, factor, idxRef);
 
-            yield return new MaterialChannel(material, "Iridescence", _GetIridescenceTexture, factor, idxRef);
-
+            var thicknessTexture = new _MaterialTexture(() => _iridescenceThicknessTexture, () => SetProperty(this, ref _iridescenceThicknessTexture, new TextureInfo()));
             var thkMin = new _MaterialParameter<float>(_MaterialParameterKey.Minimum, (float)_iridescenceThicknessMinimumDefault, () => IridescenceThicknessMinimum, v => IridescenceThicknessMinimum = v);
             var thkMax = new _MaterialParameter<float>(_MaterialParameterKey.Maximum, (float)_iridescenceThicknessMaximumDefault, () => IridescenceThicknessMaximum, v => IridescenceThicknessMaximum = v);
-
-            yield return new MaterialChannel(material, "IridescenceThickness", _GetIridescenceThicknessTexture, thkMin, thkMax);
+            yield return new MaterialChannel(material, "IridescenceThickness", thicknessTexture, thkMin, thkMax);
         }
     }
 }

+ 1 - 9
src/SharpGLTF.Core/Schema2/gltf.TextureInfo.cs

@@ -50,18 +50,10 @@ namespace SharpGLTF.Schema2
 
         #endregion
 
-        #region API
-
-        internal string _GetAnimationPointer()
-        {
-            throw new NotImplementedException();
-        }
+        #region API        
 
         public void SetTransform(Vector2 offset, Vector2 scale, float rotation, int? texCoordOverride = null)
         {
-            var oldXform = this.GetExtension<TextureTransform>();
-            if (oldXform != null) oldXform._Parent = null;
-
             var xform = new TextureTransform(this)
             {
                 TextureCoordinateOverride = texCoordOverride,

+ 2 - 60
src/SharpGLTF.Core/Schema2/gltf.TextureTransform.cs

@@ -16,14 +16,12 @@ namespace SharpGLTF.Schema2
         #region lifecycle
 
         #pragma warning disable CA1801 // Review unused parameters
-        internal TextureTransform(TextureInfo parent) { _Parent = parent; }
+        internal TextureTransform(TextureInfo parent) { }
         #pragma warning restore CA1801 // Review unused parameters
 
         #endregion
 
-        #region properties
-
-        internal TextureInfo _Parent;
+        #region properties        
 
         public Vector2 Offset
         {
@@ -77,61 +75,5 @@ namespace SharpGLTF.Schema2
         }
 
         #endregion
-
-        #region API
-
-        private string _GetAnimationPointer(string propertyName)
-        {
-            switch (propertyName)
-            {
-                case "offset": break;
-                case "rotation": break;
-                case "scale": break;
-                default: throw new ArgumentException("invalid property", nameof(propertyName));
-            }
-
-            var pointerPath = _Parent._GetAnimationPointer() + $"/extensions/KHR_texture_transform/{propertyName}";
-
-            return pointerPath;
-        }
-
-        public Matrix3x2 GetMatrix(Animation track, float time)
-        {
-            if (track == null) return this.Matrix;
-
-            var scale = track
-                .FindChannels(_GetAnimationPointer("scale"))
-                .FirstOrDefault()?.GetSamplerOrNull<Vector2>()?.CreateCurveSampler()?.GetPoint(time)
-                ?? this.Scale;
-
-            var rotation = track
-                .FindChannels(_GetAnimationPointer("rotation"))
-                .FirstOrDefault()?.GetSamplerOrNull<Single>()?.CreateCurveSampler()?.GetPoint(time)
-                ?? this.Rotation;
-
-            var offset = track
-                .FindChannels(_GetAnimationPointer("offset"))
-                .FirstOrDefault()?.GetSamplerOrNull<Vector2>()?.CreateCurveSampler()?.GetPoint(time)
-                ?? this.Offset;
-
-            var s = Matrix3x2.CreateScale(scale);
-            var r = Matrix3x2.CreateRotation(-rotation);
-            var t = Matrix3x2.CreateTranslation(offset);
-
-            return s * r * t;
-        }
-
-        internal void CopyTo(TextureTransform other)
-        {
-            if (other == null) throw new ArgumentNullException(nameof(other));
-            other.TextureCoordinateOverride = this.TextureCoordinateOverride;
-            other.Rotation = this.Rotation;
-            other.Offset = this.Offset;
-            other.Scale = this.Scale;
-        }
-
-        #endregion
     }
-
-
 }