+1 vote

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?

in Engine by (28,974 points)

1 Answer

+4 votes
Best answer

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Ă  :p

by (28,974 points)

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()

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^^"

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

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
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.