Jump to content

  • Log In with Google      Sign In   
  • Create Account


Fragmenting a mesh using csg operations


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Psilobe   Members   -  Reputation: 193

Like
0Likes
Like

Posted 27 January 2013 - 11:36 AM

HI I'm considering different ways to implementing mesh fragmentation. One example would be fracture in the unreal engine. I've found a few interesting reads about this using vornoi.

 

http://www.joesfer.com/?p=60

https://sites.google.com/site/shusenliuspage/course-work/voronoi-based-shatter-effects

 

One approach was intersecting the object with a plane, displace a few vertexes on the plane and cut the mesh using it. Creating multiple planes and rotating them would resulting in several fragments.

 

I'm not very well traversed in graphics but I also came upon constructive solid geometry and figured that using intersection operations could result in a fragmented mesh.

 

I was something something along the lines that first you separate all/some of the faces of the mesh from each other or rather create copies of these. Then you extrude these inwards. Then using different CSG operations you create the fragments using intersection operations and kinda carve out the original mesh. And to avoid too much fragmentation you only carve from the original and not the fragments so that even if the extruded faces would overlap at times this would not result in extra fragmentation.

 

I'm curious if this could work? One problem I foresee is if you have a rectangle mesh it wouldn't produce very interesting results but if you subdivided the mesh first and then pick the order of faces to intersect at random it could produce better results.

 

 

 



Sponsor:

#2 irreversible   Crossbones+   -  Reputation: 1096

Like
2Likes
Like

Posted 27 January 2013 - 09:42 PM

ON CSG

 

I looked into CSG a couple of years ago as I wanted to write my own implementation. In retrospect, in terms of time, I would've been far better off using a library. However, after doing a fair amount of research, the simplest approach turned out to be the most stable in terms of cost and flexibility; most importantly, it was the most suitable for me. The paper on the Laidlaw approach can be found here.

 

Mind you that debugging CSG code takes a lot of time and testing - you can't just assume that when you try one boundary case (eg vertex-edge) it'll work if you swap the meshes. Also, due to raycasting, Laidlaw's approach limits you to closed meshes (which is what you generally want, but not always). As far as I remember the paper has a small mistake in it, but I can't recall what it was. In any case, be ready to have to write plenty of additional code from a custom memory manager to your own triangulator (in the very least you'll need to perform convex primitive decomposition) and merger (to re-create mesh faces after CSG), which in and of themselves will take lot of time and testing. I found writing the merger probably the hardest to do so it wouldn't be dead slow, seeing as you're going to want to minimized overlapping edges and you'll be working with annoyances like T-junctions. The triangulator can be really tricky as well (I ended up implementing the slowest, but simplest approach - ear clipping) as you'll need to manage things like vertex ordering, repeated/collinear vertices, etc.

 

Overall, if you really want to implement your own CSG routine, be really methodical about it from get-go: index your vertices, pre-decompose everything into triangles for speed and thoroughly test everything at every step. The sad thing about the CSG procedure itself is that you can't really test it until you've written the bulk of it, which in Laidlaw's case is a lot of if statements, which need to be painstakingly correct.

 

If you're not absolutely bent on writing your own code, I heartily suggest you make use of a library. Ironically, since I was stubborn to write my own, I never actually compared all the different libraries out there...

 

PS - I never put enough effort into getting this working properly, but once you've done your initial decomposition, Laidlaw's approach is separable and can be extended to two threads (one per mesh), which I find to be of great value compared to other methods. Do not go with the BSP approach - it'll be dead slow as soon as the meshes have any decent number of polygons.

 

I ended up getting my code working at real-time framerates for box-cylinder (20 sides) intersection. I'm sure it can be further optimized to get real-time performance out of 40 + 40 tri meshes.

 

ON FRAGMENTING

 

I never did this, but overall I would consider three ways:

 

1) create a number of outlines of various shapes in any 3D modeling software that form a single whole. When fragmenting, simply run CSG on the object. I'm not sure how to avoid things like a chair's legs ending up in a single fragment, though (you'd probably need to scale the fragment meshes to best fit the size of the fragmented object). You could pre-rotate the fracture meshes to create fake variations of it.

 

2) pre-fracture the mesh manually (in most cases the fracturing is an offline process anyway)

 

3) consider a voxelization approach: voxelize the object when loading it and split off arbitrary "chunks" as needed; I'm not sure how to perform hole capping right off the bat, though

 

4) I wanted to find a link I saw a couple of years back regarding a pretty cool destructible material system, but couldn't find it. It was closed and still in beta AFAIR, but it handled stuff like wood chipping, etc. I did come across this, however (haven't read it yet, but hopefully it helps)



#3 Psilobe   Members   -  Reputation: 193

Like
1Likes
Like

Posted 28 January 2013 - 04:41 PM

Interesting. At first I thought using csg for this would be a good idea but as it would seem that implementing csg from scratch would be out of the question because it would probably take too much time. But experimenting with this using a ready made library might be a fun thing to do if I have the time sometime.

 

That last article was really interesting and took up several interesting topics, thanks!



#4 irreversible   Crossbones+   -  Reputation: 1096

Like
1Likes
Like

Posted 28 January 2013 - 08:53 PM

I should probably have mentioned these before, but there are two more options, although not really suitable for fragmenting geometry per se: CSG via the stencil buffer and the way Valve does rendering wounds in L4D2. The latter actually relates to subtractive CSG and uses projection to fill the hole. It's an interesting read, even if it's not directly applicable to standard geometry.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS