|
@@ -0,0 +1,186 @@
|
|
|
+<!DOCTYPE HTML>
|
|
|
+<html lang="en">
|
|
|
+ <head>
|
|
|
+ <title>three.js - geometry - vertex colors</title>
|
|
|
+ <meta charset="utf-8">
|
|
|
+ <style type="text/css">
|
|
|
+ body {
|
|
|
+ color: #808080;
|
|
|
+ font-family:Monospace;
|
|
|
+ font-size:13px;
|
|
|
+ text-align:center;
|
|
|
+
|
|
|
+ background-color: #fff;
|
|
|
+ margin: 0px;
|
|
|
+ overflow: hidden;
|
|
|
+ }
|
|
|
+
|
|
|
+ #info {
|
|
|
+ position: absolute;
|
|
|
+ top: 0px; width: 100%;
|
|
|
+ padding: 5px;
|
|
|
+ }
|
|
|
+
|
|
|
+ a {
|
|
|
+
|
|
|
+ color: #0080ff;
|
|
|
+ }
|
|
|
+
|
|
|
+ </style>
|
|
|
+ </head>
|
|
|
+ <body>
|
|
|
+
|
|
|
+ <div id="container"></div>
|
|
|
+ <div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - vertex colors - webgl</div>
|
|
|
+
|
|
|
+ <script type="text/javascript" src="js/Stats.js"></script>
|
|
|
+
|
|
|
+ <script type="text/javascript" src="../build/ThreeExtras.js"></script>
|
|
|
+
|
|
|
+ <script type="text/javascript">
|
|
|
+
|
|
|
+ var container, stats;
|
|
|
+
|
|
|
+ var camera, scene, renderer;
|
|
|
+
|
|
|
+ var mesh, mesh2, mesh3, light;
|
|
|
+
|
|
|
+ var mouseX = 0, mouseY = 0;
|
|
|
+
|
|
|
+ var windowHalfX = window.innerWidth / 2;
|
|
|
+ var windowHalfY = window.innerHeight / 2;
|
|
|
+
|
|
|
+
|
|
|
+ init();
|
|
|
+ setInterval( loop, 1000 / 60 );
|
|
|
+
|
|
|
+
|
|
|
+ function init() {
|
|
|
+
|
|
|
+ container = document.getElementById( 'container' );
|
|
|
+
|
|
|
+ camera = new THREE.Camera( 20, window.innerWidth / window.innerHeight, 1, 10000 );
|
|
|
+ camera.position.z = 1800;
|
|
|
+
|
|
|
+ scene = new THREE.Scene();
|
|
|
+
|
|
|
+ light = new THREE.DirectionalLight( 0xffffff );
|
|
|
+ light.position.set( 0, 0, 1 );
|
|
|
+ light.position.normalize();
|
|
|
+ scene.addLight( light );
|
|
|
+
|
|
|
+ var shadowMaterial = new THREE.MeshBasicMaterial( { map: ImageUtils.loadTexture( 'textures/shadow.png' ) } );
|
|
|
+ var shadowGeo = new Plane( 300, 300, 1, 1 );
|
|
|
+
|
|
|
+ mesh = new THREE.Mesh( shadowGeo, shadowMaterial );
|
|
|
+ mesh.position.y = - 250;
|
|
|
+ mesh.rotation.x = - 90 * Math.PI / 180;
|
|
|
+ scene.addObject( mesh );
|
|
|
+
|
|
|
+ mesh = new THREE.Mesh( shadowGeo, shadowMaterial );
|
|
|
+ mesh.position.y = - 250;
|
|
|
+ mesh.position.x = - 400;
|
|
|
+ mesh.rotation.x = - 90 * Math.PI / 180;
|
|
|
+ scene.addObject( mesh );
|
|
|
+
|
|
|
+ mesh = new THREE.Mesh( shadowGeo, shadowMaterial );
|
|
|
+ mesh.position.y = - 250;
|
|
|
+ mesh.position.x = 400;
|
|
|
+ mesh.rotation.x = - 90 * Math.PI / 180;
|
|
|
+ scene.addObject( mesh );
|
|
|
+
|
|
|
+ var color, p, colors = [], colors2 = [], colors3 = [],
|
|
|
+
|
|
|
+ geometry = new Icosahedron( 1 ),
|
|
|
+ geometry2 = new THREE.Geometry(),
|
|
|
+ geometry3 = new THREE.Geometry();
|
|
|
+
|
|
|
+ for( var i = 0; i < geometry.vertices.length; i++ ) {
|
|
|
+
|
|
|
+ p = geometry.vertices[ i ].position;
|
|
|
+
|
|
|
+ color = new THREE.Color( 0xffffff );
|
|
|
+ color.setHSV( ( p.y + 1 ) / 2, 1.0, 1.0 );
|
|
|
+ colors[ i ] = color;
|
|
|
+
|
|
|
+ color = new THREE.Color( 0xffffff );
|
|
|
+ color.setHSV( 0.0, ( p.y + 1 ) / 2, 1.0 );
|
|
|
+ colors2[ i ] = color;
|
|
|
+
|
|
|
+ color = new THREE.Color( 0xffffff );
|
|
|
+ color.setHSV( 0.125 * i/geometry.vertices.length, 1.0, 1.0 );
|
|
|
+ colors3[ i ] = color;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ geometry3.vertices = geometry2.vertices = geometry.vertices;
|
|
|
+ geometry3.faces = geometry2.faces = geometry.faces;
|
|
|
+
|
|
|
+ geometry2.sortFacesByMaterial();
|
|
|
+ geometry3.sortFacesByMaterial();
|
|
|
+
|
|
|
+ geometry.colors = colors;
|
|
|
+ geometry2.colors = colors2;
|
|
|
+ geometry3.colors = colors3;
|
|
|
+
|
|
|
+ var materials = [
|
|
|
+
|
|
|
+ new THREE.MeshLambertMaterial( { color: 0xffffff, shading: THREE.FlatShading, vertex_colors: true } ),
|
|
|
+ new THREE.MeshBasicMaterial( { color: 0x000000, shading: THREE.FlatShading, wireframe: true } )
|
|
|
+
|
|
|
+ ];
|
|
|
+
|
|
|
+ mesh = new THREE.Mesh( geometry, materials );
|
|
|
+ mesh.position.x = -400;
|
|
|
+ mesh.scale.x = mesh.scale.y = mesh.scale.z = 200;
|
|
|
+ mesh.rotation.x = -1.87;
|
|
|
+ scene.addObject( mesh );
|
|
|
+
|
|
|
+ mesh2 = new THREE.Mesh( geometry2, materials );
|
|
|
+ mesh2.position.x = 400;
|
|
|
+ mesh2.rotation.x = 0;
|
|
|
+ mesh2.scale = mesh.scale;
|
|
|
+ scene.addObject( mesh2 );
|
|
|
+
|
|
|
+ mesh3 = new THREE.Mesh( geometry3, materials );
|
|
|
+ mesh3.position.x = 0;
|
|
|
+ mesh3.rotation.x = 0;
|
|
|
+ mesh3.scale = mesh.scale;
|
|
|
+ scene.addObject( mesh3 );
|
|
|
+
|
|
|
+ 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 );
|
|
|
+
|
|
|
+ document.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function onDocumentMouseMove( event ) {
|
|
|
+
|
|
|
+ mouseX = ( event.clientX - windowHalfX );
|
|
|
+ mouseY = ( event.clientY - windowHalfY );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function loop() {
|
|
|
+
|
|
|
+ camera.position.x += ( mouseX - camera.position.x ) * 0.05;
|
|
|
+ camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
|
|
|
+
|
|
|
+ renderer.render( scene, camera );
|
|
|
+ stats.update();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ </script>
|
|
|
+
|
|
|
+ </body>
|
|
|
+</html>
|