CesiumGS / gltf-pipeline

Content pipeline tools for optimizing glTF assets. :globe_with_meridians:
Apache License 2.0
1.87k stars 241 forks source link

gltf-pipeline command and script producing errors while runtime #641

Closed yadunandan6176 closed 11 months ago

yadunandan6176 commented 11 months ago

Hi, I am using gltf-pipeline tool for converting my gltf file to draco compression and later to glb. I facing some difficulties while executing it.

I have done global installation of gltf-pipeline as per the README file this is the command I used npm install -g gltf-pipeline

I am trying to use draco compression for the gltf file I have, the command is very similar to that of the README file gltf-pipeline -i /path/building2gltf.gltf -o /path/building2gltfdrc.gltf -d

This is not working for me as the command is executed the error is popped up as follows:

Error
    at new RuntimeError (/usr/local/lib/node_modules/gltf-pipeline/node_modules/cesium/Build/CesiumUnminified/index.cjs:17013:11)
    at fileURLToPath (/usr/local/lib/node_modules/gltf-pipeline/lib/FileUrl.js:38:11)
    at readFile (/usr/local/lib/node_modules/gltf-pipeline/lib/readResources.js:148:24)
    at readResource (/usr/local/lib/node_modules/gltf-pipeline/lib/readResources.js:114:10)
    at readImage (/usr/local/lib/node_modules/gltf-pipeline/lib/readResources.js:73:10)
    at /usr/local/lib/node_modules/gltf-pipeline/lib/readResources.js:55:31
    at ForEach.object (/usr/local/lib/node_modules/gltf-pipeline/lib/ForEach.js:44:21)
    at ForEach.topLevel (/usr/local/lib/node_modules/gltf-pipeline/lib/ForEach.js:63:18)
    at ForEach.image (/usr/local/lib/node_modules/gltf-pipeline/lib/ForEach.js:202:18)
    at /usr/local/lib/node_modules/gltf-pipeline/lib/readResources.js:54:15
    at tryCatcher (/usr/local/lib/node_modules/gltf-pipeline/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/gltf-pipeline/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/usr/local/lib/node_modules/gltf-pipeline/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/usr/local/lib/node_modules/gltf-pipeline/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/usr/local/lib/node_modules/gltf-pipeline/node_modules/bluebird/js/release/promise.js:729:18)
    at Promise._fulfill (/usr/local/lib/node_modules/gltf-pipeline/node_modules/bluebird/js/release/promise.js:673:18) {
  message: 'Expected path.protocol to start with file:'
}

I even tried to use the pipeline as a library to run in nodejs environment. Still I face errors as the script is not very different from the README file

The script I am using is as follows:

const gltfPipeline = require("gltf-pipeline");
const fsExtra = require("fs-extra");
const processGltf = gltfPipeline.processGltf;
const gltf = fsExtra.readJsonSync("building2gltf.gltf");
const options = {
    dracoOptions: {
        compressionLevel: 10,
    },
};

exports.module = (gltf, options) => {
    processGltf(gltf, options).then(function (results) {
        fsExtra.writeJsonSync("buildingdraco.gltf", results.gltf);
    });
};

The error I am getting while executing this script is as follows:

Unhandled rejection Error
    at new RuntimeError (/node_modules/cesium/Build/CesiumUnminified/index.cjs:17013:11)
    at fileURLToPath (/node_modules/gltf-pipeline/lib/FileUrl.js:38:11)
    at readFile (/node_modules/gltf-pipeline/lib/readResources.js:148:24)
    at readResource (/node_modules/gltf-pipeline/lib/readResources.js:114:10)
    at readImage (/node_modules/gltf-pipeline/lib/readResources.js:73:10)
    at /home/yadunandan/node_modules/gltf-pipeline/lib/readResources.js:55:31
    at ForEach.object (/node_modules/gltf-pipeline/lib/ForEach.js:44:21)
    at ForEach.topLevel (/node_modules/gltf-pipeline/lib/ForEach.js:63:18)
    at ForEach.image (/node_modules/gltf-pipeline/lib/ForEach.js:202:18)
    at /home/yadunandan/node_modules/gltf-pipeline/lib/readResources.js:54:15
    at tryCatcher (/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/node_modules/bluebird/js/release/promise.js:729:18)
    at Promise._fulfill (/node_modules/bluebird/js/release/promise.js:673:18)

May I know where I am going wrong and how to make use of this library.

lilleyse commented 11 months ago

Hi @yadunandan6176, a couple questions:

yadunandan6176 commented 11 months ago

Hello @lilleyse, thanks for replying

My node version is v19.8.1. I did validate my gltf with the tool you provided it was having some errors. Then I tried with a different glTF file the command line and scripts are working fine.