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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div id="threejs-container"></div>
<h3>Check out the <a href="https://github.com/ZachSaucier/threejs-camera-spline-follower">GitHub page</a></h3>
              
            
!

CSS

              
                /* For more check out zachsaucier.com */
html, body { margin: 0; overflow: hidden; }
h3 {
  position: absolute;
  bottom: 0;
  font-family: sans-serif;
  color: white;
  padding-left: 10px;
}
              
            
!

JS

              
                // Get our container
var container = document.getElementById("threejs-container");

var scene, renderer, camera;

var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;

// Create some sample curves that can be used
var CinquefoilKnot = THREE.Curve.create(
	function( s ) {
		this.scale = ( s === undefined ) ? 10 : s;
	},
	function( t ) {
		var p = 2,
			q = 5;
		t *= Math.PI * 2;
		var tx = ( 2 + Math.cos( q * t ) ) * Math.cos( p * t ),
			ty = ( 2 + Math.cos( q * t ) ) * Math.sin( p * t ),
			tz = Math.sin( q * t );
		return new THREE.Vector3( tx, ty, tz ).multiplyScalar( this.scale );
	}
);

var sampleClosedSpline = new CinquefoilKnot();

// Keep a dictionary of curve instances
var splines = {
  SampleClosedSpline: sampleClosedSpline
};

// Initialize our project and start animating
init();
animate();

// Setup our scene
function init() {

  scene = new THREE.Scene();

  // Add some lights
  var light = new THREE.DirectionalLight(0xffffff);
  light.position.set(0, 0, 1);
  scene.add(light);

  light = new THREE.DirectionalLight(0xffffff);
  light.position.set(0, 0, -1);
  scene.add(light);

  //
  // Use the plugin to follow the curve
  camera = initFollowCamera(scene, 0);

  addTube(splines["SampleClosedSpline"], 100, true, 6, null, null, THREE.BackSide, 0x2194ce);

  //

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

  //

  window.addEventListener('resize', onWindowResize, false);

}

function onWindowResize() {

  windowHalfX = window.innerWidth / 2;
  windowHalfY = window.innerHeight / 2;

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

}

//

function animate() {

  requestAnimationFrame(animate);

  render();

}

function render() {

  // Any other rendering you want to do

  renderFollowCamera();

  renderer.render(scene, splineCamera);

}
              
            
!
999px

Console