Incorrect drawing order in ArrayMesh

Godot Version

Godot 4.2.2

Question

I’m writing a plugin to generate a tree, but its polygons look strange, maybe Flip Faces would help me? but I’m using ArrayMesh and it’s not there.

When I used this drawing method in my old project with ++ and opengl 3, everything was displayed correctly, as I understand it is all about the order of drawing the polygons, how can I draw it correctly?


321

I’m using this code:

for i in vrt.get_vertex_leaf():
					verts.append(i)
				for i in vrt.get_vertex_leaf_ind():
					indices.append(i)
				for i in vrt.get_vertex_leaf_normal():
					normals.append(i)
				ms.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, surface_array_tree)

I tried to draw in reverse order, but everything broke even worse:

for i in range(vrt.get_vertex_leaf().size()-1,0,-1):
					var vv = vrt.get_vertex_leaf()[i]
					verts.append(vv)

I think it’s your normals… But maybe not. The ends look weird. How are you generating the vertexes?

You can have it generate the normals on its own if you use the surface tool. generate_normals()

I rewrote everything using SurfaceTool, generate_normals(true), and generate_tangents(), but that didn’t solve the problem :frowning:

I doubt it’s Normals

all that flip_faces changes is which side the shadow is on, right or left

it was all about the material, I changed Cull Mode to Front and everything worked