-
Notifications
You must be signed in to change notification settings - Fork 717
/
ScreenQuad.tsx
28 lines (24 loc) · 1015 Bytes
/
ScreenQuad.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// reference: https://medium.com/@luruke/simple-postprocessing-in-three-js-91936ecadfb7
// and @gsimone ;)
import * as THREE from 'three'
import * as React from 'react'
import { ForwardRefComponent } from '../helpers/ts-utils'
function createScreenQuadGeometry() {
const geometry = new THREE.BufferGeometry()
const vertices = new Float32Array([-1, -1, 3, -1, -1, 3])
geometry.boundingSphere = new THREE.Sphere()
geometry.boundingSphere.set(new THREE.Vector3(), Infinity)
geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 2))
return geometry
}
type Props = Omit<JSX.IntrinsicElements['mesh'], 'args'>
export const ScreenQuad: ForwardRefComponent<Props, THREE.Mesh> = /* @__PURE__ */ React.forwardRef<THREE.Mesh, Props>(
function ScreenQuad({ children, ...restProps }, ref) {
const geometry = React.useMemo(createScreenQuadGeometry, [])
return (
<mesh ref={ref} geometry={geometry} frustumCulled={false} {...restProps}>
{children}
</mesh>
)
}
)