CSG at per-vertex basis.

Hello!

I want to build CSG engine. So I need
code which constructs from two meshes A and B
meshes A or B; A and B; A\B.
A and B are convex.

Can somebody help me with source code?
Please excuse my poor English.

There was a good description on flipcode.com
(or some site I got to from surfing off
there). When I say “poly” below you could
read “tree” if you only use tri-meshes.

Basically, you need to test all the polys in
your first mesh against all the polys in your
second mesh; the polys that intersect must be
sliced where they intersect (and the meshes
modified accordingly). This involves some
moderately simple geometric algebra.

Then, each poly in both of the meshes is
classified as whether it’s inside, outside
or coplanar with the surface of the other
mesh. This just involves a simple normal ray
versus poly check for each poly of the other
mesh, and count the number of intersections
in the positive direction; it’s odd for
“inside”. This works because there are no
polys that are both inside and outside,
because you split them in the previous step.

Then, decide which of the faces (polys) you
want to keep from each mesh based on the
operation you want to perform. For A-B, you
keep the polys that are in A and coplanar
with or outside B, and the polys that are in
B inside A.

Good luck!