How to add a texture for a GridMap Mesh

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JayJay99

I’m trying to develop a house procedural generator, after trying to use meshes and CSG nodes, the easiest way I come up to do this was to use a GridMap with the house “chunks” and place they together in the GridMap, it’s a lot more limited but as I don’t have a lot of procedural generation experience, I think I’m gonna stick with the simpler way.

The thing is, I don’t want just “metric” variation, I also want to use multiple textures, and it would be really annoying to create multiple meshes with the same shapes but with different textures, so, what’s the best way to do this? Should I even use GridMap for this?

:bust_in_silhouette: Reply From: Lopy

There is a more practical way of creating your MeshLibrary, through code! I describe how to do it as part of this answer.

Starting out in procedural generation with cubes seems like a reasonable choice, and GridMap is definitely capable of doing what you want. You can even generate new MeshLibrary items on the fly in a running project, if you do not need previews for those.

In terms of algorithm, you could generate a few touching room-rectangles, place floor, ceiling and walls, then punch doors. Each room can have different cell_items for it’s walls and floor. You can add furniture as cell_items too (any shape and size should work if you make you MeshLibrary using a script).

Houses are often arranged as one big rectangle with smaller ones inside it, but other shapes tend to look better (semi random arrangement). With procedural generation, an important step is visualizing what you want, so since making a prototype isn’t too hard, try making a few by hand first.