|
@@ -0,0 +1,203 @@
|
|
|
+<!DOCTYPE HTML>
|
|
|
+<html lang="en">
|
|
|
+ <head>
|
|
|
+ <title>three.js webgl - level-of-details</title>
|
|
|
+ <meta charset="utf-8">
|
|
|
+ <style type="text/css">
|
|
|
+ body {
|
|
|
+ background:#000;
|
|
|
+ color:#fff;
|
|
|
+ padding:0;
|
|
|
+ margin:0;
|
|
|
+ font-weight: bold;
|
|
|
+ overflow:hidden;
|
|
|
+ }
|
|
|
+
|
|
|
+ #info {
|
|
|
+ position: absolute;
|
|
|
+ top: 0px; width: 100%;
|
|
|
+ color: #ffffff;
|
|
|
+ padding: 5px;
|
|
|
+ font-family: Monospace;
|
|
|
+ font-size: 13px;
|
|
|
+ text-align: center;
|
|
|
+ z-index:100;
|
|
|
+ }
|
|
|
+
|
|
|
+ a { color:red }
|
|
|
+
|
|
|
+ </style>
|
|
|
+ </head>
|
|
|
+
|
|
|
+ <body>
|
|
|
+ <div id="info">
|
|
|
+ <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - level-of-details WebGL example
|
|
|
+ </div>
|
|
|
+
|
|
|
+
|
|
|
+ <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" src="../src/extras/geometries/Curve.js"></script>
|
|
|
+ <script type="text/javascript" src="../src/extras/geometries/CurvePath.js"></script>
|
|
|
+ <script type="text/javascript" src="../src/extras/geometries/Path.js"></script>
|
|
|
+ <script type="text/javascript" src="../src/extras/geometries/Shape.js"></script>
|
|
|
+ <script type="text/javascript" src="../src/extras/geometries/TextPath.js"></script>
|
|
|
+ <script type="text/javascript" src="../src/extras/geometries/ExtrudeGeometry.js"></script>
|
|
|
+ <script type="text/javascript" src="../src/extras/geometries/TextGeometry.js"></script>
|
|
|
+ -->
|
|
|
+
|
|
|
+
|
|
|
+ <!-- load the font file from canvas-text -->
|
|
|
+
|
|
|
+ <script type="text/javascript" src="fonts/helvetiker_regular.typeface.js"></script>
|
|
|
+
|
|
|
+ <script type="text/javascript">
|
|
|
+
|
|
|
+ if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
|
|
|
+
|
|
|
+ var container, stats;
|
|
|
+
|
|
|
+ var camera, scene, renderer;
|
|
|
+
|
|
|
+ var geometry, objects;
|
|
|
+
|
|
|
+ var mouseX = 0, mouseY = 0;
|
|
|
+
|
|
|
+ var windowHalfX = window.innerWidth / 2;
|
|
|
+ var windowHalfY = window.innerHeight / 2;
|
|
|
+
|
|
|
+ document.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
|
|
+
|
|
|
+ init();
|
|
|
+ animate();
|
|
|
+
|
|
|
+ function init() {
|
|
|
+
|
|
|
+ container = document.createElement( 'div' );
|
|
|
+ document.body.appendChild( container );
|
|
|
+
|
|
|
+ camera = new THREE.Camera( 45, window.innerWidth / window.innerHeight, 1, 15000 );
|
|
|
+ camera.position.z = 1000;
|
|
|
+
|
|
|
+ scene = new THREE.Scene();
|
|
|
+ scene.fog = new THREE.Fog( 0x000000, 1, 15000 );
|
|
|
+
|
|
|
+ var light = new THREE.PointLight( 0xff2200 );
|
|
|
+ light.position.set( 0, 0, 0 );
|
|
|
+ scene.addLight( light );
|
|
|
+
|
|
|
+ var light = new THREE.DirectionalLight( 0xffffff );
|
|
|
+ light.position.set( 0, 0, 1 );
|
|
|
+ light.position.normalize();
|
|
|
+ scene.addLight( light );
|
|
|
+
|
|
|
+ var wireMaterial = new THREE.MeshLambertMaterial( { color: 0x000000, wireframe: true } );
|
|
|
+
|
|
|
+ function getOptionsWithSegments(x,b, bevel) {
|
|
|
+ return {
|
|
|
+
|
|
|
+ size: 80,
|
|
|
+ height: 20,
|
|
|
+ curveSegments: x,
|
|
|
+ font: "helvetiker",
|
|
|
+ bevelSegments: b,
|
|
|
+ bevelEnabled: bevel,
|
|
|
+ bevelThickness:8,
|
|
|
+ bevelSize: 3,
|
|
|
+ steps: 1,
|
|
|
+ amount: 20,
|
|
|
+
|
|
|
+ };
|
|
|
+ };
|
|
|
+
|
|
|
+ var theText = "&"; // Try $ :)
|
|
|
+
|
|
|
+ // we could use TextPath and ExtrudeGeometry if we wish to optimize stuff futher
|
|
|
+ var geometry = [
|
|
|
+
|
|
|
+ [ new THREE.TextGeometry( theText, getOptionsWithSegments(8, 6, true)),
|
|
|
+ 300, [ new THREE.MeshPhongMaterial( { color: 0xffee00 } ), wireMaterial ] ],
|
|
|
+ [ new THREE.TextGeometry( theText, getOptionsWithSegments(5,2, true)),
|
|
|
+ 800, [ new THREE.MeshLambertMaterial( { color: 0xffaa00 } ), wireMaterial ]],
|
|
|
+ [ new THREE.TextGeometry( theText, getOptionsWithSegments(2,1, true)),
|
|
|
+ 1000, [ new THREE.MeshLambertMaterial( { color: 0x005500 } ), wireMaterial ] ],
|
|
|
+ [ new THREE.TextGeometry( theText, getOptionsWithSegments(2,1,false)),
|
|
|
+ 2000, [ new THREE.MeshLambertMaterial( { color: 0x0055ff } ), wireMaterial ]],
|
|
|
+ [ new THREE.TextGeometry( theText, getOptionsWithSegments(1,1, false)),
|
|
|
+ 10000, [ new THREE.MeshLambertMaterial( { color: 0xff1100 } ), wireMaterial ]]
|
|
|
+
|
|
|
+ ];
|
|
|
+
|
|
|
+ var i, j, mesh, lod;
|
|
|
+
|
|
|
+ for ( j = 0; j < 1000; j ++ ) {
|
|
|
+
|
|
|
+ lod = new THREE.LOD();
|
|
|
+
|
|
|
+ for ( i = 0; i < geometry.length; i++ ) {
|
|
|
+
|
|
|
+ mesh = new THREE.Mesh( geometry[ i ][ 0 ], geometry[ i ][ 2 ] );
|
|
|
+ mesh.scale.set( 1.5, 1.5, 1.5 );
|
|
|
+ mesh.updateMatrix();
|
|
|
+ mesh.matrixAutoUpdate = false;
|
|
|
+ lod.add( mesh, geometry[ i ][ 1 ] );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ lod.position.x = 10000 * ( 0.5 - Math.random() );
|
|
|
+ lod.position.y = 7500 * ( 0.5 - Math.random() );
|
|
|
+ lod.position.z = 10000 * ( 0.5 - Math.random() );
|
|
|
+ lod.updateMatrix();
|
|
|
+ lod.matrixAutoUpdate = false;
|
|
|
+ scene.addObject( lod );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ renderer = new THREE.WebGLRenderer( { clearColor:0x000000, clearAlpha: 1 } );
|
|
|
+ renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
+ renderer.sortObjects = false;
|
|
|
+ container.appendChild( renderer.domElement );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function onDocumentMouseMove(event) {
|
|
|
+
|
|
|
+ mouseX = ( event.clientX - windowHalfX ) * 10;
|
|
|
+ mouseY = ( event.clientY - windowHalfY ) * 10;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function animate() {
|
|
|
+
|
|
|
+ requestAnimationFrame( animate );
|
|
|
+ render();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function render() {
|
|
|
+
|
|
|
+ camera.position.x += ( mouseX - camera.position.x ) * .005;
|
|
|
+ camera.position.y += ( - mouseY - camera.position.y ) * .01;
|
|
|
+
|
|
|
+ renderer.render( scene, camera );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function log( text ) {
|
|
|
+
|
|
|
+ var e = document.getElementById("log");
|
|
|
+ e.innerHTML = text + "<br/>" + e.innerHTML;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ </script>
|
|
|
+
|
|
|
+ </body>
|
|
|
+</html>
|