Explorar el Código

documentation and some API changes.

Vicente Penades hace 6 años
padre
commit
f83ab047d8

+ 2 - 2
build/SharpGLTF.CodeGen/SharpGLTF.CodeGen.csproj

@@ -8,8 +8,8 @@
 
   <ItemGroup>
     <PackageReference Include="LibGit2Sharp" Version="0.26.0" />
-    <PackageReference Include="NJsonSchema.CodeGeneration" Version="9.13.29" />
-    <PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="9.13.29" />
+    <PackageReference Include="NJsonSchema.CodeGeneration" Version="9.13.34" />
+    <PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="9.13.34" />
   </ItemGroup>
 
 </Project>

+ 37 - 0
src/SharpGLTF.Core/Memory/ColorArray.cs

@@ -18,12 +18,49 @@ namespace SharpGLTF.Memory
     {
         #region constructors
 
+        /// <summary>
+        /// Initializes a new instance of the <see cref="ColorArray"/> struct.
+        /// </summary>
+        /// <param name="source">The array to wrap.</param>
+        /// <param name="byteOffset">The zero-based index of the first <see cref="Byte"/> in <paramref name="source"/>.</param>
+        /// <param name="itemsCount">The number of <see cref="Vector4"/> items in <paramref name="source"/>.</param>
+        /// <param name="byteStride">
+        /// The byte stride between elements.
+        /// If the value is zero, the size of the item is used instead.
+        /// </param>
+        /// <param name="dimensions">The number of elements per item. Currently only values 3 and 4 are supported.</param>
+        /// <param name="encoding">A value of <see cref="ENCODING"/>.</param>
+        /// <param name="normalized">True if values are normalized.</param>
         public ColorArray(Byte[] source, int byteOffset, int itemsCount, int byteStride, int dimensions = 4, ENCODING encoding = ENCODING.FLOAT, Boolean normalized = false)
             : this(new BYTES(source), byteOffset, itemsCount, byteStride, dimensions, encoding, normalized) { }
 
+        /// <summary>
+        /// Initializes a new instance of the <see cref="ColorArray"/> struct.
+        /// </summary>
+        /// <param name="source">The array to wrap.</param>
+        /// <param name="byteStride">
+        /// The byte stride between elements.
+        /// If the value is zero, the size of the item is used instead.
+        /// </param>
+        /// <param name="dimensions">The number of elements per item. Currently only values 3 and 4 are supported.</param>
+        /// <param name="encoding">A value of <see cref="ENCODING"/>.</param>
+        /// <param name="normalized">True if values are normalized.</param>
         public ColorArray(BYTES source, int byteStride = 0, int dimensions = 4, ENCODING encoding = ENCODING.FLOAT, Boolean normalized = false)
             : this(source, 0, int.MaxValue, byteStride, dimensions, encoding, normalized) { }
 
+        /// <summary>
+        /// Initializes a new instance of the <see cref="ColorArray"/> struct.
+        /// </summary>
+        /// <param name="source">The array to wrap.</param>
+        /// <param name="byteOffset">The zero-based index of the first <see cref="Byte"/> in <paramref name="source"/>.</param>
+        /// <param name="itemsCount">The number of <see cref="Vector4"/> items in <paramref name="source"/>.</param>
+        /// <param name="byteStride">
+        /// The byte stride between elements.
+        /// If the value is zero, the size of the item is used instead.
+        /// </param>
+        /// <param name="dimensions">The number of elements per item. Currently only values 3 and 4 are supported.</param>
+        /// <param name="encoding">A value of <see cref="ENCODING"/>.</param>
+        /// <param name="normalized">True if values are normalized.</param>
         public ColorArray(BYTES source, int byteOffset, int itemsCount, int byteStride, int dimensions = 4, ENCODING encoding = ENCODING.FLOAT, Boolean normalized = false)
         {
             Guard.MustBeBetweenOrEqualTo(dimensions, 3, 4, nameof(dimensions));

+ 34 - 0
src/SharpGLTF.Core/Memory/FloatingArrays.cs

@@ -548,12 +548,46 @@ namespace SharpGLTF.Memory
     {
         #region constructors
 
+        /// <summary>
+        /// Initializes a new instance of the <see cref="Vector4Array"/> struct.
+        /// </summary>
+        /// <param name="source">The array to wrap.</param>
+        /// <param name="byteOffset">The zero-based index of the first <see cref="Byte"/> in <paramref name="source"/>.</param>
+        /// <param name="itemsCount">The number of <see cref="Vector3"/> items in <paramref name="source"/>.</param>
+        /// <param name="byteStride">
+        /// The byte stride between elements.
+        /// If the value is zero, the size of the item is used instead.
+        /// </param>
+        /// <param name="encoding">A value of <see cref="ENCODING"/>.</param>
+        /// <param name="normalized">True if values are normalized.</param>
         public Vector4Array(Byte[] source, int byteOffset, int itemsCount, int byteStride, ENCODING encoding = ENCODING.FLOAT, Boolean normalized = false)
             : this(new BYTES(source), byteOffset, itemsCount, byteStride, encoding, normalized) { }
 
+        /// <summary>
+        /// Initializes a new instance of the <see cref="Vector4Array"/> struct.
+        /// </summary>
+        /// <param name="source">The array range to wrap.</param>
+        /// <param name="byteStride">
+        /// The byte stride between elements.
+        /// If the value is zero, the size of the item is used instead.
+        /// </param>
+        /// <param name="encoding">A value of <see cref="ENCODING"/>.</param>
+        /// <param name="normalized">True if values are normalized.</param>
         public Vector4Array(BYTES source, int byteStride = 0, ENCODING encoding = ENCODING.FLOAT, Boolean normalized = false)
             : this(source, 0, int.MaxValue, byteStride, encoding, normalized) { }
 
+        /// <summary>
+        /// Initializes a new instance of the <see cref="Vector4Array"/> struct.
+        /// </summary>
+        /// <param name="source">The array range to wrap.</param>
+        /// <param name="byteOffset">The zero-based index of the first <see cref="Byte"/> in <paramref name="source"/>.</param>
+        /// <param name="itemsCount">The number of <see cref="Vector3"/> items in <paramref name="source"/>.</param>
+        /// <param name="byteStride">
+        /// The byte stride between elements.
+        /// If the value is zero, the size of the item is used instead.
+        /// </param>
+        /// <param name="encoding">A value of <see cref="ENCODING"/>.</param>
+        /// <param name="normalized">True if values are normalized.</param>
         public Vector4Array(BYTES source, int byteOffset, int itemsCount, int byteStride, ENCODING encoding = ENCODING.FLOAT, Boolean normalized = false)
         {
             _Accessor = new FloatingAccessor(source, byteOffset, itemsCount, byteStride, 4, encoding, normalized);

+ 38 - 18
src/SharpGLTF.Toolkit/Materials/Channel.cs → src/SharpGLTF.Toolkit/Materials/ChannelBuilder.cs

@@ -1,35 +1,26 @@
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Numerics;
 using System.Text;
 
 namespace SharpGLTF.Materials
 {
     [System.Diagnostics.DebuggerDisplay("{Key} {Parameter}")]
-    public class MaterialChannelBuilder
+    public class ChannelBuilder
     {
         #region lifecycle
 
-        internal MaterialChannelBuilder(MaterialBuilder parent, string key)
+        internal ChannelBuilder(MaterialBuilder parent, string key)
         {
-            _Parent = parent; _Key = key;
+            Guard.NotNull(parent, nameof(parent));
+            Guard.NotNullOrEmpty(key, nameof(key));
+            Guard.IsTrue(Enum.GetNames(typeof(KnownChannels)).Contains(key), nameof(key), $"{nameof(key)} must be a name of {nameof(KnownChannels)}.");
 
-            switch (_Key)
-            {
-                case "Emissive": Parameter = Vector4.Zero; break;
-
-                case "Normal":
-                case "Occlusion":
-                    Parameter = new Vector4(1, 0, 0, 0); break;
-
-                case "BaseColor":
-                case "Diffuse":
-                    Parameter = Vector4.One; break;
+            _Parent = parent;
+            _Key = key;
 
-                case "MetalicRoughness": Parameter = new Vector4(1, 1, 0, 0); break;
-
-                case "SpecularGlossiness": Parameter = Vector4.One; break;
-            }
+            SetDefaultParameter();
         }
 
         #endregion
@@ -44,8 +35,15 @@ namespace SharpGLTF.Materials
 
         #region properties
 
+        /// <summary>
+        /// Gets the <see cref="ChannelBuilder"/> name. It must be a name of <see cref="KnownChannels"/>.
+        /// </summary>
         public String Key => _Key;
 
+        /// <summary>
+        /// Gets or sets the <see cref="ChannelBuilder"/> paramenter.
+        /// Its meaning depends on <see cref="Key"/>.
+        /// </summary>
         public Vector4 Parameter { get; set; }
 
         public TextureBuilder Texture { get; private set; }
@@ -54,12 +52,34 @@ namespace SharpGLTF.Materials
 
         #region API
 
+        public void SetDefaultParameter()
+        {
+            switch (_Key)
+            {
+                case "Emissive": Parameter = Vector4.Zero; break;
+
+                case "Normal":
+                case "Occlusion":
+                    Parameter = new Vector4(1, 0, 0, 0); break;
+
+                case "BaseColor":
+                case "Diffuse":
+                    Parameter = Vector4.One; break;
+
+                case "MetalicRoughness": Parameter = new Vector4(1, 1, 0, 0); break;
+
+                case "SpecularGlossiness": Parameter = Vector4.One; break;
+            }
+        }
+
         public TextureBuilder UseTexture()
         {
             if (Texture == null) Texture = new TextureBuilder(this);
             return Texture;
         }
 
+        public void RemoveTexture() { Texture = null; }
+
         #endregion
     }
 

+ 7 - 7
src/SharpGLTF.Toolkit/Materials/Material.cs → src/SharpGLTF.Toolkit/Materials/MaterialBuilder.cs

@@ -26,7 +26,7 @@ namespace SharpGLTF.Materials
         public const string SHADERPBRMETALLICROUGHNESS = "PBRMetallicRoughness";
         public const string SHADERPBRSPECULARGLOSSINESS = "PBRSpecularGlossiness";
 
-        private readonly List<MaterialChannelBuilder> _Channels = new List<MaterialChannelBuilder>();
+        private readonly List<ChannelBuilder> _Channels = new List<ChannelBuilder>();
 
         private MaterialBuilder _CompatibilityFallbackMaterial;
 
@@ -36,7 +36,7 @@ namespace SharpGLTF.Materials
 
         public string Name { get; set; }
 
-        public IReadOnlyCollection<MaterialChannelBuilder> Channels => _Channels;
+        public IReadOnlyCollection<ChannelBuilder> Channels => _Channels;
 
         public ALPHA AlphaMode { get; set; } = ALPHA.OPAQUE;
 
@@ -96,12 +96,12 @@ namespace SharpGLTF.Materials
             return this;
         }
 
-        public MaterialChannelBuilder GetChannel(KnownChannels channelKey)
+        public ChannelBuilder GetChannel(KnownChannels channelKey)
         {
             return GetChannel(channelKey.ToString());
         }
 
-        public MaterialChannelBuilder GetChannel(string channelKey)
+        public ChannelBuilder GetChannel(string channelKey)
         {
             Guard.NotNullOrEmpty(channelKey, nameof(channelKey));
 
@@ -110,17 +110,17 @@ namespace SharpGLTF.Materials
             return _Channels.FirstOrDefault(item => string.Equals(channelKey, item.Key, StringComparison.OrdinalIgnoreCase));
         }
 
-        public MaterialChannelBuilder UseChannel(KnownChannels channelKey)
+        public ChannelBuilder UseChannel(KnownChannels channelKey)
         {
             return UseChannel(channelKey.ToString());
         }
 
-        public MaterialChannelBuilder UseChannel(string channelKey)
+        public ChannelBuilder UseChannel(string channelKey)
         {
             var ch = GetChannel(channelKey);
             if (ch != null) return ch;
 
-            ch = new MaterialChannelBuilder(this, channelKey);
+            ch = new ChannelBuilder(this, channelKey);
             _Channels.Add(ch);
 
             return ch;

+ 7 - 10
src/SharpGLTF.Toolkit/Materials/Texture.cs → src/SharpGLTF.Toolkit/Materials/TextureBuilder.cs

@@ -16,13 +16,18 @@ namespace SharpGLTF.Materials
     {
         #region lifecycle
 
-        internal TextureBuilder(MaterialChannelBuilder parent) { _Parent = parent; }
+        internal TextureBuilder(ChannelBuilder parent)
+        {
+            Guard.NotNull(parent, nameof(parent));
+
+            _Parent = parent;
+        }
 
         #endregion
 
         #region data
 
-        private readonly MaterialChannelBuilder _Parent;
+        private readonly ChannelBuilder _Parent;
 
         #endregion
 
@@ -30,14 +35,6 @@ namespace SharpGLTF.Materials
 
         public int CoordinateSet { get; set; } = 0;
 
-        /*
-        public Single Rotation { get; set; } = 0;
-
-        public Vector2 Offset { get; set; } = Vector2.Zero;
-
-        public Vector2 Scale { get; set; } = Vector2.One;
-        */
-
         public BYTES ImageContent { get; set; }
 
         public TEXMIPMAP MinFilter { get; set; } = TEXMIPMAP.DEFAULT;

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

@@ -225,7 +225,7 @@ namespace SharpGLTF.Schema2
             }
         }
 
-        public static void CopyTo(this MaterialChannel srcChannel, Materials.MaterialChannelBuilder dstChannel)
+        public static void CopyTo(this MaterialChannel srcChannel, Materials.ChannelBuilder dstChannel)
         {
             Guard.NotNull(srcChannel, nameof(srcChannel));
             Guard.NotNull(dstChannel, nameof(dstChannel));
@@ -310,7 +310,7 @@ namespace SharpGLTF.Schema2
             }
         }
 
-        public static void CopyTo(this Materials.MaterialChannelBuilder srcChannel, MaterialChannel dstChannel)
+        public static void CopyTo(this Materials.ChannelBuilder srcChannel, MaterialChannel dstChannel)
         {
             Guard.NotNull(srcChannel, nameof(srcChannel));
             Guard.NotNull(dstChannel, nameof(dstChannel));