How to smooth meshes created with SurfaceTool?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zylann
:warning: Old Version Published before Godot 3 was released.

I am generating a mesh with SurfaceTool. However I can see the hard eges of the triangles when the mesh is rendered. I see there is add_smooth_group(), but it is not documented. How can I use it?

:bust_in_silhouette: Reply From: Zylann

I figured out I just need to put add_smooth_group(true) before generating a bunch of vertices, and those vertices will be smoothed until I call add_smooth_group(false). So for example if I need the full mesh to be smooth, I call it just after surface_tool.begin(primitive_type) and voilà :stuck_out_tongue:

Hi, after 4 years. It still not working. Your solution does not work in Godot 3.2.3. I have no idea how to achieve smooth normals. I use SurfaceTool wo generate a terrain.

surface_tool.begin(Mesh.PRIMITIVE_TRIANGLES)
surface_tool.add_smooth_group(true)
surface_tool.create_from(mesh_array, 0)
surface_tool.generate_normals()

siluck | 2020-10-03 16:58

This was in Godot 2. A lot of time has passed and maybe things changed.
Also, you use create_from. As far as I can tell, this disregards previous calls to SurfaceTool and replaces its content with the array.
Maybe you could try append_from instead?

It also sounds strange to use SurfaceTool when you seem to have a mesh already, that sounds wasteful. I suspect it’s just because you want to use generate_normals, which is quite unfortunate^^"

Zylann | 2020-10-03 17:36

I use reference mesh for calculations. For example a sphere for planet generation. This is a simple way to manipulate more complex meshes. Ok, a sphere is not really complex. But the alternative is to write pages for shpere creation. … I’m not very experienced in mesh creating in Godot. But anyway, your solution replacing create_from by append_from(mesh, 0, transform) works. It’s now smooth. Thanks

siluck | 2020-10-06 19:34

It works for me (Godot 3.2.1)

var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.add_smooth_group(true)
# adding triangles (color, uv, vertex)
st.index()
st.generate_normals()
st.commit(result)
return result

badunius | 2021-10-14 18:42