Skip to content

Commit

Permalink
Fix particles prop in Emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
hmans committed Aug 2, 2022
1 parent d68c614 commit bfd1588
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-bikes-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vfx-composer": patch
---

**Fixed:** `<Emitter>` could no longer work with `<Particles>` refs passed into its `particles` prop. Woops!
11 changes: 8 additions & 3 deletions packages/vfx-composer/src/fiber/Emitter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const Emitter = forwardRef<Object3D, EmitterProps>(
ref
) => {
const object = useRef<Object3D>(null!)
const particles = particlesProp?.current || useParticlesContext()
const particlesFromContext = useParticlesContext()

const emitterSetup = useCallback<InstanceSetupCallback>(
(props) => {
Expand All @@ -46,17 +46,22 @@ export const Emitter = forwardRef<Object3D, EmitterProps>(

setup?.(props)
},
[particles, setup]
[setup]
)

useEffect(() => {
const particles = particlesProp?.current || particlesFromContext

if (!particles) return
if (continuous) return

particlesMatrix.copy(particles!.matrixWorld).invert()
particles.emit(count, emitterSetup)
}, [particles])
}, [])

useFrame(() => {
const particles = particlesProp?.current || particlesFromContext

if (!particles) return
if (!continuous) return
particlesMatrix.copy(particles!.matrixWorld).invert()
Expand Down

0 comments on commit bfd1588

Please sign in to comment.