mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-09 04:56:01 +10:00
154 lines
3.7 KiB
HTML
154 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;
|
|
|
|
light = new THREE.DirectionalLight( 0x00aaff, 2.0 );
|
|
light.position.z = 1;
|
|
scene.addLight( light );
|
|
|
|
light = new THREE.DirectionalLight( 0x000040, 0.5 );
|
|
light.position.z = - 1;
|
|
scene.addLight( light );
|
|
|
|
material = [
|
|
new THREE.MeshLambertMaterial( { color: 0xffffff } ),
|
|
new THREE.MeshBasicMaterial( { color: 0xffffff, wireframe: true, opacity: 0.1 } )
|
|
];
|
|
|
|
object = new THREE.Mesh( new Cube( 100, 100, 100, 4, 4, 4 ), material );
|
|
object.position.x = - 200;
|
|
object.position.z = 200;
|
|
scene.addObject( object );
|
|
|
|
object = new THREE.Mesh( new Cylinder( 50, 25, 75, 100 ), material );
|
|
object.position.z = 200;
|
|
scene.addObject( object );
|
|
|
|
object = new THREE.Mesh( new 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 Plane( 100, 100, 4, 4 ), material );
|
|
object.position.x = - 200;
|
|
scene.addObject( object );
|
|
|
|
object = new THREE.Mesh( new 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 Lathe( points, 20 ), material );
|
|
object.position.x = 200;
|
|
scene.addObject( object );
|
|
|
|
object = new THREE.Mesh( new Torus( 50, 20, 20, 20 ), material );
|
|
object.position.x = - 200;
|
|
object.position.z = - 200;
|
|
scene.addObject( object );
|
|
|
|
object = new THREE.Mesh( new 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>
|