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

Wrong vertex normals and uvs after boolean subtraction #579

Closed
jirihon opened this issue Oct 25, 2023 · 7 comments · Fixed by #587
Closed

Wrong vertex normals and uvs after boolean subtraction #579

jirihon opened this issue Oct 25, 2023 · 7 comments · Fixed by #587

Comments

@jirihon
Copy link
Contributor

jirihon commented Oct 25, 2023

I have two manifolds a and b. Both have 8 vertex properties - 3 for coordinates, 3 for normals, 2 for uvs).

Manifold a is a result of previous boolean operations and you can see it in the following picture. One of its surfaces has a UV debug texture assigned. The short blue segments pointing out from the textured surface shows vertex normals for all the vertices that are involved in any triangle belonging to this surface.

image

Manifold b is a simple cuboid larger then manifold a and translated down a little bit. Here is a picture of both manifold a and b in one scene.

image

When b is subtracted from a (manifold a_minus_b), something bad happens with the normals and uvs on the textured surface. See the picture below.

image

The problematic surface is composed of three triangles. The problem is that two of the triangles uses a vertex which has normal and uv that would be good for the left adjacent surface, but not for this.

The problem occurs in specific situations only. For example, if I move the manifold b down by a different offset, the problem disappears. It seems to me that offsets which don't have accurate numeric representation (like multiples of 1/3) triggers this more often.

In case you would have time to look into this, I attach a MeshGL dump of all the manifolds - a, b and a_minus_b. The problematic triangles are 40 and 46. They use vertex 50 which has inappropriate normal and uv. I would expect that these triangles will use vertex 68 instead as it is used in the only correct triangle 38 for this surface.

wrong_normals_and_uvs_mesh_dump.txt

@jirihon
Copy link
Contributor Author

jirihon commented Oct 25, 2023

I've just noticed you merged the new triangulator. The described example works with the new triangulator. But it was quite easy to find another example of wrong normals and uvs, so I think the triangulator won't be the problem here. I'll try to prepare another example which shows the problem for the current master.

@jirihon
Copy link
Contributor Author

jirihon commented Oct 25, 2023

Here is a new mesh dump which shows the same problem for the current master.

wrong_normals_and_uvs_mesh_dump_2.txt

The problematic triangles here are 17 and 28 which use vertex 8 with inappropriate normal and uv.

image

@pca006132
Copy link
Collaborator

are there degenerate triangles in the result? or duplicated vertices at the same position?

@jirihon
Copy link
Contributor Author

jirihon commented Oct 25, 2023

are there degenerate triangles in the result? or duplicated vertices at the same position?

How do I check this? I'm using WASM bindings. I have duplicated vertices because I need different normals and uvs for different surfaces, but I set mergeFromVert and mergeToVert, so it is manifold.

@pca006132
Copy link
Collaborator

I think we don't have that API in our js binding because it is only intended for debugging.

For this bug, I feel like it may be related to degenerate triangles or vertices with same position because the normal computation for them are probably not very stable. Can you try if it works if you modify https://github.com/elalish/manifold/blob/master/src/manifold/src/impl.cpp#L70 a bit to ignore edges with length less than precision?

@elalish
Copy link
Owner

elalish commented Oct 26, 2023

Thank you for the detailed report - this definitely sounds like a bug. The next step will be turning it into a reproducible TEST; hopefully our RelatedGL testing function can help here.

@jirihon
Copy link
Contributor Author

jirihon commented Oct 26, 2023

I think we don't have that API in our js binding because it is only intended for debugging.

For this bug, I feel like it may be related to degenerate triangles or vertices with same position because the normal computation for them are probably not very stable. Can you try if it works if you modify https://github.com/elalish/manifold/blob/master/src/manifold/src/impl.cpp#L70 a bit to ignore edges with length less than precision?

I've checked the triangle areas by using cross product of the AB and AC vectors. The smallest triangle I could find in a, b and a_minus_b manifolds has area of 1560.33, so I don't think any of the triangles is degenerate.

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

Successfully merging a pull request may close this issue.

3 participants