I have asked a very similar question recently but that specific issue got solved so I decided it would be more organized to start another thread. And because realized I have no idea how to use bufferGeometry, this is a more broad question.
I am attempting to create a very simple bufferGeometry and perfom CSG operations with it. I read on the three-bvh-csg thread that it supports buffer geometries. But all my attempts lead to hollow results and non-manifold surfaces.The problem is probably in the way I am constructing my buffer geometries, because it works just fine if I use other geometries (like box, extrusion etc). does anyone know what I am doing wrong here?
This is my bufferGeometry code, when I add it to my scene the geometry looks visually fine, all faces are closed etc. :
export const CustomShapeGeometry = () => {
return (
<bufferGeometry>
<bufferAttribute
attach='attributes-position'
array={new Float32Array([
0,0,0,
10,0,0,
10,0,10,
0,0,10,
5,5,5
])}
count={5}
itemSize={3}
/>
<bufferAttribute
attach='attributes-uv'
array={new Float32Array([
0,0,
0,1,
0,2,
0,3,
1,0
])}
count={5}
itemSize={2}
/>
<bufferAttribute
attach='attributes-normal'
array={new Float32Array([
0,-1,0,
0,-1,0,
0,-1,0,
0,-1,0,
0,1,0
])}
count={5}
itemSize={3}
/>
<bufferAttribute
attach="index"
array={new Uint16Array([
0,1,2,
0,2,3,
0,1,4,
1,2,4,
2,3,4,
3,0,4
])}
count={18}
itemSize={1}
/>
</bufferGeometry>
)
}
And here is my csg code:
export const VolumeSubtraction = () => {
return (
<>
<mesh >
<meshStandardMaterial color='red' side={THREE.DoubleSide}/>
<Geometry>
<Base scale={[10,10,10]} position={[0, 20, 0]}>
<boxGeometry/>
</Base>
<Intersection position={[0, 20, 0]}>
<CustomShapeGeometry/>
</Intersection>
</Geometry>
</mesh>
</>
)
}
And the results look like this, as you can see it only intersects the faces, instead of treating it as a solid.
Intersection:
Subtraction:
And if i use any second geometry more complex than a box it starts to go completely crazy with the faces. For example like this:
Looking over this forum I saw this person with a similar issue as me, their problem was that their geometry was non-manifold, but i have no idea how to find out if that’s the case for me or how to fix it, I am a bit lost. Any help is appreciated!
Note, I do know that I could use a pyramid geometry to perform this without creating the buffer geometry point by point, but my idea is to create more complex geometries from here on, so I was testing the csg on this simpler one.