Пример #1
0
        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);
        }
Пример #2
0
        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());
            }
        }
Пример #3
0
        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());
            }
        }
Пример #4
0
 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),
     },
Пример #5
0
 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;
 }
Пример #6
0
        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());
            }
        }
Пример #7
0
 public static Glb Create(string json, ArraySegment <byte> bin)
 {
     return(new Glb(GlbChunk.CreateJson(json), GlbChunk.CreateBin(bin)));
 }