SCENE

with orbitControls, XZgrid, info

by Bai Shiuan Huang

HTML

<div id="info">HW 002<br>
<button id="lightToggle">Gallery Light Toggle</button>
<br>
  Spotlight Intensity <input type="range" id='myRange' min="1" max="100" value="50">
</div>
<div id = "text">
BBCA
</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;
}

#text {
  position: absolute;
  bottom: 0px;
  width: 100%;
  padding: 10px;
}

body {
  overflow: hidden;
}

JavaScript

var camera, scene, renderer, camera2;
var sceneHUD, cameraHUD;
var keyboard = new KeyboardState();
var angle = 0, lights = [], light1, 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);
  /////////////////////////////////////////////////////////////
  sceneHUD = new THREE.Scene();
  cameraHUD = new THREE.OrthographicCamera(-10, 10, 10, -10, -10, 1600);
  var fframe = new THREE.Mesh(new THREE.PlaneGeometry(20, 0.5), new THREE.MeshBasicMaterial({
    color: 0x000000,
    depthTest: false
  }));
  var fframe1 = new THREE.Mesh(new THREE.PlaneGeometry(0.5, 20), new THREE.MeshBasicMaterial({
    color: 0x000000,
    depthTest: false
  }));
  var fleft = fframe1.clone();
  fleft.position.set(10, 0, 0);
 ...