geo-data / cesium-terrain-builder

A C++ library and associated command line tools designed to create terrain tiles for use in the Cesium JavaScript library
Other
706 stars 338 forks source link

why cesium can not display the terrain? #110

Open Brilliant-orange opened 11 months ago

Brilliant-orange commented 11 months ago

There was a problem loading the terrain in cesium. The cesium globe displays normally after removing the terrain. In cesium1.96, chrome displays the following error: Cesium.js:85 An error occurred in "Py": Failed to obtain terrain tile X: 0 Y: 0 Level: 0. Error message: "RangeError: Invalid typed array length: 8894653434" Cesium.js:85 An error occurred in "Py": Failed to obtain terrain tile X: 1 Y: 0 Level: 0. Error message: "RangeError: Invalid typed array length: 2017542741"

cesium code like this: var terrainProvider1=new Cesium.CesiumTerrainProvider({ url:"http://localhost:9000/" }); const viewer = new Cesium.Viewer("cesiumContainer", { baseLayerPicker: false, imageryProvider: imageryProvider, terrainProvider:terrainProvider1 }); viewer.scene.globe.enableLighting=true;

However, in the latest cesium, chrome does not output any errors and just does not display the globe. How can I solve this problem? @homme @thomas001 @chris-cooper @tmizu23 @kyosho-

bingo-soft commented 11 months ago

@Brilliant-orange I faced the same problem. Unzipping generated tiles solved the issue for me.

alan14alashti commented 10 months ago

@Brilliant-orange I faced the same problem. Unzipping generated tiles solved the issue for me. @bingo-soft Would you mind tell us how did you do that? I have this problem and i don't know how to unzip terrain files. thanks.

juedao7 commented 10 months ago

写.terrain时,不能用gzwrite,那样写不出正确的.terrain,而是用fwrite方式. 修正如下:在terraintile.cpp中改写

void Terrain::writeFile(const char fileName) const { FILE terrainFile = fopen(fileName, "wb");

if (terrainFile == NULL) {
    throw CTBException("Failed to open file");
}

// Write the height data,float应该是4 * TILE_CELL_SIZE
//if (gzwrite(terrainFile, mHeights.data(), TILE_CELL_SIZE * 2) == 0)
if (fwrite( mHeights.data(),  sizeof(i_terrain_height),TILE_CELL_SIZE, terrainFile) == 0)
{
    fclose(terrainFile);
    throw CTBException("Failed to write height data");
}

// Write the child flags
if (fputc(mChildren,terrainFile ) == -1) {
    fclose(terrainFile);
    throw CTBException("Failed to write child flags");
}

// Write the water mask
if (fwrite(mMask,sizeof(char), mMaskLength,terrainFile ) == 0) {
    fclose(terrainFile);
    throw CTBException("Failed to write water mask");
}

fclose(terrainFile);

} / void Terrain::writeFile(const char fileName) const { gzFile terrainFile = gzopen(fileName, "wb");

if (terrainFile == NULL) {
    throw CTBException("Failed to open file");
}

// Write the height data,float应该是4 * TILE_CELL_SIZE
//if (gzwrite(terrainFile, mHeights.data(), TILE_CELL_SIZE * 2) == 0)
if (gzwrite(terrainFile, mHeights.data(), TILE_CELL_SIZE * sizeof(i_terrain_height)) == 0)
{
    gzclose(terrainFile);
    throw CTBException("Failed to write height data");
}

// Write the child flags
if (gzputc(terrainFile, mChildren) == -1) {
    gzclose(terrainFile);
    throw CTBException("Failed to write child flags");
}

// Write the water mask
if (gzwrite(terrainFile, mMask, mMaskLength) == 0) {
    gzclose(terrainFile);
    throw CTBException("Failed to write water mask");
}

// Try and close the file
switch (gzclose(terrainFile)) {
case Z_OK:
    break;
case Z_STREAM_ERROR:
case Z_ERRNO:
case Z_MEM_ERROR:
case Z_BUF_ERROR:
default:
    throw CTBException("Failed to close file");
}

}

poorGiser commented 9 months ago

@Brilliant-orange I faced the same problem. Unzipping generated tiles solved the issue for me. hello?how to unzip the .terrain file?

q8f13 commented 5 months ago

@Brilliant-orange I faced the same problem. Unzipping generated tiles solved the issue for me. hello?how to unzip the .terrain file?

here