Пример #1
0
        /// <summary>
        /// Writes <paramref name="model"/> to this context.
        /// </summary>
        /// <param name="baseName">The base name to use for asset files, without extension.</param>
        /// <param name="model">The <see cref="SCHEMA2"/> to write.</param>
        public void WriteBinarySchema2(string baseName, SCHEMA2 model)
        {
            Guard.NotNullOrEmpty(baseName, nameof(baseName));
            Guard.NotNull(model, nameof(model));

            model = this._PreprocessSchema2(model, this.ImageWriting == ResourceWriteMode.BufferView, true);
            Guard.NotNull(model, nameof(model));

            var ex = BinarySerialization.IsBinaryCompatible(model);

            if (ex != null)
            {
                throw ex;
            }

            model._PrepareBuffersForInternalWriting();

            model._PrepareImagesForWriting(this, baseName, ResourceWriteMode.Embedded);

            _ValidateBeforeWriting(model);

            using (var m = new MemoryStream())
            {
                using (var w = new BinaryWriter(m))
                {
                    BinarySerialization.WriteBinaryModel(w, model);
                }

                WriteAllBytesToEnd($"{baseName}.glb", m.ToArraySegment());
            }

            model._AfterWriting();
        }
Пример #2
0
        /// <summary>
        /// Writes <paramref name="model"/> to this context.
        /// </summary>
        /// <param name="baseName">The base name to use for asset files, without extension.</param>
        /// <param name="model">The <see cref="SCHEMA2"/> to write.</param>
        public void WriteTextSchema2(string baseName, SCHEMA2 model)
        {
            Guard.NotNullOrEmpty(baseName, nameof(baseName));
            Guard.NotNull(model, nameof(model));

            model = this._PreprocessSchema2(model, this.ImageWriting == ResourceWriteMode.BufferView, this.MergeBuffers);
            Guard.NotNull(model, nameof(model));

            model._PrepareBuffersForSatelliteWriting(this, baseName);

            model._PrepareImagesForWriting(this, baseName, ResourceWriteMode.SatelliteFile);

            using (var m = new MemoryStream())
            {
                model._WriteJSON(m, this.JsonIndented);

                /*
                 * using (var w = new StreamWriter(m))
                 * {
                 *  model._WriteJSON(w, this.JsonFormatting);
                 * }*/

                WriteAllBytesToEnd($"{baseName}.gltf", m.ToArraySegment());
            }

            model._AfterWriting();
        }