I need to perform 3D objects slicing, as is shown on image gray object will be sliced depending on blue plane position, in some cases front plane side will remain in others back plane side will remain of gray object. To simplify the scene I used cube and plane but my real scene objects and slicing plane might be a bit more complex.
Any algorithm to perform this will be appreciated.
I would do the following:
for each triangle in the triangle mesh:
find out how many points of the triangle are on the visible side
if there are no points on the visible side:
ignore this triangle
if there is one point on the visible side:
find the intersection points of the two lines that connect the visible point with the invisible ones with the cutting plane
add the triangle that is defined by the visible point and the intersection points to the new mesh
if there are two points on the visible side:
find the intersection points of the two lines that connect the invisible point with the visible ones with the cutting plane
add the triangle that is defined by the first visible point and the two intersetion points to the new mesh
add the triangle that is defined by both visible points and the intersection point belonging to the second visible point to the new mesh
if there are three points on the visible side:
copy this triangle to the new mesh
this will give you the cut open mesh half on the visible side. if you want the mesh to be closed where the plane cut it, you need to:
add all intersection points into a list, keeping track of the pairs (you always get either no or two intersection points)
order that list in counter-clockwise direction without changing the pairs (x)
triagonalize the created polygons
add the new triangles to the triangle list
that’s basically connecting a lot of small lines to one or more polylines. the area inside those polylines are the polygons you have to triagonalize in the next step.
If it’s a polygon, then it can be split up into triangles so you could just use the algorithm I posted above.
Or is it a polygon and you map a function, texture, whatever onto it and thereby change its “height” (called displacement mapping, if I remember correctly)?
Say somehow I applied the slicing algorithm with your posted code above or with LineRayCastPlane, main problem remains how to manipulate 3D object vertexes.
Anyway I’ll work bit more further and I’ll let you know.