CesiumGS / gltf-pipeline

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

Compression with gltf containing texture fails #632

Closed eddjharrison closed 1 year ago

eddjharrison commented 1 year ago

I have a gltf of some satellite imagery draped over a terrain model, generated using pyvista for the draping and the export of the gltf.

newvtk2.gltf.zip

Example above ^^

I run the command (wrapped in a python function):

import subprocess
def draco_compression_(input_file, output_file, compression_level):
    print('Compressing gltf...')
    command = [
        "gltf-pipeline",
        "-i", input_file,
        "-o", output_file,
        "--draco.compressionLevel", str(compression_level),
        "--stats",

    ]
    subprocess.run(command)
    print('...Compressed')

draco_compression_("newvtk2.gltf", "new_vtk2_.gltf", 7)

And get the following error:

Error
    at new RuntimeError (/usr/local/lib/node_modules/gltf-pipeline/node_modules/cesium/Build/CesiumUnminified/Cesium.js:7068:13)
    at /usr/local/lib/node_modules/gltf-pipeline/lib/compressDracoMeshes.js:270:15
    at Function.ForEach.meshPrimitive (/usr/local/lib/node_modules/gltf-pipeline/lib/ForEach.js:239:21)
    at /usr/local/lib/node_modules/gltf-pipeline/lib/compressDracoMeshes.js:144:13
    at Function.ForEach.object (/usr/local/lib/node_modules/gltf-pipeline/lib/ForEach.js:44:21)
    at Function.ForEach.topLevel (/usr/local/lib/node_modules/gltf-pipeline/lib/ForEach.js:63:18)
    at Function.ForEach.mesh (/usr/local/lib/node_modules/gltf-pipeline/lib/ForEach.js:230:18)
    at compress (/usr/local/lib/node_modules/gltf-pipeline/lib/compressDracoMeshes.js:143:11)
    at /usr/local/lib/node_modules/gltf-pipeline/lib/compressDracoMeshes.js:60:14
    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._settlePromiseCtx (/usr/local/lib/node_modules/gltf-pipeline/node_modules/bluebird/js/release/promise.js:641:10)
    at _drainQueueStep (/usr/local/lib/node_modules/gltf-pipeline/node_modules/bluebird/js/release/async.js:97:12)
    at _drainQueue (/usr/local/lib/node_modules/gltf-pipeline/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/usr/local/lib/node_modules/gltf-pipeline/node_modules/bluebird/js/release/async.js:102:5) {
  message: 'Error: Draco encoding failed.'
}

Any one have any ideas? the error message is not very fruitful.

I have another vtk that has satellite imagery as RGB values, and can create a gltf and Draco compress it no problems, but the aim is for smallest file possible, and draping satellite imagery produces a much smaller starting point pre-draco compression...

EDIT: Attached the original vtk with satellite imagery texture for anyone wishing to create the GLTF in the same way: newvtk3.vtk.zip

import pyvista as pv

terrain = pv.read("file.vtk")

pl = pv.Plotter()
_ = pl.add_mesh(terrain)

pl.export_gltf("mygltf.gltf", save_normals=True, inline_data=True)
javagl commented 1 year ago

According to https://github.khronos.org/glTF-Validator/ the glTF file contains an accessor that contains all NaNs. When the file is invalid, then this may be (and very likely is) the reason for this error.