Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                body { 
    margin: 0; 
    height: 100vh;
}
  
canvas { 
    display: block;
}

h1 {
    position: absolute;
    top: 2em;
    left: 2em;
    font-family: 'Montserrat';
    font-size: 7em;
    text-transform: uppercase;
    width: auto;
    line-height: .8em;
    border: 5px solid black;
    padding: .2em;
  }
              
            
!

JS

              
                var scene, renderer, camera, control;
var bldgs = [];

init();
setup();
animate();

//Functions ----
function init(){
  scene = new THREE.Scene();
  camera = new THREE.PerspectiveCamera( 45,window.innerWidth/window.innerHeight,1,1000 ) //FOV, Aspect Ratio, Close Plane, Far Plane
    camera.position.z = 10;
    camera.position.y = 5;
    camera.rotation.x = -Math.PI/14;
  renderer = new THREE.WebGLRenderer( {antialias: true} );
    renderer.setClearColor( "#e5e5e5" );
    renderer.setSize( window.innerWidth,window.innerHeight );
    document.body.appendChild( renderer.domElement );
  control = new THREE.OrbitControls( camera, renderer.domElement );
    //control.enableDamping = true; //Can't get this to work...
    //control.dampingFactor = -1;
    control.rotateSpeed = .3;
    control.zoomSpeed = 1.4;
}

function building( x1, y1, x2, y2, x3, y3, x4, y4, id, height ){
  this.x1 = x1;
  this.y1 = y1;
  this.x2 = x2;
  this.y2 = y2;
  this.x3 = x3;
  this.y3 = y3;
  this.x4 = x4;
  this.y4 = y4;
  this.id = id;
  this.height = height;
};

//---------------------------------------------------------------------------

function setup(){
  var defaultMat = new THREE.BoxGeometry(1, 0.001, 1);
  var material = new THREE.MeshLambertMaterial({color: 0xF7F7F7});

  // meshX = 0;
  // var len = -2;
  // var wid = -2;
  
  //Create geometry of custom foundation
  bldgs.push(
    new building( 0, 0, 1, 0.5, 1, 2, 0, 3, 'test', 0.1 )
  );
  
  var geometry = new THREE.Geometry();
 
  geometry.vertices.push(
    //Floor
    new THREE.Vector3( bldgs[0].x1, 0, bldgs[0].y1 ), //0
    new THREE.Vector3( bldgs[0].x2, 0, bldgs[0].y2 ), //1
    new THREE.Vector3( bldgs[0].x3, 0, bldgs[0].y3 ), //2
    new THREE.Vector3( bldgs[0].x4, 0, bldgs[0].y4 ), //3

    //Ceiling
    new THREE.Vector3( bldgs[0].x1, bldgs[0].height, bldgs[0].y1 ), //4
    new THREE.Vector3( bldgs[0].x2, bldgs[0].height, bldgs[0].y2 ), //5
    new THREE.Vector3( bldgs[0].x3, bldgs[0].height, bldgs[0].y3 ), //6
    new THREE.Vector3( bldgs[0].x4, bldgs[0].height, bldgs[0].y4 ), //7
  );
  
  geometry.faces.push(
    //Base
    new THREE.Face3( 0, 1, 2 ),
    new THREE.Face3( 0, 2, 3 ),
    //Top
    new THREE.Face3( 6, 5, 7 ),
    new THREE.Face3( 7, 5, 4 ),
    //Front
    new THREE.Face3( 2, 6, 3 ),
    new THREE.Face3( 3, 6, 7 ),
    //Back
    new THREE.Face3( 0, 4, 1 ),
    new THREE.Face3( 1, 4, 5 ),
    //Left
    new THREE.Face3( 3, 7, 4 ),
    new THREE.Face3( 4, 0, 3 ),
    //Right
    new THREE.Face3( 1, 5, 6 ),
    new THREE.Face3( 2, 1, 6 ),
  );
  
  geometry.computeFaceNormals();
  
  const bldg61 = new THREE.Mesh( geometry, material );
  bldg61.userData = 0.01;
  scene.add( bldg61 );
};

//---------------------------------------------------------------------------

window.addEventListener('resize', () => {
  renderer.setSize(window.innerWidth,window.innerHeight);
  camera.aspect = window.innerWidth / window.innerHeight;
  
  camera.updateProjectionMatrix();
  //control.update();
})

var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();

var light = new THREE.PointLight( 0xFFFFFF, 1, 1000 );
light.position.set( 0, 0, 10 );
scene.add( light );

var light2 = new THREE.PointLight(0xFFFFFF, 1, 1000);
light2.position.set( 20, -20, 25 );
scene.add( light2 );

function animate(){
  requestAnimationFrame( animate );
  update();
  render();
};

function update(){
  control.update();
};

function render(){
  renderer.render( scene, camera );
};

//--------------------------------------------------------------------------- 

function onMouseMove( event ) {
  event.preventDefault();

  mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
  mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

  raycaster.setFromCamera( mouse, camera );

  var intersects = raycaster.intersectObjects( scene.children );
  if (intersects.length != 0){
    for (var i = 0; i < 1; i++) {
      this.tl = new TimelineMax();
      if (intersects[i].object.userData <= 5){
        intersects[i].object.userData+=.2;
      }else {
        intersects[i].object.userData = 0.1;
      }

      var height = intersects[i].object.userData;
      //console.log(intersects[i].object.userData);
      //Raising
      this.tl.to(intersects[i].object.scale, 1, {y: ([height]*5), ease: Bounce.easeOut});
      //this.tl.to(intersects[i].object.position, .25, {y: (0), ease: Expo.easeInOut}, "=-.25");
      //console.log(intersects[i].object.uuid);
      //Lowering
      // this.tl.to(intersects[i].object.scale, 1, {y: 1, ease: Expo.easeInOut});
      // this.tl.to(intersects[i].object.position, 1, {y: -3, ease: Expo.easeInOut}, "=-1");
    }
  }
};

//---------------------------------------------------------------------------

window.addEventListener('click', onMouseMove);

              
            
!
999px

Console