Giter VIP home page Giter VIP logo

boids-js's Introduction

Boids JS

BoidsJS is an implementation of the boids algorithm. This can be used for simulation flock behavior such as birds or fish in 3D space.

There are three examples provided for similar scenes but three examples differ in performance.

  • The first example run in the browser thread and it should slow down when there are many number of entities.
  • The second example also runs in the browser thread but it uses the grid implementation for fast lookups. This example should handle more entities in the browser thread.
  • In the third example, calculation is done in 4 parallel WebWorker threads. The rendering is still done in the browser thread. Even though the simulation slows down, the UI should be updated in 60fps.

Examples

01 - Boids Example
This example show how to run boids simulation in browser thread. It uses ThreeJS for rendering.

02 - Boids with Grid Support
This example shows how to use grid support for fast lookups. Originally boids algorithm checks near-by entities for calculation and this can be optimized by placing entities in buckets (or grids)

03 - Boids with WebWorker Support [Chrome Only]
This example shows how to use WebWorkers for boids calculations. Currently it uses 4 webworkers, FPS meter shows the boids calculation. Actual browser thread is not doing much, so it is exapected to stay at 60FPS.

A Note About WebWorkers and Chrome: Webworker example only works with chrome, because Safari and Firefox does not support import statements in WebWorkers. This is usually not a problem, because using a script packer (eg. Webpack) should overcome this problem. In order to keep the examples simple, a script packet was not used.

Class Overview

BoidsController class defines a container for boids entities. All entities (flock or obstalces) are added to BoidsController. BoidsController calculates and updates entity positions and velocities.

BoidsWorker is the wrapper for BoidsController to make it work inside a WebWorker context. The responsibility of this class is to create a new BoidsController instance with the received data and run the requested iterations in this isolated context.

BoidsWorkerPlanner is a class to help creating multiple workers and distributing the work to these separate workers. It also deals with synchronization of the data among workers and the application

Entity class defines an entitiy model which has a position and a velocity. Also it has some utiliy methods.

Grid class creates cubic grid for spatial partitioning. This helps lookups to be performed faster for nearby entities. More information can be found here: http://gameprogrammingpatterns.com/spatial-partition.html

boids-js's People

Contributors

ercang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.