Topic was automatically imported from the old Question2Answer platform.
Asked By
Nuno Donato
Old Version
Published before Godot 3 was released.
To long story short, I’m looking into different methods to spread grass over a large terrain in an automatic manner (not me placing them).
I was thinking that if I could get the terrain mesh data, I could somehow go trough all the faces and place new objects at those positions, but cant find a way to do this. Is it possible at all?
Any other suggestions on how to go about this problem?
I want to do the exact same thing. Did you make your way through this?
I never used this and its not well documented, but from what I see, it doesn’t look complicated to use.
This is a guess on how to use it:
func do_stuff_with_mesh(mesh):
var tool = MeshDataTool.new()
# Initialize the tool from the mesh and a surface index.
# Meshes contain surfaces, which in turn contain vertices.
# I guess you want the first surface, but keep that in mind
# in case you have multi-material meshes
tool.create_from_surface(mesh, 0)
# Then iterate all vertices and whatever
for i in range(0, tool.get_vertex_count()):
var position = tool.get_vertex(i)
# ...
# Delete the tool once you're done with it, because it only inherits Object
# (or use .clear() if you want to re-use it for another mesh)
tool.free()
(not tested)
How did I miss this? I was looking at the surface tool, but it was only for building new stuff, not reading what was already there.