cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div id="viewport"></div>
<a class="js-btn-open-map">open / close map</a>
            
          
!
            
              html, body{
   padding:0;
	margin:0;
	width:100%;
	height:100%;
	font-family: 'Open Sans', sans-serif;
	overflow:hidden;
	background-color:#ccc;
	font-size:16px;
	position:relative;
}

canvas{
	cursor:grab;
	cursor:-webkit-grab; 
	cursor:-moz-grab;
}

canvas:active{
	cursor:grabbing;
	cursor:-webkit-grabbing; 
	cursor:-moz-grabbing;
}

.js-btn-open-map{
	color:#ccc;
   background:rgba(85,85,85, 0.75);
	cursor:pointer;
	position:absolute;
   bottom:0;
	left:50%;
	transform:translateX(-50%);
	font-weight:600;
	transition:0.25s all;
   
   padding:20px;
   display:inline-block;
   
  -webkit-user-select: none; 
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;  
  
}

.js-btn-open-map:hover{
   background:rgba(85,85,85, 0.9);
	color:#fff;
}
            
          
!
            
              var scene = new THREE.Scene();
var viewport, renderer, camera, controls, light;

// plane variables
var geometryDetailLevel = 4; 
var mapURL = 'https://maps.googleapis.com/maps/api/staticmap?size=512x512&zoom=12&center=53.523219,-113.526319&format=png&key=AIzaSyCd5ZoMYrDuVeDkXnpztEodrQ-IyXInnek';
var plane, geometry, standingX, standingZ;

// animation variables
var start, startAngle;
var animDuration = 500;
var targetAngle = 5;

window.requestAnimFrame = function(){
return (
  window.requestAnimationFrame       || 
  window.webkitRequestAnimationFrame || 
  window.mozRequestAnimationFrame    || 
  window.oRequestAnimationFrame      || 
  window.msRequestAnimationFrame     || 
  function(/* function */ callback){
    window.setTimeout(callback, 1000 / 60);
  }
);
}();

function rand(min, max) {
  return Math.random() * (max - min) + min;
}


function init() {
  scene = new THREE.Scene();
  scene.background = new THREE.Color( 0x555555 );

  var WIDTH = window.innerWidth,
      HEIGHT = window.innerHeight;
  viewport = document.getElementById('viewport');

  renderer = new THREE.WebGLRenderer();
  renderer = new THREE.WebGLRenderer({ antialias: true });
  renderer.setSize(WIDTH, HEIGHT);
  renderer.shadowMap.enabled = true;
  renderer.shadowMapSoft = true;

  renderer.shadowMapBias = 0.0039;
  renderer.shadowMapDarkness = 0.5;
  renderer.shadowMapWidth = 1024;
  renderer.shadowMapHeight = 1024;

  viewport.appendChild(renderer.domElement);
  window.addEventListener( 'resize', onWindowResize, false );


  /* ************** */
  /*                */
  /*     camera     */
  /*                */
  /* ************** */
  camera = new THREE.PerspectiveCamera(10, WIDTH / HEIGHT, 0.1, 200000);
  camera.position.set(-5, 25, 25 );
  scene.add(camera);

  controls = new THREE.OrbitControls(camera, renderer.domElement);
  controls.autoRotate = false;

  createMapTexture();

  /* ************* */
  /*               */
  /*     light     */
  /*               */
  /* ************* */
  var light = new THREE.PointLight( 0xffffff, 1.5, 70 );
  light.position.set( -geometryDetailLevel , geometryDetailLevel, geometryDetailLevel); 
  light.castShadow = true; 
  light.shadow.camera.updateProjectionMatrix();
  scene.add( light );

  var sideLight = light.clone();
  sideLight.position.set( geometryDetailLevel , 0, 0);
  sideLight.intensity = 0.6;
  scene.add( sideLight );

  var bottomLight = light.clone();
  bottomLight.position.set( geometryDetailLevel , -geometryDetailLevel, -geometryDetailLevel);
  bottomLight.intensity = 0.4;
  scene.add( bottomLight );

  animate();
}

