Custom mesh as decal on a GroundHeightMap

Hi, I’m trying to add a mesh that I created as an ExtrudePolygon to a terrain generated with a heightmap.

My idea is to add it as a decal so the polygon can take the height shape of the heightmap.

I’m using MeshBuilder.CreateDecal(decal_field, terrain, { position: new Vector3(0, 0, 0)...)

But I’m not sure if I’m able to actually pass the mesh I created as decal.

Is there any way to do this?


CreateDecal already creates a mesh with the appropriate decal shape, so you can’t use the ExtrudePolygon one. If you just want the decal to have a custom polygonal shape, you could use DynamicTexture to draw it instead Dynamic Textures | Babylon.js Documentation (, see:
Drawing HTMLCanvasElement as Decal | Babylon.js Playground (

1 Like

Hi @carolhmj thanks for your great answer! I actually started figuring out how to use the DynamicTextures you told me about. I’ve been having some problems with it.

In my example I have a shape that I would like to apply to my GroundMesh as a texture. The problem is that I cant figure out the resolution and decal size I would need to make the shape fit perfectly within the width and height of my ground:

If you’re going to apply the shape to a ground you don’t even need the decal, just assign the DynamicTexture to the ground’s material: Drawing HTMLCanvasElement as Decal | Babylon.js Playground (

1 Like

@carolhmj In this case, what happens if my ground already has a different material? Can I apply an additional material with the DynamicTexture to a specific position in the ground?

Oh in this case the new Texture Decals feature will be useful: Decals | Babylon.js Documentation (, you can just use the DynamicTexture instead of the image textures :smiley: Texture Decals | Babylon.js Playground (

1 Like

Going through the documentation and the examples this looks like just what I need. Thanks a lot. I am actually trying to implement it now on my example but not being able to render the textures properly:

You’ll need to check if the decal map is ready before rendering to it, here’s an example: Drawing HTMLCanvasElement as Decal | Babylon.js Playground (

1 Like