CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
13.02k stars 3.51k forks source link

How to load a model with both KHR_draco_mesh_compression and CESIUM_primitive_outline extensions? #10662

Closed SunnyBily closed 2 years ago

SunnyBily commented 2 years ago

Hi,

I'm trying to use Cesium to load a 3dTiles model with outlines, and the geometry of this model is compressed by draco.

I stored the compressed geometry as a bufferView, and the outlines data as a separate bufferView (outline indices are not compressed). The primitives extension part in the mesh includes both two fields: KHR_draco_mesh_compression and CESIUM_primitive_outline, like this: image

The model generated by the above method does not load properly in Cesium. image

Here is the 3dTiles model generate by my method. 3dTiles_draco_outlines.zip

The Cesium version is 1.96

What I want to know is how to properly generate the draco-compressed model with outlines?

Thanks.

SunnyBily commented 2 years ago

This issue is migrated to community forum: https://community.cesium.com/t/how-to-load-a-model-with-both-khr-draco-mesh-compression-and-cesium-primitive-outline-extensions/19918

lilleyse commented 2 years ago

@SunnyBily looks like this is a bug in CesiumJS. I opened a PR to fix it: https://github.com/CesiumGS/cesium/pull/10686

SunnyBily commented 2 years ago

@lilleyse , I modified my local code according to your submission, and the problem was solved, Thanks a lot!

lilleyse commented 2 years ago

@SunnyBily great to hear!

lilleyse commented 2 years ago

I'll just keep this open until the PR is merged.

ptrgags commented 2 years ago

@SunnyBily I merged the PR to fix the outline loading crash. That said, I noticed that the glTF file (inside the .i3dm inside the tileset) seems to be missing some details which makes it not render correctly, even with the fix. The accessors do not reference any buffer views, so most of the data in the model is ignored (including the outline indices)

"accessors": [
    // ...
    {
      "componentType": 5126,
      "count": 78,
      "type": "VEC2"

      // Missing bufferView, and possibly byteOffset.
      // Without a bufferView, the accessor values will default to all 0s!
    },
    // ...

This is because of the following line from the glTF spec

When accessor.bufferViewis undefined, the sparse accessor is initialized as an array of zeros

Some relevant parts of the glTF specification:

lilleyse commented 2 years ago

It's ok that the draco compressed attributes are missing buffer views since the data comes from the draco blob.

The problem might be that CESIUM_primitive_outline references the same accessor as indices which doesn't have a buffer view.