Carving in a mesh

Blitz3D Forums/Blitz3D Programming/Carving in a mesh

"I think you mean triangle for polygons, but what about plane?"

When I said planes, I mean the planes which the triangles lie in.

A triangle is three points, which lie on a plane. A quad is two triangles which lie on a plane. A polygon is a bunch of triangles connected together that lie on a plane.


"I guess you mean to reverse the mesh here ? So that is not visible from outside, but from inside?"

Basically, yes. But you don't actually have to flip any polygons exept those which you ultimately end up keeping that belong to the object I said to flip.


"That's not a trivial task I guess. It's exactly what puzzles me now. How I can determine that a triangle (of mesh B) is inside the mesh A ? Should I check all the vertex coordinates (of that triangle) against all the vertex coords of the mesh A?"

I think you're in a bit over your head trying to tackle CSG if you have to ask things like this. :-)

(CSG = Constructive Solid Geometry = Boolean opaerations on 3D models)

To find out which polygons of B are inside A, assuming you have used the planes defined by the polygons in A to split all the polygons in B, all polygons in B will now either be entirely inside, or entirely outside A. That's why you do the split.

To find out if they are inside or outside, all you need to do then is check every vertex in B to see which side of every polygon in A it is on. If it is on the inside side of every plane defined by a polygon in A, then it is inside A.

You then check each triangle and if any vertex that it uses is inside A then it too is inside A.

If A can be a concave object, which it may very well be if you already did one CSG operation on it, then you'll have to do a slightly different test to determine if each point is inside A. To do that, you need to cast a ray from the vertex in any direction to infinity. Let's say, along the X axis in the positive direction. If your ray crosses an odd number of polygons, then you are inside A, otherwise you are outside A.

"And more, how can I determine the vertex sequence to use, in order to add the mesh b surface triangles to ones which belongs to mesh a ? Maybe using TriangleVertex?"

Basically, find all the vertcies which you're gonna keep, and add those, and then find all the tirnagles you're going to keep, and then use that command I guess it is to find the original vertex indexes for that triangle and convert them to the new vertex indexes, because the numebrs will be different cause you have fewer vertices.


If you need more help type CSG 3D POLYGON into google and it will come up with lots of pages with info.