Skip to content

Instantly share code, notes, and snippets.

@bortels
Forked from jbeuckm/index.html
Last active September 18, 2015 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bortels/0eea4ef75799d4831dae to your computer and use it in GitHub Desktop.
Save bortels/0eea4ef75799d4831dae to your computer and use it in GitHub Desktop.
Hello, Three.js
<html>
<head>
<title>My first Three.js app</title>
<style>
body {
margin: 0;
}
canvas {
width: 100%;
height: 100%
}
</style>
</head>
<body>
<script src="https://rawgithub.com/mrdoob/three.js/master/build/three.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var tet = new THREE.Mesh(
new THREE.TetrahedronGeometry(1),
new THREE.MeshPhongMaterial({ ambient: 0xff0000, color: 0xdddddd, specular: 0x999999, shininess: 0, shading: THREE.FlatShading })
);
tet.position.set(-3, 0, 0);
scene.add(tet);
var cube = new THREE.Mesh(
new THREE.CubeGeometry(1, 1, 1),
new THREE.MeshPhongMaterial({ ambient: 0x00ff00, color: 0xdddddd, specular: 0x999999, shininess: 30, shading: THREE.FlatShading })
);
scene.add(cube);
var oct = new THREE.Mesh(
new THREE.OctahedronGeometry(1),
new THREE.MeshPhongMaterial({ ambient: 0x0000ff, color: 0xdddddd, specular: 0x999999, shininess: 60, shading: THREE.FlatShading })
);
oct.position.set(3, 0, 0);
scene.add(oct);
var light = new THREE.PointLight(0xffffff, 1, 100);
light.position.set(10, 10, 10);
scene.add(light);
var light = new THREE.AmbientLight(0x404040); // soft white light
scene.add(light);
camera.position.z = 5;
var render = function () {
requestAnimationFrame(render);
cube.rotation.x += 0.02;
cube.rotation.y += 0.02;
tet.rotation.x -= .02;
oct.rotation.x += .02;
renderer.render(scene, camera);
};
render();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment