Jelajahi Sumber

Added more documentation

Vicente Penades 6 tahun lalu
induk
melakukan
6132a1338d

+ 16 - 1
build/SharpGLTF.CodeGen/CodeGen/CodeEmitUtils.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Text;
 
 namespace SharpGLTF.CodeGen
@@ -44,10 +45,24 @@ namespace SharpGLTF.CodeGen
 
             yield return "}";
         }
-
+        
         public static IEnumerable<string> Indent(this IEnumerable<string> lines, int indent)
         {
             foreach (var l in lines) yield return l.Indent(indent);            
         }
+        
+        public static IEnumerable<string> EmitSummary(this string description, int indent)
+        {
+            if (string.IsNullOrWhiteSpace(description)) yield break;
+
+            var lines = description
+                .Split("  ")
+                .Select(item => item.Trim())
+                .ToList();
+
+            yield return "/// <summary>".Indent(indent);
+            foreach(var l in lines) yield return $"/// {l}";
+            yield return "/// </summary>".Indent(indent);
+        }
     }
 }

+ 5 - 0
build/SharpGLTF.CodeGen/CodeGen/EmitCSharp.cs

@@ -396,6 +396,7 @@ namespace SharpGLTF.CodeGen
         {
             var xclass = new CSharpClassEmitter(this)
             {
+                ClassSummary = type.Description,
                 ClassDeclaration = _GetClassDeclaration(type),
                 HasBaseClass = type.BaseClass != null
             };
@@ -492,6 +493,8 @@ namespace SharpGLTF.CodeGen
         private readonly List<string> _SerializerBody = new List<string>();
         private readonly List<string> _DeserializerSwitchBody = new List<string>();
 
+        public string ClassSummary { get; set; }
+
         public string ClassDeclaration { get; set; }
 
         public bool HasBaseClass { get; set; }
@@ -578,6 +581,8 @@ namespace SharpGLTF.CodeGen
 
         public IEnumerable<string> EmitCode()
         {
+            foreach (var l in ClassSummary.EmitSummary(0)) yield return l;
+            
             yield return ClassDeclaration;
             yield return "{";
 

+ 4 - 0
build/SharpGLTF.CodeGen/SchemaReflection/SchemaTypes.cs

@@ -33,6 +33,8 @@ namespace SharpGLTF.SchemaReflection
 
         #region properties
 
+        public String Description { get; set; }
+
         public Context Owner => _Owner;
 
         #endregion
@@ -240,6 +242,8 @@ namespace SharpGLTF.SchemaReflection
 
         public ClassType DeclaringClass => _Owner;
 
+        public String Description { get; set; }
+
         public string PersistentName => _PersistentName;                
 
         public SchemaType FieldType { get => _FieldType; set => _FieldType = value; }

+ 5 - 0
build/SharpGLTF.CodeGen/SchemaReflection/SchemaTypesReader.cs

@@ -123,6 +123,8 @@ namespace SharpGLTF.SchemaReflection
             {
                 var classDecl = ctx.UseClass(schema.Title);
 
+                classDecl.Description = schema.Description;
+
                 // process base class                
 
                 if (schema.InheritedSchema != null) classDecl.BaseClass = ctx._UseType(schema.InheritedSchema) as ClassType;
@@ -147,6 +149,9 @@ namespace SharpGLTF.SchemaReflection
                 foreach(var p in props)
                 {
                     var field = classDecl.UseField(p.Name);
+
+                    field.Description = p.Description;
+
                     field.FieldType = ctx._UseType(p, required.Contains(p.Name));
 
                     field.MinimumValue = p.Minimum;

+ 3 - 0
src/SharpGLTF.DOM/Schema2/Generated/ext.Unlit.g.cs

@@ -25,6 +25,9 @@ namespace SharpGLTF.Schema2
 {
 	using Collections;
 
+	/// <summary>
+	/// glTF extension that defines the unlit material model.
+	/// </summary>
 	partial class MaterialUnlit_KHR : glTFProperty
 	{
 	

+ 3 - 0
src/SharpGLTF.DOM/Schema2/Generated/ext.pbrSpecularGlossiness.g.cs

@@ -25,6 +25,9 @@ namespace SharpGLTF.Schema2
 {
 	using Collections;
 
+	/// <summary>
+	/// glTF extension that defines the specular-glossiness material model from Physically-Based Rendering (PBR) methodology.
+	/// </summary>
 	partial class MaterialPBRSpecularGlossiness_KHR : glTFProperty
 	{
 	

+ 85 - 0
src/SharpGLTF.DOM/Schema2/Generated/gltf.g.cs

@@ -156,6 +156,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// Indices of those attributes that deviate from their initialization value.
+	/// </summary>
 	partial class AccessorSparseIndices : glTFProperty
 	{
 	
@@ -189,6 +192,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// Array of size `accessor.sparse.count` times number of components storing the displaced accessor attributes pointed by `accessor.sparse.indices`.
+	/// </summary>
 	partial class AccessorSparseValues : glTFProperty
 	{
 	
@@ -218,6 +224,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// Sparse storage of attributes that deviate from their initialization value.
+	/// </summary>
 	partial class AccessorSparse : glTFProperty
 	{
 	
@@ -250,6 +259,11 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// A typed view into a bufferView.
+	/// A bufferView contains raw binary data.
+	/// An accessor provides a typed view into a bufferView or a subset of a bufferView similar to how WebGL's `vertexAttribPointer()` defines an attribute in a buffer.
+	/// </summary>
 	partial class Accessor : LogicalChildOfRoot
 	{
 	
@@ -313,6 +327,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// The index of the node and TRS property that an animation channel targets.
+	/// </summary>
 	partial class AnimationChannelTarget : glTFProperty
 	{
 	
@@ -340,6 +357,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// Targets an animation's sampler at a node's property.
+	/// </summary>
 	partial class AnimationChannel : glTFProperty
 	{
 	
@@ -367,6 +387,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// Combines input and output accessors with an interpolation algorithm to define a keyframe graph (but not its target).
+	/// </summary>
 	partial class AnimationSampler : glTFProperty
 	{
 	
@@ -399,6 +422,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// A keyframe animation.
+	/// </summary>
 	partial class Animation : LogicalChildOfRoot
 	{
 	
@@ -428,6 +454,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// Metadata about the glTF asset.
+	/// </summary>
 	partial class Asset : glTFProperty
 	{
 	
@@ -463,6 +492,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// A buffer points to binary geometry, animation, or skins.
+	/// </summary>
 	partial class Buffer : LogicalChildOfRoot
 	{
 	
@@ -491,6 +523,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// A view into a buffer generally representing a subset of the buffer.
+	/// </summary>
 	partial class BufferView : LogicalChildOfRoot
 	{
 	
@@ -535,6 +570,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// An orthographic camera containing properties to create an orthographic projection matrix.
+	/// </summary>
 	partial class CameraOrthographic : glTFProperty
 	{
 	
@@ -572,6 +610,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// A perspective camera containing properties to create a perspective projection matrix.
+	/// </summary>
 	partial class CameraPerspective : glTFProperty
 	{
 	
@@ -611,6 +652,10 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// A camera's projection.
+	/// A node can reference a camera to apply a transform to place the camera in the scene.
+	/// </summary>
 	partial class Camera : LogicalChildOfRoot
 	{
 	
@@ -642,6 +687,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// Reference to a texture.
+	/// </summary>
 	partial class TextureInfo : glTFProperty
 	{
 	
@@ -671,6 +719,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// A set of parameter values that are used to define the metallic-roughness material model from Physically-Based Rendering (PBR) methodology.
+	/// </summary>
 	partial class MaterialPBRMetallicRoughness : glTFProperty
 	{
 	
@@ -767,6 +818,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// The material appearance of a primitive.
+	/// </summary>
 	partial class Material : LogicalChildOfRoot
 	{
 	
@@ -823,6 +877,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// Geometry to be rendered with the given material.
+	/// </summary>
 	partial class MeshPrimitive : glTFProperty
 	{
 	
@@ -864,6 +921,11 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// A set of primitives to be rendered.
+	/// A node can contain one mesh.
+	/// A node's transform places the mesh in the scene.
+	/// </summary>
 	partial class Mesh : LogicalChildOfRoot
 	{
 	
@@ -893,6 +955,11 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// A node in the node hierarchy.
+	/// When the node contains `skin`, all `mesh.primitives` must contain `JOINTS_0` and `WEIGHTS_0` attributes.
+	/// A node can have either a `matrix` or any combination of `translation`/`rotation`/`scale` (TRS) properties. TRS properties are converted to matrices and postmultiplied in the `T * R * S` order to compose the transformation matrix; first the scale is applied to the vertices, then the rotation, and then the translation. If none are provided, the transform is the identity. When a node is targeted for animation (referenced by an animation.channel.target), only TRS properties may be present; `matrix` will not be present.
+	/// </summary>
 	partial class Node : LogicalChildOfRoot
 	{
 	
@@ -950,6 +1017,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// Texture sampler properties for filtering and wrapping modes.
+	/// </summary>
 	partial class Sampler : LogicalChildOfRoot
 	{
 	
@@ -987,6 +1057,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// The root nodes of a scene.
+	/// </summary>
 	partial class Scene : LogicalChildOfRoot
 	{
 	
@@ -1011,6 +1084,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// Joints and matrices defining a skin.
+	/// </summary>
 	partial class Skin : LogicalChildOfRoot
 	{
 	
@@ -1043,6 +1119,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// A texture and its sampler.
+	/// </summary>
 	partial class Texture : LogicalChildOfRoot
 	{
 	
@@ -1070,6 +1149,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// The root object for a glTF asset.
+	/// </summary>
 	partial class ModelRoot : glTFProperty
 	{
 	
@@ -1172,6 +1254,9 @@ namespace SharpGLTF.Schema2
 	
 	}
 
+	/// <summary>
+	/// Image data used to create a texture. Image can be referenced by URI or `bufferView` index. `mimeType` is required in the latter case.
+	/// </summary>
 	partial class Image : LogicalChildOfRoot
 	{
 	

+ 26 - 1
src/SharpGLTF.DOM/Schema2/gltf.BufferView.cs

@@ -110,7 +110,7 @@ namespace SharpGLTF.Schema2
         }
 
         /// <summary>
-        /// Checks if all the accessors use this buffer in interleaved arrangement
+        /// Checks if <paramref name="accessors"/> use this buffer in interleaved arrangement
         /// </summary>
         /// <param name="accessors">A collection of accessors that use this buffer</param>
         /// <returns>true if the buffer is interleaved</returns>
@@ -129,18 +129,43 @@ namespace SharpGLTF.Schema2
 
     public partial class ModelRoot
     {
+        /// <summary>
+        /// Creates or reuses a <see cref="BufferView"/> matching the input parameters.
+        /// </summary>
+        /// <param name="data">The array range to wrap.</param>
+        /// <param name="byteStride">For strided vertex buffers, it must be a value multiple of 4, 0 otherwise</param>
+        /// <param name="target">The type hardware device buffer, or null</param>
+        /// <returns>A <see cref="BufferView"/> wrapping <paramref name="data"/></returns>
         public BufferView UseBufferView(ArraySegment<Byte> data, int byteStride = 0, BufferMode? target = null)
         {
             Guard.NotNull(data.Array, nameof(data));
             return UseBufferView(data.Array, data.Offset, data.Count, byteStride, target);
         }
 
+        /// <summary>
+        /// Creates or reuses a <see cref="BufferView"/> matching the input parameters.
+        /// </summary>
+        /// <param name="buffer">The array to wrap.</param>
+        /// <param name="byteOffset">The zero-based index of the first Byte in <paramref name="buffer"/></param>
+        /// <param name="byteLength">The number of elements in <paramref name="buffer"/></param>
+        /// <param name="byteStride">For strided vertex buffers, it must be a value multiple of 4, 0 otherwise</param>
+        /// <param name="target">The type hardware device buffer, or null</param>
+        /// <returns>A <see cref="BufferView"/> wrapping <paramref name="buffer"/></returns>
         public BufferView UseBufferView(Byte[] buffer, int byteOffset = 0, int? byteLength = null, int byteStride = 0, BufferMode? target = null)
         {
             Guard.NotNull(buffer, nameof(buffer));
             return UseBufferView(UseBuffer(buffer), byteOffset, byteLength, byteStride, target);
         }
 
+        /// <summary>
+        /// Creates or reuses a <see cref="BufferView"/> matching the input parameters.
+        /// </summary>
+        /// <param name="buffer">The buffer to wrap.</param>
+        /// <param name="byteOffset">The zero-based index of the first Byte in <paramref name="buffer"/></param>
+        /// <param name="byteLength">The number of elements in <paramref name="buffer"/></param>
+        /// <param name="byteStride">For strided vertex buffers, it must be a value multiple of 4, 0 otherwise</param>
+        /// <param name="target">The type hardware device buffer, or null</param>
+        /// <returns>A <see cref="BufferView"/> wrapping <paramref name="buffer"/></returns>
         public BufferView UseBufferView(Buffer buffer, int byteOffset = 0, int? byteLength = null, int byteStride = 0, BufferMode? target = null)
         {
             Guard.NotNull(buffer, nameof(buffer));

+ 11 - 7
src/SharpGLTF.DOM/SharpGLTF.csproj

@@ -27,12 +27,10 @@
     </AssemblyAttribute>    
   </ItemGroup>
 
-  <ItemGroup>
-    <None Include="Schema2\Generated\*.cs">
-      <ExcludeFromStyleCop>true</ExcludeFromStyleCop>
-    </None>
-  </ItemGroup>
-
+  <PropertyGroup>
+    <DocumentationFile>bin\Docs\SharpGLTF.xml</DocumentationFile>
+  </PropertyGroup>
+  
   <ItemGroup>
     <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />    
     <PackageReference Include="System.Memory" Version="4.5.2" />
@@ -43,11 +41,17 @@
     </PackageReference>
   </ItemGroup>
 
+  <ItemGroup>
+    <None Include="Schema2\Generated\*.cs">
+      <ExcludeFromStyleCop>true</ExcludeFromStyleCop>
+    </None>
+  </ItemGroup>
+
   <PropertyGroup>
     <CodeAnalysisRuleSet>..\..\SharpGLTF.ruleset</CodeAnalysisRuleSet>
     <AssemblyName>SharpGLTF</AssemblyName>
     <PackageIconUrl>https://raw.githubusercontent.com/vpenades/SharpGLTF/master/build/Icons/glTF2Sharp.png</PackageIconUrl>    
-  </PropertyGroup>
+  </PropertyGroup>  
 
   <ItemGroup>
     <AdditionalFiles Include="..\..\stylecop.json" />