gkjohnson / three-bvh-csg

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

Extra split triangles no correctly culled #29

Closed gkjohnson closed 2 years ago

gkjohnson commented 2 years ago

Follow on from #28

Looks like there's a triangle not getting split:

image

Next step: find the triangle that that's clipped from and the other triangles it's intersecting

gkjohnson commented 2 years ago

Though it looks like there's two overlapping triangles unexpectedly:

image
gkjohnson commented 2 years ago
// split tri
            new THREE.Triangle(
                new THREE.Vector3( 0.1269903190542666, -0.15988833933004354, 0 ),
                new THREE.Vector3( 0.5269903250147311, 0.5329319712626076, 0 ),
                new THREE.Vector3( 0.32699033693566004, 0.5329319712626077, 0.20000000298023224 ),
            )

// splitting tris
            new THREE.Triangle(
                new THREE.Vector3( 0.6000000238418579, 0, 0.20000000298023224 ),
                new THREE.Vector3( 0.30000001192092896, 0.5196152329444885, 0.20000000298023224 ),
                new THREE.Vector3( 0.20000000298023224, 0.3464101552963257, 2.4492935397342132e-17 ),
            ),
            new THREE.Triangle(
                new THREE.Vector3( 0.4000000059604645, 0, 2.4492935397342132e-17 ),
                new THREE.Vector3( 0.6000000238418579, 0, 0.20000000298023224 ),
                new THREE.Vector3( 0.20000000298023224, 0.3464101552963257, 2.4492935397342132e-17 ),
            ),
            new THREE.Triangle(
                new THREE.Vector3( 0.4000000059604645, 0, 2.4492935397342132e-17 ),
                new THREE.Vector3( 0.20000000298023224, 0.3464101552963257, 2.4492935397342132e-17 ),
                new THREE.Vector3( 0.30000001192092896, 0.5196152329444885, -0.20000000298023224 ),
            ),
            new THREE.Triangle(
                new THREE.Vector3( 0.800000011920929, 0, -4.8985870794684264e-17 ),
                new THREE.Vector3( 0.6000000238418579, 0, -0.20000000298023224 ),
                new THREE.Vector3( 0.4000000059604645, 0.6928203105926514, -4.8985870794684264e-17 ),
            ),
            new THREE.Triangle(
                new THREE.Vector3( 0.800000011920929, 0, 0 ),
                new THREE.Vector3( 0.4000000059604645, 0.6928203105926514, 0 ),
                new THREE.Vector3( 0.30000001192092896, 0.5196152329444885, 0.20000000298023224 ),
            )
gkjohnson commented 2 years ago

reduced problem triangle set


const tri = new THREE.Triangle(
    new THREE.Vector3( 0.1269903190542666, -0.15988833933004354, 0 ),
    new THREE.Vector3( 0.5269903250147311, 0.5329319712626076, 0 ),
    new THREE.Vector3( 0.32699033693566004, 0.5329319712626077, 0.20000000298023224 ),
);

const tris = [

    // lower tri
    new THREE.Triangle(
        new THREE.Vector3( 0.4000000059604645, 0, 2.4492935397342132e-17 ),
        new THREE.Vector3( 0.6000000238418579, 0, 0.20000000298023224 ),
        new THREE.Vector3( 0.20000000298023224, 0.3464101552963257, 2.4492935397342132e-17 ),
    ),

    // upper tri
    new THREE.Triangle(
        new THREE.Vector3( 0.800000011920929, 0, 0 ),
        new THREE.Vector3( 0.4000000059604645, 0.6928203105926514, 0 ),
        new THREE.Vector3( 0.30000001192092896, 0.5196152329444885, 0.20000000298023224 ),
    )
];
gkjohnson commented 2 years ago

Fixed in https://github.com/gkjohnson/three-mesh-bvh/pull/438