• Stars
    star
    273
  • Rank 150,780 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

WebGL shader for mixed grid-particle fluid simulation

âš  Update: This code has been deprecated and replaced by the following repo: https://github.com/amandaghassaei/gpu-io/tree/main/examples/fluid

FluidSimulation

WebGL shader for mixed grid-particle fluid simulation.

Live demo at apps.amandaghassaei.com/FluidSimulation.

This simulation solves the Navier-Stokes equations for incompressible fluids in a GPU fragment shader. On top of the grid-based fluid simulation are thousands of Lagrangian particles, which follow the fluid flow and create semi-transparent trails as they move. To increase performance, the velocity vector field of the fluid is solved at a lower resolution and linearly interpolated.

To learn more about the math involved behind the simulation, check out the following sources:

By Amanda Ghassaei, live demo at apps.amandaghassaei.com/FluidSimulation/.

Instructions

Swipe across the screen to apply a force to the fluid. The direction and magnitude of the force will depend on the movement of your cursor. This app has mostly been tested in Chrome and Firefox, so if you're having trouble, try switching browsers.

This app also supports exporting vector paths as SVG or G-Code for pen plotting (among other things). To start, press the spacebar to freeze the simulation and enter the vector export workflow:

(at any time you can press spacebar again to re-enter and modify the underlying fluid simulation)

From the export workflow you can specify a number of parameters:

  • Num Particles sets the number of particles to run through the fluid.
  • Trail Length sets the number of time steps to iterate each particle, more time equals longer trails. Increasing this number will increase the processing time required for export.
  • Trail Subsampling sets the resolution of the time steps for particle iteration. Increase this if you notice that your resulting vector files are not smooth enough for your application (especially for fast-moving particles). Increasing this number will increase the processing time required for export.
  • Regenerate button initializes a new set of particles and generates trails for them.

Additionally you can control some parameters for SVG export:

  • Min Segment Length sets the target minimum segment length in your resulting svg file. This is not a hard guarantee, as clipping of line segments near the boundary may result in segments shorter than this value. But this can help reduce the size of your file. The length is defined in terms of px (you can adjust the px size of the simulation by adjusting the size of the browser window).
  • Save SVG button initiates an SVG save.

The options for G-code export include:

  • Width sets the width in inches of the resulting toolpath. Aspect ratio will be preserved.
  • Height sets the height in inches of the resulting toolpath. Aspect ratio will be preserved.
  • Min Segment Length is similar to the SVG option, but measured in inches. You will likely want to set this to something larger than zero to prevent your machine from slowing down too much due to a very dense toolpath.
  • Retract Height sets the clearance height of your pen in inches during move operations (not drawing). This height should be above your Draw Height.
  • Draw Height sets the height of the pen in inches when in contact with paper.
  • Feed Rate sets the rate of movement (measured in inches per minute) while drawing. The toolpaths uses rapid moves when at clearance height.
  • Draw Both Directions is part of the toolpath optimization process, meant to minimize the total travel length of the pen when it is not in contact with the paper. This parameter tells the optimizer to ignore the directionality of the particle trail when drawing, which often results in a better optimized path.
  • Save G-Code button initiates a G-code save (as .nc file).

The resulting toolpath looks like this:

And some plots:

Development

Install all dependencies with npm:

npm install

Start a dev server:

npm run start

Build src to dist:

npm run build

More Repositories

1

gpu-io

A GPU-accelerated computing library for running physics simulations and other GPGPU computations in a web browser.
TypeScript
1,204
star
2

OrigamiSimulator

Realtime WebGL origami simulator
JavaScript
1,083
star
3

canvas-capture

Record the canvas as an image, mp4 video, or gif from the browser
JavaScript
205
star
4

VortexShedding

A realtime fluid flow simulation on the GPU using WebGL
JavaScript
142
star
5

Fusion360-Scripts

A collection of Fusion360 scripts, mostly for generating animations
Python
103
star
6

LaserCutRecord

