CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
12.74k stars 3.45k forks source link

3DTile polygons slow when using a function to define color #8729

Open Akbalder opened 4 years ago

Akbalder commented 4 years ago

Using a function to specify the color of polygons in 3Dtiles slows everything down. When using a function as color style, it isn't possible anymore to move the view fluidly.

I tried color: { evaluateColor: function (feature, result) { return Cesium.Color.clone(Cesium.Color.BLUE, result); } } and color: { conditions : [ ['true', 'color("blue")'] ] }

There is no problem when using directly a color: color: 'color("blue")'

Sandcastle example: https://sandcastle.cesium.com/#c=dVNNb9swDP0rRC5xgFTqEAwF2rTYlqxDgQ4b1qy7+KLITKxNlgJKcj+C/PfRVhK0K6aLTfI98omkWkXQGnxAgktw+AAzDCY14r73FUPdmzPvojIOaTiGbemAT0Qidn0n35oK6fxA1IQq4i9PtlpkSDEq3W50UbrStVxtjV77qq+XC4uDR3T2V/6zDD46AyrS9QIfIzOGrMs5NXwJWFmzruM8kYrGOwaditO3CYqsQEq4Rx09wWQOC2MxgCIEfNwgmQb5mhaUqyDWCCtPjYpgAoS0/M0siB50rTg1GJchKSZC0ee95qSN52QVcrNsGENAPO9DfOoYN+FcyrWJdVoK7RuZO/blTk6qk9hJkZEQj9aJ4zvLTuN1LyTIrHyuosqt7GEYX08ufybzRQ4WW0hkj+O58e4HBp9Io1iRbz4GxtxUxfuzydkI+jHtpxI0OhQb7oqJpsUgVFUV+4q5l3tDhPhk8f8i7rpwsV8b7a3nZdliq2ziRZlle5Wc7qdXrHh9uKVjIAzJxtFh37pDyCF3rNFRhbbeYfHK9en25+cj/6Kn73b9Dg7Gg2mv9ion/WCajafYdagQQkZsNpZFBblM+g/fTIfQJZjKA2lamRZMdVkO/nkY5QC0VSFwZJWsvTPPWA6uppLxr2jWq8q49bcWyaqnDlK/u7rNTiHEVLL5lhW9t0tFLzL+BQ

OmarShehata commented 4 years ago

I think the issue here is that there are too many tiles on screen in that specific vector tiles Sandcastle. If you try it on the 3D buildings tileset here it works smoothly: https://sandcastle.cesium.com/index.html?src=3D%20Tiles%20Feature%20Styling.html

Vector tiles are still experimental and not officially part of the 3D Tiles specification.

I'm closing this because I'm not sure there's anything actionable here, but @lilleyse feel free to re-open if you think otherwise.

Akbalder commented 4 years ago

It's a problem specific to polygons. I used tiles made by the Cesium team which work smoothly when not using a function to specify the color: https://sandcastle.cesium.com/index.html?src=3D%20Tiles%20Terrain%20Classification.html

lilleyse commented 4 years ago

I'm kinda surprised it's this slow. Vector tiles need to rebatch commands if any colors change but the colors are the same here. We're expecting to do more vector tiles work in the summer and we can look into it then. @Akbalder you're welcome to investigate it the meantime.

Akbalder commented 4 years ago

I checked the code.

When the color function is evaluated, one command is created per polygon.

The function rebatchCommands(primitive, context) of file Source/Scene/Vector3DTilePrimitive.js, exits before rebatching commands because of this condition:

if (needToRebatch && !primitive.forceRebatch && primitive._framesSinceLastRebatch < 120) {
  ++primitive._framesSinceLastRebatch;
  return;
}

It then draws the polygons using a command per polygon instead of one command per color.