-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Large performance cost for coplanar triangles #199
Comments
Can you please produce a live demonstration using jsfiddle or another web editor? |
Yes, I created a jsfiddle here: https://jsfiddle.net/st2am1Lw/4/ |
Hi, has it been resolved at the moment? |
The issue is still open so no, it has not been resolved. |
I met this issue with lacking triangles for coplanar triangles.
I increased the EPSILON values:
const EPSILON = 1e-5;
const COPLANAR_EPSILON = 1e-5;
const PARALLEL_EPSILON = 1e-5; It works like a charm now. |
This only deals with the missing triangles, is that correct? Possibly related to #188, as well.
1e-10 to 1e-5 is a fairly big jump. Have you tried any intermediate values. These are very hard values to tune, it seems 😅 I'm a little hesitant to just change them without an understanding of the side effects but maybe it's an okay thing to do. Are you seeing cases where you have triangles doubled up on top of eachother after the change? |
In my case, I want to compute the floor plan from the meshes of the walls of a 3D apartment.
In this case:
I got cases when I have triangles doubled but I cannot reproduce them (I tried a lot of stuff in this project). |
I expect at some point this is unavoidable in the general case with the current approach due to floating point errors. I think anything close to perfect result would require using integer calculations. Though some of the solutions laid out in #51 or #97 could help improve things a bit.
Perhaps it makes sense to expose these epsilon values as options on the triangulator or CSG evaluator classes? If you'd like to make a PR for something like this I can look into getting it merged so this is available. |
Increasing the epsilon seems like a code smell. Shouldn’t it really be used to just avoid floating point precision issues? When you get away from that use, you are typically trading one failure for another. Also, 1e-5 can barely be called an epsilon. You are just tuning the algorithm at that point. If this is necessary, seems you would want to instead pass it to the evaluator as some “distanceFactor” with values 0.0001 to 1. 🤷♂️ |
This is why I'm suggesting to expose this as a configurable option. This is an incredibly difficult problem - one that I don't believe is completely avoidable without integer math. Vertices further from the origin will have large floating point epsilons, floating error compounds on operations like multiplication (dot products, matrix math) so the epsilon required will change depending on the math used, and so on. I don't think there is a one-size-fits-all value for this. Of course the code could probably be tuned to account for error more intelligently so if you're interested in contributing to help address the errors feel free to become more familiar with the code. This project was developed completely in free time and I have fixed a lot of floating pointer error-related issues. But tracking every problem down is not a priority for me. If a configuration option is a low-friction solution that enables people to do their work then I don't see the harm in adding it with a reasonable documentation note. |
Hello, It also works with the original EPSILON values, but if I replace this line: three-bvh-csg/src/core/TriangleSplitter.js Line 210 in f107dbb
By this one:
|
OK I have dig into the issue instead of f****g around. All happens in 1st issue: coplanarity uncertaintyLet say In
In this picture, AB is the smallest edge of the triangle used to compute the plane. 2nd issue: error propagationI do tens of CSG operation on the same coplanar points, so the error can accumulate. I noticed that, if we detect that and edge is coplanar to a triangle, forcing the edge to belongs to the triangle plane allows to avoid artifacts. |
Hello there,
I noticed a strong performance slowdown for CSG operations when sides of the objects lie within each other.
The following example demonstrates the issue.
Setting
varyHeight
to true results in a total processing time of about 100ms on my system.Setting
varyHeight
to false however results in the ends of the cylinders to overlap with many coplanar triangles and a processing time of about 300 seconds, about three thousand times slower than the version with varying heights.Is there anything one can do to avoid this issue other than avoiding coplanar triangles at all?
Best regards,
Marc
The text was updated successfully, but these errors were encountered: