Skip to main content

Class: Fluid

physics/fluid/fluid.Fluid

Simulates a fluid using SPH (Smooth Particle Hydrodynamics).

see SPH Fluid Sim in Processing

see Processing Code

see Particle-based Viscoelastic Fluid Sim

Constructors

constructor

โ€ข new Fluid(opts)

Creates an Fluid with the given options.

Parameters

NameTypeDescription
optsFluidOptionsThe options to setup the fluid with

Defined in

src/physics/fluid/fluid.ts:77

Properties

collisionGroup

โ€ข collisionGroup: number

Defined in

src/physics/fluid/fluid.ts:51


color

โ€ข color: Color

Defined in

src/physics/fluid/fluid.ts:55


debug

โ€ข debug: boolean

Defined in

src/physics/fluid/fluid.ts:63


debugShapes

โ€ข debugShapes: Map<Particle, Circle>

Defined in

src/physics/fluid/fluid.ts:65


debugTex

โ€ข debugTex: Texture

Defined in

src/physics/fluid/fluid.ts:64


kdTree

โ€ข kdTree: kdTree

Defined in

src/physics/fluid/fluid.ts:53


maxParticles

โ€ข maxParticles: number

Defined in

src/physics/fluid/fluid.ts:50


particleRadius

โ€ข particleRadius: number

Defined in

src/physics/fluid/fluid.ts:49


particles

โ€ข particles: Particle[] = []

Defined in

src/physics/fluid/fluid.ts:41


physics

โ€ข physics: Physics

The physics world the fluid sim was added to.

Defined in

src/physics/fluid/fluid.ts:70


renderThreshold

โ€ข renderThreshold: number

Defined in

src/physics/fluid/fluid.ts:56


restDensity

โ€ข restDensity: number

Defined in

src/physics/fluid/fluid.ts:43


smoothingRadius

โ€ข smoothingRadius: number

Defined in

src/physics/fluid/fluid.ts:44


smoothingRadiusSqr

โ€ข smoothingRadiusSqr: number

Defined in

src/physics/fluid/fluid.ts:45


stiffness

โ€ข stiffness: number

Defined in

src/physics/fluid/fluid.ts:46


stiffnessNear

โ€ข stiffnessNear: number

Defined in

src/physics/fluid/fluid.ts:47


translate

โ€ข Private translate: vec2

Defined in

src/physics/fluid/fluid.ts:158


zIndex

โ€ข zIndex: number

The z layer of the fluid.

Defined in

src/physics/fluid/fluid.ts:61

Methods

addParticle

โ–ธ addParticle(pos): boolean

Adds a particle to the fluid at the given position.

Parameters

NameTypeDescription
posvec2The position to create the particle at in world space.

Returns

boolean

Wether or not the particle was added

Defined in

src/physics/fluid/fluid.ts:104


debugRender

โ–ธ debugRender(): void

Renders the particles of the fluid as individual circles.

Returns

void

Defined in

src/physics/fluid/fluid.ts:189


integrate

โ–ธ integrate(delta, gravity): void

Integrate any forces on the particle, including gravity, and integrate velocity.

Also resets the particle's density from the last update.

Parameters

NameTypeDescription
deltanumberThe time since the last update
gravityvec2-

Returns

void

Defined in

src/physics/fluid/fluid.ts:167


render

โ–ธ render(): void

Queues the fluid to be renderer using the fluid renderer.

Returns

void

Defined in

src/physics/fluid/fluid.ts:182


update

โ–ธ update(delta): void

Steps the fluid simulation forward in time.

Parameters

NameTypeDescription
deltanumberThe time since the last update

Returns

void

Defined in

src/physics/fluid/fluid.ts:125