# 3D forests polygons

**URL:** <https://community.cesium.com/t/3d-forests-polygons/37044>\
**Category:** CesiumJS\
**Created:** [December 2, 2024, 11:06pm UTC](https://community.cesium.com/t/3d-forests-polygons/37044 "2024-12-02T23:06:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Davor\_Fiedler](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/davor_fiedler/32/1987_2.png) [@Davor\_Fiedler](https://community.cesium.com/u/Davor_Fiedler)\
**Post date:** [December 2, 2024, 11:06pm UTC](https://community.cesium.com/t/3d-forests-polygons/37044/1 "2024-12-02T23:06:20Z")

</div>

Working on the code for the web 3D topographic map in which the forest polygons will be populated with 3D trees (like Swiss topo with vegetation).  
First version working as intended but noticed quite heavy load on PC computer resources while displaying/generating forests with 3d trees. 3D trees model used is in glb format, size 124kb, and is part of my ion asset as 3D tileset.

 ![3d_šuma](https://global.discourse-cdn.com/cesium/original/3X/f/1/f137cfc2e9b565b7921338178269b1c01f84bd64.jpeg)

My question for a community would be: is there any advice or recommendations how to improve speed processing and displaying large amount of 3D forests, and Im talking about country size areas. Is there any way to generate 3D forests and then save it for later usage in real time … something like geowebcache or something.

Thanks for any comment/advice/recommendation  
Davor

---

<div class="post-metadata">

**Author:** ![Marco13](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/marco13/32/2757_2.png) [@Marco13](https://community.cesium.com/u/Marco13)\
**Post date:** [December 2, 2024, 11:12pm UTC](https://community.cesium.com/t/3d-forests-polygons/37044/2 "2024-12-02T23:12:57Z")

</div>

Many instances of the same model (with variations in position, orientation, and size) can be represented with the (legacy) [I3DM tile format](https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/Instanced3DModel), or by using the [`EXT_mesh_gpu_instancing` glTF extension](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing). In terms of rendering performance: You should be able to easily render a few ten thousand instances smoothly with that.

There is a thread that describes some context, even with the exact example of trees to make forests, at [From I3dm to EXT\_mesh\_gpu\_instancing? - #10 by bertt](https://community.cesium.com/t/from-i3dm-to-ext-mesh-gpu-instancing/19731/10) . The underlying repository that contains some example data sets, including examples that use `EXT_mesh_gpu_instancing`, can be found at [GitHub - bertt/cesium\_3dtiles\_samples](https://github.com/bertt/cesium_3dtiles_samples)

---

<div class="post-metadata">

**Author:** ![Davor\_Fiedler](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/davor_fiedler/32/1987_2.png) [@Davor\_Fiedler](https://community.cesium.com/u/Davor_Fiedler)\
**Post date:** [December 6, 2024, 11:39pm UTC](https://community.cesium.com/t/3d-forests-polygons/37044/3 "2024-12-06T23:39:55Z")

</div>

Thank you very much for the informations!

---

<div class="post-metadata">

**Author:** ![Davor\_Fiedler](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/davor_fiedler/32/1987_2.png) [@Davor\_Fiedler](https://community.cesium.com/u/Davor_Fiedler)\
**Post date:** [December 6, 2024, 11:46pm UTC](https://community.cesium.com/t/3d-forests-polygons/37044/4 "2024-12-06T23:46:32Z")

</div>

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.

 ![3d stablo6](https://global.discourse-cdn.com/cesium/original/3X/8/b/8bd0c642b8e7d5d7a40f28cd19a9d90ce19dc23e.jpeg)

_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:

 ![3d stablo0](https://global.discourse-cdn.com/cesium/original/3X/b/d/bd21a880bae0b53626849ff0e47dfb2c8c7cb8ef.jpeg)

```
// 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!

---

<div class="post-metadata">

**Author:** ![Marco13](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/marco13/32/2757_2.png) [@Marco13](https://community.cesium.com/u/Marco13)\
**Post date:** [December 7, 2024, 5:07pm UTC](https://community.cesium.com/t/3d-forests-polygons/37044/5 "2024-12-07T17:07:19Z")

</div>

There are a few things that are not clear here. And I’m not sure whether I misunderstood the goal, or you misunderstood some parts of the approach.

The code snippets that you posted are not complete. But it _looks_ like you are creating a tileset, and then, creating _many_ other tilesets, with the same `url` (!), but different `modelMatrix` values (for the different tree positions). If this is correct, then it seems to be unrelated to the approach that involves `EXT_mesh_gpu_instancing`.

The intended workflow here seems to be that you have that `GLB` file, and want to display _many_ instances of this GLB file, at the cartographic positions that are stored in that CSV file. The main part of this could be accomplished by creating a GLB file that uses `EXT_mesh_gpu_instancing` to create the instances. The information for the instances (i.e. their positions) have to be _derived_ from the cartographic positions. This can be a bit tricky (due to some coordinate system conversions that may be necessary). But even when you have the positions of the instances, there are still different options for representing _where on earth_ these instances should be displayed. This information _could_ be contained in the glTF itself. Or it could be stored as the `tile.transform` of a tile in a tileset.

And right now, it is not even clear whether you _want_ a tileset, or a single GLB file that contains everything.

However, I did a few experiments, and created a snippet (based on the `3d-tiles-tools`) that shows a possible approach. It offers the functionality to read a GLB and a CSV file (in the format that you showed) and create a GLB with `EXT_mesh_gpu_instancing` that contains the corresponding instances. Until now, this is **only** an experiment. But the goal is to work towards a solution for [Extend tileset creation function to assign multiple positions · Issue #130 · CesiumGS/3d-tiles-tools · GitHub](https://github.com/CesiumGS/3d-tiles-tools/issues/130) and [Consider convenience functions to create instanced models · Issue #84 · CesiumGS/3d-tiles-tools · GitHub](https://github.com/CesiumGS/3d-tiles-tools/issues/84) that may cover the most common use-cases. And the use case that you described probably is a pretty common one.

A comment with the experiment and further information is at [Consider convenience functions to create instanced models · Issue #84 · CesiumGS/3d-tiles-tools · GitHub](https://github.com/CesiumGS/3d-tiles-tools/issues/84#issuecomment-2525245632)

---

<div class="post-metadata">

**Author:** ![Davor\_Fiedler](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/davor_fiedler/32/1987_2.png) [@Davor\_Fiedler](https://community.cesium.com/u/Davor_Fiedler)\
**Post date:** [December 18, 2024, 7:38pm UTC](https://community.cesium.com/t/3d-forests-polygons/37044/6 "2024-12-18T19:38:24Z")

</div>

It was my fault, primary in understanding which approach would be the best for the project.  
After some testing decided to proceed with `EXT_mesh_gpu_instancing`, but was unable to create working script for generating tileset.json + instanced.glb from input glb 3D tree model and csv file with trees locations…

Will try again in the future when all of this exit experimental phase and there will be more manuals/examples/how-to available

---

<div class="post-metadata">

**Author:** ![Marco13](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/marco13/32/2757_2.png) [@Marco13](https://community.cesium.com/u/Marco13)\
**Post date:** [December 18, 2024, 8:35pm UTC](https://community.cesium.com/t/3d-forests-polygons/37044/7 "2024-12-18T20:35:39Z")

</div>

There is no specific timeline for this feature. But any feedback about what you’d like to see as part of the functionality of the `3d-tiles-tools` (either here, or as a comment in [the issue where this is tracked](https://github.com/CesiumGS/3d-tiles-tools/issues/84#issuecomment-2525245632)), or which step in your attempt of creating the instanced GLB from the CSV did not work, could be helpful.
