How to add colored polygons at runtime?

Hi,

I’m trying to theme 3D Tile Sets at runtime by adding colored polygons.

Short questions:

  1. Does anyone know how to dynamically set a Material Instance (MI) layer name at run time?
  2. Does anyone know how to dynamically set Material Layer Blend (MLB) parameters at run time? (I can create a Material Instance Dynamic (MID) - but are the parameters on the MLB accessible via the MID?)
  3. Can I use Actor->AddComponent to add a CesiumPolygonRasterOverlay(CPRO) at run time?

I’m trying to do all this in Blueprints - but if I need to switch to C++, I can do that.

Background:

There may well be a better way of achieving my goal - any suggestions most gratefully received!

I’m trying to add colored polygons at run time. Here’s my approach as pseudo code

UPDATE
I misunderstood how the layers work in the Material Instance. I’ll be working on a fixed palette (set in editor at the design time) for now and it will change some aspects of my approach. However, I still think I need to be able to set MLB parameters at run time for my original goal of allowing users to choose any color they want at runtime (e.g. using a color wheel).

For Each Polygon (e.g. West District tinted yellow):

  1. Create a material instance (MI)
  2. Create a material layer blend (MLB) - controls color (e.g. yellow) and opacity (e.g. 1)
  3. Replace the clipping layer (top layer) of the MI with the MLB and set its name (e.g. West_District)
  4. Create the Cesium Cartographic Polygon (CPoly)
  5. For the world terrain (CTS_Terrain) and/or the world buildings (CTS_Buildings)
  6. Add a CesiumPolygonRasterOverlay (CPRO) component to the CTS
  7. Add the CPoly to the Polygons array of the CPRO
  8. Uncheck Exclude TIles Inside of the CPRO
  9. Set the Material Layer Key to the MLB top layer name (e.g. West_District)

So, I’m hoping to end up with an overlay for each separate polygon from the input file. That’s because I believe each raster overlay is limited to one material. I know it’s possible to achieve the effect I want by creating a GeoTIFF - but I don’t want to have to generate those each time a user draws on a map.

I can successfully create and add the CPoly’s.

However, I’m having trouble with the following:

  • setting the MLB parameters (color and opacity)
  • renaming the top layer of the MI to give it a unique “Material Layer Key” that the CPRO can reference
  • adding the CPRO using AddComponent (this may, or may not be working - I can’t tell!)

Here are my blueprints:

Calling code (read from JSON and successfully parsing):

Creating a Material Instance (the thing I need MOST help with):

Creating (spawning) a Cesium Cartographic Polygon (works as expected - included for completeness)

Adding a Cesium Polygon Raster Overlay component to a Cesium 3D Tileset (this may or may not be working - not sure!)

1 Like

OK - according to this post: Material Blend Layer's Scalar Parameter at runtime? - Blueprint - Epic Developer Community Forums

After more investigation on this matter, I gathered that one cannot modify Material Blend Layer’s scalar parameter from BP.

So, now I have to find out if I can do this with C++…

I did it by Blueprint.

Cesium for Unreal BIM+GIS Demo - 倾斜摄影动态单体化实现简单征拆管理_哔哩哔哩_bilibili

1 Like

@WuduHenry - Excellent - well done! :slight_smile:

Do you have any tips for me on how to modify the blend layer dynamically?

Or are you using a preset palette of colors that you designed into your app?

I need to be able to let the users set the colors, opacity and line style at runtime.

Thanks!

I have a fixed palette version working (I set up 10 colors in the Editor and then at run time the user can select from one of those 10 colors). It’s implemented with Blueprints.

When I figure out how to dynamically create and set parameters for Material Layer Blend, I’ll update this approach to allow the user to input any RGBA color.

Maybe you can try to use “ParameterCollection” to modify the material’s color dynamically.

1 Like

Ah yes - Parameter Collections! I forgot about those. Thanks - I’ll take a look.