threex.cannonjs is a threex game extension for three.js. It provides realistic physics easy to include in your own games. So you can take object in your game and make them fall as if it was the real world! You can code a pool game in a day! You make rocks falls from the sky in a realistic fasion! Sky is the limit! It is a warper over the excelent library cannon.js physics library. It has been written by Stefan Hedman or @schteppe on twitter.
- examples/basic.html [view source] : It shows this feature, and that one which is coded like that.
- examples/domino.html [view source] : It show dominos falling on each others like on tv :)
You can install it manually. Just do
<script src='threex.cannonjs.js'></script>
You can install with bower.
bower install threex.cannonjs
then you add that in your html
<script src="bower_components/threex.cannonjs/threex.cannonjs.js"></script>
Init the physics world
var worldx = new THREEx.CannonWorld().start();
create a physics body from a THREE.Mesh
var bodyx = new THREEx.CannonBody(mesh)
add this physics body to our physics world and keep updating it
worldx.add(bodyx)
updateFcts.push(function(delta, now){
bodyx.update(delta, now);
});
one may wish to setup an initial velocity
bodyx.body.angularVelocity.set(0,2,0);