BufferGeometry and Three-bvh-csg not working together

So I have a list of points in a 3D space, and I have a list triangles that show how each of them connect. I input both of these into BufferGeometry as attributes and it displays the shape just fine. In three.js it looks normal, and has all faces closed.

However, when I try to use it with three-bvh-csg I get nothing, and i have no idea why. I assume it could be because for some reason csg sees it as a non-manifold geometry, but I am not sure how to tell if that is the case, and if so how to fix that. Has anyone faced this issue before? Is there a solution?

Here is how I create this geometry:

export const CustomGeometry = () => {
    return (
        <bufferGeometry>
            <bufferAttribute
                attach='attributes-position'
                array={new Float32Array([-17.696252822875977, 0, 19.3864688873291, -6.360003471374512, 0, -16.741426467895508, 21.877092361450195, 0, -9.136500358581543, 10.539518356323242, 0, 26.87751579284668, 0.8028643727302551, 14.598217010498047, 9.191112518310547, 3.376246452331543, 14.602235794067383, 1.003333330154419])}
                count={6}
                itemSize={3}
            />
            <bufferAttribute
                attach="index"
                array={new Uint16Array([2, 3, 0, 0, 1, 2, 4, 3, 0, 4, 0, 1, 1, 5, 4, 5, 1, 2, 5, 2, 3, 3, 4, 5])}
                count={24}
                itemSize={1}
            />
        </bufferGeometry>
    )
}

And this is the very basic usage of three-bvh-csg, with the react wrapper react-three-csg:


const CsgGeometry= (props) => {
    return (
        <Geometry>
            <Base scale={[20, 20, 20]}>
                <boxGeometry/>
            </Base>
            <Addition>
                 <CustomGeometry/>
            </Addition>
         </Geometry>
    )
}

And the error I get is this, which is what leads me to suspect it might be a manifold problem

Error: CSG Operations: Attribute uv not available on geometry.

Based on the error, perhaps it’s complaining that your ‘base’ geometry has a UV attribute and your ‘addition’ geometry does not? Either removing UVs from the boxGeometry or adding them to the custom geometry might resolve that.

3 Likes

You’re right, that fixed it!! Thank you so much! I defined the UV attributes then it complained about the normals, once I defined that, it started working well.

1 Like

Since fixing the UV issues yesterday I started messing with the buffer geometries and I noticed the intersections, subtractions etc are all hollow. Maybe this should be the topic of a new question, but I wonder if they could be related.