public void WriteTo(string path) { var buffer = glTF.buffers[0]; var json = glTF.ToJson(); using (var s = new FileStream(path, FileMode.Create)) { GlbHeader.WriteTo(s); var pos = s.Position; s.Position += 4; // skip total size int size = 12; { var chunk = new GlbChunk(json); size += chunk.WriteTo(s); } { var chunk = new GlbChunk(buffer.GetBytes()); size += chunk.WriteTo(s); } s.Position = pos; var bytes = BitConverter.GetBytes(size); s.Write(bytes, 0, bytes.Length); } Debug.Log(json); }
public static byte[] ToBytes(string json, ArraySegment <byte> body) { using (var s = new MemoryStream()) { GlbHeader.WriteTo(s); var pos = s.Position; s.Position += 4; // skip total size int size = 12; { var chunk = new GlbChunk(json); size += chunk.WriteTo(s); } { var chunk = new GlbChunk(body); size += chunk.WriteTo(s); } s.Position = pos; var bytes = BitConverter.GetBytes(size); s.Write(bytes, 0, bytes.Length); return(s.ToArray()); } }
public byte[] ToGlbBytes() { var json = ToJson(); var buffer = buffers[0]; using (var s = new MemoryStream()) { GlbHeader.WriteTo(s); var pos = s.Position; s.Position += 4; // skip total size int size = 12; { var chunk = new GlbChunk(json); size += chunk.WriteTo(s); } { var chunk = new GlbChunk(buffer.GetBytes()); size += chunk.WriteTo(s); } s.Position = pos; var bytes = BitConverter.GetBytes(size); s.Write(bytes, 0, bytes.Length); return(s.ToArray()); } }
public static GltfData CreateFromGltfDataForTest(glTF gltf, ArraySegment <byte> bytes) { return(new GltfData( string.Empty, string.Empty, gltf, new List <GlbChunk> { new GlbChunk(), // json GlbChunk.CreateBin(bytes), },
public Glb(GlbChunk json, GlbChunk binary) { if (json.ChunkType != GlbChunkType.JSON) { throw new ArgumentException(); } Json = json; if (binary.ChunkType != GlbChunkType.BIN) { throw new ArgumentException(); } Binary = binary; }
public byte[] ToGlbBytes(bool UseUniJSONSerializer = false) { string json; if (UseUniJSONSerializer) { json = JsonSchema.FromType(GetType()).Serialize(this); } else { json = ToJson(); } var buffer = buffers[0]; using (var s = new MemoryStream()) { GlbHeader.WriteTo(s); var pos = s.Position; s.Position += 4; // skip total size int size = 12; { var chunk = new GlbChunk(json); size += chunk.WriteTo(s); } { var chunk = new GlbChunk(buffer.GetBytes()); size += chunk.WriteTo(s); } s.Position = pos; var bytes = BitConverter.GetBytes(size); s.Write(bytes, 0, bytes.Length); return(s.ToArray()); } }
public static Glb Create(string json, ArraySegment <byte> bin) { return(new Glb(GlbChunk.CreateJson(json), GlbChunk.CreateBin(bin))); }