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.

            
              body {
  background-color: #000;
  margin: 0;
  overflow: hidden;
  padding: 0;
}
            
          
!
            
              /**
 * @file
 * The main scene.
 */

/**
 * Define constants.
 */
const TEXTURE_PATH = 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/123879/';

/**
 * Set our global variables.
 */
var camera,
    scene,
    renderer,
    effect,
    controls,
    element,
    container,
    spotlight,
    rotationPoint;

document.addEventListener( 'mousemove', onDocumentMouseMove, false );

init();
animate(); 

/**
 * Initializer function.
 */
function init() {
  // Build the container
  container = document.createElement( 'div' );
  document.body.appendChild( container );
  
  // Create the scene.
  scene = new THREE.Scene();
  
  // Create a rotation point.
  rotationPoint = new THREE.Object3D();
  rotationPoint.position.set( -150, 100, 100 );
  scene.add(rotationPoint);
  
    // Create the camera.
  camera = new THREE.PerspectiveCamera(
   50, // Angle
    window.innerWidth / window.innerHeight, // Aspect Ratio.
    1, // Near view.
    23000 // Far view.
  );
  camera.position.x = -50;
  //camera.position.y = 100;
  camera.position.z = 10;
  rotationPoint.add( camera );

  // Build the renderer.
  renderer = new THREE.WebGLRenderer( { antialias: true, alpha: true } );
  element = renderer.domElement;
  renderer.setSize( window.innerWidth, window.innerHeight );
  renderer.shadowMapEnabled = true;
  renderer.shadowMapType = THREE.PCFSoftShadowMap;
  container.appendChild( element );
  
  // Lights
  var light = new THREE.HemisphereLight(0x333333, 0x000000, 1);
  scene.add(light);
  
  // Build the controls.
  controls = new THREE.OrbitControls( camera, element );
  controls.enablePan = true;
  controls.enableZoom = true; 
  controls.maxDistance = 1; 
  controls.minDistance = 1;
  controls.target.copy( new THREE.Vector3( 0, 0, 0 ) );
  
  function setOrientationControls(e) {
    if (!e.alpha) {
     return;
    }

    controls = new THREE.DeviceOrientationControls( camera );
    controls.connect();

    window.removeEventListener('deviceorientation', setOrientationControls, true);
  }
  window.addEventListener('deviceorientation', setOrientationControls, true);
  
  // Ambient lights
  var ambient = new THREE.AmbientLight( 0x555555);
  scene.add( ambient );

  // Add the skymap.
  //addSkybox();
  
  createFloor();
  createWalls();
  createCeiling();
  createChimney();
  createChimneyBase();
  createChimneyOpening();
  createBox();
  createChimneyOpeningTop();
  
  spotLight = new THREE.SpotLight( 0x995500, 0.7 );
  spotLight.position.set( 145, 55, 175 );

  spotLight.castShadow = true;
  spotLight.shadowCameraVisible = true;

  spotLight.shadow.mapSize.width = 300;
  spotLight.shadow.mapSize.height = 300;

  spotLight.shadow.camera.near = 50;
  spotLight.shadow.camera.far = 400;
  spotLight.shadow.camera.fov = 30;

  scene.add( spotLight );
  
  var light = new THREE.PointLight(0x995500, 1, 400);
  light.position.set(175, 55, 175);
  scene.add(light);
  
  var light = new THREE.PointLight(0x995500, 1, 200);
  light.position.set(-50, 55, -100);
  scene.add(light);
  
  window.addEventListener('resize', onWindowResize, false);
}

/**
 * Events to fire upon window resizing.
 */
function onWindowResize() {
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(window.innerWidth, window.innerHeight);
}

/**
 * Updates to apply to the scene while running.
 */
function update() {
  camera.updateProjectionMatrix();
 
  spotLight.rotation.y += 0.005;
  
}

/**
 * Render the scene.
 */
function render() {
  renderer.render(scene, camera);
  
}

/**
 * Animate the scene.
 */
function animate() {
  requestAnimationFrame(animate);
  update();
  render();
}