function rotate(centerX, centerY, angleInDegrees){
  var angleInRadians = angleInDegrees * (Math.PI / 180.0);
  var centerXOffset = 0;
  var centerYOffset = 0;
   
  return [
    Math.round((centerXOffset + ( Math.cos(angleInRadians))) * 1000) / 1000,
    Math.round((centerYOffset + ( Math.sin(angleInRadians))) * 1000) / 1000
  ];
}


function createMap(materials){
  geometry = new THREE.PlaneGeometry(geometryDetailLevel, geometryDetailLevel, 4, 0 ); // width, height, width segments, height segments  
  for (var i = 0, len = geometry.faces.length; i < len; i++) {
    var face = geometry.faces[i].clone();
    face.materialIndex = 1;
    geometry.faces.push(face);
    geometry.faceVertexUvs[0].push(geometry.faceVertexUvs[0][i].slice(0));
  }

  plane = new THREE.Mesh( geometry, new THREE.MultiMaterial(materials) );
  plane.recieveShadow = true;
  plane.castShadow = true; 
  geometry.recieveShadow = true;
  geometry.castShadow = true; 
  geometry.computeVertexNormals();

  scene.add( plane );
  plane.rotateX(-90 * Math.PI / 180);

  startAngle = 89;

  point = rotate(0, 0, startAngle);
  standingX = point[0];
  standingZ = point[1];

  for(var i=0; i<plane.geometry.vertices.length; i++){
    vertex = plane.geometry.vertices[i];
    vertex.origX = vertex.x;
    vertex.origY = vertex.y;

    vertex.x = vertex.origX * standingX;
    if(vertex.origX == 1 || vertex.origX == -1){
      vertex.z = standingZ;  
    }
  }

  geometry.verticesNeedUpdate = true;

  window.setTimeout(function(){
    start = null;
    window.requestAnimFrame(step);
  }, 500);
}


function step(timestamp) {
  if (!start) start = timestamp;
  timestampDifference = timestamp - start;
  if(timestampDifference< animDuration){
    timestampRatio = timestampDifference / animDuration;
  }else{
    timestampRatio = 1;
  }

  angle = startAngle - timestampRatio * (startAngle - targetAngle);
  point = rotate(0, 0, angle);

  standingX = point[0];
  standingZ = point[1];

  for(var i=0; i<plane.geometry.vertices.length; i++){
    vertex = plane.geometry.vertices[i];
    vertex.x = vertex.origX * standingX;
    if(vertex.origX == 1 || vertex.origX == -1){
      vertex.z = standingZ;  
    }
  }
  geometry.verticesNeedUpdate = true;

  if(timestampDifference < animDuration){
    timestampRatio = timestampDifference / animDuration;
    window.requestAnimationFrame(step);
  }else{
    startAngle = [targetAngle, targetAngle = startAngle][0];
  }

}

function createMapTexture(){
  var loader = new THREE.TextureLoader();
  loader.crossOrigin = 'anonymous';
    loader.load(
      mapURL,
      function ( texture ) {
        var frontMaterial = new THREE.MeshPhongMaterial({
          color: 0xffffff,
          shading : THREE.FlatShading,
          side: THREE.FrontSide,
        });
        frontMaterial.map = texture;

        var backMaterial = frontMaterial.clone();
        backMaterial.side = THREE.BackSide;

        var materials = [backMaterial, frontMaterial];
        createMap(materials);
      },
      function ( xhr ) { // Function called when download progresses
        console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
      },
      // Function called when download errors
      function ( xhr ) {
        console.log( 'An error happened' );
      }
    );
}

function onWindowResize( event ) {
  SCREEN_HEIGHT = window.innerHeight;
  SCREEN_WIDTH  = window.innerWidth;
  renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
  camera.updateProjectionMatrix();
}

function animate() {
  requestAnimationFrame(animate);
  renderer.render(scene, camera);
  controls.update();
}

btn_js_open_map = document.querySelector(".js-btn-open-map");
btn_js_open_map.addEventListener("click", function(e){
  start = null;
  window.requestAnimFrame(step);
});

init();


            
          
!
999px
Loading ..................

Console