Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 6.79 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.         <title>Skybox (Three.js)</title>
  5.         <meta charset="utf-8">
  6.         <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7.         <link rel=stylesheet href="css/base.css"/>
  8. </head>
  9. <body>
  10.  
  11. <script src="three.js"></script>
  12. <script src="Detector.js"></script>
  13. <script src="stats.js"></script>
  14. <script src="OrbitControls.js"></script>
  15. <script src="THREEx.KeyboardState.js"></script>
  16. <script src="THREEx.FullScreen.js"></script>
  17. <script src="THREEx.WindowResize.js"></script>
  18.  
  19. <!-- jQuery code to display an information button and box when clicked. -->
  20. <script src="jquery-1.9.1.js"></script>
  21. <script src="jquery-ui.js"></script>
  22. <link rel=stylesheet href="jquery-ui.css" />
  23. <link rel=stylesheet href="info.css"/>
  24. <script src="info.js"></script>
  25. <div id="infoButton"></div>
  26. <div id="infoBox" title="Demo Information">
  27. This three.js demo is part of a collection at
  28. <a href="http://stemkoski.github.io/Three.js/">http://stemkoski.github.io/Three.js/</a>
  29. </div>
  30. <!-- ------------------------------------------------------------ -->
  31.  
  32. <div id="ThreeJS" style="position: absolute; left:0px; top:0px"></div>
  33. <script>
  34. /*
  35.         Three.js "tutorials by example"
  36.         Author: Lee Stemkoski
  37.         Date: July 2013 (three.js v59dev)
  38. */
  39.  
  40. // MAIN
  41.  
  42. // standard global variables
  43. var container, scene, camera, renderer, controls, stats;
  44. var keyboard = new THREEx.KeyboardState();
  45. var clock = new THREE.Clock();
  46. // custom global variables
  47. var cube;
  48.  
  49. // CUSTOM
  50. var polyhedron, sphere, cube2, mirrorSphere, sphere2;
  51.  
  52. init();
  53. animate();
  54.  
  55. // FUNCTIONS          
  56. function init()
  57. {
  58.         // SCENE
  59.         scene = new THREE.Scene();
  60.         function createMesh(geom, imageFile) {
  61.             var texture = THREE.ImageUtils.loadTexture("textures/" + imageFile)
  62.             var mat = new THREE.MeshPhongMaterial();
  63.             mat.map = texture;
  64.  
  65.             var mesh = new THREE.Mesh(geom, mat);
  66.             return mesh;
  67.         }
  68.         // CAMERA
  69.         var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
  70.         var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000;
  71.         camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
  72.         scene.add(camera);
  73.         camera.position.set(0,150,400);
  74.         camera.lookAt(scene.position);
  75.         // RENDERER
  76.         if ( Detector.webgl )
  77.                 renderer = new THREE.WebGLRenderer( {antialias:true} );
  78.         else
  79.                 renderer = new THREE.CanvasRenderer();
  80.         renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
  81.         container = document.getElementById( 'ThreeJS' );
  82.         container.appendChild( renderer.domElement );
  83.         // EVENTS
  84.         THREEx.WindowResize(renderer, camera);
  85.         THREEx.FullScreen.bindKey({ charCode : 'm'.charCodeAt(0) });
  86.         // CONTROLS
  87.         controls = new THREE.OrbitControls( camera, renderer.domElement );
  88.         // STATS
  89.         stats = new Stats();
  90.         stats.domElement.style.position = 'absolute';
  91.         stats.domElement.style.bottom = '0px';
  92.         stats.domElement.style.zIndex = 100;
  93.         container.appendChild( stats.domElement );
  94.         // LIGHT
  95.         var light = new THREE.PointLight(0xffffff);
  96.         light.position.set(0,250,0);
  97.         scene.add(light);
  98.         // FLOOR
  99.         var floorTexture = new THREE.ImageUtils.loadTexture( 'textures/checkerboard.jpg' );
  100.         floorTexture.wrapS = floorTexture.wrapT = THREE.RepeatWrapping;
  101.         floorTexture.repeat.set( 10, 10 );
  102.         var floorMaterial = new THREE.MeshBasicMaterial( { map: floorTexture, side: THREE.DoubleSide } );
  103.         var floorGeometry = new THREE.PlaneGeometry(100, 100, 10, 10);
  104.         var floor = new THREE.Mesh(floorGeometry, floorMaterial);
  105.         floor.position.y = -0.5;
  106.         floor.rotation.x = Math.PI / 2;
  107.        
  108.        
  109.         polyhedron = createMesh(new THREE.IcosahedronGeometry(5, 0), "metal-rust.jpg");
  110.         polyhedron.position.x = 12;
  111.         scene.add(polyhedron);
  112.  
  113.         sphere = createMesh(new THREE.SphereGeometry(5, 20, 20), "floor-wood.jpg");
  114.         scene.add(sphere);
  115.  
  116.         cube2 = createMesh(new THREE.CubeGeometry(5, 5, 5), "brick-wall.jpg");
  117.         cube2.position.x = -12;
  118.         scene.add(cube2);
  119.         console.log(cube2.geometry.faceVertexUvs);
  120.        
  121.        
  122.        
  123.        
  124.         ////////////
  125.         // CUSTOM //
  126.         ////////////
  127.        
  128.            
  129.  
  130.         // axes
  131.         var axes = new THREE.AxisHelper(100);
  132.         scene.add( axes );
  133.        
  134.         var imagePrefix = "textures/dawnmountain-";
  135.         var directions  = ["xpos", "xneg", "ypos", "yneg", "zpos", "zneg"];
  136.         var imageSuffix = ".png";
  137.         var skyGeometry = new THREE.CubeGeometry( 5000, 5000, 5000 );  
  138.        
  139.         var materialArray = [];
  140.         for (var i = 0; i < 6; i++)
  141.                 materialArray.push( new THREE.MeshBasicMaterial({
  142.                         map: THREE.ImageUtils.loadTexture( imagePrefix + directions[i] + imageSuffix ),
  143.                         side: THREE.BackSide
  144.                 }));
  145.         var skyMaterial = new THREE.MeshFaceMaterial( materialArray );
  146.         var skyBox = new THREE.Mesh( skyGeometry, skyMaterial );
  147.         scene.add( skyBox );
  148.  
  149.         var sphereGeom =  new THREE.SphereGeometry( 50, 32, 16 ); // radius, segmentsWidth, segmentsHeight
  150.         mirrorSphereCamera = new THREE.CubeCamera( 0.1, 5000, 512 );
  151.         // mirrorCubeCamera.renderTarget.minFilter = THREE.LinearMipMapLinearFilter;
  152.         scene.add( mirrorSphereCamera );
  153.         var mirrorSphereMaterial = new THREE.MeshBasicMaterial( { envMap: mirrorSphereCamera.renderTarget } );
  154.         mirrorSphere = new THREE.Mesh( sphereGeom, mirrorSphereMaterial );
  155.         mirrorSphere.position.set(75,50,0);
  156.         mirrorSphereCamera.position = mirrorSphere.position;
  157.         scene.add(mirrorSphere);
  158.        
  159.         function createMeshehehe(geom, imageFile, bump) {
  160.             var texture = THREE.ImageUtils.loadTexture("textures/" + imageFile)
  161.             geom.computeVertexNormals();
  162.             var mat = new THREE.MeshPhongMaterial();
  163.             mat.map = texture;
  164.  
  165.             if (bump) {
  166.                 var bump = THREE.ImageUtils.loadTexture("textures/" + bump)
  167.                 mat.bumpMap = bump;
  168.                 mat.bumpScale = 0.2;
  169.                 console.log('d');
  170.             }
  171.  
  172.  
  173.             // create a multimaterial
  174.             var mesh = new THREE.Mesh(geom, mat);
  175.  
  176.             return mesh;
  177.         }
  178.        
  179.         sphere2 = createMeshehehe(new THREE.CubeGeometry(15, 15, 2), "stone.jpg", "stone-bump.jpg");
  180.         sphere2.rotation.y = 8;
  181.         sphere2.position.x = -56;
  182.         scene.add(sphere2);
  183.         console.log(sphere2.geometry.faceVertexUvs);
  184. }
  185.  
  186. function animate()
  187. {
  188.     requestAnimationFrame( animate );
  189.    
  190.     polyhedron.rotation.y += 0.01;
  191.     polyhedron.rotation.x += 0.03;
  192.    
  193.     sphere.rotation.y += 0.02;
  194.     sphere.rotation.x -= 0.01;
  195.    
  196.     cube2.rotation.y -= 0.03;
  197.     cube2.rotation.x += 0.03;
  198.    
  199.     mirrorSphere.rotation.y -= 0.02;
  200.     mirrorSphere.rotation.x -= 0.03;
  201.    
  202.     sphere2.rotation.y -= 0.05;
  203.     sphere2.rotation.x += 0.03;
  204.    
  205.     render();              
  206.     update();
  207. }
  208.  
  209. function update()
  210. {
  211.         if ( keyboard.pressed("z") )
  212.         {
  213.                 // do something
  214.         }
  215.        
  216.         controls.update();
  217.         stats.update();
  218. }
  219.  
  220. function render()
  221. {
  222.     mirrorSphere.visible = false;
  223.     mirrorSphereCamera.updateCubeMap(renderer, scene);
  224.     mirrorSphere.visible = true;
  225.     renderer.render( scene, camera );
  226.  
  227. }
  228.  
  229. </script>
  230.  
  231. </body>
  232. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement