karl- / pb_CSG

A C# port of CSG.js by Evan W (http://evanw.github.io/csg.js/).
MIT License
634 stars 99 forks source link

Intersection creates artifact #11

Open brookman opened 4 years ago

brookman commented 4 years ago

When I intersect a standard cube and a standard sphere there is an artifact in the corner: image It doesn't matter if I move the objects. The problem also appears if there are no zero-width situations.

TomTales commented 4 years ago

I have the same issue. I tried detecting these and removing them by doing an 'island' detection, but when you're doing loads of intersection sooner or later some fail.

JaineshPathak commented 3 years ago

I have the same issue. I tried detecting these and removing them by doing an 'island' detection, but when you're doing loads of intersection sooner or later some fail.

Hi.

I am interested in Island detection you mentioned. Can you help me out?

TomTales commented 3 years ago

Hi.

I am interested in Island detection you mentioned. Can you help me out?

Well it's been a while, but at the time I did get it partially working. Basically what I did is I selected a vertex and added the 3 vertices that are part of the triangle to a list of discovered vertices. Then for each of those vertices, I searched for another vertex that's in the same position but part of another triangle and add that to the list together with the other two vertices that are part of that triangle. When a vertex is already in the list you do not check its neighboring vertices. Sooner or later there will be no new vertices to check and you've found an island. Then repeat if necessary for a vertex that isn't in the first island or you can just delete all triangles/vertices that aren't in the bigger part, assuming there are at max two islands. Please note that this algorithm sucks and will never be fast enough to use effectively. It is however good and fun practice. For me this still left some artifacts so I actually wrote my own boolean operator for meshes, which turned out to work really well with no artifacts I could find, but once again it was very very slow, so not very practical.

Hope this helps!

JaineshPathak commented 3 years ago

Hi. I am interested in Island detection you mentioned. Can you help me out?

Well it's been a while, but at the time I did get it partially working. Basically what I did is I selected a vertex and added the 3 vertices that are part of the triangle to a list of discovered vertices. Then for each of those vertices, I searched for another vertex that's in the same position but part of another triangle and add that to the list together with the other two vertices that are part of that triangle. When a vertex is already in the list you do not check its neighboring vertices. Sooner or later there will be no new vertices to check and you've found an island. Then repeat if necessary for a vertex that isn't in the first island or you can just delete all triangles/vertices that aren't in the bigger part, assuming there are at max two islands. Please note that this algorithm sucks and will never be fast enough to use effectively. It is however good and fun practice. For me this still left some artifacts so I actually wrote my own boolean operator for meshes, which turned out to work really well with no artifacts I could find, but once again it was very very slow, so not very practical.

Hope this helps!

Sorry for late reply. I know its weird to ask, but is it possible for you to share your code? I have written a script myself where mesh splitting works, but the game freezes in between while doing splitting operation.

I can share my code as well.

TomTales commented 3 years ago

Sorry for late reply. I know its weird to ask, but is it possible for you to share your code? I have written a script myself where mesh splitting works, but the game freezes in between while doing splitting operation.

I can share my code as well.

Oh boy. Man, I still have the projects but it's such a mess and it's multiple attempts mixed together. Like honestly, it would probably take you more time to figure out what the code means than to try and implement the crude algorithm I described. As for the freezing, yes, it's slow. Mine is just as slow. I would advise you to focus on understanding how it works and writing your own implementation before remotely trying to get it to be performant enough to use without freezing or stuttering. If you don't need it to be real-time you could try making it asynchronous, but yeah, sounds like you're almost at the point where I stopped messing with mesh fracturing.

If you really want then here are the scripts I made. Good luck! Scripts.zip

JaineshPathak commented 3 years ago

Sorry for late reply. I know its weird to ask, but is it possible for you to share your code? I have written a script myself where mesh splitting works, but the game freezes in between while doing splitting operation. I can share my code as well.

Oh boy. Man, I still have the projects but it's such a mess and it's multiple attempts mixed together. Like honestly, it would probably take you more time to figure out what the code means than to try and implement the crude algorithm I described. As for the freezing, yes, it's slow. Mine is just as slow. I would advise you to focus on understanding how it works and writing your own implementation before remotely trying to get it to be performant enough to use without freezing or stuttering. If you don't need it to be real-time you could try making it asynchronous, but yeah, sounds like you're almost at the point where I stopped messing with mesh fracturing.

If you really want then here are the scripts I made. Good luck! Scripts.zip

Thank you so much for the scripts.