-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Change signature * In component, too * Cool * Eh * Implement partial uploads * Cleanup * Tweak * changeset * Hmpf * Do cursor handling and partial uploads in onBeforeRender * Cleanup * Okay! * Bursts * Don't use Timeline Composer for a moment * Cleanup * Hrm * Simplify * Cleanup * I hate everything * Meh * ts-ignore * Use Repeat from Timeline Composer * Upgrade Timeline Composer * Upgrade dev dependencies * Disable partical uploads for now * Only upload our own attributes * Make partial uploads safer * Upgrade TC * delay test * wrap in repeat * times * Use timeline components from 3vfx for now * Remove debug code * Simplifty
- Loading branch information
Showing
16 changed files
with
300 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"vfx-composer": minor | ||
--- | ||
|
||
**Added:** Partial attribute buffer uploads! Now only the parts of the buffers that have been used for newly spawned particles are actually uploaded to the GPU. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,49 @@ | ||
import { InstancedMeshProps } from "@react-three/fiber" | ||
import { extend, InstancedMeshProps, Node } from "@react-three/fiber" | ||
import React, { | ||
forwardRef, | ||
useEffect, | ||
useImperativeHandle, | ||
useState | ||
useRef | ||
} from "react" | ||
import { Particles as ParticlesImpl } from "../Particles" | ||
import { VFXMaterial as ParticlesMaterialImpl } from "../VFXMaterial" | ||
import { VFXMaterial as VFXMaterialImpl } from "../VFXMaterial" | ||
|
||
export type ParticlesProps = InstancedMeshProps & { | ||
material?: ParticlesMaterialImpl | ||
export type ParticlesProps = Omit<InstancedMeshProps, "material" | "args"> & { | ||
args?: ConstructorParameters<typeof ParticlesImpl> | ||
material?: VFXMaterialImpl | ||
maxParticles?: number | ||
safetyBuffer?: number | ||
} | ||
|
||
export const Particles = forwardRef<ParticlesImpl, ParticlesProps>( | ||
({ maxParticles = 1000, geometry, material, ...props }, ref) => { | ||
/* We're using useState because it gives better guarantees than useMemo. */ | ||
const [particles, setParticles] = useState( | ||
() => new ParticlesImpl(geometry, material, maxParticles) | ||
) | ||
extend({ VfxComposerParticles: ParticlesImpl }) | ||
|
||
/* We still want to update the particles when the props change. */ | ||
useEffect(() => { | ||
setParticles(new ParticlesImpl(geometry, material, maxParticles)) | ||
}, [geometry, material, maxParticles]) | ||
declare global { | ||
namespace JSX { | ||
interface IntrinsicElements { | ||
vfxComposerParticles: ParticlesProps | ||
} | ||
} | ||
} | ||
|
||
export const Particles = forwardRef<ParticlesImpl, ParticlesProps>( | ||
( | ||
{ maxParticles = 1000, safetyBuffer = 100, geometry, material, ...props }, | ||
ref | ||
) => { | ||
const particles = useRef<ParticlesImpl>(null!) | ||
|
||
/* Setup particles in an effect (after materials and geometry are assigned) */ | ||
useEffect(() => { | ||
particles.setupParticles() | ||
return () => particles.dispose() | ||
}, [particles]) | ||
particles.current.setupParticles() | ||
}, []) | ||
|
||
useImperativeHandle(ref, () => particles) | ||
useImperativeHandle(ref, () => particles.current) | ||
|
||
return <primitive object={particles} {...props} /> | ||
return ( | ||
<vfxComposerParticles | ||
args={[geometry, material, maxParticles, safetyBuffer]} | ||
ref={particles} | ||
{...props} | ||
/> | ||
) | ||
} | ||
) |
Oops, something went wrong.