Selectively rendering tileset features

I’m trying to figure out if it is possible to achieve a certain effect with Cesium for Unity. I am using the OSM building tileset, and I want to only render the geometry for whichever building a certain raycast is hitting, and not render the rest of the tileset. It sounds like I could do this in Unreal using metadata styling, but that this is not currently supported in Unity.

Are there any alternative approaches? I don’t need full styling. I just need the tileset to not render at all by default, while still having the geometry available for raycasts, and then selectively render only the feature the raycast is currently hitting.

I’m prepared to modify source code (including C++), but would need a bit of direction on how to start.

Thank you for any advice you can provide!

Hi @Tyler_Hatch, welcome to the community!
I can’t think of any way to do that right now, short of major changes to Cesium for Unity itself. Buildings are rendered in batches (many buildings in each draw command), so it’s not simply a matter of skipping rendering of all-but-one model. You would need to add a way to get the building feature IDs into the material as vertex or texture data so that your custom material could discard fragments from other buildings. This is essentially what the Unreal styling system allows. Implementing such a system in Unity is definitely possible, but it’s a lot of work, and not the sort of thing I can guide you through.

Hi @Kevin_Ring, thank you for the response, and for all your work with this amazing product!

I figured the selective rendering approach was probably was not currently possible. However, I’m wondering if there might be a way to work around the issue in order complete the prototype I’m building. It appears that you can do raycasts against OSM buildings and get OSM metadata for each individual building, suggesting that their is some distinguishable representation of the geometry of a single OSM building somewhere in the internals of Cesium for Unity, because that would have to exist in order to raycast against it.

If I can somehow access that geometry, whatever form it is in, I imagine I could just create a proxy mesh that is created from that geometry, and render that myself, outside of Cesium for Unity. Do you know of a way to achieve that? Even just a nudge in the general direction of where the code is that handles OSM metadata raycasts would be helpful; I could not find it myself while looking through repo.

Thanks again!

It appears that you can do raycasts against OSM buildings and get OSM metadata for each individual building, suggesting that their is some distinguishable representation of the geometry of a single OSM building somewhere in the internals of Cesium for Unity, because that would have to exist in order to raycast against it.

Yep, absolutely. There are several ways of encoding metadata in a 3D Tiles tileset, but the most common one - and the one used by Cesium OSM Buildings - is to add a vertex attribute that indicates the “feature ID”. Each vertex in the mesh can be associated with a different feature, and this ID is essentially an index into a table of metadata properties. This is the extension that is used to add features to a glTF:

EXT_structural_metdata is used to encode the metadata associated with the features:

The challenge will be in surfacing this in such a way that it can be accessed in a Unity Material.

Here’s the function in Cesium for Unity that gets feature data given a triangle index: