Finally i found the solution, the trimesh doesnt work with Mesh.PRIMITIVE_TRIANGLE_FAN
, but with Mesh.PRIMITIVE_TRIANGLES
and add_triangle_fan()
so here is a working example
func _ready():
var mesh = Mesh.new()
var vertices = [Vector3(1,0,0), Vector3(1,0,1), Vector3(0,0,1),Vector3(0,0,0)]
var UVs = [Vector2(0,0), Vector2(0,1), Vector2(1,1), Vector2(1,0)]
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.add_triangle_fan(vertices,UVs)
st.commit(mesh)
$MeshInstance.mesh = mesh
$MeshInstance/StaticBody/CollisionShape.shape = mesh.create_trimesh_shape()