For a couple of days trying to use 3Dtileset instead of glb as source of 3D trees for the forest areas, but cant make it visible on globe/map.
Workflow:
//Load csv file with lat, lon,height of the trees positions inside forest polygon.
Longitude,Latitude,Height
14.541356,44.478599,43.32
14.544385,44.478860,50.01
*//Load the 3D Trees tileset from Cesium Ion*
async function load3DTreesTileset() {
try {
const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(2886489);
viewer.scene.primitives.add(tileset);
console.log("3D Trees tileset loaded successfully!");
... code...
***// Place trees at the specified positions***
async function placeTreesAtPositions(treePositions, tileset) {
const pos = treePositions[0]; // Test only the first tree
const cartesianPosition = Cesium.Cartesian3.fromDegrees(pos.lon, pos.lat, pos.height);
const modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(cartesianPosition);
const scaleMatrix = Cesium.Matrix4.fromUniformScale(5.0); // Apply scaling
Cesium.Matrix4.multiply(modelMatrix, scaleMatrix, modelMatrix);
const instanceTileset = new Cesium.Cesium3DTileset({
url: tileset.url,
modelMatrix: modelMatrix,
});
viewer.scene.primitives.add(instanceTileset);
console.log(`Tree (test) placed at: Longitude: ${pos.lon}, Latitude: ${pos.lat}, Height: ${pos.height}`);
}
everything works without any errors, coordinates & heights are correct but cant get trees 3dTiles to become visible on map/globe…
Even test version with points instead of 3D tiles working fine:
// Place trees at the specified positions
async function placeTreesAtPositions(treePositions) {
const terrainProvider = viewer.terrainProvider;
for (const pos of treePositions) {
const cartographic = Cesium.Cartographic.fromDegrees(pos.lon, pos.lat, pos.height);
const cartesianPosition = Cesium.Cartesian3.fromRadians(
cartographic.longitude,
cartographic.latitude,
cartographic.height
);
const modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(cartesianPosition);
// Add
point representation at the position
viewer.entities.add({
position: cartesianPosition,
point: {
pixelSize: 5,
color: Cesium.Color.GREEN
}
});
console.log(`Tree placed at: Longitude: ${pos.lon}, Latitude: ${pos.lat}, Height: ${pos.height}`);
}
}
[
Something doing wrong, and any help would be much appreciated!