All Projects → schteppe → Cannon.js

schteppe / Cannon.js

Licence: other
A lightweight 3D physics engine written in JavaScript.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to Cannon.js

Torque
2d 纯计算高性能刚体物理引擎
Stars: ✭ 62 (-98.36%)
Mutual labels:  physics-engine
Box2DSwift
Box2DSwift is a Swift port of Box2D Physics Engine.
Stars: ✭ 38 (-99%)
Mutual labels:  physics-engine
TaichiGAME
GPU Accelerated Motion Engine based on Taichi Lang.
Stars: ✭ 35 (-99.07%)
Mutual labels:  physics-engine
CubbyFlow
Voxel-based fluid simulation engine for computer games
Stars: ✭ 215 (-94.32%)
Mutual labels:  physics-engine
multiplayer-babylon-js-game
Multiplayer BabylonJS game with Server and Client-Side physics engine synchronization
Stars: ✭ 74 (-98.04%)
Mutual labels:  physics-engine
Vortex2D
Real-time fluid simulation engine running on GPU with Vulkan
Stars: ✭ 91 (-97.59%)
Mutual labels:  physics-engine
Py3ODE
Port of PyODE for Python 3
Stars: ✭ 29 (-99.23%)
Mutual labels:  physics-engine
Oimophysics
A cross-platform 3D physics engine
Stars: ✭ 269 (-92.89%)
Mutual labels:  physics-engine
alien
ALIEN is a CUDA-powered artificial life simulation program.
Stars: ✭ 2,493 (-34.1%)
Mutual labels:  physics-engine
box2d-optimized
A very fast and scalable physics engine, based on Box2D.
Stars: ✭ 50 (-98.68%)
Mutual labels:  physics-engine
Playground
A playground for android developers
Stars: ✭ 41 (-98.92%)
Mutual labels:  physics-engine
ign-physics
Abstract physics interface designed to support simulation and rapid development of robot applications.
Stars: ✭ 40 (-98.94%)
Mutual labels:  physics-engine
Rayon
Rigid body simulation for Minecraft
Stars: ✭ 25 (-99.34%)
Mutual labels:  physics-engine
kosm
Kosm for Android source code
Stars: ✭ 33 (-99.13%)
Mutual labels:  physics-engine
Flame
A physical engine used to simulate water,snow,sand.etc
Stars: ✭ 44 (-98.84%)
Mutual labels:  physics-engine
Legion-Engine
Rythe is a data-oriented C++17 game engine built to make optimal use of modern hardware.
Stars: ✭ 502 (-86.73%)
Mutual labels:  physics-engine
glazejs
A high performance 2D game engine built in Typescript
Stars: ✭ 96 (-97.46%)
Mutual labels:  physics-engine
Dyn4j
Java Collision Detection and Physics Engine
Stars: ✭ 317 (-91.62%)
Mutual labels:  physics-engine
vpx-js
🎮 Visual Pinball in the Browser
Stars: ✭ 38 (-99%)
Mutual labels:  physics-engine
amethyst physics
Amethyst physics engine abstraction layer
Stars: ✭ 29 (-99.23%)
Mutual labels:  physics-engine

cannon.js

Lightweight 3D physics for the web

Inspired by three.js and ammo.js, and driven by the fact that the web lacks a physics engine, here comes cannon.js. The rigid body physics engine includes simple collision detection, various body shapes, contacts, friction and constraints.

Demos - Documentation - Rendering hints - NPM package - CDN

Browser install

Just include cannon.js or cannon.min.js in your html and you're done:

<script src="cannon.min.js"></script>

Node.js install

Install the cannon package via NPM:

npm install --save cannon

Alternatively, point to the Github repo directly to get the very latest version:

npm install --save schteppe/cannon.js

Example

The sample code below creates a sphere on a plane, steps the simulation, and prints the sphere simulation to the console. Note that Cannon.js uses SI units (metre, kilogram, second, etc.).

// Setup our world
var world = new CANNON.World();
world.gravity.set(0, 0, -9.82); // m/s²

// Create a sphere
var radius = 1; // m
var sphereBody = new CANNON.Body({
   mass: 5, // kg
   position: new CANNON.Vec3(0, 0, 10), // m
   shape: new CANNON.Sphere(radius)
});
world.addBody(sphereBody);

// Create a plane
var groundBody = new CANNON.Body({
    mass: 0 // mass == 0 makes the body static
});
var groundShape = new CANNON.Plane();
groundBody.addShape(groundShape);
world.addBody(groundBody);

var fixedTimeStep = 1.0 / 60.0; // seconds
var maxSubSteps = 3;

// Start the simulation loop
var lastTime;
(function simloop(time){
  requestAnimationFrame(simloop);
  if(lastTime !== undefined){
     var dt = (time - lastTime) / 1000;
     world.step(fixedTimeStep, dt, maxSubSteps);
  }
  console.log("Sphere z position: " + sphereBody.position.z);
  lastTime = time;
})();

If you want to know how to use cannon.js with a rendering engine, for example Three.js, see the Examples.

Features

  • Rigid body dynamics
  • Discrete collision detection
  • Contacts, friction and restitution
  • Constraints
    • PointToPoint (a.k.a. ball/socket joint)
    • Distance
    • Hinge (with optional motor)
    • Lock
    • ConeTwist
  • Gauss-Seidel constraint solver and an island split algorithm
  • Collision filters
  • Body sleeping
  • Experimental SPH / fluid support
  • Various shapes and collision algorithms (see table below)
Sphere Plane Box Convex Particle Heightfield Trimesh
Sphere Yes Yes Yes Yes Yes Yes Yes
Plane - - Yes Yes Yes - Yes
Box - - Yes Yes Yes Yes (todo)
Cylinder - - Yes Yes Yes Yes (todo)
Convex - - - Yes Yes Yes (todo)
Particle - - - - - (todo) (todo)
Heightfield - - - - - - (todo)
Trimesh - - - - - - -

Todo

The simpler todos are marked with @todo in the code. Github Issues can and should also be used for todos.

Help

Create an issue if you need help.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].