function onDocumentMouseMove( event ) {
  event.preventDefault();
}

function createBox() {
  // Create the crate.  
  var loader = new THREE.TextureLoader();
  loader.crossOrigin = "";
  loader.load( TEXTURE_PATH + 'WoodPlanks029_COL_VAR1_1K.jpg', function( texture ) {

    texture.anisotropy = renderer.getMaxAnisotropy();
    texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
    texture.repeat.set(1, 1);

    var normal = loader.load( TEXTURE_PATH + 'WoodPlanks029_NRM_1K.jpg');
    normal.anisotropy = renderer.getMaxAnisotropy();
    normal.wrapS = normal.wrapT = THREE.ReapeatWrapping;
    normal.repeat.set(1, 1);

    var displace = loader.load( TEXTURE_PATH + 'WoodPlanks029_DISP_1K.jpg');
    displace.anisotropy = renderer.getMaxAnisotropy();
    displace.wrapS = displace.wrapT = THREE.ReapeatWrapping;
    displace.repeat.set(1, 1); 
    
    var spec = loader.load( TEXTURE_PATH + 'WoodPlanks029_REFL_1K.jpg');
    spec.anisotropy = renderer.getMaxAnisotropy();
    spec.wrapS = spec.wrapT = THREE.RepeatWrapping;
    spec.repeat.set(1, 1);

    var material = new THREE.MeshPhongMaterial({
      color: 0xffffff,
      specular: 0x555555,
      specularMap: spec,
      map: texture,
      displacementMap: displace,
      normalMap: normal,
    });
    var geometry = new THREE.BoxGeometry( 50, 50, 50 );
    var box = new THREE.Mesh(geometry, material);
    box.position.set(170, 25, 170);
    box.castShadow = true;
    scene.add(box);
    
    var geometry = new THREE.BoxGeometry( 48, 48, 48 );
    var boxInt = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial( {color: 0x444444} ));
    boxInt.position.set(170, 24, 170);
    boxInt.castShadow = true;
    boxInt.receiveShadow = true;
    scene.add(boxInt);
  });
}

function createChimney() {
  // Create the chimney.  
  var loader = new THREE.TextureLoader();
  loader.crossOrigin = "";
  loader.load( TEXTURE_PATH + 'Bricks01_COL_VAR1_1K.jpg', function( texture ) {

    texture.anisotropy = renderer.getMaxAnisotropy();
    texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
    texture.repeat.set(0.5, 1);

    var normal = loader.load( TEXTURE_PATH + 'Bricks01_NRM_1K.jpg');
    normal.anisotropy = renderer.getMaxAnisotropy();
    normal.wrapS = normal.wrapT = THREE.ReapeatWrapping;
    normal.repeat.set(0.5, 1);

    var displace = loader.load( TEXTURE_PATH + 'Bricks01_DISP_1K.jpg');
    displace.anisotropy = renderer.getMaxAnisotropy();
    displace.wrapS = displace.wrapT = THREE.ReapeatWrapping;
    displace.repeat.set(0.5, 1); 
    
    var spec = loader.load( TEXTURE_PATH + 'Bricks01_REFL_1K.jpg');
    spec.anisotropy = renderer.getMaxAnisotropy();
    spec.wrapS = spec.wrapT = THREE.RepeatWrapping;
    spec.repeat.set(0.5, 1);

    // Create the floor object.
    var material = new THREE.MeshPhongMaterial({
      color: 0xffffff,
      specular: 0x555555,
      specularMap: spec,
      map: texture,
      displacementMap: displace,
      normalMap: normal,
    });
    var geometry = new THREE.BoxGeometry( 75, 150, 20 );
    var chimney = new THREE.Mesh(geometry, material);
    chimney.position.set(200, 125, 0);
    chimney.rotation.y = -Math.PI/2;
    chimney.castShadow = true;
    scene.add(chimney);
    
  });
}

