Skip to content

Commit 2a78d95

Browse files
author
v 1 r t l
authored
Merge pull request #195 from CodyJasonBennett/feat/godrays-sun-ref
feat(GodRays): accept mesh ref
2 parents fb716cc + 852b148 commit 2a78d95

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/effects/GodRays.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import { GodRaysEffect } from 'postprocessing'
22
import React, { Ref, forwardRef, useMemo, useContext } from 'react'
33
import { Mesh, Points } from 'three'
44
import { EffectComposerContext } from '../EffectComposer'
5+
import { useLayoutEffect } from 'react'
6+
import { resolveRef } from '../util'
57

68
type GodRaysProps = ConstructorParameters<typeof GodRaysEffect>[2] & {
7-
sun: Mesh | Points
9+
sun: Mesh | Points | React.MutableRefObject<Mesh | Points>
810
}
911

1012
export const GodRays = forwardRef(function GodRays(props: GodRaysProps, ref: Ref<GodRaysEffect>) {
1113
const { camera } = useContext(EffectComposerContext)
12-
const effect = useMemo(() => new GodRaysEffect(camera, props.sun, props), [camera, props])
14+
const effect = useMemo(() => new GodRaysEffect(camera, resolveRef(props.sun), props), [camera, props])
15+
// @ts-ignore v6.30.2 https://github.com/pmndrs/postprocessing/pull/470/commits/091ef6f9516ca02efa7576305afbecf1ce8323ae
16+
useLayoutEffect(() => void (effect.lightSource = resolveRef(props.sun)), [effect, props.sun])
1317
return <primitive ref={ref} object={effect} dispose={null} />
1418
})

0 commit comments

Comments
 (0)