-
-
Notifications
You must be signed in to change notification settings - Fork 4.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 obj loader #6047
Fix obj loader #6047
Conversation
Remove restriction that normals are per vertex
Files without normals now created errors
Face indices would have been first vertex index for all vertices
Hi, thanks for the fix, I would like to ask two things: firstly, could you post a file where the problem occurs, so that I can understand the problem better? And secondly, you have changed a lot of formatting (most importantly, indentation), which makes the changes very unclear and difficult to review. Could you revert all formatting changes, please? |
Github doesn't allow me to upload the file directly as an obj file so i attach it as a zip. Sorry for the formatting issues i'll fix them and push the changes. |
The diff should now only cover the relevant lines. |
Thank you, the diff is much clearer now. And I think your solution of storing normals and averaging them per vertex makes sense. pcl::PointCloud<pcl::PointNormal> cloud;
pcl::fromPCLPointCloud2(blob, cloud);
EXPECT_EQ(cloud.size(), 8);
for(const auto& point: cloud) {
Eigen::Vector3f expected_normal(point.x, point.y, point.z);
expected_normal.normalize();
EXPECT_NEAR(expected_normal.x(), point.x, 1e-4);
EXPECT_NEAR(expected_normal.y(), point.y, 1e-4);
EXPECT_NEAR(expected_normal.z(), point.z, 1e-4);
} Which basically tests whether the vector from the cube center to the point is the same as the point normal. If you think this is good, would you be willing to add this to this pull request? I am also wondering about the use of normals in the obj file format, maybe you have an intuition about this. In the file you uploaded, for each face, all vertices have the same normal (the normal of the face). If this is the intended use of the normals, it is strange why the creators of the file format chose to have the normals specified per vertex (redundant) instead of per face (e.g. |
Vector3f storage was uninitialized
I integrated the suggested test into the existing one. The obj file i provided also has one more irregularity e.g. in line 3512 it reuses vn 1227 in (i guess) an attempt to compress the file by deduplication. |
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.
Thanks again for the pull request and the background information!
This pull request enables the obj loader to load files which do not use exactly one normal per vertex and also allow for loading of files where normal indices are used for multiple vertices. (e.g. obj files exported by blender).
To do so it accumulates the normals used per vertex over the faces and computes normals for the vertices.