Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SurfaceTool.add_smooth_group() has no effect #65104

Closed
Mathis-Z opened this issue Aug 30, 2022 · 4 comments · Fixed by #68034
Closed

SurfaceTool.add_smooth_group() has no effect #65104

Mathis-Z opened this issue Aug 30, 2022 · 4 comments · Fixed by #68034

Comments

@Mathis-Z
Copy link

Godot version

3.5 a264b68

System information

Manjaro Linux

Issue description

SurfaceTool.add_smooth_group() is supposed to generate smooth normals for the vertices it is called for but it does not have any effect.
I looked into the C++ source code and think I know what is causing the issue. In SurfaceTool.generate_normals() a HashMap is used to find double vertices (ones that are exactly the same) and then add the normals of the double vertices together. This way a vertex on the edge of two faces will get the sum of the normals for both faces as its smoothed normal.
The problem is that the HashMap does not only check for the hash of two objects to be the same but also checks if both objects are the very same object. This is obviously not true for any two vertices since they are separate objects and thus no smooth normals are calculated.

Steps to reproduce

  1. Create a MeshInstance with a script attached
  2. In the script use SurfaceTool to create a mesh and call "name of your SurfaceTool-Object".add_smooth_group(true) before every call to .add_vertex()
  3. use SurfaceTool.generate_normals() to get your normals

Minimal reproduction project

SurfaceTool.zip

@Hiiamwilliam
Copy link

I think you're supposed to call add_smooth_group only once, before calling any add_vertex. If you do this you'll get different results in the MRP.

@Mathis-Z
Copy link
Author

You are right, if you call it once before adding any vertex, you get smoothed normals but calling it for every vertex gets you "hard" normals again...
I do not think this behaviour is correct because it is not documented this way and it also does not really make sense, right? https://docs.godotengine.org/de/stable/classes/class_surfacetool.html#class-surfacetool-method-add-smooth-group
I am very confused now...

@Hiiamwilliam
Copy link

I think the documentation could be clearer about this. There are other add_x that are called per vertex, and add_smooth_group method description doesn't really clarify it shouldn't.

What I think happens is that you can't smooth the normals of a group if the group has only one vertex. So you need to call add_smooth_group(true) and then add the vertices. That's why if you call it once before adding any vertex the whole mesh will have smooth normals.

The Procedural Geometry SurfaceTool tutorial does mention add_smooth_group should be called before add_vertex, but the way it's written it can be understood as "Called before add_vertex for every vertex".

Speaking of Procedural Geometry, I just noticed, but only the ArrayMesh class actually has a link to its respective tutorial. SurfaceTool tutorial links to the 3D Voxel Demo on the Asset Library, but not the tutorial, and both ImmediateGeometry and MeshDataTool don't even mention they have tutorials...

@akien-mga
Copy link
Member

Fixed by #68034.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants