Hi, I’d like to implement the clipping function like the following sample on react-three-fiber in next.js app. I tried to find an example, but it hard to find. https://threejs.org/examples/#webgl_clipping
Please let me know if someone know a good way or examples.
making this a component as you did above is not wrong but then it should be a side effect (useEffect) and have a cleanup because if you unmount the component it should go back to default:
function ClippingPlane() {
const { gl } = useThree()
useEffect(() => {
// Save previous defaults
const { clippingPlanes, localClippingEnabled } = gl
const plane = new Plane(new Vector3(0, -1, 0), 0.8)
gl.clippingPlanes = [plane]
gl.localClippingEnabled = true
// Go back to defaults on unmount
return () => Object.assign(gl, { clippingPlanes, localClippingEnabled})
}, [])
return null
}
and now you have a re-usable component that’s safe to mount/unmount without causing left-overs.