Particulate.js
Particulate.js is a JavaScript particle physics micro library (~3.7kb gz) designed to be simple, extensible, fast, and stable; it is capable of running a simulation with tens of thousands of particles and tens of thousands of constraints in real time. The core system is derived from that described in Advanced Character Physics by Thomas Jakobsen.
Website – Examples – Docs – Tests
Usage
The library provides an interface for defining a particle system with many inter-particle constraints and globally acting forces. Internal management of particle positions and state is designed to be easily integrated with a WebGL rendering pipeline, although no specific rendering scheme is required.
Install
Install with npm or bower or download the built package.
npm install particulate --save
bower install particulate --save
Then include the library as an AMD or commonJS module, or browser global.
;
var Particulate = ;
var Particulate = windowParticulate;
Integrate Renderer
The following is a simplified version of the chain example, rendered with Three.js:
// ..................................................// Define particle chain system// var particleCount = 5;var relaxIterations = 2; var system = ParticulateParticleSystem;var dist = ParticulateDistanceConstraint;var pin = ParticulatePointConstraint;var gravity = ParticulateDirectionalForce; system;system;system; // ..................................................// Integrate with Three.js// var scene = ; // Use system positions buffervar vertices = systempositions 3; // Use distance constraint indicesvar indices = distindices; // Particlesvar dotsGeom = ;dotsGeom; var dots = dotsGeom size : 2 ; // Connectionsvar linesGeom = ;linesGeom;linesGeom; var lines = linesGeom ; scene;scene; { system; dotsGeomattributespositionneedsUpdate = true; // Flag to update WebGL buffer ;}
Development
Grunt is used for building and testing the library. You should have one path for each dependency:
which node npm grunt
After resolving development dependencies, run:
npm install
Test
Run a development server with grunt server
.
Visit localhost:8000/examples/
to view examples or localhost:8000/test/
to run tests.
The development version of the library will be automatically rebuilt when any file matching /src/**/*
changes.
Tests can also be run from the command line with grunt test
.
Build
Running grunt build
will generate a fully commented development version of the library as well as
a minified production version in /dist
.
Document
Source code is documented in-line using YUIDoc syntax
and compiled by running grunt yuidoc
.
Contribute
There is not a formal style guide, but please maintain the existing coding style. Any new or changed functionality should be documented and covered by unit tests.