Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <script>console.clear();</script>
<script src="https://unpkg.com/three@0.87.1/build/three.js"></script>
<script src="https://unpkg.com/three@0.87.1/examples/js/controls/OrbitControls.js"></script>
<script src="https://unpkg.com/three@0.87.1/examples/js/loaders/MTLLoader.js"></script>
<script src="https://unpkg.com/three@0.87.1/examples/js/loaders/OBJLoader.js"></script>
              
            
!

CSS

              
                canvas { display: block; }
html { overflow: hidden; background: #000; }
              
            
!

JS

              
                
const backgroundColor = 0x000000;

/*////////////////////////////////////////*/

var renderCalls = [];
function render () {
  requestAnimationFrame( render );
  renderCalls.forEach((callback)=>{ callback(); });
}
render();

/*////////////////////////////////////////*/

var scene = new THREE.Scene();

var camera = new THREE.PerspectiveCamera( 80, window.innerWidth / window.innerHeight, 0.1, 800 );
camera.position.set(0,0,14);
camera.lookAt(new THREE.Vector3(0,0,0));

var renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( backgroundColor );//0x );

renderer.toneMapping = THREE.LinearToneMapping;
renderer.toneMappingExposure = Math.pow( 0.94, 5.0 );

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

document.body.appendChild( renderer.domElement);

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

/* ////////////////////////////////////////////////////////////////////////// */

var controls = new THREE.OrbitControls( camera );

controls.rotateSpeed = 0.3;
controls.zoomSpeed = 0.9;

controls.minDistance = 3;
controls.maxDistance = 20;

//controls.minPolarAngle = 0; // radians
//controls.maxPolarAngle = Math.PI /2; // radians

controls.enableDamping = true;
controls.dampingFactor = 0.05;

renderCalls.push(function(){
  controls.update()
});


/* ////////////////////////////////////////////////////////////////////////// */


var light = new THREE.PointLight( 0xffffcc, 4, 65 );
light.position.set( 0, 20, 40 );
scene.add( light );

var light2 = new THREE.AmbientLight( 0x20202A, 6, 100 );
scene.add( light2 );

/* ////////////////////////////////////////////////////////////////////////// */


var geometry = new THREE.BoxBufferGeometry( 9, 0.1, 2 );
var scanMaterial = new THREE.MeshPhongMaterial({ 
  transparent: true, 
  opacity: 0.9, 
  color: 0x44ff44, 
  blending: THREE.AdditiveBlending
});
var scanCube = new THREE.Mesh( geometry, scanMaterial );
scene.add( scanCube );


/* ////////////////////////////////////////////////////////////////////////// */


renderer.localClippingEnabled = true;

var clipPlanes = [
  new THREE.Plane( new THREE.Vector3( 0, 5.8, 0 ), 0 )
];

var wireClipIn = new THREE.Plane( new THREE.Vector3( 0, 5.8, 0 ), 0 );
var wireClipOut = new THREE.Plane( new THREE.Vector3( 0, -5.8, 0 ), 0 );

var clipPlanesWireframe = [ wireClipIn, wireClipOut ];



var tl = new TimelineMax({ repeat: -1, yoyo: true, delay: 1, repeatDelay: 1 });


tl.from( scanCube.scale, 0.5, { x: 0, y: 0, ease: 'Power3.easeInOut' });

tl.fromTo( scanCube.position, 2, {
  y: 6.1,
},{
  y: -5.9,
  ease: 'Power4.easeInOut'
}, 0);

tl.fromTo( wireClipIn, 2, {
  constant: -1,
},{
  constant: 1,
  ease: 'Power4.easeInOut',
}, 0);

tl.to( scanCube.scale, 0.5, { x: 0, y: 0, ease: 'Power3.easeInOut' }, '-=0.5');

tl.addLabel('fillIn', '+=1');

tl.to( scanCube.scale, 0.5, { x: 1, y: 1, ease: 'Power3.easeInOut' }, 'fillIn');

tl.fromTo( scanCube.position, 2, {
  y: 6.1,
},{
  y: -5.9,
  ease: Power3.easeInOut
}, 'fillIn');

tl.fromTo( clipPlanes, 2, {
  constant: -1,
},{
  constant: 1,
  ease: 'Power4.easeInOut',
}, 'fillIn');

tl.fromTo( wireClipOut, 2, {
  constant: 1,
},{ 
  constant: -1,
  ease: 'Power4.easeInOut',
}, 'fillIn');

tl.to( scanCube.scale, 0.5, { x: 0, ease: 'Power3.easeInOut' },'-=0.5');


/* ////////////////////////////////////////////////////////////////////////// */
/* Scene Spin */

// tl.to(scene.rotation, 2, {
//   y: Math.PI * -2,
//   ease: 'Power3.easeInOut'
// }, 0);

// tl.to(scene.rotation, 2, {
//   y: Math.PI * 2,
//   ease: 'Power3.easeInOut'
// }, 'fillIn');

/* ////////////////////////////////////////////////////////////////////////// */
/* Load Model */


var mtlLoader = new THREE.MTLLoader();
mtlLoader.crossOrigin = true;
mtlLoader.setPath( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/39255/' );
mtlLoader.load( 'GameBoy.mtl', function( materials ) {

  materials.preload();
  var objLoader = new THREE.OBJLoader();
  console.log(materials);
  objLoader.setMaterials( materials );
  objLoader.setPath( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/39255/' );
  objLoader.load( 'GameBoy.obj', function ( object ) {
    
    for ( var key in materials.materials ) {
      materials.materials[key].reflectivity = 0.3; 
      materials.materials[key].shininess = 10; 
      materials.materials[key].side = THREE.DoubleSide;
      materials.materials[key].clippingPlanes = clipPlanes;
      materials.materials[key].clipIntersection = true;
      materials.materials[key].needsUpdate = true;
    }

    object.position.set(0, -5.5, -1);
    scanCube.position.set(0, 0, -0.75);
    //object.rotation.set(Math.PI / -2, 0, 0);

    scene.add( object );

    var clone = object.clone();
    clone.traverse(function(obj){
      if ( obj.material ) { 
        obj.material = new THREE.MeshPhongMaterial({ 
          wireframe: true, 
          color: 0x00FF00,
          clippingPlanes: clipPlanesWireframe,
          clipIntersection: false
        });
      }
    });
    scene.add(clone);

    tl.progress(1);
    tl.timeScale(2);
    tl.play();

  });
});

/* */


              
            
!
999px

Console