Files
three.js/examples/webgl_geometries.html
T
Mr.doob 76e7ea3461 Added namespace to all the objects that missed it (geometries, uniforms, etc)
WebGLRenderer antialias is off by default (considering Firefox doesn't support it...)
Formatting clean up here and there
2011-04-09 12:38:39 +01:00

152 lines
3.7 KiB
HTML

<!DOCTYPE HTML>
<html lang="en">
<head>
<title>three.js webgl - geometries</title>
<meta charset="utf-8">
<style type="text/css">
body {
font-family: Monospace;
background-color: #000;
margin: 0px;
overflow: hidden;
}
#log { color:#fff; position:absolute; top:50px; text-align:left; display:block; z-index:100; pointer-events:none; }
</style>
</head>
<body>
<pre id="log"></pre>
<script type="text/javascript" src="../build/Three.js"></script>
<script type="text/javascript" src="js/Detector.js"></script>
<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
<script type="text/javascript" src="js/Stats.js"></script>
<script type="text/javascript">
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var container, stats;
var camera, scene, renderer;
init();
animate();
function init() {
container = document.createElement('div');
document.body.appendChild(container);
camera = new THREE.Camera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
camera.position.y = 200;
camera.position.z = 800;
scene = new THREE.Scene();
var light, object, material;
scene.addLight( new THREE.AmbientLight( 0x404040 ) );
light = new THREE.DirectionalLight( 0xffffff, 2.0 );
light.position.z = 1;
scene.addLight( light );
material = [
new THREE.MeshLambertMaterial( { map: THREE.ImageUtils.loadTexture( 'textures/UV.jpg' ) } ),
new THREE.MeshBasicMaterial( { color: 0xffffff, wireframe: true, opacity: 0.1 } )
];
object = new THREE.Mesh( new THREE.Cube( 100, 100, 100, 4, 4, 4 ), material );
object.position.x = - 200;
object.position.z = 200;
scene.addObject( object );
object = new THREE.Mesh( new THREE.Cylinder( 50, 25, 75, 100 ), material );
object.position.z = 200;
scene.addObject( object );
object = new THREE.Mesh( new THREE.Icosahedron( 2 ), material );
object.position.x = 200;
object.position.z = 200;
object.scale.x = object.scale.y = object.scale.z = 75;
scene.addObject( object );
object = new THREE.Mesh( new THREE.Plane( 100, 100, 4, 4 ), material );
object.position.x = - 200;
scene.addObject( object );
object = new THREE.Mesh( new THREE.Sphere( 75, 20, 10 ), material );
scene.addObject( object );
var points = [];
for ( var i = 0; i < 50; i ++ ) {
points.push( new THREE.Vector3( Math.sin( i * 0.2 ) * 15 + 50, 0, ( i - 5 ) * 2 ) );
}
object = new THREE.Mesh( new THREE.Lathe( points, 20 ), material );
object.position.x = 200;
scene.addObject( object );
object = new THREE.Mesh( new THREE.Torus( 50, 20, 20, 20 ), material );
object.position.x = - 200;
object.position.z = - 200;
scene.addObject( object );
object = new THREE.Mesh( new THREE.TorusKnot( 50, 10, 50, 20 ), material );
object.position.z = - 200;
scene.addObject( object );
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
container.appendChild( stats.domElement );
}
//
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
var timer = new Date().getTime() * 0.0001;
camera.position.x = Math.cos( timer ) * 800;
camera.position.z = Math.sin( timer ) * 800;
for ( var i = 0, l = scene.objects.length; i < l; i++ ) {
var object = scene.objects[ i ];
object.rotation.x += 0.01;
object.rotation.y += 0.005;
}
renderer.render( scene, camera );
}
</script>
</body>
</html>