Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why cesium can not display the terrain? #110

Open
Brilliant-orange opened this issue Sep 28, 2023 · 6 comments
Open

why cesium can not display the terrain? #110

Brilliant-orange opened this issue Sep 28, 2023 · 6 comments

Comments

@Brilliant-orange
Copy link

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
Copy link

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

@alan14alashti
Copy link

alan14alashti commented Nov 1, 2023

@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
Copy link

juedao7 commented Nov 6, 2023

写.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
Copy link

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

@q8f13
Copy link

q8f13 commented Apr 7, 2024

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

here

@ShuPink
Copy link

ShuPink commented Dec 2, 2024

I know its been over a year since this issue was opened, but figured I'd leave this here in case anyone else is experiencing this issue.

Rather than unzipping the gzipped terrain tile, what solved it for me was that I had to configure my server to set the following headers for .terrain files, as

 res.setHeader("Content-Type", "application/vnd.quantized-mesh");
 res.setHeader("Content-Encoding", "gzip");

These links helped me figure this out.

tum-gis/cesium-terrain-builder-docker#8 (comment)
https://stackoverflow.com/questions/31164976/unable-to-serve-terrain-files-in-cesium-sandcastle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants