Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.
For the best experience please use the latest Chrome, Safari or Firefox browser.
Lightweight library that provides a object model with:
<script src="js/three.min.js"></script>
<style type="text/css">
body { margin: 0px; overflow: hidden; }
</style>
<script src="js/three.min.js"></script><script>
var scene, renderer;
init();
function init() {
scene = new THREE.Scene();
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth,
window.innerHeight);
document.body.appendChild(renderer.domElement);
}
</script>
var camera;
//...
camera = new THREE.PerspectiveCamera(45,
window.innerWidth / window.innerHeight, 1, 10000);
camera.position.set(0, 0, 1000);
To render each frame we call:
renderer.render(scene, camera);
// Create a Geometry
geometry = new THREE.CubeGeometry(200, 200, 200);
// Create a Material
material = new THREE.MeshLambertMaterial({
color : 0xffffff,
});
// Create a Mesh with the Geometry and the Material
mesh = new THREE.Mesh(geometry, material);
// Add it to the Scene
scene.add(mesh);
// Create a Point Light
pointLight = new THREE.PointLight( 0xffffff );
// Set the point light position
pointLight.position =
new THREE.Vector3(1000,1000,0);
// Add the light to the scene
scene.add( pointLight );
More light types:
animate();
function animate() {
// Ask for the next frame
requestAnimationFrame(animate);
// Rotate Cube
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;
// Render Frame
renderer.render(scene, camera);
}
<script src="js/ColladaLoader.js"></script>
var loader = new THREE.ColladaLoader();
loader.options.convertUpAxis = true;
loader.load('./car.dae', function(collada) {
// Onload function
car = collada.scene;
init();
animate();
});
camera = new THREE.PerspectiveCamera(45,
window.innerWidth / window.innerHeight, 1, 10000);
camera.position = new THREE.Vector3(0, 1000, 1000);
camera.lookAt(new THREE.Vector3(0, 0, 0));
function animate() {
requestAnimationFrame(animate);
car.rotation.y += 0.02;
renderer.render(scene, camera);
}
keyDown = new Array();
for (i = 0; i < 300; i++) keyDown[i] = false;
document.onkeydown = function(event) {
keyDown[event.keyCode] = true;
}
document.onkeyup = function(event) {
keyDown[event.keyCode] = false;
}
if (keyDown[38]) { // if Up is pressed
if (speed < 100) speed += 0.5;
} else {
speed -= 1;
if (speed < 0) speed = 0;
}
if (speed > 0) {
if (keyDown[37]) car.rotation.y += 0.02;
if (keyDown[39]) car.rotation.y -= 0.02;
}
And move the car:
car.position.x += speed * Math.sin(car.rotation.y);
car.position.z += speed * Math.cos(car.rotation.y);
camera.lookAt(car.position);
geometry = new THREE.PlaneGeometry(
50000, 50000, 100, 100);
material = new THREE.MeshBasicMaterial({
color : 0xcccccc,
wireframe : true});
mesh = new THREE.Mesh(geometry, material);
mesh.rotation.x = Math.PI / 2;
scene.add(mesh);