Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slicing a 3D model?

Tags:

c#

unity3d

3d

I want to slice a 3D model relative to an infinite plane(In WPF). I'm checking if edges intersect with the infinite plane. If true, I'll create a new point at the intersection position, so I'm getting a couple of points that I want to generate a cap on so that the model is closed after slicing. For example, if this is the cross section, the result would be as follows: Example result Note: The triangulation ain't important. I just need triangles.

I also need to detect the holes as follows(holes are marked in red): Example result with holes

If it is impossible to do it the way I think(It seems to be so), the how should I do it? How do developers cap an object after being sliced?

There is also too much confusion. For example, The first picture's result may be: Confusion What am I missing??


EDIT: After some research, I knew one thing that I am missing: enter image description here

The input is now robust, and I need the exact same output. How do I accomplish that??

like image 387
None Avatar asked Jan 05 '17 18:01

None


2 Answers

In the past, I have done this kind of thing using a BSP.

Sorry to be so vague, but its not a a trivial problem!

Basically you convert your triangle mesh into the BSP representation, add your clipping plane to the BSP, and then convert it back into triangles.

like image 199
Leo Bartkus Avatar answered Oct 18 '22 10:10

Leo Bartkus


As code11 said already you have too few data to solve this, the points are not enough.

Instead of clipping edges to produce new points you should clip entire triangles, which would give you new edges. This way, instead of a bunch of points you'd have a bunch of connected edges.

In your example with holes, with this single modification you'd get a 3 polygons - which is almost what you need. Then you will need to compute only the correct triangulation.

Look for CSG term or Constructive Solid Geometry.

EDIT:

If the generic CSG is too slow for you and you have clipped edges already then I'd suggest to try an 'Ear Clipping' algorithm.

Here's some description with support for holes: https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf

You may try also a 'Sweep Line' approach: http://sites-final.uclouvain.be/mema/Poly2Tri/

And similar question on SO, with many ideas: Polygon Triangulation with Holes

I hope it helps.

like image 36
kolenda Avatar answered Oct 18 '22 08:10

kolenda