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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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 {
  font-family: Monospace;
  background-color: #000;
  color: #fff;
  margin: 0px;
  overflow: hidden;
}

.btn-explode {
  position: absolute;
  bottom: 20px;
  left: 50%;
}

              
            
!

JS

              
                var container,
  camera,
  scene,
  renderer,
  controls,
  raycaster,
  parts,
  mouse = new THREE.Vector2(),
  INTERSECTED;

init();
animate();

function init() {
  container = document.createElement("div");
  document.body.appendChild(container);

  // Camera
  camera = new THREE.PerspectiveCamera(
    10,
    window.innerWidth / window.innerHeight,
    1,
    2000
  );
  camera.position.set(100, 10, 300);

  controls = new THREE.OrbitControls(camera);
  controls.target.set(0, 0, 0);
  controls.update();

  scene = new THREE.Scene();
  scene.background = new THREE.Color(0x000000);
  //            scene.fog = new THREE.Fog(0xa0a0a0, 200, 1000);

  //            light = new THREE.HemisphereLight(0xffffff, 0x444444);
  //            light.position.set(0, 100, 0);
  //            scene.add(light);
  //
  //            light = new THREE.DirectionalLight(0xbfbfbf);
  //            light.position.set(0, 50, 0);
  //            light.castShadow = true;
  //            light.shadow.camera.top = 180;
  //            light.shadow.camera.bottom = -100;
  //            light.shadow.camera.left = -120;
  //            light.shadow.camera.right = 120;
  //            scene.add(light);

  var ambientLight = new THREE.AmbientLight(0xffffff, 0.4);
  scene.add(ambientLight);

  var pointLight = new THREE.PointLight(0xffffff, 0.3);
  camera.add(pointLight);
  scene.add(camera);

  // ground
  var mesh = new THREE.Mesh(
    new THREE.PlaneBufferGeometry(2000, 2000),
    new THREE.MeshPhongMaterial({
      color: 0xffffff,
      depthWrite: false
    })
  );
  mesh.rotation.x = -Math.PI / 2;
  mesh.receiveShadow = true;
  scene.add(mesh);

  //            var grid = new THREE.GridHelper(2000, 20, 0x000000, 0x000000);
  //            grid.material.opacity = 0.2;
  //            grid.material.transparent = true;
  //            scene.add(grid);

  // Model
  var onProgress = function(xhr) {
    if (xhr.lengthComputable) {
      var percentComplete = xhr.loaded / xhr.total * 100;
      console.log(Math.round(percentComplete, 2) + "% downloaded");
    }
  };

  var onError = function(xhr) {};

  var loader = new THREE.OBJLoader();
  loader.load(
    "https://raw.githubusercontent.com/nxhoang/Three.js-Fxb-and-Textures/master/models/obj/S19AOBA852.obj",
    function(object) {
      object.traverse(function(child) {
        if (child instanceof THREE.Mesh) {
          child.material = new THREE.MeshPhongMaterial({
            color: 0xffffff
          });
        }
      });
      scene.add(object);

      parts = object.children;
    },
    onProgress,
    onError
  );

  raycaster = new THREE.Raycaster();

  // Renderer
  renderer = new THREE.WebGLRenderer({
    antialias: true
  });
  renderer.setClearColor(0xf0f0f0);

  renderer.setPixelRatio(window.devicePixelRatio);
  renderer.setSize(window.innerWidth, window.innerHeight);
  renderer.sortObjects = false;
  container.appendChild(renderer.domElement);

  document.addEventListener("mousemove", onDocumentMouseMove, false);
  window.addEventListener("resize", onWindowResize, false);
}

function onWindowResize() {
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();

  renderer.setSize(window.innerWidth, window.innerHeight);
}

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

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

// Animation
function animate() {
  requestAnimationFrame(animate);
  render();
}

function render() {
  //            theta += 0.1;
  //
  //            camera.position.x = radius * Math.sin(THREE.Math.degToRad(theta));
  //            camera.position.y = radius * Math.sin(THREE.Math.degToRad(theta));
  //            camera.position.z = radius * Math.cos(THREE.Math.degToRad(theta));
  //            camera.lookAt(scene.position);
  //
  //            camera.updateMatrixWorld();

  // find intersections
  //if (skull){
  raycaster.setFromCamera(mouse, camera);

  var intersects = raycaster.intersectObjects(scene.children, true);

  if (intersects.length > 0) {
    if (INTERSECTED != intersects[0].object) {
      if (INTERSECTED)
        INTERSECTED.material.emissive.setHex(INTERSECTED.currentHex);

      INTERSECTED = intersects[0].object;

      if (INTERSECTED.name !== "") {
        INTERSECTED.currentHex = INTERSECTED.material.emissive.getHex();
        INTERSECTED.material.emissive.setHex(0xff0000);
      }
    }
  } else {
    if (INTERSECTED)
      INTERSECTED.material.emissive.setHex(INTERSECTED.currentHex);

    INTERSECTED = null;
  }
  //}
  renderer.render(scene, camera);
}

function ExplodeProduct() {
  //            alert(parts.length);
  //            parts[0].position.setX(10);

  parts.forEach(function(i, v) {
    //                alert(i.position.x + ", " + i.position.y + ", " + i.position.z);

    i.position.setX(10);
    i.position.setY(10);
    i.position.setZ(10);
  });
}

              
            
!
999px

Console