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

              
                
              
            
!

CSS

              
                body {margin:0; overflow:hidden;}

              
            
!

JS

              
                
      var container;

			var camera, scene, renderer;

			var mouseX = 0, mouseY = 0;
      var mesh, materialShader;
			var windowHalfX = window.innerWidth / 2;
			var windowHalfY = window.innerHeight / 2;

			init();
			animate();

			function init() {

				container = document.createElement( 'div' );
				document.body.appendChild( container );

				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
				camera.position.z = 100;

				scene = new THREE.Scene();


        //LIGHTS
        
        var hemi = new THREE.HemisphereLight( 0x02c7dd, 0x080820, 1 );
        scene.add( hemi );
        var point = new THREE.PointLight( 0x94b1e0, 1, 82 );
        point.position.set( 50, 50, 50 );
        scene.add( point );        

				var manager = new THREE.LoadingManager();
				manager.onProgress = function ( item, loaded, total ) {

					console.log( item, loaded, total );

				};

				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 material = new THREE.MeshToonMaterial( { color: 0x6ADFFF, shininess: 30 } );;
				material.onBeforeCompile = function ( shader ) {
				shader.uniforms.time = { value: 0 };
				shader.vertexShader = 'uniform float time;\n' + shader.vertexShader;
				shader.vertexShader = shader.vertexShader.replace(
						'#include <begin_vertex>',
						[
							'float theta = sin( time + position.y ) / 2.0;',
							'float c = cos( theta );',
							'float s = sin( theta );',
							'mat3 m = mat3( c, 0, s, 0, 1, 0, -s, 0, c );',
							'vec3 transformed = vec3( position ) * m;',
							'vNormal = vNormal * m;'
						].join( '\n' )
					);
					materialShader = shader;
				};

				// model

				var loader = new THREE.OBJLoader( manager );
				loader.load( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/1037366/mes.obj', function ( object ) {

					object.traverse( function ( child ) {

						if ( child instanceof THREE.Mesh ) {

							child.material = material;

						}

					} );

					object.position.y = -22;
          object.scale.x = 7;
          object.scale.y = 7;
          object.scale.z = 7;
					scene.add( object );

				}, onProgress, onError );
        
				//
        
        //BACKGROUND
        
        var cylinder = new THREE.CylinderBufferGeometry( 20, 20, 32, 32 );
        cylinder.scale(-40, 40, 40);
        
        THREE.TextureLoader.prototype.crossOrigin = 'anonymous';

        var back = new THREE.MeshBasicMaterial({
        map: new THREE.TextureLoader().load( 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/1037366/rick2.jpg' )
        });
        
         mesh1 = new THREE.Mesh(cylinder, back);
         scene.add(mesh1);
         mesh1.position.z = -130;
         mesh1.rotation.y = 7;
         mesh1.rotation.x = -0.15;

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

				document.addEventListener( 'mousemove', onDocumentMouseMove, false );

				//

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

			}

			function onWindowResize() {

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

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

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

			}

			function onDocumentMouseMove( event ) {

				mouseX = ( event.clientX - windowHalfX ) / 4;

			}

			//

			function animate() {

				requestAnimationFrame( animate );
				render();

			}

			function render() {

				camera.position.x += ( mouseX - camera.position.x ) * .006;
				camera.lookAt( scene.position );
        
        
				if ( mesh ) {
					mesh.rotation.y += 0.05 * ( targetX - mesh.rotation.y );
					mesh.rotation.x += 0.05 * ( targetY - mesh.rotation.x );
				}
				if ( materialShader ) {
					materialShader.uniforms.time.value = performance.now() / 400;
				}

				renderer.render( scene, camera );
        renderer.domElement.id = 'c';
       
			}

// MODEL Mr. Meeseeks(https://sketchfab.com/models/14ac18210c954a3ebb1eafa789df8007) by AlmondFeather
              
            
!
999px

Console