function createChimneyBase() {
  // Create the chimney base.  
  var loader = new THREE.TextureLoader();
  loader.crossOrigin = "";
  loader.load( TEXTURE_PATH + 'Bricks01_COL_VAR1_1K.jpg', function( texture ) {

    texture.anisotropy = renderer.getMaxAnisotropy();
    texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
    texture.repeat.set(1, 1);

    var normal = loader.load( TEXTURE_PATH + 'Bricks01_NRM_1K.jpg');
    normal.anisotropy = renderer.getMaxAnisotropy();
    normal.wrapS = normal.wrapT = THREE.ReapeatWrapping;
    normal.repeat.set(1, 1);

    var displace = loader.load( TEXTURE_PATH + 'Bricks01_DISP_1K.jpg');
    displace.anisotropy = renderer.getMaxAnisotropy();
    displace.wrapS = displace.wrapT = THREE.ReapeatWrapping;
    displace.repeat.set(1, 1); 
    
    var spec = loader.load( TEXTURE_PATH + 'Bricks01_REFL_1K.jpg');
    spec.anisotropy = renderer.getMaxAnisotropy();
    spec.wrapS = spec.wrapT = THREE.RepeatWrapping;
    spec.repeat.set(1, 1);

    var material = new THREE.MeshPhongMaterial({
      color: 0xffffff,
      specular: 0x555555,
      specularMap: spec,
      map: texture,
      displacementMap: displace,
      normalMap: normal,
    });
    var geometry = new THREE.BoxGeometry( 150, 150, 40 );
    var chimneyBase = new THREE.Mesh(geometry, material);
    chimneyBase.position.set(180, 0, 0);
    chimneyBase.rotation.y = -Math.PI/2;
    chimneyBase.castShadow = true;
    scene.add(chimneyBase);
  });
}

function createChimneyOpening() {
  // Create the chimney base.  
  var loader = new THREE.TextureLoader();
  loader.crossOrigin = "";
  loader.load( TEXTURE_PATH + 'Bricks01_COL_VAR1_1K.jpg', function( texture ) {

    texture.anisotropy = renderer.getMaxAnisotropy();
    texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
    texture.repeat.set(0.1, 0.3);

    var normal = loader.load( TEXTURE_PATH + 'Bricks01_NRM_1K.jpg');
    normal.anisotropy = renderer.getMaxAnisotropy();
    normal.wrapS = normal.wrapT = THREE.ReapeatWrapping;
    normal.repeat.set(0.1, 0.3);

    var displace = loader.load( TEXTURE_PATH + 'Bricks01_DISP_1K.jpg');
    displace.anisotropy = renderer.getMaxAnisotropy();
    displace.wrapS = displace.wrapT = THREE.ReapeatWrapping;
    displace.repeat.set(0.1, 0.3); 
    
    var spec = loader.load( TEXTURE_PATH + 'Bricks01_REFL_1K.jpg');
    spec.anisotropy = renderer.getMaxAnisotropy();
    spec.wrapS = spec.wrapT = THREE.RepeatWrapping;
    spec.repeat.set(0.1, 0.3);

    var material = new THREE.MeshPhongMaterial({
      color: 0xffffff,
      specular: 0x555555,
      specularMap: spec,
      map: texture,
      displacementMap: displace,
      normalMap: normal,
    });
    
    var geometry = new THREE.BoxGeometry( 15, 40, 50 );
    var chimneyO1 = new THREE.Mesh(geometry, material);
    chimneyO1.position.set(150, 20, -20);
    chimneyO1.rotation.y = -Math.PI/2;
    chimneyO1.castShadow = true;
    chimneyO1.receiveShadow = true;
    scene.add(chimneyO1);
    
    var geometry = new THREE.BoxGeometry( 15, 40, 50 );
    var chimneyO2 = new THREE.Mesh(geometry, material);
    chimneyO2.position.set(150, 20, 20);
    chimneyO2.rotation.y = -Math.PI/2;
    chimneyO2.castShadow = true;
    chimneyO2.receiveShadow = true;
    scene.add(chimneyO2);
    

    
    var geometry = new THREE.BoxGeometry( 10, 40, 25 );
    var boxInt = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial( {color: 0x000000} ));
    boxInt.position.set(160, 20, 0);
    boxInt.castShadow = true;
    scene.add(boxInt);
  });
}

