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

              
                <script src="https://threejs.org/build/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.3.4/gsap.min.js"></script>
<script src="https://threejs.org/examples/js/libs/dat.gui.min.js"></script>

<div class="btnList">
<!--     <button class="animate" id="camMove">
      Ball One
    </button> -->
  <button class="animate" id="camMove" onclick="moveCamera()">Ball One</button>
    <button class="animate" id="camMoveTwo">
      Ball Two
    </button>
  <button class="animate" id="camMoveThree">
      Ball Three
    </button>
  <button class="animate" id="camMoveFour">
      Ball Four
    </button>
  <button class="animate" id="camMoveFive">
      Ball Five
    </button>
  <button class="animate" id="camMoveSix">
      Ball Six
    </button>
  <button class="animate" id="camMoveSev">
      Ball Seven
    </button>
 </div>

<!-- <div class="buttons">
  <button class="animate" id="camMove">Ball One</button>
  <button>Ball Two</button>
  <button>Ball Three</button>
</div>
 -->
              
            
!

CSS

              
                body {
    overflow: hidden;
	  margin: 0;
}

.btnList {
  position: absolute;
}

.animate {
  background-color: #4CAF55; 
  border: none;
  color: white;
  padding: 10px 20px;
  text-align: center;
  text-decoration: none;
/*   display: inline-block; */
  display: flex;
  flex-direction: column;
  font-size: 14px;
  margin: 10px;
  cursor: pointer;
}

#camMove {
  background-color: #0000ff;
}

#camMoveTwo {
  background-color: #ff0000;
}

#camMoveThree {
  background-color: #009900;
}

#camMoveFour {
  background-color: #e67300;
}

#camMoveFive {
  background-color: #9900cc;
}

#camMoveSix {
  background-color: #ffcc00;
}

#camMoveSev {
  background-color: #99ccff;
}

              
            
!

JS

              
                var camera, scene, renderer;
var geometry, material, mesh;
var controls;
var testGroup;

init();
animate();

function init() {  
  scene = new THREE.Scene();
  
  camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.01, 1000);
  camera.position.set(0, 20, 50);  
  
  amLights = new THREE.AmbientLight( 0x404040, 0.75 );
  scene.add(amLights);

  renderer = new THREE.WebGLRenderer({
    antialias: true
  });
  renderer.setSize(window.innerWidth, window.innerHeight);
  renderer.setPixelRatio(window.devicePixelRatio);
	renderer.setClearColor(0x000000);
  document.body.appendChild(renderer.domElement);

  controls = new THREE.OrbitControls(camera, renderer.domElement);
  controls.zoomSpeed = 2.0;
	controls.panSpeed = 0.5;
}


testGroup = new THREE.Group();
               

//Spheres
ball1 = new THREE.SphereGeometry(0.3, 50, 50);
material = new THREE.MeshBasicMaterial({ color: 0x0000ff });
ballOne = new THREE.Mesh(ball1, material);
ballOne.position.set(-17.6, 0, 28.9);
// ballOne.lookAt(camera.position);
// scene.add(ballOne);
testGroup.add(ballOne);

document.querySelector("#camMove").onclick = function(){
  var aabb = new THREE.Box3().setFromObject( ballOne );
  var center = aabb.getCenter( new THREE.Vector3() );
  var size = aabb.getSize( new THREE.Vector3() );
  
   gsap.to( controls.target, {
    duration: 0.5,
    x: center.x,
    y: center.y,
    z: center.z,
    ease: "power2.in",
    onUpdate: function() {
      controls.update( center );
    }
  } );
  
  gsap.to( camera.position, {
    delay: 0.6,
    duration: 2,
    // ease: "power2.in",
    ease: "power2.out",
    y: center.y + size.y,
    // x: center.,
    // z: center.z,
    
    onUpdate: function() {
      camera.lookAt( center );
      // camera.lookAt(ballOne.center)
    }
  } ); 
}


ball2 = new THREE.SphereGeometry(0.5, 50, 50);
material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
ballTwo = new THREE.Mesh(ball2, material);
ballTwo.position.set(2, -1, -12.9);
testGroup.add(ballTwo);

document.querySelector("#camMoveTwo").onclick = function(){
  var aabb = new THREE.Box3().setFromObject( ballTwo );
  var center = aabb.getCenter( new THREE.Vector3() );
  var size = aabb.getSize( new THREE.Vector3() );  
  
   gsap.to( controls.target, {
    duration: 0.5,
    x: center.x,
    y: center.y,
    z: center.z,
    ease: "power2.in",
    onUpdate: function() {
      controls.update();
    }
  } );
  
  gsap.to( camera.position, {
    delay: 0.6,
    duration: 2,
    // ease: "power2.in",
    ease: "power2.out",
    x: center.x,
    y: center.y,    
    z: center.z + size.z * 2,
    onUpdate: function() {
      camera.lookAt( center );
    }
  } ); 
}


ball3 = new THREE.SphereGeometry(1, 50, 50);
material = new THREE.MeshBasicMaterial({ color: 0x009900 });
ballThree = new THREE.Mesh(ball3, material);
ballThree.position.set(16, 1, 8);
testGroup.add(ballThree);

