Skip to content

Commit

Permalink
Mark instance matrix as dirty when controlled particle unmounts.
Browse files Browse the repository at this point in the history
  • Loading branch information
hmans committed Sep 26, 2022
1 parent 4785f05 commit 8376e3e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-owls-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vfx-composer-r3f": patch
---

When a controlled particles is unmounted, it will now automatically mark the particle system's instance matrix for reupload.
3 changes: 2 additions & 1 deletion packages/vfx-composer-r3f/src/Particle.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Object3DProps, useFrame } from "@react-three/fiber"
import { Object3DProps } from "@react-three/fiber"
import React, {
forwardRef,
useImperativeHandle,
Expand Down Expand Up @@ -41,6 +41,7 @@ export const Particle = forwardRef<Object3D, Object3DProps>((props, ref) => {
return () => {
ecs.destroyEntity(entity)
particles.setMatrixAt(cursor, hideMatrix)
particles.instanceMatrix.needsUpdate = true
}
}, [particles])

Expand Down
2 changes: 1 addition & 1 deletion packages/vfx-composer-r3f/src/Particles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const Particles = forwardRef<ParticlesImpl, ParticlesProps>(
)

useFrame(() => {
if (!ecs.entities.length) return
if (ecs.entities.length === 0) return

/* Make sure the effect's world matrix is up to date */
particles.updateMatrixWorld()
Expand Down

0 comments on commit 8376e3e

Please sign in to comment.