function createChimneyOpeningTop() {
    // Create the chimney base.  
  var loader = new THREE.TextureLoader();
  loader.crossOrigin = "";
  loader.load( TEXTURE_PATH + 'Bricks01_COL_VAR1_1K.jpg', function( texture ) {

    texture.anisotropy = renderer.getMaxAnisotropy();
    texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
    texture.repeat.set(0.5, 0.2);

    var normal = loader.load( TEXTURE_PATH + 'Bricks01_NRM_1K.jpg');
    normal.anisotropy = renderer.getMaxAnisotropy();
    normal.wrapS = normal.wrapT = THREE.ReapeatWrapping;
    normal.repeat.set(0.5, 0.2);

    var displace = loader.load( TEXTURE_PATH + 'Bricks01_DISP_1K.jpg');
    displace.anisotropy = renderer.getMaxAnisotropy();
    displace.wrapS = displace.wrapT = THREE.ReapeatWrapping;
    displace.repeat.set(0.5, 0.2); 
    
    var spec = loader.load( TEXTURE_PATH + 'Bricks01_REFL_1K.jpg');
    spec.anisotropy = renderer.getMaxAnisotropy();
    spec.wrapS = spec.wrapT = THREE.RepeatWrapping;
    spec.repeat.set(0.5, 0.2);

    var material = new THREE.MeshPhongMaterial({
      color: 0xffffff,
      specular: 0x555555,
      specularMap: spec,
      map: texture,
      displacementMap: displace,
      normalMap: normal,
    });
    
    var geometry = new THREE.BoxGeometry( 55, 25, 50 );
    var chimneyO3 = new THREE.Mesh(geometry, material);
    chimneyO3.position.set(150, 50, 0);
    chimneyO3.rotation.y = -Math.PI/2;
    chimneyO3.castShadow = true;
    chimneyO3.receiveShadow = true;
    scene.add(chimneyO3);
  });
}

function createFloor() {
  // Create a floor.  
  var loader = new THREE.TextureLoader();
  loader.crossOrigin = "";
  loader.load( TEXTURE_PATH + 'WoodPlanksWorn33_COL_VAR1_1K.jpg', function( texture ) {

    texture.anisotropy = renderer.getMaxAnisotropy();
    texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
    texture.repeat.set(4, 4);

    var normal = loader.load( TEXTURE_PATH + 'WoodPlanksWorn33_NRM_1K.jpg');
    normal.anisotropy = renderer.getMaxAnisotropy();
    normal.wrapS = normal.wrapT = THREE.ReapeatWrapping;
    normal.repeat.set(4, 4);

    var displace = loader.load( TEXTURE_PATH + 'WoodPlanksWorn33_AO_1K.jpg');
    displace.anisotropy = renderer.getMaxAnisotropy();
    displace.wrapS = displace.wrapT = THREE.ReapeatWrapping;
    displace.repeat.set(4, 4); 
    
    var spec = loader.load( TEXTURE_PATH + 'WoodPlanksWorn33_REFL_1K.jpg');
    spec.anisotropy = renderer.getMaxAnisotropy();
    spec.wrapS = spec.wrapT = THREE.RepeatWrapping;
    spec.repeat.set(4, 4);

    // Create the floor object.
    var material = new THREE.MeshPhongMaterial({
      color: 0xffffff,
      specular: 0x555555,
      specularMap: spec,
      map: texture,
      displacementMap: displace,
      normalMap: normal,
    });
    var geometry = new THREE.PlaneGeometry( 400, 400 );
    var floor = new THREE.Mesh(geometry, material);
    floor.position.set(0, 0, 0);
    floor.rotation.x = -Math.PI/2;
    floor.receiveShadow = true;
    scene.add(floor);
  });
}

