Skip to content

Commit 4865a95

Browse files
author
v 1 r t l
authored
Merge pull request #180 from pmndrs/react-18-last-pp-last-three
Update rpp to work with latest React, R3F and PP, add GH actions
2 parents c472e31 + b2aca7d commit 4865a95

20 files changed

+2771
-6189
lines changed

.github/workflows/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
ci:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: actions/setup-node@v3
15+
with:
16+
node-version: "16"
17+
cache: "yarn"
18+
- name: "install deps and build"
19+
run: yarn install --frozen-lockfile

.travis.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

package.json

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212
],
1313
"license": "MIT",
1414
"type": "module",
15-
"main": "dist/index.cjs",
16-
"module": "dist/index.js",
17-
"types": "dist/index.d.ts",
15+
"main": "./dist/index.cjs",
16+
"module": "./dist/index.js",
17+
"exports": {
18+
"types": "./dist/index.d.ts",
19+
"require": "./dist/index.cjs",
20+
"import": "./dist/index.js"
21+
},
22+
"types": "./dist/index.d.ts",
1823
"sideEffects": false,
1924
"files": [
2025
"dist"
@@ -39,53 +44,46 @@
3944
"typegen": "tsc --emitDeclarationOnly || true"
4045
},
4146
"dependencies": {
42-
"postprocessing": "^6.30.1",
43-
"react-merge-refs": "^1.1.0",
47+
"postprocessing": "^6.30.2",
4448
"screen-space-reflections": "2.5.0",
45-
"three-stdlib": "^2.8.11"
49+
"three-stdlib": "^2.21.10"
4650
},
4751
"devDependencies": {
48-
"@babel/core": "^7.17.8",
49-
"@babel/plugin-transform-modules-commonjs": "7.17.7",
50-
"@babel/plugin-transform-parameters": "7.16.7",
51-
"@babel/plugin-transform-runtime": "7.17.0",
52-
"@babel/plugin-transform-template-literals": "7.16.7",
53-
"@babel/preset-env": "^7.16.11",
54-
"@babel/preset-react": "7.16.7",
55-
"@babel/preset-typescript": "^7.16.7",
56-
"@react-three/fiber": "^7.0.26",
57-
"@rollup/plugin-babel": "^5.3.1",
58-
"@rollup/plugin-commonjs": "^21.0.3",
59-
"@rollup/plugin-json": "^4.1.0",
60-
"@rollup/plugin-node-resolve": "^13.1.3",
61-
"@types/react": "^17.0.43",
62-
"@types/react-dom": "^17.0.14",
63-
"@types/react-test-renderer": "^17.0.1",
64-
"@types/three": "^0.139.0",
65-
"@typescript-eslint/eslint-plugin": "^5.17.0",
66-
"@typescript-eslint/parser": "^5.17.0",
67-
"eslint": "^8.12.0",
68-
"eslint-config-prettier": "^8.5.0",
52+
"@babel/core": "^7.21.4",
53+
"@babel/plugin-transform-runtime": "7.21.4",
54+
"@babel/preset-env": "^7.21.4",
55+
"@babel/preset-react": "7.18.6",
56+
"@babel/preset-typescript": "^7.21.4",
57+
"@react-three/fiber": "^8.13.0",
58+
"@rollup/plugin-babel": "^6.0.3",
59+
"@rollup/plugin-commonjs": "^24.1.0",
60+
"@rollup/plugin-node-resolve": "^15.0.2",
61+
"@types/react": "^18.2.0",
62+
"@types/react-dom": "^18.2.1",
63+
"@types/three": "^0.150.2",
64+
"@typescript-eslint/eslint-plugin": "^5.59.1",
65+
"@typescript-eslint/parser": "^5.59.1",
66+
"eslint": "^8.39.0",
67+
"eslint-config-prettier": "^8.8.0",
6968
"eslint-import-resolver-alias": "^1.1.2",
70-
"eslint-plugin-import": "^2.25.4",
71-
"eslint-plugin-prettier": "^4.0.0",
72-
"eslint-plugin-react": "^7.29.4",
73-
"eslint-plugin-react-hooks": "^4.3.0",
74-
"husky": "^7.0.4",
75-
"husky-run": "^0.0.0",
76-
"lint-staged": "^12.3.7",
77-
"prettier": "^2.6.1",
78-
"react": "^17.0.2",
79-
"react-dom": "^17.0.2",
80-
"rimraf": "^3.0.2",
81-
"rollup": "^2.70.1",
82-
"rollup-plugin-filesize": "^9.1.2",
83-
"rollup-plugin-terser": "^7.0.2",
84-
"typescript": "^4.6.3"
69+
"eslint-plugin-import": "^2.27.5",
70+
"eslint-plugin-prettier": "^4.2.1",
71+
"eslint-plugin-react": "^7.32.2",
72+
"eslint-plugin-react-hooks": "^4.6.0",
73+
"husky": "^8.0.3",
74+
"lint-staged": "^13.2.2",
75+
"prettier": "^2.8.8",
76+
"react": "^18.2.0",
77+
"react-dom": "^18.2.0",
78+
"rimraf": "^5.0.0",
79+
"rollup": "^3.21.0",
80+
"rollup-plugin-filesize": "^10.0.0",
81+
"three": "^0.151.3",
82+
"typescript": "^5.0.4"
8583
},
8684
"peerDependencies": {
87-
"@react-three/fiber": ">=7.0",
88-
"react": ">=17.0",
89-
"three": ">=0.136.0"
85+
"@react-three/fiber": ">=8.0",
86+
"react": ">=18.0",
87+
"three": ">= 0.138.0 < 0.152.0"
9088
}
9189
}

