JSFiddle - React, Tailwind, and code Playground
JavaScript
var initScene, render,
projector, renderer, scene, ground, light,
camera, box, pointLight;
// projector = new THREE.Projector;
scene = new THREE.Scene;
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColorHex(0x0000ff, 1);
renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;
renderer.shadowMapType = THREE.PCFSoftShadowMap;
renderer.physicallyBasedShading = true;
document.body.appendChild( renderer.domElement );
// Light
light = new THREE.DirectionalLight( 0xFFFFFF );
light.position.set( 20, 80, 0 );
light.target.position.copy( scene.position );
scene.add( new THREE.DirectionalLightHelper(light, 2.5) );
light.castShadow = true;
// light.shadowCameraLeft = -60;
// light.shadowCameraTop = 60;
// light.shadowCameraRight = 60;
// light.shadowCameraBottom = -60;
// light.shadowCameraNear = 1;
// light.shadowCameraFar = 200;
// light.shadowBias = 10;
// light.shadowMapWidth = light.shadowMapHeight = 2040;
// light.shadowDarkness = .7;
// light.shadowCameraVisible = true;
scene.add( light );
box = new THREE.Mesh(
new THREE.CubeGeometry( 5, 5, 40 ),
new THREE.MeshLambertMaterial({
color: 0x00ff00,
// opacity: 0.7,
// transparent: true,
// depthWrite: false
}));
box.position.set( 10, 20, 10 );
box.castShadow = true;
scene.add(box);
ground = new THREE.Mesh(
new THREE.CubeGeometry(100, 1, 100),
new THREE.MeshLambertMaterial({
color: 0xff0000,
// opacity: 0.3,
// transparent: true
}));
ground.position.set( 0, 5, 0 );
ground.receiveShadow = true;
scene.add( ground );
camera = new THREE.PerspectiveCamera(
65, window.innerWidth / window.innerHeight, 1, 1000
);
camera.position.set( 100, 100, 100 );
camera.lookAt( scene.position );
scene.add( camera );
renderer.render( scene, camera );
scene.simulate();