Esempio n. 1
0
        /// <summary>
        /// Writes <paramref name="model"/> to this context using the glTF json container.
        /// </summary>
        /// <param name="baseName">The base name to use for asset files, without extension.</param>
        /// <param name="model">The <see cref="MODEL"/> to write.</param>
        /// <remarks>
        /// If the model has associated resources like binary assets and textures,<br/>
        /// these additional resources will be also written as associated files using the pattern:<br/>
        /// <br/>
        /// "<paramref name="baseName"/>.{Number}.bin|png|jpg|dds"
        /// </remarks>
        public void WriteTextSchema2(string baseName, MODEL model)
        {
            Guard.NotNullOrEmpty(baseName, nameof(baseName));
            Guard.NotNull(model, nameof(model));

            // merge images when explicitly requested.
            var mergeImages = this.ImageWriting == ResourceWriteMode.BufferView;

            model = this._PreprocessSchema2(model, mergeImages, this.MergeBuffers, this.BuffersMaxSize);
            Guard.NotNull(model, nameof(model));

            model._PrepareBuffersForSatelliteWriting(this, baseName);

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

            _ValidateBeforeWriting(model);

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

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

            model._AfterWriting();
        }
        /// <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="MODEL"/> to write.</param>
        public void WriteTextSchema2(string baseName, MODEL 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);

            _ValidateBeforeWriting(model);

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

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

            model._AfterWriting();
        }