gkjohnson / three-bvh-csg

A flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh
MIT License
628 stars 49 forks source link

Question about getOperationAction in operations.js and when it ignores triangles #211

Closed ToyboxZach closed 5 months ago

ToyboxZach commented 5 months ago

Describe the bug

I am diving into some issues with basic shape CSG that we are running into and I am running into a weird case when subtracting an e from a box (just using basic thee box and text geometries)

I end up with an extra face on the bottom that should not have been added:

image image

Expected behavior

No invalid face showing up.

I have dived down into it and the questionable place ends up being in getOperationAction


export function getOperationAction( operation, hitSide, invert = false ) {

    switch ( operation ) {

        case ADDITION:

            if ( hitSide === FRONT_SIDE || ( hitSide === COPLANAR_ALIGNED && ! invert ) ) {

                return ADD_TRI;

            }

            break;
        case SUBTRACTION:

            if ( invert ) {

                if ( hitSide === BACK_SIDE ) {

                    return INVERT_TRI;

                }

            } else {

                if ( hitSide === FRONT_SIDE || hitSide === COPLANAR_OPPOSITE ) {

                    return ADD_TRI;

                }

            }

            break;

I'm curious why subtraction allows "hitSide === COPLANAR_OPPOSITE" if the face is coplanar with the object we are subtracting, I would expect it not to be added, why do we enable COPLANAR_OPPOSITE. I would assume that if we are point the face into the middle of the subtraction, we should remove it anyways.

ToyboxZach commented 5 months ago

Realized what was happening