CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
12.37k stars 3.38k forks source link

Add support for vector tile points clamping #11544

Open gdiehlEB opened 9 months ago

gdiehlEB commented 9 months ago

Summary:

As stated in the docs, the classificationType option for Cesium3dTileset currently ‘... is not supported for points or instanced 3D models.’

When used to create tilesets consisting of both line and points entities the classification only applies to the line entities and not the points.

Example:

Cesium3DTileset.fromUrl can be used to create an instance consisting of lines and labelled points in a Cesium viewer, and providing the option classificationType: Cesium.ClassificationType.TERRAIN will clamp the lines entities to the terrain but not the points.

Example code:

const viewer = new Cesium.Viewer("cesiumContainer");

//tileset consists of lines.vctr, points.vctr and tileset.json
const tileset = await Cesium.Cesium3DTileset.fromUrl('/Apps/SampleData/tileset.json', {
  classificationType: Cesium.ClassificationType.TERRAIN,
});

tileset.style = new Cesium.Cesium3DTileStyle({
  color: "rgb(255, 0, 0, 1)",
});

viewer.scene.primitives.add(tileset);
viewer.zoomTo(tileset);

Result: Linework entities are clamped to terrain with points floating above.

Request:

Provide classification support for points, in order to enable clamping of instances that consist of both lines and points entities to terrain or other 3d tilesets by providing the classificationType option with Cesium.ClassificationType.TERRAIN or Cesium.ClassificationType.CESIUM_3D_TILES values.

ggetz commented 9 months ago

Hi @gdiehlEB, thanks for the request!

I believe this is a duplicate of https://github.com/CesiumGS/cesium/issues/6714. I'm going to close this issue and add your a link to your writeup there to keep conversation in one place. Thanks!

gdiehlEB commented 3 months ago

@ggetz While testing the implementation from my draft PR with the new heightReference options, I found clamping to a 3D tile works if the 3d Tile is added directly to viewer.scene.primitives but not if it is added via a PrimitiveCollection.

So setting heightReference.CLAMP_TO_3D_TILE will clamp a point, etc to tileset in this case:

const tileset = await Cesium.Cesium3DTileset.fromUrl('/Apps/SampleData/b3dmTileset.json', {
});
viewer.scene.primitives.add(tileset);

but not in this case:

const tileset = await Cesium.Cesium3DTileset.fromUrl('/Apps/SampleData/b3dmTileset.json', {
});

const collection = new Cesium.PrimitiveCollection();
collection.add(tileset);

viewer.scene.primitives.add(collection);

This is something I'd like to add support for as part of this issue. Do you have any thoughts as to what that would entail, any pitfalls, etc? I am familarizing myself with both of your recent PRs to get a better understanding but figure you might have some good insight.

gdiehlEB commented 3 months ago

This is something I'd like to add support for as part of this issue.

Will open a 2nd PR separate from #11710 to support clamping to tilesets within hierarchies of Primitives.