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

              
                <div class='root' id='root'/>
              
            
!

CSS

              
                body {
	background-color: #000;
	margin: 0px;
	overflow: hidden;
}
.root {
  width: 100%;
  height: 100%
}
              
            
!

JS

              
                var container = document.getElementById('root')
var renderer = new THREE.WebGLRenderer({antialias: true});
    renderer.setPixelRatio(window.devicePixelRatio)
	  renderer.setSize( window.innerWidth, window.innerHeight );

    //renderer.shadowMap.enabled = true;
    renderer.shadowMap.type = THREE.PCFShadowMap; // default THREE.PCFShadowMap
    //renderer.shadowMap.autoUpdate = false;
    //renderer.shadowMap.needsUpdate = true;

    document.body.appendChild( renderer.domElement );
    var scene = new THREE.Scene();
    var camera = new THREE.PerspectiveCamera( 50, window.innerWidth/window.innerHeight, 0.1, 1000 );
    let controls = new THREE.TrackballControls( camera, renderer.domElement );
    let stats = new Stats();
    container.appendChild( stats.dom );

    var light = new THREE.DirectionalLight(0xffffff, 1)
    light.position.set(100,10,50)
    var target = new THREE.Object3D()
    target.position.set(0,0,0)
    light.target = target
    scene.add(light.target)

    light.shadow.camera.left = -10
    light.shadow.camera.right = 10
    light.shadow.camera.top = 10
    light.shadow.camera.bottom = -10
    light.shadow.camera.near = 10
    light.shadow.camera.far = 400
    light.shadow.mapSize.width = 512

      //Create a helper for the shadow camera (optional)
    var helper = new THREE.CameraHelper( light.shadow.camera );


    light.castShadow = true



    scene.add(new THREE.AmbientLight(0x333333))

    camera.position.set(10,10,10);
    camera.lookAt(new THREE.Vector3(0,0,0))



    var geometry = new THREE.BoxBufferGeometry( 5, 5, 5 );
    var material = new THREE.MeshPhongMaterial( { color: 0x00ff00, specular: 0x303030, emissive: 0x202020 } );
    var cube = new THREE.Mesh( geometry, material );
    cube.translateZ(2.5)
    cube.castShadow = true
      
    var planeGeo = new THREE.PlaneGeometry(20,20)
    var material1 = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x303030, emissive: 0x202020,/* map: texture*/ } );
    var plane = new THREE.Mesh(planeGeo, material1)
    plane.receiveShadow = true

    let shadowCube = new THREE.ShadowMesh(cube)
    let lightPosition4D = new THREE.Vector4();
		lightPosition4D.x = light.position.x;
		lightPosition4D.y = light.position.y;
		lightPosition4D.z = light.position.z;
				// amount of light-ray divergence. Ranging from:
				// 0.001 = sunlight(min divergence) to 1.0 = pointlight(max divergence)
		lightPosition4D.w = 0.001;
			var normalVector = new THREE.Vector3( 0, 0, 1 );
			var planeConstant = 0.01; // this value must be slightly higher than the groundMesh's y position of 0.0
			var groundPlane = new THREE.Plane( normalVector, planeConstant );

    scene.add(shadowCube)
shadowCube.update(groundPlane, lightPosition4D);
    scene.add(camera)
    scene.add(cube)
    scene.add(plane)
    scene.add(light)
    scene.add( helper )
    var animate = function () {
      requestAnimationFrame( animate );
      controls.update();
       stats.update();
      renderer.render(scene, camera);
		};

    animate();
              
            
!
999px

Console