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

Degenerate Triangles will result in NPE #724

Open
dbt-padberg opened this issue Oct 15, 2024 · 1 comment
Open

Degenerate Triangles will result in NPE #724

dbt-padberg opened this issue Oct 15, 2024 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@dbt-padberg
Copy link

dbt-padberg commented Oct 15, 2024

Describe the bug

There are usages of Three.js's Triangle.getInterpolation(...) in this library that can result in a Null-Pointer-Exception.

The documentation (https://threejs.org/docs/index.html?q=Triangle#api/en/math/Triangle.getInterpolation) says:

Returns the value barycentrically interpolated for the given point on the triangle. Returns null if the triangle is degenerate.

What is a degenerate triangle? https://en.wikipedia.org/wiki/Degeneracy_(mathematics)#:~:text=A%20degenerate%20triangle%20is%20a,angle%20and%20two%20undefined%20angles.

E.g. https://github.com/search?q=repo%3Agkjohnson%2Fthree-mesh-bvh+intersection.normal&type=code

In my case the code or my meshes have provided a degenerate triangle which returned null.
Screenshot 2024-10-15 at 15 35 34

It could be that other usages are affected too:
https://github.com/search?q=repo%3Agkjohnson%2Fthree-mesh-bvh+getInterpolation&type=code

To Reproduce

Sadly I am currently not able to provide an example. Hopefully I can provide some in a few days.

Expected behavior

There should be null checks and a logically fallback. Or at least some precheck to prevent this error.

Platform:

  • Device: Desktop
  • OS: MacOS
  • Browser: Chrome
  • Three.js version: ==0.169.0
  • Library version: ==0.8.1 (+ three-bvh-csg == 0.0.16)
@dbt-padberg dbt-padberg added the bug Something isn't working label Oct 15, 2024
@gkjohnson
Copy link
Owner

Hello! Thanks for the report. An example would be useful here - though CSG will likely not be working nicely with degenerate triangles in the first place and should probably be removed before operating. However I understand that's not always easily doable or may even occur during a previous operation.

Up until about a month ago this is how three.js' raycasting worked, which this library aims to reproduce the results of exactly. The new barycoord attribute sampling implementation I added to three.js about a month ago should solve this issue but will instead result in a 0, 0, 0 barycoordinate value (and therefore 0, 0, 0 value for interpolated uv, normal, etc).

I'd prefer not to make breaking changes to accommodate such a recent three.js release (eg we should avoid using the getInterpolatedAttribute function) but if you'd like to submit a PR that updates the the raycasting to align with three.js' behavior (ie just add some null checks) we can get that merged.

@gkjohnson gkjohnson added this to the v0.8.2 milestone Oct 17, 2024
@gkjohnson gkjohnson modified the milestones: v0.8.2, v0.8.3, v0.8.4 Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants