How to make procedural meshes in Godot?

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

I’m making a KSP/SimpleRockets 2-like game, & I’m wondering if you can make something similar to the KSP fairing building system with procedural meshes.

What do you mean with procedural meshes? Do you mean building with primitives or modifying them with procedural shaders?

Bubu | 2021-04-18 13:21

:bust_in_silhouette: Reply From: Jummit

The wiki has some good documentation on the options Godot provides:

For something like rocket parts, you could also modify existing meshes by tweaking its size, or the position of certain vertices. For that, MeshDataTool would work best.
Here is an example of proceduraly stretching a part:

var data_tool :=
data_tool.create_from_surface(load("mesh.obj"), 0)
for vertex_id in data_tool.get_vertex_count():
	var vertex := data_tool.get_vertex(vertex_id)
	# push all vertices that are on the right more to the right
	if vertex.x > .5:
		data_tool.set_vertex(vertex_id, vertex + Vector3.RIGHT)