help generating a mesh correctly

Godot Version

4.4 Stable

Question

Hello! I am trying to generate a mesh using an array of Vector3 positions labeled “vertices”. It is for a tool script I’m working on that simulates physics and records the points to that array. I have attached screenshots; it generates something, but not what I’m looking for. It’s been days now and I can’t figure out what I’m doing wrong. If anyone can help, thank you!!!

The points in the array I’m using:

What the mesh looks like when I try to generate with that array and the code I wrote:

The code function that takes the array of Vector3 positions to try and generate a mesh:

Thank you all again! I hope someone can help :slight_smile:

This function be better in text.

Generally I would recommend Blender unless you will be making dynamically changes to the mesh.

Posting guidelines in #Help channel

What are you looking for?

Hi, I’m looking for a function that takes in an array of Vector3s (the pink spheres represent the positions I’m using) and creates a mesh by connecting those points with triangles

You can connect those points into triangles in a very large number of ways. So you first need to define the topology of the resulting mesh i.e. decide which points will go into which triangles. Then pick the corresponding point triplets from the vertex set and use their indices to define triangles. Just picking the points in sequential order from the array may not get you what you want, depending on the order you filled that array with the points.