function createWalls() {
  // Create the wall textures.  
  var loader = new THREE.TextureLoader();
  var material;
  loader.crossOrigin = "";
  loader.load( TEXTURE_PATH + 'WoodWallCabin003_COL_VAR1_1K.jpg', function( texture ) {

    texture.anisotropy = renderer.getMaxAnisotropy();
    texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
    texture.repeat.set(2, 2);

    var normal = loader.load( TEXTURE_PATH + 'WoodWallCabin003_NRM_1K.jpg');
    normal.anisotropy = renderer.getMaxAnisotropy();
    normal.wrapS = normal.wrapT = THREE.ReapeatWrapping;
    normal.repeat.set(2, 2);

    var displace = loader.load( TEXTURE_PATH + 'WoodWallCabin003_DISP_1K.jpg');
    displace.anisotropy = renderer.getMaxAnisotropy();
    displace.wrapS = displace.wrapT = THREE.ReapeatWrapping;
    displace.repeat.set(2, 2);    

    var spec = loader.load( TEXTURE_PATH + 'WoodWallCabin003_REFL_1K.jpg');
    spec.anisotropy = renderer.getMaxAnisotropy();
    spec.wrapS = spec.wrapT = THREE.RepeatWrapping;
    spec.repeat.set(2, 2);
    
    // Create the floor object.
    var material = new THREE.MeshPhongMaterial({
      color: 0xffffff,
      specular: 0xffffff,
      specularMap: spec,
      map: texture,
      displacementMap: displace,
      normalMap: normal,
    });
    
    // Create each wall.
    for (var counter = 0; counter <= 3; counter++) {
      var geometry = new THREE.PlaneGeometry( 400, 200 );
      var wall = new THREE.Mesh(geometry, material);
      if (counter == 0) {
        wall.position.set(200, 100, 0);
        wall.rotation.y = -Math.PI/2;
      } else if (counter == 1) {
        wall.position.set(-200, 100, 0);
        wall.rotation.y = Math.PI/2;
      } else if (counter == 2) {
        wall.position.set(0, 100, 200);
        wall.rotation.y = Math.PI;
      } else {
        wall.position.set(0, 100, -200);
      }
      wall.receiveShadow = true;
      scene.add(wall);
    }
  });
}

function createCeiling() {
  // Create a ceiling.  
  var loader = new THREE.TextureLoader();
  loader.crossOrigin = "";
  loader.load( TEXTURE_PATH + 'ChippedPaint017_COL_VAR1_1K.jpg', function( texture ) {

    texture.anisotropy = renderer.getMaxAnisotropy();
    texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
    texture.repeat.set(4, 4);

    var normal = loader.load( TEXTURE_PATH + 'ChippedPaint017_NRM_1K.jpg');
    normal.anisotropy = renderer.getMaxAnisotropy();
    normal.wrapS = normal.wrapT = THREE.RepeatWrapping;
    normal.repeat.set(4, 4);

    var displace = loader.load( TEXTURE_PATH + 'ChippedPaint017_DISP_1K.jpg');
    displace.anisotropy = renderer.getMaxAnisotropy();
    displace.wrapS = displace.wrapT = THREE.RepeatWrapping;
    displace.repeat.set(4, 4);    
    
    var spec = loader.load( TEXTURE_PATH + 'ChippedPaint017_REFL_1K.jpg');
    spec.anisotropy = renderer.getMaxAnisotropy();
    spec.wrapS = spec.wrapT = THREE.RepeatWrapping;
    spec.repeat.set(4, 4);

    // Create the floor object.
    var material = new THREE.MeshPhongMaterial({
      color: 0xffffff,
      specular: 0xffffff,
      specularMap: spec,
      map: texture,
      displacementMap: displace,
      normalMap: normal,
    });
    var geometry = new THREE.PlaneGeometry( 400, 400 );
    var ceiling = new THREE.Mesh(geometry, material);
    ceiling.position.set(0, 200, 0);
    ceiling.rotation.x = Math.PI/2;
    //floor.rotation.y = Math.PI;
    scene.add(ceiling);
  });
}
            
          
!
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