How can I determine when a model loaded via the Entity API has finished loading?

Hello,

I am working with Cesium and loading a GLB model using the Entity API. Since the model resource is hosted online, the downloading and loading can take some time. I have subsequent operations that depend on the model being fully loaded, and hence, I need to ascertain the exact moment when the model has been fully loaded into the scene.

I have explored the following approaches:

  1. Polling certain attributes of the Entity, such as position. However, I realized this isn’t a reliable indicator, as the position attribute might be set even before the model is actually rendered.
  2. Using the Primitive API since it offers the readyPromise. But I’m more inclined to stick with the Entity API as I have already written a substantial amount of code based on it. Transitioning to the Primitive API would require significant refactoring, which is not only inconvenient but could also introduce new challenges.
  3. Manual, visual confirmation, but this isn’t an automated solution.

My question is: Is there a way (perhaps an event, flag, or another method) to determine when a model loaded via the Entity API has fully loaded? Or are there recommended approaches to handle this asynchronous loading scenario?

Thank you for your assistance!

1 Like

I managed track loading of model entity by doing following:

  1. Add model entity with explicit id
  2. Find the data source where the entity belongs to (I used custom, but I believe there is a default data source)
  3. Find instance of ModelVisualizer inside dataSource._visualizers array.
  4. Wait until entry with key entity.id appears inside modelVisualizer._modelHash object. The entry is object that holds modelPrimitive property and couple of other fields, including loadFailed flag. Note: it won’t appear until entity.show is set to true
  5. Wait until entityModelHash.modelPrimitive.ready or entityModelHash.loadFailed