Pārlūkot izejas kodu

Breaking Change: Moved ReadContext and WriteContext from IO back to Schema2 namespace.
These classes have become too specific to schema2 to be outside the namespace.

Vicente Penades 4 gadi atpakaļ
vecāks
revīzija
b7a003c13d

+ 0 - 0
src/SharpGLTF.Core/IO/Unknown.cs → src/SharpGLTF.Core/IO/UnknownNode.cs


+ 7 - 7
src/SharpGLTF.Core/IO/BinarySerialization.cs → src/SharpGLTF.Core/Schema2/Serialization.Binary.cs

@@ -3,11 +3,11 @@ using System.Collections.Generic;
 using System.IO;
 using System.Text;
 
+using MODEL = SharpGLTF.Schema2.ModelRoot;
+
 namespace SharpGLTF.Schema2
 {
-    using ROOT = ModelRoot;
-
-    static class BinarySerialization
+    static class _BinarySerialization
     {
         #region constants
 
@@ -131,7 +131,7 @@ namespace SharpGLTF.Schema2
         /// <remarks>
         /// Due to the limitations of Binary Format, not all models can be saved as Binary.
         /// </remarks>
-        public static Exception IsBinaryCompatible(ROOT model)
+        public static Exception IsBinaryCompatible(MODEL model)
         {
             try
             {
@@ -149,11 +149,11 @@ namespace SharpGLTF.Schema2
         }
 
         /// <summary>
-        /// Writes a <see cref="ROOT"/> instance into a <see cref="BinaryWriter"/>.
+        /// Writes a <see cref="MODEL"/> instance into a <see cref="BinaryWriter"/>.
         /// </summary>
         /// <param name="binaryWriter">The destination <see cref="BinaryWriter"/> stream.</param>
-        /// <param name="model">The source <see cref="ROOT"/> instance.</param>
-        public static void WriteBinaryModel(this BinaryWriter binaryWriter, ROOT model)
+        /// <param name="model">The source <see cref="MODEL"/> instance.</param>
+        public static void WriteBinaryModel(this BinaryWriter binaryWriter, MODEL model)
         {
             var ex = IsBinaryCompatible(model); if (ex != null) throw ex;
 

+ 34 - 31
src/SharpGLTF.Core/IO/ReadContext.cs → src/SharpGLTF.Core/Schema2/Serialization.ReadContext.cs

@@ -3,16 +3,13 @@ using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Text;
-
-// using Newtonsoft.Json;
 using System.Text.Json;
-using SharpGLTF.Schema2;
 
 using BYTES = System.ArraySegment<byte>;
-using SCHEMA2 = SharpGLTF.Schema2.ModelRoot;
+using MODEL = SharpGLTF.Schema2.ModelRoot;
 using VALIDATIONMODE = SharpGLTF.Validation.ValidationMode;
 
-namespace SharpGLTF.IO
+namespace SharpGLTF.Schema2
 {
     /// <summary>
     /// Callback used for loading associated files of current model.
@@ -24,9 +21,9 @@ namespace SharpGLTF.IO
     public delegate String UriResolver(String relativeUri);
 
     /// <summary>
-    /// Context for reading a <see cref="SCHEMA2"/>.
+    /// Context for reading a <see cref="MODEL"/>.
     /// </summary>
-    public class ReadContext : Schema2.ReadSettings
+    public class ReadContext : ReadSettings
     {
         #region lifecycle
 
@@ -81,6 +78,12 @@ namespace SharpGLTF.IO
             _CheckSupportedExtensions = checkExtensions;
         }
 
+        public ReadContext WithSettingsFrom(ReadSettings settings)
+        {
+            settings?.CopyTo(this);
+            return this;
+        }
+
         internal ReadContext(ReadContext other)
             : base(other)
         {
@@ -146,7 +149,7 @@ namespace SharpGLTF.IO
         {
             using (var stream = File.OpenRead(filePath))
             {
-                bool isBinary = BinarySerialization._Identify(stream);
+                bool isBinary = _BinarySerialization._Identify(stream);
 
                 if (isBinary) return _ReadGLB(stream).Validation;
 
@@ -157,21 +160,21 @@ namespace SharpGLTF.IO
         }
 
         /// <summary>
-        /// Reads a <see cref="SCHEMA2"/> instance from a <see cref="Stream"/> containing a GLB or a GLTF file.
+        /// Reads a <see cref="MODEL"/> instance from a <see cref="Stream"/> containing a GLB or a GLTF file.
         /// </summary>
         /// <param name="stream">A <see cref="Stream"/> to read from.</param>
-        /// <returns>A <see cref="SCHEMA2"/> instance.</returns>
-        public SCHEMA2 ReadSchema2(Stream stream)
+        /// <returns>A <see cref="MODEL"/> instance.</returns>
+        public MODEL ReadSchema2(Stream stream)
         {
             Guard.NotNull(stream, nameof(stream));
             Guard.IsTrue(stream.CanRead, nameof(stream));
 
-            bool binaryFile = BinarySerialization._Identify(stream);
+            bool binaryFile = _BinarySerialization._Identify(stream);
 
             return binaryFile ? ReadBinarySchema2(stream) : ReadTextSchema2(stream);
         }
 
-        internal SCHEMA2 _ReadFromDictionary(string fileName)
+        internal MODEL _ReadFromDictionary(string fileName)
         {
             var json = this.ReadAllBytesToEnd(fileName);
 
@@ -183,11 +186,11 @@ namespace SharpGLTF.IO
         }
 
         /// <summary>
-        /// Reads a <see cref="SCHEMA2"/> instance from a <see cref="Stream"/> containing a GLTF file.
+        /// Reads a <see cref="MODEL"/> instance from a <see cref="Stream"/> containing a GLTF file.
         /// </summary>
         /// <param name="stream">A <see cref="Stream"/> to read from.</param>
-        /// <returns>A <see cref="SCHEMA2"/> instance.</returns>
-        public SCHEMA2 ReadTextSchema2(Stream stream)
+        /// <returns>A <see cref="MODEL"/> instance.</returns>
+        public MODEL ReadTextSchema2(Stream stream)
         {
             Guard.NotNull(stream, nameof(stream));
             Guard.IsTrue(stream.CanRead, nameof(stream));
@@ -202,11 +205,11 @@ namespace SharpGLTF.IO
         }
 
         /// <summary>
-        /// Reads a <see cref="SCHEMA2"/> instance from a <see cref="Stream"/> containing a GLB file.
+        /// Reads a <see cref="MODEL"/> instance from a <see cref="Stream"/> containing a GLB file.
         /// </summary>
         /// <param name="stream">A <see cref="Stream"/> to read from.</param>
-        /// <returns>A <see cref="SCHEMA2"/> instance.</returns>
-        public SCHEMA2 ReadBinarySchema2(Stream stream)
+        /// <returns>A <see cref="MODEL"/> instance.</returns>
+        public MODEL ReadBinarySchema2(Stream stream)
         {
             Guard.NotNull(stream, nameof(stream));
             Guard.IsTrue(stream.CanRead, nameof(stream));
@@ -222,7 +225,7 @@ namespace SharpGLTF.IO
 
         #region core
 
-        private (SCHEMA2 Model, Validation.ValidationResult Validation) _ReadGLB(Stream stream)
+        private (MODEL Model, Validation.ValidationResult Validation) _ReadGLB(Stream stream)
         {
             Guard.NotNull(stream, nameof(stream));
 
@@ -230,7 +233,7 @@ namespace SharpGLTF.IO
 
             try
             {
-                chunks = BinarySerialization.ReadBinaryFile(stream);
+                chunks = _BinarySerialization.ReadBinaryFile(stream);
             }
             catch (System.IO.EndOfStreamException ex)
             {
@@ -247,22 +250,22 @@ namespace SharpGLTF.IO
 
             var context = this;
 
-            if (chunks.ContainsKey(BinarySerialization.CHUNKBIN))
+            if (chunks.ContainsKey(_BinarySerialization.CHUNKBIN))
             {
                 // clone self
-                var binChunk = chunks[BinarySerialization.CHUNKBIN];
+                var binChunk = chunks[_BinarySerialization.CHUNKBIN];
                 context = new ReadContext(context);
                 context._BinaryChunk = binChunk;
             }
 
-            var jsonChunk = chunks[BinarySerialization.CHUNKJSON];
+            var jsonChunk = chunks[_BinarySerialization.CHUNKJSON];
 
             return context._Read(jsonChunk);
         }
 
-        private (SCHEMA2 Model, Validation.ValidationResult Validation) _Read(ReadOnlyMemory<Byte> jsonUtf8Bytes)
+        private (MODEL Model, Validation.ValidationResult Validation) _Read(ReadOnlyMemory<Byte> jsonUtf8Bytes)
         {
-            var root = new SCHEMA2();
+            var root = new MODEL();
             var vcontext = new Validation.ValidationResult(root, this.Validation);
 
             #if !SUPRESSTRYCATCH
@@ -359,7 +362,7 @@ namespace SharpGLTF.IO
         public static bool IdentifyBinaryContainer(Stream stream)
         {
             Guard.NotNull(stream, nameof(stream));
-            return BinarySerialization._Identify(stream);
+            return _BinarySerialization._Identify(stream);
         }
 
         public static String ReadJson(Stream stream)
@@ -370,9 +373,9 @@ namespace SharpGLTF.IO
 
             if (binaryFile)
             {
-                var chunks = BinarySerialization.ReadBinaryFile(stream);
+                var chunks = _BinarySerialization.ReadBinaryFile(stream);
 
-                return Encoding.UTF8.GetString(chunks[BinarySerialization.CHUNKJSON]);
+                return Encoding.UTF8.GetString(chunks[_BinarySerialization.CHUNKJSON]);
             }
 
             using (var streamReader = new StreamReader(stream))
@@ -389,9 +392,9 @@ namespace SharpGLTF.IO
 
             if (binaryFile)
             {
-                var chunks = BinarySerialization.ReadBinaryFile(stream);
+                var chunks = _BinarySerialization.ReadBinaryFile(stream);
 
-                return chunks[BinarySerialization.CHUNKJSON];
+                return chunks[_BinarySerialization.CHUNKJSON];
             }
 
             return stream.ReadBytesToEnd();

+ 15 - 16
src/SharpGLTF.Core/Schema2/gltf.Serialization.Read.cs → src/SharpGLTF.Core/Schema2/Serialization.ReadSettings.cs

@@ -2,26 +2,26 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
-using System.Text;
 
 using BYTES = System.ArraySegment<byte>;
-
+using MODEL = SharpGLTF.Schema2.ModelRoot;
 using VALIDATIONMODE = SharpGLTF.Validation.ValidationMode;
 
 namespace SharpGLTF.Schema2
 {
-    using MODEL = ModelRoot;
-
     /// <summary>
     /// Callback used to intercept the loading of textures so they can be
     /// decoded by the client engine and uploaded to the GPU if neccesary.
     /// </summary>
     /// <param name="image">The Image containing the texture</param>
-    /// <returns>true if we want to keep the image memory data in Image. Otherwise the memory will be cleared.</returns>
+    /// <returns>
+    /// True if we want to keep the image memory data inside <see cref="Image"/>.<br/>
+    /// Otherwise the memory will be cleared and <see cref="Image"/> will be empty.
+    /// </returns>
     public delegate Boolean ImageDecodeCallback(Image image);
 
     /// <summary>
-    /// Read settings and base class of <see cref="IO.ReadContext"/>
+    /// Read settings and base class of <see cref="ReadContext"/>
     /// </summary>
     public class ReadSettings
     {
@@ -79,7 +79,7 @@ namespace SharpGLTF.Schema2
         {
             Guard.FilePathMustExist(filePath, nameof(filePath));
 
-            var context = IO.ReadContext.CreateFromFile(filePath);
+            var context = ReadContext.CreateFromFile(filePath);
 
             return context.Validate(filePath);
         }
@@ -98,9 +98,9 @@ namespace SharpGLTF.Schema2
         {
             Guard.FilePathMustExist(filePath, nameof(filePath));
 
-            var context = IO.ReadContext.CreateFromFile(filePath);
-
-            if (settings != null) settings.CopyTo(context);
+            var context = ReadContext
+                .CreateFromFile(filePath)
+                .WithSettingsFrom(settings);
 
             using (var s = File.OpenRead(filePath))
             {
@@ -135,10 +135,9 @@ namespace SharpGLTF.Schema2
             Guard.NotNull(stream, nameof(stream));
             Guard.IsTrue(stream.CanRead, nameof(stream));
 
-            var context = IO.ReadContext
-                .Create(f => throw new NotSupportedException());
-
-            if (settings != null) settings.CopyTo(context);
+            var context = ReadContext
+                .Create(f => throw new NotSupportedException())
+                .WithSettingsFrom(settings);
 
             return context.ReadBinarySchema2(stream);
         }
@@ -161,7 +160,7 @@ namespace SharpGLTF.Schema2
 
             using (var s = File.OpenRead(filePath))
             {
-                json = IO.ReadContext.ReadJsonBytes(s);
+                json = ReadContext.ReadJsonBytes(s);
             }
 
             return ParseSatellitePaths(json);
@@ -211,7 +210,7 @@ namespace SharpGLTF.Schema2
         {
         }
 
-        internal void _ResolveSatelliteDependencies(IO.ReadContext context)
+        internal void _ResolveSatelliteDependencies(ReadContext context)
         {
             // resolve satellite buffers
 

+ 21 - 17
src/SharpGLTF.Core/IO/WriteContext.cs → src/SharpGLTF.Core/Schema2/Serialization.WriteContext.cs

@@ -2,15 +2,13 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
-using System.Text;
 
 using SharpGLTF.Memory;
-using SharpGLTF.Schema2;
 
 using BYTES = System.ArraySegment<byte>;
-using SCHEMA2 = SharpGLTF.Schema2.ModelRoot;
+using MODEL = SharpGLTF.Schema2.ModelRoot;
 
-namespace SharpGLTF.IO
+namespace SharpGLTF.Schema2
 {
     /// <summary>
     /// Callback used for saving associated files of the current model.
@@ -113,10 +111,16 @@ namespace SharpGLTF.IO
             return this;
         }
 
+        public WriteContext WithSettingsFrom(WriteSettings settings)
+        {
+            settings?.CopyTo(this);
+            return this;
+        }
+
         /// <summary>
-        /// These settings are used exclusively by <see cref="SCHEMA2.DeepClone"/>.
+        /// These settings are used exclusively by <see cref="MODEL.DeepClone"/>.
         /// </summary>
-        /// <returns>A <see cref="WriteContext"/> instance to be used by <see cref="SCHEMA2.DeepClone()"/></returns>
+        /// <returns>A <see cref="WriteContext"/> instance to be used by <see cref="MODEL.DeepClone()"/></returns>
         internal WriteContext WithDeepCloneSettings()
         {
             _UpdateSupportedExtensions = false;
@@ -174,8 +178,8 @@ namespace SharpGLTF.IO
         /// Writes <paramref name="model"/> to this context.
         /// </summary>
         /// <param name="baseName">The base name to use for asset files, without extension.</param>
-        /// <param name="model">The <see cref="SCHEMA2"/> to write.</param>
-        public void WriteTextSchema2(string baseName, SCHEMA2 model)
+        /// <param name="model">The <see cref="MODEL"/> to write.</param>
+        public void WriteTextSchema2(string baseName, MODEL model)
         {
             Guard.NotNullOrEmpty(baseName, nameof(baseName));
             Guard.NotNull(model, nameof(model));
@@ -203,8 +207,8 @@ namespace SharpGLTF.IO
         /// Writes <paramref name="model"/> to this context.
         /// </summary>
         /// <param name="baseName">The base name to use for asset files, without extension.</param>
-        /// <param name="model">The <see cref="SCHEMA2"/> to write.</param>
-        public void WriteBinarySchema2(string baseName, SCHEMA2 model)
+        /// <param name="model">The <see cref="MODEL"/> to write.</param>
+        public void WriteBinarySchema2(string baseName, MODEL model)
         {
             Guard.NotNullOrEmpty(baseName, nameof(baseName));
             Guard.NotNull(model, nameof(model));
@@ -212,7 +216,7 @@ namespace SharpGLTF.IO
             model = this._PreprocessSchema2(model, this.ImageWriting == ResourceWriteMode.BufferView, true);
             Guard.NotNull(model, nameof(model));
 
-            var ex = BinarySerialization.IsBinaryCompatible(model);
+            var ex = _BinarySerialization.IsBinaryCompatible(model);
             if (ex != null) throw ex;
 
             model._PrepareBuffersForInternalWriting();
@@ -225,7 +229,7 @@ namespace SharpGLTF.IO
             {
                 using (var w = new BinaryWriter(m))
                 {
-                    BinarySerialization.WriteBinaryModel(w, model);
+                    _BinarySerialization.WriteBinaryModel(w, model);
                 }
 
                 WriteAllBytesToEnd($"{baseName}.glb", m.ToArraySegment());
@@ -243,7 +247,7 @@ namespace SharpGLTF.IO
         /// but immediately after preprocessing and buffer setup, so the model can be correctly validated.
         /// </summary>
         /// <param name="model">The model to validate.</param>
-        private void _ValidateBeforeWriting(SCHEMA2 model)
+        private void _ValidateBeforeWriting(MODEL model)
         {
             if (_NoCloneWatchdog) return;
 
@@ -263,11 +267,11 @@ namespace SharpGLTF.IO
         /// <summary>
         /// Prepares the model for writing with the appropiate settings, creating a defensive copy if neccesary.
         /// </summary>
-        /// <param name="model">The source <see cref="SCHEMA2"/> instance.</param>
+        /// <param name="model">The source <see cref="MODEL"/> instance.</param>
         /// <param name="imagesAsBufferViews">true if images should be stored as buffer views.</param>
         /// <param name="mergeBuffers">true if it's required the model must have a single buffer.</param>
-        /// <returns>The source <see cref="SCHEMA2"/> instance, or a cloned and modified instance if current settings required it.</returns>
-        private SCHEMA2 _PreprocessSchema2(SCHEMA2 model, bool imagesAsBufferViews, bool mergeBuffers)
+        /// <returns>The source <see cref="MODEL"/> instance, or a cloned and modified instance if current settings required it.</returns>
+        private MODEL _PreprocessSchema2(MODEL model, bool imagesAsBufferViews, bool mergeBuffers)
         {
             Guard.NotNull(model, nameof(model));
 
@@ -282,7 +286,7 @@ namespace SharpGLTF.IO
             if (mergeBuffers | imagesAsBufferViews)
             {
                 // cloning check is done to prevent cloning from entering in an infinite loop where each clone attempt triggers another clone request.
-                if (_NoCloneWatchdog) throw new InvalidOperationException($"Current settings require creating a densive copy before model modification, but calling {nameof(SCHEMA2.DeepClone)} is not allowed with the current settings.");
+                if (_NoCloneWatchdog) throw new InvalidOperationException($"Current settings require creating a densive copy before model modification, but calling {nameof(MODEL.DeepClone)} is not allowed with the current settings.");
 
                 model = model.DeepClone();
             }

+ 15 - 26
src/SharpGLTF.Core/Schema2/gltf.Serialization.Write.cs → src/SharpGLTF.Core/Schema2/Serialization.WriteSettings.cs

@@ -1,16 +1,12 @@
 using System;
-using System.Collections.Generic;
 using System.IO;
-using System.Linq;
-using System.Text;
 
 using BYTES = System.ArraySegment<byte>;
+using MODEL = SharpGLTF.Schema2.ModelRoot;
 using VALIDATIONMODE = SharpGLTF.Validation.ValidationMode;
 
 namespace SharpGLTF.Schema2
 {
-    using MODEL = ModelRoot;
-
     /// <summary>
     /// Determines how resources are written.
     /// </summary>
@@ -38,7 +34,7 @@ namespace SharpGLTF.Schema2
     }
 
     /// <summary>
-    /// Write settings and base class of <see cref="IO.WriteContext"/>
+    /// Write settings and base class of <see cref="WriteContext"/>
     /// </summary>
     public class WriteSettings
     {
@@ -72,7 +68,7 @@ namespace SharpGLTF.Schema2
         /// <summary>
         /// Gets or sets a callback hook that controls the image writing behavior.
         /// </summary>
-        public IO.ImageWriterCallback ImageWriteCallback { get; set; }
+        public ImageWriterCallback ImageWriteCallback { get; set; }
 
         /// <summary>
         /// Gets or sets a value indicating whether to merge all the buffers in <see cref="MODEL.LogicalBuffers"/> into a single buffer.
@@ -137,11 +133,10 @@ namespace SharpGLTF.Schema2
         {
             Guard.FilePathMustBeValid(filePath, nameof(filePath));
 
-            var context = IO.WriteContext
+            var context = WriteContext
                 .CreateFromFile(filePath)
-                .WithBinarySettings();
-
-            settings?.CopyTo(context);
+                .WithBinarySettings()
+                .WithSettingsFrom(settings);
 
             var name = Path.GetFileNameWithoutExtension(filePath);
 
@@ -160,10 +155,9 @@ namespace SharpGLTF.Schema2
         {
             Guard.FilePathMustBeValid(filePath, nameof(filePath));
 
-            var context = IO.WriteContext
-                .CreateFromFile(filePath);
-
-            settings?.CopyTo(context);
+            var context = WriteContext
+                .CreateFromFile(filePath)
+                .WithSettingsFrom(settings);
 
             var name = Path.GetFileNameWithoutExtension(filePath);
 
@@ -188,13 +182,6 @@ namespace SharpGLTF.Schema2
                     return ss.ReadToEnd();
                 }
             }
-
-            /*
-            using (var ss = new StringWriter())
-            {
-                _WriteJSON(ss, fmt);
-                return ss.ToString();
-            }*/
         }
 
         /// <summary>
@@ -222,11 +209,13 @@ namespace SharpGLTF.Schema2
             Guard.NotNull(stream, nameof(stream));
             Guard.IsTrue(stream.CanWrite, nameof(stream));
 
-            var context = IO.WriteContext.CreateFromStream(stream);
+            var context = WriteContext
+                .CreateFromStream(stream)
+                .WithSettingsFrom(settings);
 
             if (settings != null)
             {
-                settings.CopyTo(context);
+                // override settings with required values for GLB writing.
                 context.MergeBuffers = true;
                 context.ImageWriting = ResourceWriteMode.Default;
             }
@@ -250,7 +239,7 @@ namespace SharpGLTF.Schema2
             }
         }
 
-        internal void _PrepareBuffersForSatelliteWriting(IO.WriteContext context, string baseName)
+        internal void _PrepareBuffersForSatelliteWriting(WriteContext context, string baseName)
         {
             // setup all buffers to be written as satellite files
             for (int i = 0; i < this._buffers.Count; ++i)
@@ -271,7 +260,7 @@ namespace SharpGLTF.Schema2
             }
         }
 
-        internal void _PrepareImagesForWriting(IO.WriteContext context, string baseName, ResourceWriteMode rmode)
+        internal void _PrepareImagesForWriting(WriteContext context, string baseName, ResourceWriteMode rmode)
         {
             if (context.ImageWriting != ResourceWriteMode.Default) rmode = context.ImageWriting;
 

+ 3 - 3
src/SharpGLTF.Core/Schema2/gltf.Buffer.cs

@@ -39,14 +39,14 @@ namespace SharpGLTF.Schema2
         const string EMBEDDEDOCTETSTREAM = "data:application/octet-stream";
         const string EMBEDDEDGLTFBUFFER = "data:application/gltf-buffer";
 
-        internal void _ResolveUri(IO.ReadContext context)
+        internal void _ResolveUri(ReadContext context)
         {
             _Content = _LoadBinaryBufferUnchecked(_uri, context);
 
             _uri = null; // When _Data is not empty, clear URI
         }
 
-        private static Byte[] _LoadBinaryBufferUnchecked(string uri, IO.ReadContext context)
+        private static Byte[] _LoadBinaryBufferUnchecked(string uri, ReadContext context)
         {
             var data = uri.TryParseBase64Unchecked(EMBEDDEDGLTFBUFFER, EMBEDDEDOCTETSTREAM);
             if (data != null) return data;
@@ -65,7 +65,7 @@ namespace SharpGLTF.Schema2
         /// </summary>
         /// <param name="writer">The satellite asset writer</param>
         /// <param name="satelliteUri">A local satellite URI</param>
-        internal void _WriteToSatellite(IO.WriteContext writer, string satelliteUri)
+        internal void _WriteToSatellite(WriteContext writer, string satelliteUri)
         {
             writer.WriteAllBytesToEnd(satelliteUri, new ArraySegment<byte>(_Content.GetPaddedContent()));
 

+ 2 - 2
src/SharpGLTF.Core/Schema2/gltf.Images.cs

@@ -136,7 +136,7 @@ namespace SharpGLTF.Schema2
 
         #region binary read
 
-        internal void _ResolveUri(IO.ReadContext context)
+        internal void _ResolveUri(ReadContext context)
         {
             // No uri to decode.
             if (String.IsNullOrWhiteSpace(_uri)) return;
@@ -198,7 +198,7 @@ namespace SharpGLTF.Schema2
         /// </summary>
         /// <param name="writer">The satellite asset writer</param>
         /// <param name="satelliteUri">A local satellite URI</param>
-        internal void _WriteToSatellite(IO.WriteContext writer, string satelliteUri)
+        internal void _WriteToSatellite(WriteContext writer, string satelliteUri)
         {
             if (!_SatelliteContent.HasValue)
             {

+ 2 - 2
src/SharpGLTF.Core/Schema2/gltf.Root.cs

@@ -55,7 +55,7 @@ namespace SharpGLTF.Schema2
         {
             // prepare the in-memory temporary storage
             var dict = new Dictionary<string, ArraySegment<Byte>>();
-            var wcontext = IO.WriteContext
+            var wcontext = WriteContext
                 .CreateFromDictionary(dict)
                 .WithDeepCloneSettings();
 
@@ -67,7 +67,7 @@ namespace SharpGLTF.Schema2
 
             // restore the model from the temporary storage
 
-            var rcontext = IO.ReadContext.CreateFromDictionary(dict, wcontext._UpdateSupportedExtensions);
+            var rcontext = ReadContext.CreateFromDictionary(dict, wcontext._UpdateSupportedExtensions);
             rcontext.Validation = Validation.ValidationMode.Skip;
             var cloned = rcontext._ReadFromDictionary("deepclone.gltf");
 

+ 25 - 14
src/SharpGLTF.Toolkit/IO/Zip.cs

@@ -7,8 +7,23 @@ using SharpGLTF.Schema2;
 
 namespace SharpGLTF.IO
 {
+    /// <summary>
+    /// Represents a context to read gltf files from a Zip archive.
+    /// </summary>
     public sealed class ZipReader : IDisposable
     {
+        #region static API
+
+        public static ModelRoot LoadGltf2(string zipPath, ReadSettings settings = null)
+        {
+            using (var zip = new ZipReader(zipPath))
+            {
+                return zip.LoadGltf2(settings);
+            }
+        }
+
+        #endregion
+
         #region lifecycle
 
         public ZipReader(string zipPath)
@@ -22,14 +37,6 @@ namespace SharpGLTF.IO
             _Archive = null;
         }
 
-        public static ModelRoot LoadSchema2(string zipPath, ReadSettings settings = null)
-        {
-            using (var zip = new ZipReader(zipPath))
-            {
-                return zip.LoadSchema2(settings);
-            }
-        }
-
         #endregion
 
         #region data
@@ -54,17 +61,17 @@ namespace SharpGLTF.IO
                 .OrderBy(item => item.FullName);
         }
 
-        public ModelRoot LoadSchema2(ReadSettings settings = null)
+        public ModelRoot LoadGltf2(ReadSettings settings = null)
         {
             var gltfFile = ModelFiles.First();
-            return this._LoadSchema2(gltfFile, settings);
+            return this._LoadGltf2(gltfFile, settings);
         }
 
-        private ModelRoot _LoadSchema2(string gltfFile, ReadSettings settings = null)
+        private ModelRoot _LoadGltf2(string gltfFile, ReadSettings settings = null)
         {
-            var context = ReadContext.Create(_ReadAsset);
-
-            settings?.CopyTo(context);
+            var context = ReadContext
+                .Create(_ReadAsset)
+                .WithSettingsFrom(settings);
 
             using (var m = new System.IO.MemoryStream())
             {
@@ -107,6 +114,9 @@ namespace SharpGLTF.IO
         #endregion
     }
 
+    /// <summary>
+    /// Represents a context to write gltf files to a Zip archive.
+    /// </summary>
     public sealed class ZipWriter : IDisposable
     {
         #region lifecycle
@@ -135,6 +145,7 @@ namespace SharpGLTF.IO
         public void AddModel(string filePath, ModelRoot model, WriteSettings settings = null)
         {
             Guard.NotNullOrEmpty(filePath, nameof(filePath));
+            Guard.NotNull(model, nameof(model));
 
             var baseName = System.IO.Path.GetFileNameWithoutExtension(filePath);
 

+ 3 - 0
src/SharpGLTF.Toolkit/Materials/ChannelBuilder.cs

@@ -6,6 +6,9 @@ using System.Text;
 
 namespace SharpGLTF.Materials
 {
+    /// <summary>
+    /// Represents a <see cref="MaterialBuilder"/> texture channel.
+    /// </summary>
     [System.Diagnostics.DebuggerDisplay("{_GetDebuggerDisplay(),nq}")]
     public class ChannelBuilder
     {

+ 1 - 1
tests/SharpGLTF.Tests/IO/JsonContentTests.cs

@@ -205,7 +205,7 @@ namespace SharpGLTF.IO
         {
             // for some reason, System.IO.Path.GetFullPath() does not recogninze an empty string as the current directory.
 
-            var currDirContext0 = ReadContext.CreateFromDirectory(string.Empty);
+            var currDirContext0 = Schema2.ReadContext.CreateFromDirectory(string.Empty);
             Assert.NotNull(currDirContext0);            
         }
     }

+ 1 - 1
tests/SharpGLTF.Toolkit.Tests/Materials/ContentSharingTests.cs

@@ -88,7 +88,7 @@ namespace SharpGLTF.Materials
             // define the texture sharing hook; this is a pretty naive approach, but it's good
             // enough to demonstrate how it works.
 
-            string imageSharingHook(IO.WriteContext ctx, string uri, Memory.MemoryImage image)
+            string imageSharingHook(WriteContext ctx, string uri, Memory.MemoryImage image)
             {
                 Assert.IsTrue(new string[] { tex1, tex2 }.Contains(image.SourcePath) );