Cube in Babylon.js
Babylon.js Hispano
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/babylonjs/2.3.0/babylon.js"></script>
<script type="text/javascript" src="https://rawgit.com/kripken/ammo.js/master/builds/ammo.js"></script>
<canvas id="main"></canvas>
CSS
html, body, canvas{
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
JavaScript
// Initialize Ammo
if(typeof Ammo == "function"){
Ammo();
}
var canvas = document.getElementById("main");
var engine = new BABYLON.Engine(canvas);
var scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color3(0.6,0.6,0.6);
var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
camera.setTarget(BABYLON.Vector3.Zero());
camera.attachControl(canvas, true);
var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
light.intensity = 0.7;
var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene);
sphere.position.y = 1;
var ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene);
// Ammo hello world
var collisionConfiguration = new Ammo.btDefaultCollisionConfiguration(),
dispatcher = new Ammo.btCollisionDispatcher(collisionConfiguration),
overlappingPairCache = new Ammo.btDbvtBroadphase(),
solver = new Ammo.btSequentialImpulseConstraintSolver(),
dynamicsWorld = new Ammo.btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicsWorld.setGravity(new Ammo.btVector3(0, -10, 0));
var groundShape = new Ammo.btBoxShape(new Ammo.btVector3(50, 50, 50)),
bodies = [],
groundTransform = new Ammo.btTransform();
groundTransform.setIdentity();
groundTransform.setOrigin(new Ammo.btVector3(0, -50, 0));
(function() {
var mass = 0,
isDynamic = (mass !== 0),
localInertia = new Ammo.btVector3(0, 0, 0);
if (isDynamic)
groundShape.calculateLocalInertia(mass, localInertia);
var myMotionState = new Ammo.btDefaultMotionState(groundTransform),
rbInfo = new Ammo.btRigidBodyConstructionInfo(mass, myMotionState, groundShape, localInertia),
body = new Ammo.btRigidBody(rbInfo);
body.setRestitution(2);
dynamicsWorld.addRigidBody(body);
bodies.push(body);
})();
(function() {
var colShape = new...