CesiumGS / obj2gltf

Convert OBJ assets to glTF
Apache License 2.0
1.71k stars 307 forks source link

Console logs output size, but no file is present #103

Closed LanceMcCarthy closed 7 years ago

LanceMcCarthy commented 7 years ago

A single screenshot would best explain this:

image

As you can see the conversion looks like it was successful as the conole logs the converted glb file size, however I'm not seeing the file afterwards.

Am I looking in the wrong place? Where did the file get exported to?

lilleyse commented 7 years ago

After retrieving the glb it is now up to the developer to save that to a file. It's probably worth updating the README to give an example of that.

LanceMcCarthy commented 7 years ago

@lilleyse Thank you for the prompt response.

Yes, an example would be great. Is the glb object a byte[] at that point (when using binary flag)?

lilleyse commented 7 years ago

Check out https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/104. It's a Buffer at that point.

LanceMcCarthy commented 7 years ago

Did it, thank you for the guidance.

For anyone else reading this in the future, here's the successful script:

var obj2gltf = require('obj2gltf');
var fs = require('fs');

var options = {
    binary: true,
    output: "Breach.glb"
}

obj2gltf("Breach.obj", options)
    .then(function(glb) {
        console.log(glb.length);

        //Note: glb is now a Buffer

        // Go here to learn more https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback
        fs.writeFile(options.output, glb, (err) => {
            if (err) throw err;
            console.log('The file has been saved!');
        });
    });