CesiumGS / gltf-pipeline

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

Error: glTF model references separate files but no resourceDirectory is supplied #623

Closed jhosseeth closed 1 year ago

jhosseeth commented 1 year ago

When I use the code implementation as docs said

const fs = require('fs-extra')
const gltfPipeline = require("gltf-pipeline")
const gltfToGlb = gltfPipeline.gltfToGlb
const gltf = await fs.readJson(gltfPath)
const { glb } = await gltfToGlb(gltf)

I get this error Error at new RuntimeError: glTF model references separate files but no resourceDirectory is supplied

Reviewing the library code, I understood that it was mandatory to send a second options parameter to indicate where the folder with the GLTF model files was

const options = {
    resourceDirectory: "GLTF_DIR_PATH"
}

Adding options param fixed my issue const { glb } = await gltfToGlb(gltf, options) maybe it can help other people who have same problem