Skip to content

Instantly share code, notes, and snippets.

@elephantatech
Created July 12, 2013 19:32
Show Gist options
  • Save elephantatech/5987118 to your computer and use it in GitHub Desktop.
Save elephantatech/5987118 to your computer and use it in GitHub Desktop.
simple three.js sample with cube mesh
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
background-color: #ffffff;
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r57/three.min.js"></script>
<script>
var camera, scene, renderer;
var geometry, material, mesh;
var init = function () {
renderer = new THREE.CanvasRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.z = 500;
scene = new THREE.Scene();
geometry = new THREE.CubeGeometry( 400, 400, 400 );
geometry2 = new THREE.CubeGeometry( 200, 200, 200 );
geometry3 = new THREE.CubeGeometry( 100, 100, 100 );
geometry4 = new THREE.CubeGeometry( 50, 50, 50 );
material = new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true, wireframeLinewidth: 5 } );
material2 = new THREE.MeshBasicMaterial( { color: 0xff0000,wireframe: true, wireframeLinewidth: 5 } );
material3 = new THREE.MeshBasicMaterial( { color: 0x00ff00,wireframe: true, wireframeLinewidth: 5 } );
material4 = new THREE.MeshBasicMaterial( { color: 0x0000ff,wireframe: true, wireframeLinewidth: 5 } );
mesh = new THREE.Mesh( geometry, material );
mesh2 = new THREE.Mesh(geometry2, material2);
mesh3 = new THREE.Mesh(geometry3, material3);
mesh4 = new THREE.Mesh(geometry4, material4);
scene.add( mesh );
scene.add( mesh2 );
scene.add( mesh3 );
scene.add( mesh4 );
}
var animate = function () {
requestAnimationFrame( animate );
mesh.rotation.x = Date.now() * 0.0005;
mesh.rotation.y = Date.now() * 0.001;
mesh2.rotation.x = Date.now() * 0.001;
mesh2.rotation.y = Date.now() * 0.001;
mesh3.rotation.x = Date.now() * 0.01;
mesh3.rotation.y = Date.now() * 0.01;
mesh4.rotation.x = Date.now() * 0.1;
mesh4.rotation.y = Date.now() * 0.1;
renderer.render( scene, camera );
}
init();
animate();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment