Adding vertices to procedural mesh generator

Hello everyone.

This is going to be a little rough, so stay with me :slight_smile:

Here is what I have currently working:

I have a mesh (generated with script) that is built like this:

1------2
|   /  |
| /    |
0------3

I’ve added 4 gameobjects around the mesh like this:

(light green are vertices, blue are gameobjects)

example1

When I drag a gameobject, I’m rebuilding the mesh to fit the new locations of the gameobjects.

This way, I’m getting a stretched out mesh.

#######################################################

The problem is, I don’t want the mesh to be stretched.

I want to add more vertices when I drag the gameobjects around.

Something like this:

(light green are vertices, drak green are double vertices, blue are gameobjects, orange is the dragged gameobject)

example2

So the mesh should be built like this:

1-----2/5-----6
|   /  |   /  |
|  /   |  /   |
0-----3/4-----7

Imagine I’m dragging another gameobject:

(light green are vertices, drak green are double vertices, blue are gameobjects, orange is the dragged gameobject)

example3

So now the mesh should be built like this:

 9------10/13-------14
 |    /   |     /   |
 |   /    |    /    |
1/8----2/5/11/12----6/15
 |   /    |     /   |
 |  /     |   /     |
 0-------3/4--------7

So here is where I’m struggling.

I have no clue how to go about managing the vertices (and triangles and uvs).

Any ideas, leads, scripts will be appreciated.

Thanks a lot!

If i got you right you want something like this

I didn’t use gameobjects as handles but dragging areas around the plane. You can even grab a corner (outside of the plane) to drag two directions at once.

Keep in mind that Unity has a vertex limit of 65000 which equals roundabout 127 x 127 tiles.

The scene has only two gameobjects. One with the camera (and a modified MouseOrbit script) and one with this script.

Simply google “procedural mesh generation unity”. There are plenty of tutorials. You simply need to create array of vertices and indices and assign them to your mesh.