lib/writeGltf.js
function writeGltf(gltf, options) {
    return encodeTextures(gltf)
        .then(function() {
            const binary = options.binary;
            const separate = options.separate;
            const separateTextures = options.separateTextures;

            const promises = [];
            if (separateTextures) {
                promises.push(writeSeparateTextures(gltf, options));
            } else {
                writeEmbeddedTextures(gltf);
            }

            if (separate) {
                promises.push(writeSeparateBuffers(gltf, options));
            } else if (!binary) {
                writeEmbeddedBuffer(gltf);
            }

            const binaryBuffer = gltf.buffers[0].extras._obj2gltf.source;

            return Promise.all(promises)
                .then(function() {
                    deleteExtras(gltf);
                    removeEmpty(gltf);
                    if (binary) {
                        return gltfToGlb(gltf, binaryBuffer);
                    }
                    return gltf;
                });
        });
}
function writeGltf(gltf, options) {
    return encodeTextures(gltf)
        .then(function() {
            const binary = options.binary;
            const separate = options.separate;
            const separateTextures = options.separateTextures;

            const promises = [];
            if (separateTextures) {
                promises.push(writeSeparateTextures(gltf, options));
            } else {
                writeEmbeddedTextures(gltf);
            }

            if (separate) {
                promises.push(writeSeparateBuffers(gltf, options));
            } else if (!binary) {
                writeEmbeddedBuffer(gltf);
            }

            const binaryBuffer = gltf.buffers[0].extras._obj2gltf.source;

            return Promise.all(promises)
                .then(function() {
                    deleteExtras(gltf);
                    removeEmpty(gltf);
                    if (binary) {
                        return gltfToGlb(gltf, binaryBuffer);
                    }
                    return gltf;
                });
        });
}
function writeGltf ( gltf , options ) { return encodeTextures ( gltf ) . then ( function ( ) { const binary = options . binary ; const separate = options . separate ; const separateTextures = options . separateTextures ; const promises = [ ] ; if ( separateTextures ) { promises . push ( writeSeparateTextures ( gltf , options ) ) ; } else { writeEmbeddedTextures ( gltf ) ; } if ( separate ) { promises . push ( writeSeparateBuffers ( gltf , options ) ) ; } else if ( ! binary ) { writeEmbeddedBuffer ( gltf ) ; } const binaryBuffer = gltf . buffers [ 0 ] . extras . _obj2gltf . source ; return Promise . all ( promises ) . then ( function ( ) { deleteExtras ( gltf ) ; removeEmpty ( gltf ) ; if ( binary ) { return gltfToGlb ( gltf , binaryBuffer ) ; } return gltf ; } ) ; } ) ; }
Write glTF resources as embedded data uris or external files.

@param {Object} gltf The glTF asset.
@param {Object} options The options object passed along from lib/obj2gltf.js
@returns {Promise} A promise that resolves to the glTF JSON or glb buffer.

@private
Write glTF resources as embedded data uris or external files .