I know that it is possible to attach an event to a model to know when it is ready to render.
But I’m not sure how that can be done when using CZML, since I have no control about creation of model.
It is even possible with current version of Cesium?
I need this to manually calculate a model scale for each different kind of model.
If not possible to do it via onreadytorender then if you can think of a clever way tell me
So there’s no cut and dry way to do this, but one way would be to get the list of primitives in scene.primitives and pull out all of the models, something like:
var primitives = viewer.scene.primitives;
dataSource.loadUrl(’…’).then(function() {
for(var i = 0, len = primitives.length; i < len; i++) {
var primitive = primitives[i];
if(primitive instanceof Model) {
primitive.readyToRender.addEventListener(…)
}
}
})
However, the model.scale property will be overwritten by the ModelVisualizer (which handles displaying models from external data sources like CZML). If you want to set the scale you would need to modify the entity.model.scale property from the loaded czml file. Assuming you had a model primitive that came from CZML, you could do something like
primitive.id.model.scale = new Cesium.ConstantProperty(xxx); //where xxx is the scale you want to set.
Is there a reason you don’t just precompute the scale as part of the CZML? Can you explain more about your use case?
I see, that will probably work!
And I did a mistake in my post, what I will calculate is the minimumPixelSize property, not the scale.
This will be done by using the model bounding box after the model is loaded.