Pen Settings

HTML

CSS

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

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

              
                <head>
	
	<script src="../js/stats.min.js"></script>
	
	<meta name='viewport'  content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' />
     
	<style>
		body { margin: 0; touch-action: none;}
		canvas { width: 100%; height: 100% ; touch-action: none;}
		
	</style>
	
	<script  type="module">

		 import * as THREE from  'https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.module.js';

		// Basic Threejs variables
		var scene;
		var camera;
		var renderer;
		var clock;
	
		// main light
		var light;
		
		function init()
		{
		
			clock = new THREE.Clock();
			scene = new THREE.Scene();
			
			// ---------------- RENDERER ----------------
			
			renderer = new THREE.WebGLRenderer( { antialias : true } );
			renderer.setPixelRatio( window.devicePixelRatio  );
			renderer.setSize( window.innerWidth, window.innerHeight );
			renderer.shadowMap.enabled = true; 							// IMPORTANT FOR SHADOWS !!!
			document.body.appendChild( renderer.domElement );
			
			// ---------------- CAMERA ----------------
			
			camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
			camera.position.set( -7, 15, -15 );
			camera.lookAt(new THREE.Vector3(0,0,0));
			scene.add( camera );
			
			// ---------------- LIGHTS ----------------
			
			var ambientLight = new THREE.AmbientLight( 0xcccccc, 0.2 );
			scene.add( ambientLight );
			
			//POINTLIGHT , FOR SHADOWS
			const color = 0xFFFFFF;
			const intensity = 0.5;
			light = new THREE.PointLight(color, intensity);
			light.castShadow = true; 								// IMPORTANT FOR SHADOWS !!!
			light.position.set(0, 10, 0);
			scene.add(light);

			const helper = new THREE.PointLightHelper(light);
			scene.add(helper);
			
			// ---------------- EVENTS ----------------
			
			window.addEventListener( 'resize', onWindowResize, false );
			
			// ---------------- SCENE 3D ELEMENTS ----------------
			
			//PLANE
			const planeGeo = new THREE.PlaneGeometry(100, 100);
			const planeMat = new THREE.MeshPhongMaterial({ color : 'white',side: THREE.DoubleSide});
			const meshplane = new THREE.Mesh(planeGeo, planeMat);
			meshplane.receiveShadow = true;						// IMPORTANT FOR SHADOWS !!!
			meshplane.rotation.x = Math.PI /2;
			scene.add(meshplane);
			
			//CUBE
			const cubeGeo = new THREE.BoxGeometry(2, 2, 2);
			const cubeMat = new THREE.MeshPhongMaterial({color: '#8AC'});
			const meshcube = new THREE.Mesh(cubeGeo, cubeMat);
			meshcube.castShadow = true;						// IMPORTANT FOR SHADOWS !!!
			meshcube.position.set(5, 1, 5);
			scene.add(meshcube);
			
			//SPHERE
			const sphereGeo = new THREE.SphereGeometry(2, 32, 32);
			const sphereMat = new THREE.MeshPhongMaterial({color: '#CA8'});
			const meshsphere = new THREE.Mesh(sphereGeo, sphereMat);
			meshsphere.castShadow = true;						// IMPORTANT FOR SHADOWS !!!
			meshsphere.position.set(-5, 2, -5);
			scene.add(meshsphere);
			
			// ---------------- STARTING THE GAME MAIN LOOP ----------------

			render();
		}
		
		function render()
		{
	
			var delta = clock.getDelta();  		//get delta time between two frames
			var elapsed = clock.elapsedTime; 	//get elapsed time
			
			light.position.y = Math.sin(elapsed) * 8 + 10 ; // floating light 
			
			renderer.render( scene, camera ); 	// We are rendering the 3D world
			requestAnimationFrame( render );	// we are calling render() again,  to loop
		}
		
		function onWindowResize()
		{
			camera.aspect = window.innerWidth / window.innerHeight;
			camera.updateProjectionMatrix();

			renderer.setSize( window.innerWidth, window.innerHeight );
		}
	
		init();
		
	</script>
	
</head>

<body>

</body>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console