generate vector cutting paths from digital audio to make a working record
Processing
55
star
7

SoapFlow

Jupyter Notebook
42
star
8

MassSpringShader

WebGL Shader that implements a mass-spring-damper physical simulation
HTML
41
star
9

3DPrintedRecord

3d printable record stl generator using Processing and Python
Processing
37
star
10

tellurion-orrery

CAD files and info for building an orrery from scratch
JavaScript
34
star
11

ShellFormFinding

Web-based simulation tool that allows you to design 3D forms in pure compression
JavaScript
28
star
12

ConwayShader

WebGL Shader for Conway's Game of Life
TypeScript
22
star
13

Lithograph3DPrint

converts an image to a 3d printable heightmap or lithophane (http://en.wikipedia.org/wiki/Lithophane)
Processing
20
star
14

MeshWriter

Live three.js coding with STL and OBJ export
JavaScript
19
star
15

botanigram

Create "growing" animations of plants from a single photograph
TypeScript
18
star
16

Sugarcube-Arduino-Library

A grid-based midi instrument, with accelerometer and gyroscope for playful interactions
Max
18
star
17

Genetic-Images

a Processing sketch that generates images from translucent polygons using a genetic algorithm
Processing
18
star
18

marbling-experiment

An early experiment toward building a marbling simulation
TypeScript
16
star
19

msh-parser

Finite element .msh format parser, written in TypeScript
TypeScript
15
star
20

MotionMagnification

Eulerian, Lagrangian, and Phase-Based Motion Magnification in MATLAB
MATLAB
13
star
21

stl-parser

Standalone module for parsing binary and ASCII STL files, written in TypeScript
TypeScript
12
star
22

salesforce-tower

3D visualization for artwork on Salesforce Tower
JavaScript
11
star
23

TrussOptimization2D

Web-based design and optimization tool that uses real-time simulation feedback to inform the design process.
JavaScript
11
star
24

ProjectionMappingAlignment

WebGL app that breaks out many of the threejs camera parameters to fine tune projection mapping alignment
JavaScript
11
star
25

ScratchSerialExtension

A Serial Communication Extension for Scratch
JavaScript
11
star
26

ffmpeg-scripts

A collection of ffmpeg scripts I'm using to generate gifs and mp4
Shell
10
star
27

vector-math

A minimal vector math library to handle 2D/3D translations and rotations.
TypeScript
10
star
28

ReactionDiffusionShader

WebGL Shader for a Gray-Scott reaction diffusion system
JavaScript
10
star
29

MichellStructures

Web-based simulation tool that visualizes geometric properties and static internal forces in a loaded Michell cantilever
JavaScript
9
star
30

CurvedCreases

JavaScript
6
star
31

AMOEBA

JavaScript
5
star
32

LinkageOptimization

JavaScript
4
star
33

Linkages

A planar linkage optimization tool
nesC
3
star
34

LenticularProcessor

a Processing sketch for preparing a stack of images for a lenticlar lens
Processing
2
star
35

AMOEBA-2.5D

JavaScript
2
star
36

NodeSerialPortBoilerplate

Simple demo to get serial ports up and running with node and client-side javascript
JavaScript
2
star
37

event-dispatcher

Parent class to support custom event listeners, written in TypeScript.
TypeScript
2
star
38

StepperRotaryStage

A geared, rotary stage made from 3D printed and laser cut parts (and some off the shelf components). Modeled parametrically in Fusion360.
1
star
39

ActiveBendingHybridStructures

JavaScript
1
star
40

ms-thesis

TeX
1
star
41

Processing-Linkage-Generator

leg linkages designed in Processing, exported to STL for 3D Printing via ModelBuilder Library
Processing
1
star
42

ImageMagick

a collection of ImageMagick scripts
Shell
1
star
43

type-checks

A collection of JavaScript type checks.
TypeScript
1
star
44

RecordProcessor

A web app for designing custom records, outputs to laser cutter, CNC mill...
JavaScript
1
star