I plan to load a large amount of 3D models on Cesium, including 400,000 building models, 500,000 tree models, 150,000 road lamp, 20,000 traffic light.
For handling the models to smoothly rendering on Cesium, I design a tile-liked scheme.
First, I try to load the 500,000 tree models using the scheme.
The idea is very simple:
- Divide the geographical range of the city into amounts of tiles, named with s?x???y???. The models fall in each tile are packed into the s?x???y??? .czml. There are 1,425 czml files in total.
- detect which czml files should be loaded.
var posLR = scene.camera.pickEllipsoid(new Cesium.Cartesian2(viewer.canvas.width, viewer.canvas.height), ellipsoid);
var posLL = scene.camera.pickEllipsoid(new Cesium.Cartesian2(0, viewer.canvas.height), ellipsoid);
var cartographic_LL = ellipsoid.cartesianToCartographic(posLL);
var LL_lon = Cesium.Math.toDegrees(cartographic_LL.longitude);
var LL_lat = Cesium.Math.toDegrees(cartographic_LL.latitude);
var cartographic_LR = ellipsoid.cartesianToCartographic(posLR);
var LR_lon = Cesium.Math.toDegrees(cartographic_LR.longitude);
var LR_lat = Cesium.Math.toDegrees(cartographic_LR.latitude);
if ((LR_lon-LL_lon)/2<f_length_x) // simple way,need to be modified.
{
framx=Math.floor((LL_lon-base_x)/f_length_x);
framy=Math.floor((base_y-LL_lat)/f_length_y)+2;
if (HadLoad[framx][framy]==0)
{
var czmlfile=“Model/tree/4/s4x”+framx.toString()+“y”+framy.toString()+".czml";
workQueue= new WorkQueue(showBuilding(czmlfile));
HadLoad[framx][framy]=1;
}
}
function showBuilding(file)
{
viewer.dataSources.add(Cesium.CzmlDataSource.load(file));
}
The scheme seems works as shown in the video: http://youtu.be/HG5ifpfncBU
My observations:
-
the performance is good when the scene only cover a small area, no matter what the models had been load or not.
-
the performance is also good even the scene cover a lager range if the models had not been load.
-
the performance is bad if many models had been loaded in the scene. (at 2’10’’ in the video)
My question:
- Can I hidden(or unload) some of the loaded czml files( or models) if needed (ex: when they are far from the viewpoint) ? and how to do?