2022-11-07 14:23:59 +00:00
|
|
|
import * as THREE from 'three'
|
|
|
|
|
|
|
|
export class ThreePointLight {
|
|
|
|
private readonly shadowBuffer: THREE.WebGLRenderTarget
|
|
|
|
private readonly light: THREE.PerspectiveCamera
|
|
|
|
|
|
|
|
constructor () {
|
2024-10-13 17:37:01 +00:00
|
|
|
this.shadowBuffer = new THREE.WebGLRenderTarget(2048.0, 2048.0)
|
2022-11-07 14:23:59 +00:00
|
|
|
this.shadowBuffer.depthBuffer = true
|
|
|
|
this.shadowBuffer.depthTexture = new THREE.DepthTexture(0, 0)
|
|
|
|
|
2024-10-13 17:37:01 +00:00
|
|
|
this.light = new THREE.PerspectiveCamera(35.0, this.shadowBuffer.width / this.shadowBuffer.height, 0.1, 1000.0)
|
|
|
|
this.light.lookAt(0.0, 0.0, 0.0)
|
2022-11-07 14:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ziggle (frame: number) {
|
2024-10-13 17:37:01 +00:00
|
|
|
const e = frame * 10.0
|
2022-11-07 14:23:59 +00:00
|
|
|
|
|
|
|
this.light.position.copy(new THREE.Vector3(
|
|
|
|
this.light.position.x * Math.sin(e),
|
|
|
|
this.light.position.y,
|
2024-10-13 17:37:01 +00:00
|
|
|
this.light.position.z * Math.cos(e),
|
2022-11-07 14:23:59 +00:00
|
|
|
))
|
|
|
|
|
2024-10-13 17:37:01 +00:00
|
|
|
this.light.lookAt(0.0, 0.0, 0.0)
|
2022-11-07 14:23:59 +00:00
|
|
|
this.light.updateProjectionMatrix()
|
|
|
|
}
|
|
|
|
|
|
|
|
getLight () {
|
|
|
|
return this.light
|
|
|
|
}
|
|
|
|
|
|
|
|
getLightPosition () {
|
|
|
|
return this.light.position
|
|
|
|
}
|
|
|
|
|
|
|
|
getShadowMap () {
|
|
|
|
return this.shadowBuffer.depthTexture
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy () {
|
|
|
|
this.shadowBuffer.dispose()
|
|
|
|
}
|
|
|
|
}
|