Generate a plane mesh custom line dynamically

Godot Version

4.3.stable

Question

This is a plane mesh with some subdivisions and a vertex shader applied, so that it follows a sinusoidal shape.

I would like to obtain the same result without the shader, generating the mesh real time. I would like to pass in the function of the shape (like in this case the sin() function) and generate a similar plane mesh that follows the passed in function.
The problem of doing this by shader is that I don’t know how to generate a similar collision shape, and I need it.
I tried with the Path3D and CSGPolygon3D nodes, but I couldn’t find a way to paint the shape smoothly with the right tangents on the path points. Also I would like it to be a one face plane mesh, not a polygon.
Any suggestion on where to look to do this?

You can try with ImmediateMesh maybe

But I feel like using Blender might be better in this case, although I’m far from being an expert on this matter.

2 Likes

Thanks, I’ll try with ImmediateMesh and let you know if I was able to make it work!

Unfortunately I need to create the mesh dynamically, the curve can change when instantiating the scene, so I cannot use Blender because the output depends on some variables that are in the scene.

Thanks, I’ll try with ImmediateMesh and let you know if I was able to make it work!

One trick you can use to make building a mesh is to have an actual mesh you can read that you make and import yourself, like a strip you have above with the spans and length you want, then what you do is read all of the vert/uv/normal/tri information from it and then build a new one based on that data. But before you build the new mesh, make a math pass on the verts to make that wave.

What is cool about that is you don’t have to do any of the ordered stuff to get a solid seamless mesh with good UV’s, the triangles pointing the right side up, because that information is already in your source mesh, all you have to do is pass everything from that to your new mesh, but modify the vert positions.

2 Likes