Problem with local Terrain tiling in Cesium

Hi everyone,

I’m experiencing some issues with rendering custom terrain tiles in CesiumJS. I’m working on creating a moon globe and have generated image tiles in QGIS and terrain tiles using cesium-terrain-builder. Both tile directory are being served locally using a simple Python script with CORS support. However, I’m encountering errors in the console, and the terrain is not rendered correctly.

Issue with Terrain3 (Heightmap)

The terrain tiles were generated using the following CTB command:

ctb-tile --start-zoom 6 -e 0 -o terrain3 output_half_resolution.tif

The source TIFF file is from Astropedia, and its resolution was reduced using QGIS to avoid overflow errors as suggested in the CTB documentation, after being reprojected to WGS84. Here is the error message from the console:

An error occurred in "CesiumTerrainProvider": Failed to obtain terrain tile X: 4 Y: 2 Level: 3. Error message: "RangeError: Invalid typed array length: 4225"

Cesium.js:43 An error occurred in "CesiumTerrainProvider": Failed to obtain terrain tile X: 2 Y: 1 Level: 2. Error message: "RangeError: Invalid typed array length: 4225"


The tiles exist in the folder and are accessible via the browser at http://localhost:8003/3/2/4.terrain. However, the terrain exaggeration seems uneven and excessively high, but I’m unsure if it’s purely due to exaggeration.
This is how it looks.

Issue with Terrain4 (Q Mesh Format)

The terrain tiles were generated using the LOLA DEM dataset from Astropedia. The dataset was reprojected to WGS84 in QGIS, and the tiles were generated with the following commands:

ctb-tile -f Mesh -C -N --start-zoom 5 -e 0 -o terrain4 output_half_resolution.tif

ctb-tile -f Mesh -C -N -l --start-zoom 5 -e 0 -o terrain4 output_half_resolution.tif

Here is the error message from the console:

An error occurred in "CesiumTerrainProvider": Failed to obtain terrain tile X: 0 Y: 0 Level: 0. Error message: "RangeError: Invalid typed array length: 6990332499"
Cesium.js:43 An error occurred in "CesiumTerrainProvider": Failed to obtain terrain tile X: 1 Y: 0 Level: 0. Error message: "RangeError: Invalid typed array length: 5691507168"

The tiles exist in the folder and are accessible via the browser at http://localhost:8004/0/0/0.terrain. However, no globe is rendered on the screen.

Code Snippet

Here is the code snippet I’m using to set up the Cesium viewer:

var ellipsoid = new Cesium.Ellipsoid(1737000, 1737000, 1737000);
Cesium.Ellipsoid.default = ellipsoid;
var mapProjection = new Cesium.GeographicProjection(ellipsoid);
var globe = new Cesium.Globe(ellipsoid);

var opts = {
  mapProjection: mapProjection,
  globe: globe,
  baseLayerPicker: false,
  imageryProvider: new Cesium.UrlTemplateImageryProvider({
    url: "http://localhost:8000/{z}/{x}/{y}.png",
    minimumLevel: 0,
    maximumLevel: 10,
  }),
};

var viewer = new Cesium.Viewer("cesiumContainer", opts);
const terrain = new Cesium.CesiumTerrainProvider({
  ellipsoid: ellipsoid,
  url: "http://localhost:8004/",
});

viewer.terrainProvider = terrain;

// viewer.scene.verticalExaggeration = 10.0;
// viewer.scene.verticalExaggerationRelativeHeight = 2400.0;
console.log(viewer.scene);

// UI changes
globe.showGroundAtmosphere = false;
viewer.scene.fog.enabled = false;
viewer.scene._globe.showWaterEffect = false;
viewer.scene.skyAtmosphere.show = false;
viewer.scene.moon.show = false;

Attempts to Fix

  1. Terrain3 (Heightmap): The terrain is rendered but with exaggerated and uneven heights. I’m not sure if it’s caused by the exaggeration or another issue.

  2. Terrain4 (Q Mesh Format): The terrain is not rendered at all, and I’m receiving RangeError: Invalid typed array length in the console.

  3. Vertical Exaggeration: Tried adding viewer.scene.verticalExaggeration = 10.0 and viewer.scene.verticalExaggerationRelativeHeight = 2400.0 based on this sandcastle example, but it seems to have no effect.

  4. Serving Files: Confirmed that the files exist and are accessible via a browser.

Any help or suggestions would be greatly appreciated!

Thanks in advance.