Last active
April 8, 2019 20:10
-
-
Save turner/5db8957fe0a3daa927b6fcf073517b71 to your computer and use it in GitHub Desktop.
SpotLight With Shadow. Near/Far Clip Planes Not Updating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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