Hi there,
I am building a framework for taking cityJSON file, converting them to CityGML and then upload them on Cesium. Everything works perfectly but now I am trying to show the created 3DTiles on an html page. For some reason, my code doesn’t show the contained buildings but zooms onto the correct area and has the correct bounding volume.
This is the code snippet for the visualization of the cesium front end:
<script type="text/javascript">
const data = JSON.parse('{{ DATA | safe }}');
function loadCesium(callback) {
var script = document.createElement('script');
script.src = 'https://cesium.com/downloads/cesiumjs/releases/1.95/Build/Cesium/Cesium.js';
script.onload = function() {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'https://cesium.com/downloads/cesiumjs/releases/1.95/Build/Cesium/Widgets/widgets.css';
document.head.appendChild(link);
callback();
};
document.body.appendChild(script);
}
loadCesium(async function() {
const asset_id = data.asset_id;
const token = data.token;
Cesium.Ion.defaultAccessToken = token;
const viewer = new Cesium.Viewer('cesiumContainer', {
requestRenderMode: true,
terrainProvider: Cesium.createWorldTerrain()
});
try {
const resource = await Cesium.IonResource.fromAssetId(asset_id);
const tileset = new Cesium.Cesium3DTileset({ url: resource });
tileset.readyPromise.then(function(tileset) {
// Manually set the camera to the tileset bounding sphere if available
const boundingSphere = tileset.boundingSphere;
if (boundingSphere) {
viewer.camera.flyToBoundingSphere(boundingSphere, {
duration: 3 // Seconds
});
} else {
console.error('Bounding sphere is undefined');
}
const extras = tileset.asset.extras;
if (Cesium.defined(extras) && Cesium.defined(extras.ion)) {
if (Cesium.defined(extras.ion.defaultStyle)) {
tileset.style = new Cesium.Cesium3DTileStyle(extras.ion.defaultStyle);
}
} else {
console.error('No ion extras found in tileset');
}
viewer.scene.primitives.add(tileset);
tileset.tileFailed.addEventListener(function(error) {
console.error('Tile failed to load:', error);
});
tileset.allTilesLoaded.addEventListener(function() {
console.log('All tiles loaded');
});
}).catch(function(error) {
console.error('Error during tileset loading:', error);
});
} catch (error) {
console.error("Error loading tileset:", error);
}
});
</script>
I checked several times the console and printed all the related info. The only thing that doesn’t make sense to me is that, if I print tileset.root, the _content attribute is an Empty3DTileContent.
If I try to open the same asset in CesiumSandcastle, the buildings are shown correctly:
I will put the image of what I get in my html page here: