Closed kirill-osipov closed 2 years ago
Hello! What's the motivation for your question? It's possible that a structure like this could be used to improve CSG operation performance but I haven't done work in that vein myself. There is a three.js issue here that discusses CSG operations but I believe most referenced solutions are ports or adaptations of CSG.js.
Yes. Performance of libraries based on CSG.js is not enough for usage models with 200+ polygons in real-time.
I am not an expert in CSG so I can't confidently recommend anything specific. My understanding is that CSG typically uses different data structures for processing operations.
CSG.js uses BSP and as was said, using BSP as algorithm for splitting was a terrible idea. But, for example, as I can see Godot uses BVH
Interesting -- I didn't know Godot was using a BVH for its CSG. It seems like there should be a better way to do it but a BVH should be able to be used to speed up some of the steps to running something like a brute force process for the geometry operations.
I haven't looked into Godot's implementation but some quick first thoughts on how I'd do something like this with a BVH:
The ray-crossing algorithm may require care when dealing with vertex and edge crossings to ensure a single edge is not double counted but in theory it seems like that should work. And of course the BVH can be used to improve the performance of steps 1 and 3 of the process. That's what comes to mind at first, at least. I'm sure there's more to consider.
I don't plan to work on this but if you're interested in pursuing it I'd be happy to offer guidance in getting a new example page going to show a basic CSG demo if you want to work on that!
Thank you for your comprehensive reply. I think I can take it.
Awesome! I'll be interested to see what you come up with -- and if you wind up working to make an example page in this repo and would like some help feel free to make draft PR!
This would be really useful
I've created a repo with a CSG implementation using three-mesh-bvh here:
Is it possible to use the library for CSG similar way as was done in CSG.js