public static GltfBinaryReaderBase GetBynaryReader(int version, GltfRoot root, byte[] chunk) { switch (version) { case 2: return(new GltfBinaryReaderV2(root, chunk)); case 1: default: throw new NotImplementedException($"Version {version} not implemented"); } }
public Scene Read() { //The 12-byte header consists of three 4-byte entries: _header = new GlbHeader(); //magic equals 0x46546C67. It is ASCII string glTF, and can be used to identify data as Binary glTF. _header.Magic = _stream.ReadUInt <LittleEndianConverter>(); //version indicates the version of the Binary glTF container format. This specification defines version 2. _header.Version = _stream.ReadUInt <LittleEndianConverter>(); //length is the total length of the Binary glTF, including Header and all Chunks, in bytes. _header.Length = _stream.ReadUInt <LittleEndianConverter>(); if (_header.Version != 2) { throw new NotImplementedException($"Version {_header.Version} not implemented"); } //Chunk 0 Json uint jsonChunkLength = _stream.ReadUInt <LittleEndianConverter>(); string jsonChunkType = _stream.ReadString(4); if (jsonChunkType != "JSON") { throw new GltfReaderException("Chunk type does not match", _stream.Position); } _root = JsonConvert.DeserializeObject <GltfRoot>(_stream.ReadString((int)jsonChunkLength)); //Chunk 1 bin uint binChunkLength = _stream.ReadUInt <LittleEndianConverter>(); string binChunkType = _stream.ReadString(4); //Check the chunk type if (binChunkType != "BIN\0") { throw new GltfReaderException("Chunk type does not match", _stream.Position); } byte[] binChunk = _stream.ReadBytes((int)binChunkLength); _binaryStream = new StreamIO(binChunk); return(GltfBinaryReaderBase.GetBynaryReader((int)_header.Version, _root, binChunk).Read()); }
protected Dictionary <int, StreamIO> _buffers; //TODO: implement gltf reader for multiple buffers public GltfBinaryReaderBase(GltfRoot root, byte[] chunk) { this._root = root; this._chunk = new StreamIO(chunk); }
public GltfBinaryReaderV2(GltfRoot root, byte[] chunk) : base(root, chunk) { }