Esempio n. 1
0
        public ModelRoot LoadModel(string gltfFile, ReadSettings settings = null)
        {
            var context = ReadContext
                          .Create(_ReadAsset)
                          .WithSettingsFrom(settings);

            return(context.ReadSchema2(gltfFile));
        }
Esempio n. 2
0
        private (SCHEMA2 Model, Validation.ValidationResult Validation) _ReadGLB(Stream stream)
        {
            Guard.NotNull(stream, nameof(stream));

            var chunks = BinarySerialization.ReadBinaryFile(stream);

            var context = this;

            if (chunks.ContainsKey(BinarySerialization.CHUNKBIN))
            {
                context = new ReadContext(context); // clone instance
                context._BinaryChunk = chunks[BinarySerialization.CHUNKBIN];
            }

            var jsonChunk = chunks[BinarySerialization.CHUNKJSON];

            return(context._Read(new BYTES(jsonChunk)));
        }
Esempio n. 3
0
        private ModelRoot _LoadGltf2(string gltfFile, ReadSettings settings = null)
        {
            var context = ReadContext
                          .Create(_ReadAsset)
                          .WithSettingsFrom(settings);

            using (var m = new System.IO.MemoryStream())
            {
                using (var s = _Archive.GetEntry(gltfFile).Open())
                {
                    s.CopyTo(m);
                }

                m.Position = 0;

                return(context.ReadSchema2(m));
            }
        }
Esempio n. 4
0
        private (SCHEMA2 Model, Validation.ValidationResult Validation) _ReadGLB(Stream stream)
        {
            Guard.NotNull(stream, nameof(stream));

            var chunks = glb.ReadBinaryFile(stream);

            var dom = Encoding.UTF8.GetString(chunks[glb.CHUNKJSON]);

            var context = this;

            if (chunks.ContainsKey(glb.CHUNKBIN))
            {
                context = new ReadContext(context); // clone instance
                context._BinaryChunk = chunks[glb.CHUNKBIN];
            }

            return(context._ParseGLTF(dom));
        }
Esempio n. 5
0
        private (SCHEMA2 Model, Validation.ValidationResult Validation) _ReadGLB(Stream stream)
        {
            Guard.NotNull(stream, nameof(stream));

            IReadOnlyDictionary <uint, byte[]> chunks;

            try
            {
                chunks = BinarySerialization.ReadBinaryFile(stream);
            }
            catch (System.IO.EndOfStreamException ex)
            {
                var vr = new Validation.ValidationResult(null, this.Validation);
                vr.SetError(new Validation.SchemaException(null, ex.Message));
                return(null, vr);
            }
            catch (Validation.SchemaException ex)
            {
                var vr = new Validation.ValidationResult(null, this.Validation);
                vr.SetError(ex);
                return(null, vr);
            }

            var context = this;

            if (chunks.ContainsKey(BinarySerialization.CHUNKBIN))
            {
                // clone self
                var binChunk = chunks[BinarySerialization.CHUNKBIN];
                context = new ReadContext(context);
                context._BinaryChunk = binChunk;
            }

            var jsonChunk = chunks[BinarySerialization.CHUNKJSON];

            return(context._Read(jsonChunk));
        }
Esempio n. 6
0
 internal ReadContext(ReadContext other)
     : base(other)
 {
     this._FileReader  = other._FileReader;
     this.ImageDecoder = other.ImageDecoder;
 }