|
@@ -0,0 +1,204 @@
|
|
|
|
+<!DOCTYPE HTML>
|
|
|
|
+<html lang="en">
|
|
|
|
+ <head>
|
|
|
|
+ <title>three.js - panorama demo</title>
|
|
|
|
+ <meta charset="utf-8">
|
|
|
|
+ <style type="text/css">
|
|
|
|
+ body {
|
|
|
|
+ background-color: rgb(200,200,200);
|
|
|
|
+ margin: 0px;
|
|
|
|
+ overflow: hidden;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #info {
|
|
|
|
+ position: absolute;
|
|
|
|
+ top: 0px; width: 100%;
|
|
|
|
+ color: #ffffff;
|
|
|
|
+ padding: 5px;
|
|
|
|
+ font-family:Monospace;
|
|
|
|
+ font-size:13px;
|
|
|
|
+ font-weight: bold;
|
|
|
|
+ text-align:center;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ a {
|
|
|
|
+ color: #ffffff;
|
|
|
|
+ }
|
|
|
|
+ </style>
|
|
|
|
+ </head>
|
|
|
|
+ <body>
|
|
|
|
+
|
|
|
|
+ <div id="container"></div>
|
|
|
|
+ <div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - panorama demo. cubemap by <a href="http://www.zfight.com/" target="_blank">Jochum Skoglund</a>.</div>
|
|
|
|
+
|
|
|
|
+ <script type="text/javascript" src="../build/Three.js"></script>
|
|
|
|
+ <script type="text/javascript" src="../src/extras/primitives/Cube.js"></script>
|
|
|
|
+
|
|
|
|
+ <script type="text/javascript">
|
|
|
|
+
|
|
|
|
+ var camera, scene, renderer;
|
|
|
|
+
|
|
|
|
+ var fov = 75,
|
|
|
|
+ texture_placeholder, wireframe,
|
|
|
|
+ isUserInteracting = false,
|
|
|
|
+ onMouseDownMouseX = 0, onMouseDownMouseY = 0,
|
|
|
|
+ lon = 90, onMouseDownLon = 0,
|
|
|
|
+ lat = 0, onMouseDownLat = 0,
|
|
|
|
+ phi = 0, theta = 0;
|
|
|
|
+
|
|
|
|
+ init();
|
|
|
|
+
|
|
|
|
+ function init() {
|
|
|
|
+
|
|
|
|
+ var container, mesh;
|
|
|
|
+
|
|
|
|
+ container = document.getElementById( 'container' );
|
|
|
|
+
|
|
|
|
+ camera = new THREE.Camera( fov, window.innerWidth / window.innerHeight, 1, 1100 );
|
|
|
|
+
|
|
|
|
+ scene = new THREE.Scene();
|
|
|
|
+
|
|
|
|
+ texture_placeholder = document.createElement( 'canvas' );
|
|
|
|
+ texture_placeholder.width = 128;
|
|
|
|
+ texture_placeholder.height = 128;
|
|
|
|
+
|
|
|
|
+ wireframe = new THREE.MeshBasicMaterial( { color: 0xffffff, opacity: 0, wireframe: true } );
|
|
|
|
+
|
|
|
|
+ var context = texture_placeholder.getContext( '2d' );
|
|
|
|
+ context.fillStyle = 'rgb( 200, 200, 200 )';
|
|
|
|
+ context.fillRect( 0, 0, texture_placeholder.width, texture_placeholder.height );
|
|
|
|
+
|
|
|
|
+ var materials = [];
|
|
|
|
+ materials.push( [ loadTexture( 'textures/cube/skybox/px.jpg' ), wireframe ] ); // right
|
|
|
|
+ materials.push( [ loadTexture( 'textures/cube/skybox/nx.jpg' ), wireframe ] ); // left
|
|
|
|
+ materials.push( [ loadTexture( 'textures/cube/skybox/py.jpg' ), wireframe ] ); // top
|
|
|
|
+ materials.push( [ loadTexture( 'textures/cube/skybox/ny.jpg' ), wireframe ] ); // bottom
|
|
|
|
+ materials.push( [ loadTexture( 'textures/cube/skybox/pz.jpg' ), wireframe ] ); // back
|
|
|
|
+ materials.push( [ loadTexture( 'textures/cube/skybox/nz.jpg' ), wireframe ] ); // front
|
|
|
|
+
|
|
|
|
+ mesh = new THREE.Mesh( new Cube( 300, 300, 300, 7, 7, materials, true ), new THREE.MeshFaceMaterial() );
|
|
|
|
+ mesh.overdraw = true;
|
|
|
|
+ scene.addObject( mesh );
|
|
|
|
+
|
|
|
|
+ renderer = new THREE.CanvasRenderer();
|
|
|
|
+ renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
+
|
|
|
|
+ container.appendChild( renderer.domElement );
|
|
|
|
+
|
|
|
|
+ document.addEventListener( 'mousedown', onDocumentMouseDown, false );
|
|
|
|
+ document.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
|
|
|
+ document.addEventListener( 'mouseup', onDocumentMouseUp, false );
|
|
|
|
+ document.addEventListener( 'mousewheel', onDocumentMouseWheel, false );
|
|
|
|
+
|
|
|
|
+ document.addEventListener( 'touchstart', onDocumentTouchStart, false );
|
|
|
|
+ document.addEventListener( 'touchmove', onDocumentTouchMove, false );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function loadTexture( path ) {
|
|
|
|
+
|
|
|
|
+ var material = new THREE.MeshBasicMaterial( { map: new THREE.Texture( texture_placeholder, THREE.UVMapping ) } );
|
|
|
|
+
|
|
|
|
+ var texture = new Image();
|
|
|
|
+
|
|
|
|
+ texture.onload = function () {
|
|
|
|
+
|
|
|
|
+ material.map.image = this;
|
|
|
|
+ render();
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ texture.src = path;
|
|
|
|
+
|
|
|
|
+ return material;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function onDocumentMouseDown( event ) {
|
|
|
|
+
|
|
|
|
+ event.preventDefault();
|
|
|
|
+
|
|
|
|
+ isUserInteracting = true;
|
|
|
|
+
|
|
|
|
+ wireframe.opacity = 0.2;
|
|
|
|
+
|
|
|
|
+ onPointerDownPointerX = event.clientX;
|
|
|
|
+ onPointerDownPointerY = event.clientY;
|
|
|
|
+
|
|
|
|
+ onPointerDownLon = lon;
|
|
|
|
+ onPointerDownLat = lat;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function onDocumentMouseMove( event ) {
|
|
|
|
+
|
|
|
|
+ if ( isUserInteracting ) {
|
|
|
|
+
|
|
|
|
+ lon = ( onPointerDownPointerX - event.clientX ) * 0.1 + onPointerDownLon;
|
|
|
|
+ lat = ( event.clientY - onPointerDownPointerY ) * 0.1 + onPointerDownLat;
|
|
|
|
+ render();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function onDocumentMouseUp( event ) {
|
|
|
|
+
|
|
|
|
+ isUserInteracting = false;
|
|
|
|
+ wireframe.opacity = 0;
|
|
|
|
+ render();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function onDocumentMouseWheel( event ) {
|
|
|
|
+
|
|
|
|
+ fov -= event.wheelDeltaY * 0.05;
|
|
|
|
+ camera.projectionMatrix = THREE.Matrix4.makePerspective( fov, window.innerWidth / window.innerHeight, 1, 1100 );
|
|
|
|
+ render();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ function onDocumentTouchStart( event ) {
|
|
|
|
+
|
|
|
|
+ if( event.touches.length == 1 ) {
|
|
|
|
+
|
|
|
|
+ event.preventDefault();
|
|
|
|
+
|
|
|
|
+ onPointerDownPointerX = event.touches[ 0 ].pageX;
|
|
|
|
+ onPointerDownPointerY = event.touches[ 0 ].pageY;
|
|
|
|
+
|
|
|
|
+ onPointerDownLon = lon;
|
|
|
|
+ onPointerDownLat = lat;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function onDocumentTouchMove( event ) {
|
|
|
|
+
|
|
|
|
+ if( event.touches.length == 1 ) {
|
|
|
|
+
|
|
|
|
+ event.preventDefault();
|
|
|
|
+
|
|
|
|
+ lon = ( onPointerDownPointerX - event.touches[0].pageX ) * 0.1 + onPointerDownLon;
|
|
|
|
+ lat = ( event.touches[0].pageY - onPointerDownPointerY ) * 0.1 + onPointerDownLat;
|
|
|
|
+
|
|
|
|
+ render();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function render() {
|
|
|
|
+
|
|
|
|
+ lat = Math.max( - 85, Math.min( 85, lat ) );
|
|
|
|
+ phi = ( 90 - lat ) * Math.PI / 180;
|
|
|
|
+ theta = lon * Math.PI / 180;
|
|
|
|
+
|
|
|
|
+ camera.target.position.x = 500 * Math.sin( phi ) * Math.cos( theta );
|
|
|
|
+ camera.target.position.y = 500 * Math.cos( phi );
|
|
|
|
+ camera.target.position.z = 500 * Math.sin( phi ) * Math.sin( theta );
|
|
|
|
+
|
|
|
|
+ renderer.render( scene, camera );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ </script>
|
|
|
|
+ </body>
|
|
|
|
+</html>
|