Skip to content

Instantly share code, notes, and snippets.

@automata
Created May 2, 2012 02:01
Show Gist options
  • Save automata/2573034 to your computer and use it in GitHub Desktop.
Save automata/2573034 to your computer and use it in GitHub Desktop.
three.js example
var c = document.getElementById("threejsCanvas");
var cContext = c.getContext("2d");
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 60,
window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 500;
camera.target = new THREE.Vector3();
scene.add( camera );
var geometry = new THREE.CubeGeometry( 100, 100, 100 );
var material = new THREE.MeshNormalMaterial();
group = new THREE.Object3D();
for ( var i = 0; i < 200; i ++ ) {
var mesh = new THREE.Mesh( geometry, material );
mesh.position.x = Math.random() * 2000 - 1000;
mesh.position.y = Math.random() * 2000 - 1000;
mesh.position.z = Math.random() * 2000 - 1000;
mesh.rotation.x = Math.random() * 360 * ( Math.PI / 180 );
mesh.rotation.y = Math.random() * 360 * ( Math.PI / 180 );
mesh.matrixAutoUpdate = false;
mesh.updateMatrix();
group.add( mesh );
}
scene.add( group );
renderer = new THREE.CanvasRenderer({canvas: c});
renderer.setSize( 400, 400 );
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
group.rotation.x = Math.sin( Date.now() * 0.0002 ) * 0.5;
group.rotation.y = Math.sin( Date.now() * 0.0003 ) * 0.5;
group.rotation.z = Math.sin( Date.now() * 0.0002 ) * 0.5;
renderer.render( scene, camera );
}
animate();
@tonussi
Copy link

tonussi commented May 2, 2012

interessante.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment