Quick way to get terrain height

I am trying to render a shape which is following terrain. I am tessellating the shape in a web worker. Once the tessellation is complete I am then using the globe getHeight method to determine the altitude height at the given cartographic . Since the shape has several hundred/thousand points calling getHeight that many times makes the UI not as responsive as I would like.

I am wondering if anybody has a good idea on how to determine the terrain height in a web worker?

Thanks in advance

Jerry

In addition to putting onto a web worker, you might want to make a custom get height function.

https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/Globe.js

Globe.prototype.getHeight

Each time you call this it goes through a list of many tiles to find what tile it falls upon. However if you already know which tile or tiles it is on perhaps you can save some time by not going through the list each call. I’m not sure how much time this would save, but it might help some. This is assuming the shape only takes up a few tiles.

Due to the limited nature of WebWorkers, your best bet is to include or copy sampleTerrain.js into your worker and use that. I don’t see a reason that it wouldn’t work in a worker. The only draw back is that you need to know exactly what level of terrain you want to query. We plan on greatly improving terrain querying in the near future, but that won’t help in the Web Worker situation since you can’t share data with the main thread.

We are actively working on draping polygons and lines over terrain and that avoid expensive tessellation in favor of GPU techniques (which also give much better results), so depending on your time frame you might want to just wait for for the official implementation to be complete (in a release or two).

Unfortunately Globe.prototype.getHeight doesn’t take a group of points at a time like sampleTerrain does, though I believe that with Globe.prototype.getHeight there is no promise/when waiting, the renderable tiles are already present in local memory. Though as Matt mentioned sampleTerrain should work in a web worker as its difficult for web workers to access resources in the main thread.

I wonder if it’s possible to force a section of terrain to stay fixed at a certain level of LOD regardless of how far the camera is so you wouldn’t have to recalculate each time the LOD changes. If you follow the highest detail of terrain then it displays a lower detail level of terrain there would be gaps and buries.

Hyper Sonic,

Did some profiling and found that the time was being spent in the line:
var intersection = tile.data.pick(ray, undefined, false, scratchGetHeightIntersection);

Was able to increase the performance by replacing the call TerrainData interpolateHeight instead. Thanks for your suggestion

So it wasn’t so much determining which tile that takes alot of time, but rather determining exactly where on a triangle the point is on. interpolateHeight seems to simply assume that the point falls on the barycenter of the triangle, rather than seek the exact location, though this would be an approximation. Are the results close enough?

Have their been any improvements on terrain querying in core Cesium? I see this thread is about 18 months old.

I’m developing a feature that shows a “Terrain Profile”, which requires the terrain height (above/below reference geoid).

Great, that’s what I need, thanks, Hyper Sonic!

Hi David,

Take a look at sampleTerrainMostDetailed, I think that solves your problem.

Thanks,

Gabby