How to retrieve "extras" from GLTF file

Greetings,

I have loaded a GLTF model using CesiumJS. It’s done in a manner similar to what described in example: Cesium Sandcastle

The GLTF model which I am loading has few properties attached as “extras” ( glTF™ 2.0 Specification ).

I would like to know how I can retrieve the properties stored in the extras of a GLTF model. Is there any example which I can refer to.

Thanks,
Sourabh

I haven’t tried it because I don’t have a GLTF file with “extras”, but I can access _gltfJsonLoader from the model, so I guess it would be accessed with code like this.

const model = await Cesium.Model.fromGltfAsync({....});
const extras = model._loader._gltfJsonLoader._gltf.extras;

Thanks for the information. Sadly, its not giving the output which I am looking for.

The GLTF file has multiple mesh objects and each object has some custom-properties attached as extras. I can see these properties in three.js; where they come as ‘userData’. I am not sure about following:

  1. how to traverse to individual mesh object in the GLTF
  2. how to retrieve these “extras” from each mesh object.

Regards.

Model.fromGltfAsync has a gltfCallback property you can take advantage of to grab the gltf JOSN content:

try {
 const model = await Cesium.Model.fromGltfAsync({
   url: "../../SampleData/models/CesiumMan/Cesium_Man.glb",
   gltfCallback: gltf => {
     /** This is the glTF JSON content */
   }
 });
 viewer.scene.primitives.add(model);
} catch (error) {
 console.log(`Failed to load model. ${error}`);
}

Try the the glTF spec for details about how to traverse the glTF object to find what you need.

Thanks I will try this.