add_triangle_fan ( ) in godot

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By shotaku

I don’t understand the add_triangle_fan() function
what does it mean even though i know how to create SurfaceTool?
I can’t find much documentation about it
Can you explain it to me, please?
the hardest thing is its parameters

:bust_in_silhouette: Reply From: Wakatta

Agree with you that the documentation should provide more examples on how their mesh tools are to be used because as is, it expects you to have prior extensive knowledge of openGL syntax.

Even with that knowledge winding orders are completely different and … getting back on topic

Triangle Fan

So TRIANGLE_FAN is used for drawing complex shapes like polygons (not Pokédex entry #137) with the first vertex being central and additional vertices literally winding around like a Chinese/Japanese paper fan.

The parameters are the same as used for Surface tool but more bundled using arrays instead of having to add one vertex / color / uv / normal at a time

You can run a for loop like this

#not actual code

var vertices = PoolVector3Array()
var normals = PoolVector3Array()
var uvs = PoolVector2Array()
var colors = PoolColorArray()

vertices.resize(size_y * size_x)

for y in range(height):
    for x in range(width):
        vertices[ y * width + x ] = Vector3(-PI + 2 * x * PI / (width -1), -PI / 2 + y * PI / (height-1), 0)
        normals[ y * width + x ] = vertices[ y * width + x ].normalize()
         uvs[ y * width + x ] = Vector2(y / 2, x / 2)
         colors[ y * width + x ] =
add_triangle_fan(vertices, uvs, colors, [], normals, [])

As opposed to doing

var st =
st.add_uv(Vector2(0, 0))
st.add_vertex(Vector3(0, 0, 0))

st.add_uv(Vector2(0.5, 0.5))
st.add_vertex(Vector3(0, -30, 10))

st.add_uv(Vector2(0.8, 0.8))
st.add_vertex(Vector3(-30, 10, 0))