css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id="stats">
  <h1>Select an area</h1>
  <a id="map-link" target="_blank">Map</a>    
  <form>
    <select name="geo">
      <option value="athabasca">Athabasca Glacier</option>
      <option value="coldeliseran">Col de l'Iseran</option>
      <option value="everest" selected>Mount Everest</option>
      <option value="franzjosefglacier">Franz Josef Glacier</option>
      <option value="grouse">Grouse Grind</option>
      <option value="jotunheimen">Jotunheimen</option>
      <option value="k2">K2</option>
      <option value="kangchenjunga">Kangchenjunga</option>
      <option value="everest-valley">Khumbu Glacier</option>
      <option value="lakecomo">Lake Como</option>
      <option value="petra">Petra</option>
      <option value="sanfrancisco">San Francisco</option>
      <option value="valparaiso">Valparaíso</option>
    </select>
  </form> 
  <span id="loading"></span>
</div>
<div id="viewport"></div>
            
          
!
            
              html, body{
  padding:0;
  margin:0;
  height:100%;
  font-family: 'Open Sans', sans-serif;

  overflow:hidden;
  background-color:#000;
  font-size:16px;
}
*, *:before, *:after {
  box-sizing: border-box;
}
#stats{
  width:100%;
  text-align:center;
  color:#fff;
  padding:20px;
  float:left;
  display:block;
}
a{
  color:#fff;
}
canvas{
  cursor:grab;
  cursor:-webkit-grab; 
  cursor:-moz-grab;
}

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

h1{
  font-size:1rem;
  width:50%;
  text-align:left;
  float:left;
  padding:0;
  margin:0.65rem 0 0.25rem;
  display:none;
}

#map-link{
  margin-top:0.65rem;
  float:right;
}


form{
  float:left;
}
select{
  max-width:300px;
  width:100%;
  border:1px solid #fff;
  padding:0.625rem;
  color:#fff;
  font-size:16px;
  background:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"  viewBox="0 0 7.364 4.682"><polygon fill="#fff" class="cls-1" points="7.364 0 3.682 4.682 0 0 7.364 0"/></svg>');
  background-position:calc(100% - 10px) center;
  background-repeat:no-repeat;
  background-size:15px auto;
  -webkit-appearance: none;
  -webkit-border-radius: 0;
  -moz-border-radius: 0;
  border-radius: 0;
}
select:focus{
  outline: 0;
}
#loading{
  width:100%;
  font-size:0.75rem;
  float:left;
}
@media(min-width:480px){
  h1{
    width:33%;
    display:block;
  }
  form{
    width:33%;
  }
  #map-link{
    float:right;
  }
}
@media(min-width:768px){
  h1{
    width:auto;
  }
  form{
    width:100%;
  }
  #stats{
    position:absolute;
    top:0;
    right:0;
    width:250px;
    height:auto;
    text-align:right;
    background-color:rgba(255,255,255,0.1);
  }
}
            
          
!
            
              var scene = new THREE.Scene();
var viewport, renderer, camera, controls, particleDistance, centerPoint = {};
var transitionDuration = 1000;
var baseURL = '';
var mountainGeometry, mountainParticles;
var loader = new THREE.JSONLoader();
var pointsPlot = new Array();
var geoname;
THREE.ImageUtils.crossOrigin = ""
THREE.ImageUtils.crossOrigin = "anonymous"
init();


function init() {
  baseURL = 'https://s3.ca-central-1.amazonaws.com/kevinnewcombe/three-terrain/';
  // set up the scene and camera
  scene = new THREE.Scene();
  var WIDTH = window.innerWidth,
      HEIGHT = window.innerHeight;

  viewport = document.getElementById('viewport');

  renderer = new THREE.WebGLRenderer();
  renderer = new THREE.WebGLRenderer({ antialias: 0, clearAlpha: 0, alpha:true });
  renderer.setSize(WIDTH, HEIGHT);
  renderer.setClearColor( 0x000000, 0 ); // the default
  renderer.shadowMap.enabled = true;
  viewport.appendChild(renderer.domElement);
  window.addEventListener( 'resize', onWindowResize, false );

  scene.fog = new THREE.Fog( 0x111111, 22000, 25000 );

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

  controls = new THREE.OrbitControls(camera, renderer.domElement);
  controls.autoRotate = true;
  controls.autoRotateSpeed = 0.25; 
  createGroundPlane();
  animate();
}

function createGroundPlane(){
  mountainGeometry = new THREE.Geometry();
  mountainGeometry.dynamic = true;
  mountainGeometry.__dirtyVertices = true;
  mountainGeometry.verticesNeedUpdate = true;

  var material = new THREE.PointsMaterial();
  material.sizeAttenuation = false;
  centerX = 0;
  centerZ = 0;

  totalX = 150;
  totalZ = 150;

  particleDistance = 25;
  for ( var x = 0; x < totalX; x ++ ) {
    xplot = x - Math.round((totalX-1)/2);
    zArray = new Array();
    for ( var z = 0; z < totalZ; z ++ ) {
      var vertex = new THREE.Vector3();
      vertex.x = x*particleDistance - particleDistance*(totalX-1)/2;
      vertex.z = z*particleDistance - particleDistance*(totalZ-1)/2;
      zplot = z - Math.round((totalZ-1)/2);
      zArray[zplot] = vertex;
      mountainGeometry.vertices.push( vertex );
    }
    pointsPlot[xplot] = zArray;
  }
  
  mountainParticles = new THREE.Points( mountainGeometry, material );
  mountainParticles.sortParticles = true;
  mountainParticles.position.y = -700;
  scene.add( mountainParticles );
  loadGeography('everest');
}

function loadGeography(filename){
  e = document.querySelector('select[name="geo"]');
  select = e.options[e.selectedIndex].value;
  if(select){
    filename = select;
  } 
  var request = new XMLHttpRequest();
  request.open('GET', baseURL+'_terrain/'+filename+'.json?v=2');
  request.onprogress = function(evt){
    document.getElementById('loading').innerHTML = Math.round((evt.loaded / evt.total)*100)+'%';
  }
  request.onload = function() {
    document.getElementById('loading').innerHTML = '';
    if (request.status >= 200 && request.status < 400) {
      var data = JSON.parse(request.responseText);
      centerPoint.lat = data.boundaries[2] + (data.boundaries[0] - data.boundaries[2]) / 2;
      centerPoint.lng = data.boundaries[3] + (data.boundaries[1] - data.boundaries[3]) / 2;
      document.getElementById('map-link').setAttribute('href', 'https://www.google.ca/maps/place/'+centerPoint.lat+','+centerPoint.lng);
      console.log(centerPoint.lat+','+centerPoint.lng);
      for(var i = 0; i<data.coords.length; i++){
        m = data.coords[i];
        x = m[0];
        y = m[1];
        z = m[2];

        v = pointsPlot[x][z];

        target = { 
          y:(y - data.lowest_point)*particleDistance, 
          ease:Power3.easeOut
        }

        tween = TweenMax.to(v, 1.5, target );
        target.onUpdate = function () {
         mountainGeometry.verticesNeedUpdate = true;
        };  
      }
    } else {
      alert('Sorry, there was an error loading the geography.');
    }
  };

  request.onerror = function() {
    alert('Sorry, there was an error loading the geography.');
  };
  request.send();
}

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();
}

document.addEventListener('DOMContentLoaded',function() {
 document.querySelector('select[name="geo"]').onchange=loadGeography;
},false);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console