Pen Settings



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


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


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.


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.


                <!-- My scene -->
<canvas id="scene"></canvas>
<!-- Video used as texture -->
<video controls crossOrigin="Anonymous" muted autoplay playsinline>
  <source src=""/>

  I created a collection of small examples in Three.js to understand very quickly the purpose of some functions.
  You can visit the 'website' of the entire collection of pens here :

  You can also see the collection in CodePen

  Do not hesitate to comment if there is something wrong (I'm still learning)

  Thanks !


  margin: 0;
  overflow: hidden;

  position: absolute;
  top: 0;
  left: 0;


                var renderer, scene, camera, cube, texture, canvas, ctx, video;

var ww = window.innerWidth,
	wh = window.innerHeight;

function init(){

	renderer = new THREE.WebGLRenderer({canvas : document.getElementById('scene')});

	scene = new THREE.Scene();

	camera = new THREE.PerspectiveCamera(50,ww/wh, 0.1, 10000 );
  //Select the video element in the DOM
  video = document.querySelector("video");
  //Mute the sound of the video
  video.muted = true;
  //Loop the video to play it infinitely
  video.loop = true;
  video.crossOrigin = 'anonymous';
  //Add event listener to check when the video is enough loaded to be played
  video.addEventListener("canplay", onVideoReady);
  //Hack for mobile & tablet
  renderer.domElement.addEventListener("click", function(){;

var onVideoReady = function(){
    //Start the video;
    //Create a canvas to draw the video on it
    canvas = document.createElement("canvas");
    //Get the context of the canvas
    ctx = canvas.getContext("2d");
    //Set the dimension of the canvas --> Should always be power of 2 (256,512,1024, etc)
    canvas.width = 512;
    canvas.height = 512;
  document.body.appendChild(canvas);"absolute"; = "0px"; = "0px"; = "50px";
    //Create a plane in our scene

    //Render the scene and start request animation frame
    //Remove the event listener on 'canplay' event
    video.removeEventListener("canplay", onVideoReady);
var createPlane = function(){

  //Create a texture from the canvas
  texture = new THREE.CanvasTexture(canvas);
	//Create a plane geometry
	var geometry = new THREE.BoxBufferGeometry(150,150,150);
  //Create a Basic material with the texture as map
	var material = new THREE.MeshBasicMaterial({
    map : texture
  //Create a mesh from the geometry and the material
	cube = new THREE.Mesh(geometry, material);

	//Add the plane in the scene

var render = function () {
  //Draw the video in the canvas
  ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
  //Warn ThreeJs that the texture should be updated
  texture.needsUpdate = true;
  //Rotate the cube
  cube.rotation.x += 0.004;
  cube.rotation.y += 0.004;
  cube.rotation.z += 0.004;

	//Render the scene into the canvas
	renderer.render(scene, camera);