-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Fix bug in CylinderMesh when computing normals #67336
Conversation
scene/resources/primitive_meshes.cpp
Outdated
@@ -789,7 +789,7 @@ void CylinderMesh::create_mesh_array(Array &p_arr, float top_radius, float botto | |||
|
|||
Vector3 p = Vector3(x * radius, y, z * radius); | |||
points.push_back(p); | |||
normals.push_back(Vector3(x, 0.0, z)); | |||
normals.push_back(Vector3(x, (bottom_radius - top_radius)/height, z).normalized()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This y component is constant so it could be computed only once outside the for loop.
Style wise, you should also have spaces around /
(run clang-format locally to make sure to us the right style).
The whole class might need a thorough review because there might be other calculations which expect a cylinder to be... a cylinder. |
b2eaff7
to
35844d9
Compare
Thanks for the help. I've fixed the formatting. I'm a first time contributor, so I could be wrong but I don't think the tangent needs to be changed. I'm not positive what the tangent is calculating as there are at least two orthogonal tangents to the normal. But it seems like the tangent is pointing along the rings of the cylinder, and so that vector wouldn't change if the side gets slanted. Let me know if I'm thinking of this wrong. I have a PR in with unit tests for all the |
Makes sense yes. Seems like you missed part of my review comment:
I.e. you could compute |
35844d9
to
491ec62
Compare
Thanks! And congrats for your first merged Godot contribution 🎉 |
Thanks for your help! :-) |
Cherry-picked for 3.6. |
Cherry-picked for 3.5.2 |
While writing unit tests for
CylinderMesh
I realized the following bug. When the top radius and bottom radius are different, the normal should be slanted in they
direction to some degree.However, in
primitive_meshes.cpp
, they
component of the normals along the side of the cylinder was always set to zero. Essentially, the normals were being computed as if it were a right cylinder, as opposed to a sort of trapezoidal cylinder with different radii on top and bottom.