rollup.config.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import path from 'path'
2-
import babel from '@rollup/plugin-babel'
2+
import { babel } from '@rollup/plugin-babel'
33
import resolve from '@rollup/plugin-node-resolve'
4-
import json from '@rollup/plugin-json'
54
import filesize from 'rollup-plugin-filesize'
65

76
const root = process.platform === 'win32' ? path.resolve('/') : '/'
87
const external = (id) => !id.startsWith('.') && !id.startsWith(root)
9-
const extensions = ['.js', '.jsx', '.ts', '.tsx', '.json']
8+
const extensions = ['.js', '.jsx', '.ts', '.tsx']
109

1110
const getBabelOptions = ({ useESModules }, targets) => ({
1211
babelrc: false,
@@ -27,7 +26,6 @@ export default [
2726
output: { file: `dist/index.js`, format: 'esm' },
2827
external,
2928
plugins: [
30-
json(),
3129
babel(getBabelOptions({ useESModules: true }, '>5%, not dead, not ie 11, not op_mini all, node >=12')),
3230
filesize(),
3331
resolve({ extensions }),
@@ -37,6 +35,6 @@ export default [
3735
input: `./src/index.tsx`,
3836
output: { file: `dist/index.cjs`, format: 'cjs' },
3937
external,
40-
plugins: [json(), babel(getBabelOptions({ useESModules: false })), filesize(), resolve({ extensions })],
38+
plugins: [babel(getBabelOptions({ useESModules: false })), filesize(), resolve({ extensions })],
4139
},
4240
]

src/EffectComposer.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { HalfFloatType, TextureDataType } from 'three'
1+
import type { TextureDataType } from 'three'
2+
import { HalfFloatType } from 'three'
23
import React, {
34
forwardRef,
45
useMemo,
@@ -8,14 +9,15 @@ import React, {
89
useRef,
910
useImperativeHandle,
1011
} from 'react'
11-
import { useThree, useFrame } from '@react-three/fiber'
12+
import { useThree, useFrame, useInstanceHandle } from '@react-three/fiber'
1213
import {
1314
EffectComposer as EffectComposerImpl,
1415
RenderPass,
1516
EffectPass,
1617
NormalPass,
1718
// @ts-ignore
1819
DepthDownsamplingPass,
20+
Effect,
1921
} from 'postprocessing'
2022
import { isWebGL2Available } from 'three-stdlib'
2123

@@ -26,7 +28,7 @@ export const EffectComposerContext = createContext<{
2628
camera: THREE.Camera
2729
scene: THREE.Scene
2830
resolutionScale?: number
29-
}>(null)
31+
}>(null!)
3032

3133
export type EffectComposerProps = {
3234
enabled?: boolean
@@ -48,8 +50,8 @@ export const EffectComposer = React.memo(
4850
(
4951
{
5052
children,
51-
camera,
52-
scene,
53+
camera: _camera,
54+
scene: _scene,
5355
resolutionScale,
5456
enabled = true,
5557
renderPriority = 1,
@@ -63,8 +65,8 @@ export const EffectComposer = React.memo(
6365
ref
6466
) => {
6567
const { gl, scene: defaultScene, camera: defaultCamera, size } = useThree()
66-
scene = scene || defaultScene
67-
camera = camera || defaultCamera
68+
const scene = _scene || defaultScene
69+
const camera = _camera || defaultCamera
6870

6971
const [composer, normalPass, downSamplingPass] = useMemo(() => {
7072
const webGL2Available = isWebGL2Available()
@@ -118,21 +120,22 @@ export const EffectComposer = React.memo(
118120
)
119121

120122
const group = useRef(null)
123+
const instance = useInstanceHandle(group)
121124
useLayoutEffect(() => {
122-
let effectPass
123-
if (group.current && group.current.__r3f && composer) {
124-
effectPass = new EffectPass(camera, ...(group.current as any).__r3f.objects)
125+
let effectPass: EffectPass
126+
if (group.current && instance.current && composer) {
127+
effectPass = new EffectPass(camera, ...(instance.current.objects as unknown as Effect[]))
125128
effectPass.renderToScreen = true
126129
composer.addPass(effectPass)
127130
if (normalPass) normalPass.enabled = true
128-
if (downSamplingPass) downSamplingPass.enabled = true
131+
if (downSamplingPass) downSamplingPass.enabled = true
129132
}
130133
return () => {
131134
if (effectPass) composer?.removePass(effectPass)
132135
if (normalPass) normalPass.enabled = false
133136
if (downSamplingPass) downSamplingPass.enabled = false
134137
}
135-
}, [composer, children, camera, normalPass, downSamplingPass])
138+
}, [composer, children, camera, normalPass, downSamplingPass, instance])
136139

137140
// Memoize state, otherwise it would trigger all consumers on every render
138141
const state = useMemo(

src/Selection.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ export function Selection({ children, enabled = true }: { enabled?: boolean; chi
1818
return <selectionContext.Provider value={value}>{children}</selectionContext.Provider>
1919
}
2020

21-
2221
export function Select({ enabled = false, children, ...props }: SelectApi) {
2322
const group = useRef<THREE.Group>(null!)
2423
const api = useContext(selectionContext)
2524
useEffect(() => {
2625
if (api && enabled) {
2726
let changed = false
28-
const current = []
27+
const current: THREE.Object3D<THREE.Event>[] = []
2928
group.current.traverse((o) => {
3029
o.type === 'Mesh' && current.push(o)
3130
if (api.selected.indexOf(o) === -1) changed = true

src/effects/DepthOfField.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DepthOfFieldEffect } from 'postprocessing'
2-
import React, { Ref, forwardRef, useMemo, useLayoutEffect, useContext } from 'react'
2+
import { Ref, forwardRef, useMemo, useLayoutEffect, useContext } from 'react'
33
import { ReactThreeFiber, useThree } from '@react-three/fiber'
4-
import { Texture, Vector3 } from 'three'
4+
import { type DepthPackingStrategies, type Texture, Vector3 } from 'three'
55
import { EffectComposerContext } from '../EffectComposer'
66

77
type DOFProps = ConstructorParameters<typeof DepthOfFieldEffect>[1] &
@@ -22,14 +22,14 @@ export const DepthOfField = forwardRef(function DepthOfField(
2222
const { camera } = useContext(EffectComposerContext)
2323
const effect = useMemo(() => new DepthOfFieldEffect(camera, props), [camera, props])
2424
useLayoutEffect(() => {
25-
if (target) {
25+
if (target && typeof target !== 'number') {
2626
const vec: Vector3 =
2727
target instanceof Vector3
2828
? new Vector3().set(target.x, target.y, target.z)
2929
: new Vector3().set(target[0], target[1], target[2])
3030
effect.target = vec
3131
}
32-
if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing)
32+
if (depthTexture) effect.setDepthTexture(depthTexture.texture, depthTexture.packing as DepthPackingStrategies)
3333
invalidate()
3434
}, [target, depthTexture, effect])
3535
return <primitive ref={ref} object={effect} dispose={null} />

src/effects/Glitch.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { GlitchEffect, GlitchMode } from 'postprocessing'
2-
import React, { Ref, forwardRef, useMemo, useLayoutEffect } from 'react'
2+
import { Ref, forwardRef, useMemo, useLayoutEffect } from 'react'
33
import { ReactThreeFiber, useThree } from '@react-three/fiber'
44
import { useVector2 } from '../util'
55

66
export type GlitchProps = ConstructorParameters<typeof GlitchEffect>[0] &
77
Partial<{
8-
mode: typeof GlitchMode[keyof typeof GlitchMode]
8+
mode: GlitchMode
99
active: boolean
1010
delay: ReactThreeFiber.Vector2
1111
duration: ReactThreeFiber.Vector2
@@ -21,15 +21,13 @@ export const Glitch = forwardRef<GlitchEffect, GlitchProps>(function Glitch(
2121
const delay = useVector2(props, 'delay')
2222
const duration = useVector2(props, 'duration')
2323
const strength = useVector2(props, 'strength')
24-
const effect = useMemo(() => new GlitchEffect({ ...props, delay, duration, strength }), [
25-
delay,
26-
duration,
27-
props,
28-
strength,
29-
])
24+
const effect = useMemo(
25+
() => new GlitchEffect({ ...props, delay, duration, strength }),
26+
[delay, duration, props, strength]
27+
)
3028
useLayoutEffect(() => {
3129
effect.mode = active ? props.mode || GlitchMode.SPORADIC : GlitchMode.DISABLED
3230
invalidate()
33-
}, [active, effect, props.mode])
31+
}, [active, effect, invalidate, props.mode])
3432
return <primitive ref={ref} object={effect} dispose={null} />
3533
})

src/effects/LUT.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
import { LUTEffect } from 'postprocessing'
2-
import React, { forwardRef, Ref, useMemo, useLayoutEffect } from 'react'
3-
import { Texture } from 'three'
41
import { useThree } from '@react-three/fiber'
2+
import { LUT3DEffect, BlendFunction } from 'postprocessing'
3+
import React, { forwardRef, Ref, useLayoutEffect, useMemo } from 'react'
4+
import type { Texture } from 'three'
55

6-
type LUTProps = ConstructorParameters<typeof LUTEffect>[1] & {
6+
export type LUTProps = {
77
lut: Texture
8+
blendFunction?: BlendFunction
9+
tetrahedralInterpolation?: boolean
810
}
911

10-
export const LUT = forwardRef(function LUT({ lut, tetrahedralInterpolation, ...props }: LUTProps, ref: Ref<LUTEffect>) {
12+
export const LUT = forwardRef(function LUT(
13+
{ lut, tetrahedralInterpolation, ...props }: LUTProps,
14+
ref: Ref<LUT3DEffect>
15+
) {
16+
const effect = useMemo(() => new LUT3DEffect(lut, props), [lut, props])
1117
const invalidate = useThree((state) => state.invalidate)
12-
const effect = useMemo(() => new LUTEffect(lut, props), [lut, props])
1318

1419
useLayoutEffect(() => {
15-
if (lut) effect.setLUT(lut)
16-
if (tetrahedralInterpolation) effect.setTetrahedralInterpolationEnabled(tetrahedralInterpolation)
20+
if (tetrahedralInterpolation) effect.tetrahedralInterpolation = tetrahedralInterpolation
21+
if (lut) effect.lut = lut
1722
invalidate()
18-
}, [effect, lut, tetrahedralInterpolation])
23+
}, [effect, invalidate, lut, tetrahedralInterpolation])
1924

2025
return <primitive ref={ref} object={effect} dispose={null} />
2126
})

0 commit comments

Comments
 (0)