-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a decoder with support for parsing the Draco header
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
namespace Draco.IO; | ||
|
||
public class DracoDecoder | ||
{ | ||
public DracoHeader? Header { get; private set; } | ||
|
||
public void Decode(string path) | ||
{ | ||
using var fs = new FileStream(path, FileMode.Open, FileAccess.Read); | ||
Decode(new BinaryReader(fs)); | ||
} | ||
|
||
public void Decode(Stream stream) | ||
{ | ||
Decode(new BinaryReader(stream)); | ||
} | ||
|
||
public void Decode(BinaryReader binaryReader) | ||
{ | ||
using var buffer = new DecoderBuffer(binaryReader); | ||
Header = ParseHeader(buffer); | ||
buffer.BitStream_Version = Header.Version; | ||
} | ||
|
||
private static DracoHeader ParseHeader(DecoderBuffer buffer) | ||
{ | ||
var dracoMagic = buffer.ReadASCIIBytes(Constants.DracoMagic.Length); | ||
if (dracoMagic != Constants.DracoMagic) | ||
{ | ||
throw new InvalidDataException("Invalid Draco file."); | ||
} | ||
var majorVersion = buffer.ReadByte(); | ||
var minorVersion = buffer.ReadByte(); | ||
var encoderType = buffer.ReadByte(); | ||
var encoderMethod = buffer.ReadByte(); | ||
var flags = buffer.ReadUInt16(); | ||
|
||
return new DracoHeader( | ||
majorVersion: majorVersion, | ||
minorVersion: minorVersion, | ||
encoderType: encoderType, | ||
encoderMethod: encoderMethod, | ||
flags: flags | ||
); | ||
} | ||
} |