document.querySelector("#camMoveThree").onclick = function(){
  var aabb = new THREE.Box3().setFromObject( ballThree )
  var center = aabb.getCenter( new THREE.Vector3() );
  var size = aabb.getSize( new THREE.Vector3() );  
   
  gsap.to( controls.target, {
    duration: 0.5,
    x: center.x,
    y: center.y,
    z: center.z,    
    ease: "power2.in",
    onUpdate: function() {
      controls.update();
    }
  } );
  
   gsap.to( camera.position, {
    delay: 0.6,
    duration: 2,
    ease: "power2.out",
    x: center.x, 
    y: center.y,
    z: center.z + size.z * 2,
    onUpdate: function() {
      camera.lookAt( center );
    }
  } ); 
}

ball4 = new THREE.SphereGeometry(1.5, 50, 50);
material = new THREE.MeshBasicMaterial({ color: 0xe67300 });
ballFour = new THREE.Mesh(ball4, material);
ballFour.position.set(-6, -2.5, 18);
testGroup.add(ballFour);

document.querySelector("#camMoveFour").onclick = function(){
  var aabb = new THREE.Box3().setFromObject( ballFour );
  var center = aabb.getCenter( new THREE.Vector3() );
  var size = aabb.getSize( new THREE.Vector3() );
  
  gsap.to( controls.target, {
    duration: 0.5,
    x: center.x,
    y: center.y,
    z: center.z,    
    ease: "power2.in",
    onUpdate: function() {
      controls.update();
    }
  } );
  
   gsap.to( camera.position, {
    delay: 0.6,
    duration: 2,
    // ease: "power2.in",
    ease: "power2.out",
    x: center.x, 
    y: center.y,
    z: center.z + size.z * 2,
    onUpdate: function() {
      camera.lookAt( center );
    }
  } );  
}

ball5 = new THREE.SphereGeometry(2, 50, 50);
material = new THREE.MeshBasicMaterial({ color: 0x9900cc });
ballFive = new THREE.Mesh(ball5, material);
ballFive.position.set(-26, 2.1, -32);
testGroup.add(ballFive);

document.querySelector("#camMoveFive").onclick = function() {
  var aabb = new THREE.Box3().setFromObject( ballFive );
  var center = aabb.getCenter( new THREE.Vector3() );
  var size = aabb.getSize( new THREE.Vector3() );
  
  gsap.to( controls.target, {
    duration: 0.5,
    x: center.x,
    y: center.y,
    z: center.z,
    ease: "power2.in",
    onUpdate: function() {
      controls.update();
    }
  } );
  
   gsap.to( camera.position, {
    delay: 0.6,
    duration: 2,
    ease: "power2.out",
    x: center.x, 
    y: center.y,
    z: center.z + size.z * 2,
    onUpdate: function() {
      camera.lookAt( center );
    }
  } );  
}


ball6 = new THREE.SphereGeometry(3.5, 50, 50);
material = new THREE.MeshBasicMaterial({ color: 0xffcc00 });
ballSix = new THREE.Mesh(ball6, material);
ballSix.position.set(20, -3, -28);
testGroup.add(ballSix);

document.querySelector("#camMoveSix").onclick = function(){
  var aabb = new THREE.Box3().setFromObject( ballSix );
  var center = aabb.getCenter( new THREE.Vector3() );
  var size = aabb.getSize( new THREE.Vector3() );
  
  gsap.to( controls.target, {
    duration: 0.5,
    x: center.x,
    y: center.y,
    z: center.z,
    ease: "power2.in",
    onUpdate: function() {
      controls.update();
    }
  } );
  
   gsap.to( camera.position, {
    delay: 0.6,
    duration: 2,
    // ease: "power2.in",
    ease: "power2.out",
    x: center.x,
    y: center.y,
    z: center.z + size.z * 2,
    onUpdate: function() {
      camera.lookAt( center );
    }
  } );  
}

ball7 = new THREE.SphereGeometry(0.75, 50, 50);
material = new THREE.MeshBasicMaterial({ color: 0x99ccff });
ballSeven = new THREE.Mesh(ball7, material);
ballSeven.position.set(20, 3, 35);
testGroup.add(ballSeven);

document.querySelector("#camMoveSev").onclick = function(){
  var aabb = new THREE.Box3().setFromObject( ballSeven );
  var center = aabb.getCenter( new THREE.Vector3() );
  var size = aabb.getSize( new THREE.Vector3() );
  
  gsap.to( controls.target, {
    duration: 0.5,
    x: center.x,
    y: center.y,
    z: center.z,
    ease: "power2.in",
    onUpdate: function() {
      controls.update();
    }
  } );
  
   gsap.to( camera.position, {
    delay: 0.6,
    duration: 2,
    // ease: "power2.in",
    ease: "power2.out",
    x: center.x,
    y: center.y,
    z: center.z + size.z * 2,
    onUpdate: function() {
      camera.lookAt( center );
    }
  } );  
}

scene.add(testGroup);

//grid
var grid = new THREE.GridHelper(100, 25);
grid.material.opacity = 0.5;
grid.material.transparent = true;
scene.add(grid);

// dat.gui
// var gui = new dat.GUI();

// var parameters = {
//   reset: function() {
//     resetScene()
//   }
// };
// gui.open();

function resetScene() {
  gsap.to( camera.position, {
    duration: 1,  
    x: 0,
    y: 20,
    z: 50,
    onUpdate: function () {
      camera.updateProjectionMatrix();
      controls.update();
    }
  } );

gsap.to( controls.target, {
  duration: 1,
  x: 0,
  y: 0,
  z: 0,
  onUpdate: function () {
    controls.update();
    }
  } );
}
// gui.add( parameters, 'reset' ).name( "Reset Scene" );
//************ END SCENE RESET *********************



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

function render() {
  // plane.lookAt( camera.position );
  renderer.render(scene, camera);
}

              
            
!
999px

Console