Hi community :)
I have a question about using
MultiMesh with a different material per instance.
Let's say I want to draw a chunk that contains 16x16x256 cubes like in Minecraft.
The way I actually do this is by using one
MultiMeshInstance node with a
MultiMesh assigned to it. The
instance_count of the appropriate
MultiMesh is set to 65536. The
mesh of the
MultiMesh is set to an
ArrayMesh that represents my cube. After setting all things up, I can draw exactly 65536 cubes with only one draw call which is what I wanted so far. But now comes the problem: Assigning materials to the cubes.
First I only wanted every instance to use the same material. In this case a simple
SpatialMaterial so that all cubes look like grass blocks. This was very easy so at the end all 65536 cubes looked like grass blocks. To achieve this I used the
surface_set_material() function of the
ArrayMesh instance that represents my cube.
Then I wanted two different block types within my chunk, a grass block and a stone block. And there is my problem: I can not figure out how to set a material per instance. Currently I have to set the material directly within the
ArrayMesh instance that represents my cube. Which leads to only grass blocks or only stone blocks within my chunk...
Is there a way to have one
MultiMeshInstance node with one
MultiMesh assigned to it and a different material per instance of the MultiMesh's
So that I can just say something like:
# No really code:
MultiMesh.mesh = cube
MultiMesh.instance_count = 65536
Or is there another way to achieve this?
I hope that I presented my problem in a way that it's understandable what I try to achieve.
If you need more detail then just let me know.
And sorry for my english. English is not my native language :)
Thank you! :)