Skip to content

Instantly share code, notes, and snippets.

@turner
Last active April 8, 2019 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turner/5db8957fe0a3daa927b6fcf073517b71 to your computer and use it in GitHub Desktop.
Save turner/5db8957fe0a3daa927b6fcf073517b71 to your computer and use it in GitHub Desktop.
SpotLight With Shadow. Near/Far Clip Planes Not Updating
import * as THREE from './threejs_es6/three.module.js';
class SpotLightDropShadow {
constructor({ color, intensity, shadowSize, near, far, doShowHelper}) {
let spotLight = new THREE.SpotLight( color, intensity );
spotLight.castShadow = true;
spotLight.shadow.mapSize.width = shadowSize;
spotLight.shadow.mapSize.height = shadowSize;
spotLight.shadow.camera.near = near;
spotLight.shadow.camera.far = far;
if (doShowHelper) {
this.shadowHelper = new THREE.CameraHelper(spotLight.shadow.camera);
}
this.spotLight = spotLight;
}
addToScene(scene) {
scene.add(this.spotLight.target);
scene.add(this.spotLight);
if (this.shadowHelper) {
scene.add(this.shadowHelper);
}
}
pose({ position, target, near, far }) {
this.spotLight.position.copy(position);
this.spotLight.target.position.copy(target);
this.spotLight.shadow.camera.near = near;
this.spotLight.shadow.camera.far = far;
this.spotLight.shadow.update(this.spotLight);
}
}
export default SpotLightDropShadow;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment