Skip to content

Instantly share code, notes, and snippets.

@adammw
Last active August 29, 2015 14:02
Show Gist options
  • Save adammw/f03dedaa9c2a15a3b126 to your computer and use it in GitHub Desktop.
Save adammw/f03dedaa9c2a15a3b126 to your computer and use it in GitHub Desktop.
THREE.ImageUtils.crossOrigin = true;
Physijs.scripts.worker = 'https://rawgit.com/chandlerprall/Physijs/master/physijs_worker.js';
Physijs.scripts.ammo = 'https://rawgit.com/chandlerprall/Physijs/master/examples/js/ammo.js';'
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;
document.body.appendChild( renderer.domElement );
var scene = new Physijs.Scene({ fixedTimeStep: 1 / 120 });
scene.setGravity(new THREE.Vector3( 0, -30, 0 ));
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
var geometry = new THREE.SphereGeometry(2, 32, 32);
var material = new THREE.MeshLambertMaterial({
color: '#fff',
map: THREE.ImageUtils.loadTexture('http://i.imgur.com/vGbKR7M.png')
});
var ball = new Physijs.SphereMesh( geometry, material, undefined, {restitution: 1.5} );
ball.position.x = 5;
ball.position.y = 5;
ball.position.z = 5;
ball.castShadow = true;
ball.receiveShadow = true;
scene.add( ball );
camera.position.z = 15;
var ground = new Physijs.BoxMesh(
new THREE.CubeGeometry(50, 1, 50),
new THREE.MeshBasicMaterial({color: '#333'}),
0 // mass
);ground.receiveShadow = true;
scene.add( ground );
// add subtle ambient lighting
var ambientLight = new THREE.AmbientLight(0xbbbbbb);
scene.add(ambientLight);
// directional lighting
var directionalLight = new THREE.DirectionalLight(0xffffff);
directionalLight.position.set(1, 1, 1).normalize();
scene.add(directionalLight);
function render() {
requestAnimationFrame(render);
scene.simulate();
renderer.render(scene, camera);
}
render();
<html>
<head>
<style>
html, body { margin: 0; padding: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="https://threejs.org/build/three.min.js"></script>
<script src="https://rawgit.com/chandlerprall/Physijs/master/physi.js"></script>
<script src="script.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment