@@ -13,47 +13,42 @@ public class GltfReader : ReaderBase
1313 {
1414 private GlbHeader _header ;
1515 private GltfRoot _root ;
16- private readonly StreamIO _stream ;
1716 private StreamIO _binaryStream ;
1817
18+ private readonly StreamIO _streamIO ;
19+
1920 public GltfReader ( string path ) : this ( new FileStream ( path , FileMode . Open ) ) { }
2021
21- public GltfReader ( Stream stream )
22+ public GltfReader ( Stream stream ) : base ( stream )
2223 {
23- if ( stream == null )
24- throw new ArgumentNullException ( nameof ( stream ) ) ;
25-
26- if ( ! stream . CanSeek )
27- throw new ArgumentException ( "The stream must support seeking. Try reading the data into a buffer first" ) ;
28-
29- this . _stream = new StreamIO ( stream ) ;
24+ this . _streamIO = new StreamIO ( this . _stream ) ;
3025 }
3126
3227 /// <summary>
3328 /// Read the GLTF file
3429 /// </summary>
35- public Scene Read ( )
30+ public override Scene Read ( )
3631 {
3732 //The 12-byte header consists of three 4-byte entries:
3833 this . _header = new GlbHeader ( ) ;
3934 //magic equals 0x46546C67. It is ASCII string glTF, and can be used to identify data as Binary glTF.
40- this . _header . Magic = this . _stream . ReadUInt < LittleEndianConverter > ( ) ;
35+ this . _header . Magic = this . _streamIO . ReadUInt < LittleEndianConverter > ( ) ;
4136 //version indicates the version of the Binary glTF container format. This specification defines version 2.
42- this . _header . Version = this . _stream . ReadUInt < LittleEndianConverter > ( ) ;
37+ this . _header . Version = this . _streamIO . ReadUInt < LittleEndianConverter > ( ) ;
4338 //length is the total length of the Binary glTF, including Header and all Chunks, in bytes.
44- this . _header . Length = this . _stream . ReadUInt < LittleEndianConverter > ( ) ;
39+ this . _header . Length = this . _streamIO . ReadUInt < LittleEndianConverter > ( ) ;
4540
4641 if ( this . _header . Version != 2 )
4742 throw new NotSupportedException ( $ "Version { this . _header . Version } not supported") ;
4843
4944 //Chunk 0 Json
50- uint jsonChunkLength = this . _stream . ReadUInt < LittleEndianConverter > ( ) ;
51- string jsonChunkType = this . _stream . ReadString ( 4 ) ;
45+ uint jsonChunkLength = this . _streamIO . ReadUInt < LittleEndianConverter > ( ) ;
46+ string jsonChunkType = this . _streamIO . ReadString ( 4 ) ;
5247
5348 if ( jsonChunkType != "JSON" )
54- throw new GltfReaderException ( "Chunk type does not match" , this . _stream . Position ) ;
49+ throw new GltfReaderException ( "Chunk type does not match" , this . _streamIO . Position ) ;
5550
56- string json = this . _stream . ReadString ( ( int ) jsonChunkLength ) ;
51+ string json = this . _streamIO . ReadString ( ( int ) jsonChunkLength ) ;
5752
5853#if NETFRAMEWORK || NETSTANDARD
5954 _root = Newtonsoft . Json . JsonConvert . DeserializeObject < GltfRoot > ( json ) ;
@@ -62,14 +57,14 @@ public Scene Read()
6257#endif
6358
6459 //Chunk 1 bin
65- uint binChunkLength = this . _stream . ReadUInt < LittleEndianConverter > ( ) ;
66- string binChunkType = this . _stream . ReadString ( 4 ) ;
60+ uint binChunkLength = this . _streamIO . ReadUInt < LittleEndianConverter > ( ) ;
61+ string binChunkType = this . _streamIO . ReadString ( 4 ) ;
6762
6863 //Check the chunk type
6964 if ( binChunkType != "BIN\0 " )
70- throw new GltfReaderException ( "Chunk type does not match" , this . _stream . Position ) ;
65+ throw new GltfReaderException ( "Chunk type does not match" , this . _streamIO . Position ) ;
7166
72- byte [ ] binChunk = this . _stream . ReadBytes ( ( int ) binChunkLength ) ;
67+ byte [ ] binChunk = this . _streamIO . ReadBytes ( ( int ) binChunkLength ) ;
7368 this . _binaryStream = new StreamIO ( binChunk ) ;
7469
7570 var reader = GltfBinaryReaderBase . GetBynaryReader ( ( int ) this . _header . Version , this . _root , binChunk ) ;
@@ -81,7 +76,6 @@ public Scene Read()
8176 /// <inheritdoc/>
8277 public override void Dispose ( )
8378 {
84- this . _stream . Dispose ( ) ;
8579 this . _binaryStream ? . Dispose ( ) ;
8680 }
8781 }
0 commit comments