Skip to content

Commit

Permalink
Add quaternion to components
Browse files Browse the repository at this point in the history
  • Loading branch information
hmans committed Jun 7, 2022
1 parent 3cbc31f commit 3869d43
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chatty-pumpkins-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vfx": patch
---

**New:** Added `quaternion` to the components passed to `setup`, allowing you to initialize each particle's original rotation.
1 change: 1 addition & 0 deletions apps/examples/src/effects/Explosion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const Dirt = ({ delay = 0 }) => (
.applyAxisAngle(new Vector3(0, 1, 0), between(0, Math.PI * 2))

c.position.copy(direction).multiplyScalar(3 + plusMinus(0.2))
c.quaternion.random()

c.velocity.copy(direction).multiplyScalar(10 + power(3) * 10)

Expand Down
4 changes: 3 additions & 1 deletion packages/vfx/src/MeshParticles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const tmpMatrix4 = new Matrix4()

const components = {
position: new Vector3(),
quaternion: new Quaternion(),
velocity: new Vector3(),
acceleration: new Vector3(),
delay: 0,
Expand Down Expand Up @@ -123,6 +124,7 @@ export const MeshParticles = forwardRef<InstancedMesh, MeshParticlesProps>(
for (let i = 0; i < count; i++) {
/* Reset components */
components.position.set(0, 0, 0)
components.quaternion.set(0, 0, 0, 1)
components.velocity.set(0, 0, 0)
components.acceleration.set(0, 0, 0)
components.scaleStart.set(1, 1, 1)
Expand All @@ -141,7 +143,7 @@ export const MeshParticles = forwardRef<InstancedMesh, MeshParticlesProps>(
playhead.current,
tmpMatrix4.compose(
components.position,
tmpRotation,
components.quaternion,
tmpScale.setScalar(1)
)
)
Expand Down

0 comments on commit 3869d43

Please sign in to comment.