I have a scene where I need to display a FAIRLY large (~250) of simple 3D models.
The GLB file contain a simple blender cube, with a simple rotation animation (it’s ~5kb large).
Here is a screenshot : Imgur: The magic of the Internet
And another one : Imgur: The magic of the Internet
As you can see, the number or the size or complexity of the objects displayed is fairly low and yet the CPU usage is very high. If I try to display 1000~ cubes, which seems reasonable, the CPU doesn’t quit the 100%. 2000 it crashes.
So I guess I am not using the good method ?
Here is the code repsonsible to display the cubes :
function addBox(viewer, longitude, latitude, modelUri) {
const modelHeight = 50;
const heightAboveTerrain = 50;
const minimumVisibleDistance = 0;
const maximumVisibleDistance = 10000;
const terrainProvider = viewer.terrainProvider;
const positions = [Cesium.Cartographic.fromDegrees(longitude, latitude)];
return Cesium.sampleTerrainMostDetailed(terrainProvider, positions)
.then((updatedPositions) => {
const terrainHeight = updatedPositions[0].height;
const positionHeight = terrainHeight + heightAboveTerrain;
const position = Cesium.Cartesian3.fromDegrees(longitude, latitude, positionHeight);
const hpr = new Cesium.HeadingPitchRoll(0, 0, 0);
const orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
const scale = modelHeight / 50; // Assuming the original model is 50m tall
const entity = viewer.entities.add({
name: 'GLB Model',
position: position,
orientation: orientation,
model: {
uri: modelUri,
scale: scale,
heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
minimumVisibleDistance,
maximumVisibleDistance
)
}
});
return entity;
});
}
I loop through 250 pairs of coordinates, and I display my 100 cubes like that :
questBoxes.forEach(questBox => {
addBox(viewer, questBox.lng, questBox.lat, './models/cube.glb');
})
}
I am not even trying to display a BIG number of BIG models. Just 200 cubes, and the CPU is already through the roof.
Any idea ? How other people do ? It seems like a common usecase.