Hi, I am back again with a little problem.
I am trying to create a mesh through code, but for some reason some edges are created between two vertices that shouldn't be connected together.
Ultimately my goal is to attempt to create a terrain from a heightmap image (in png format most likely) and then create rivers and such in a similar way.
Here is what I mean in the form of an image:

And here is the code that I use to create the quads and triangles:
Am I missing something or is it simply due to the order I create the vertices in?
I create the vertices in a clockwise order.
extends MeshInstance
var tmpMesh = Mesh.new()
var vertices = PoolVector3Array()
var UVs = PoolVector2Array()
var mat = SpatialMaterial.new()
var color = Color(0.023438, 0.908447, 1)
func create_triangle(x, y, z):
vertices.push_back(Vector3(x,z,y))
vertices.push_back(Vector3(x+1,z,y))
vertices.push_back(Vector3(x+1,z,y+1))
UVs.push_back(Vector2(x,y))
UVs.push_back(Vector2(x,y+1))
UVs.push_back(Vector2(x+1,y+1))
func create_triangle_opposite(x, y, z):
vertices.push_back(Vector3(x,z,y+1))
vertices.push_back(Vector3(x,z,y))
vertices.push_back(Vector3(x+1,z,y+1))
UVs.push_back(Vector2(x,y))
UVs.push_back(Vector2(x,y+1))
UVs.push_back(Vector2(x+1,y+1))
func create_quad(x, y, z):
create_triangle(x,y,z)
create_triangle_opposite(x,y,z)
func _ready():
create_quad(0,0,0)
create_quad(1,0,0)
create_quad(1,1,0)
create_quad(0,1,0)
mat.albedo_color = color
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_LINE_LOOP)
st.set_material(mat)
for v in vertices.size():
st.add_color(color)
st.add_uv(UVs[v])
st.add_vertex(vertices[v])
st.commit(tmpMesh)
mesh = tmpMesh
Thank you in advance for your help!