SCENE
with orbitControls, XZgrid, info
by Bai Shiuan Huang
HTML
<div id="info">HW 002<br>
<button id="cameraToggle">Camera Toggle</button>
<button id="lightToggle">Gallery Light Toggle</button>
<br>
Spotlight Intensity <input type="range" id='myRange' min="1" max="100" value="50">
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/94/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://jyunming-chen.github.io/tutsplus/js/KeyboardState.js"></script>
CSS
#info {
position: absolute;
top: 0px;
width: 100%;
padding: 10px;
text-align: center;
color: #ffff00;
}
body {
overflow: hidden;
}
JavaScript
var camera, scene, renderer, camera2;
var keyboard = new KeyboardState();
var angle = 0, lights = [], light1, toggle1 = false, toggle2 = false;
class makeSpotLight{
constructor(pos, look){
this.mesh = new THREE.Object3D();
let cylinder = new THREE.Mesh(new THREE.CylinderGeometry( 1, 5, 10, 32 ), new THREE.MeshPhongMaterial({color:0x38daff}));
cylinder.rotation.x = -Math.PI/2;
this.mesh.add(cylinder);
this.mesh.position.copy(pos);
this.mesh.lookAt(look.position);
scene.add(this.mesh);
this.light = new THREE.SpotLight( 0xffffff );
this.light.target = look;
this.light.position.copy(pos);
this.light.castShadow = true;
this.light.shadow.mapSize.width = 1024;
this.light.shadow.mapSize.height = 1024;
this.light.distance = 150;
this.light.angle = Math.PI/4;
this.light.shadow.camera.near = 100;
this.light.shadow.camera.far = 500;
this.light.shadow.camera.fov = 50;
scene.add(this.light);
}
}
init();
animate();
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 1000);
//camera.position.z = 50;
camera.position.y = 450;
camera.lookAt(0, 0, 0);
camera2 = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 1000);
camera2.position.y = 300;
camera2.position.z = 200;
camera2.position.x = -200;
camera2.lookAt(0, 0, 0);
scene.add(camera);
scene.add(camera2);
var light2 = new THREE.AmbientLight(0xffffff, 0.3);
light1 = new THREE.DirectionalLight( 0xffffff, 1, 100 );
light1.position.set( 0, 1, 0 ); //default; light shining from top
light1.castShadow = true; // default false
//Set up shadow properties for the light
light1.shadow.mapSize.width = 512; // default
light1.shadow.mapSize.height = 512; // default
light1.shadow.camera.near = 0.5; // default
light1.shadow.camera.far = 500; // default
scene.add(light1, light2);
//scene.add(new...