in backup/renderers/renderer-gsi-gl2/src/GSIGL2Renderer.ts [580:669]
private initLights() {
if (this.props.lights) {
// gltf to three
if (this.props.lights.ambientLight) {
const name = 'AmbientLight'
let aLight: THREE.AmbientLight = this.lights.getObjectByName(name) as THREE.AmbientLight
if (!aLight) {
aLight = new THREE.AmbientLight()
this.lights.add(aLight)
}
if (this.props.lights.ambientLight.color) {
aLight.color = new THREE.Color(colorToString(this.props.lights.ambientLight.color))
}
aLight.intensity = this.props.lights.ambientLight.intensity ?? 1.0
aLight.name = name
aLight.matrixAutoUpdate = false
}
if (this.props.lights.directionalLights) {
const dLights = this.props.lights.directionalLights
dLights.forEach((item, index) => {
const name = 'DirectionalLight.' + index
let dlight: THREE.DirectionalLight = this.lights.getObjectByName(
name
) as THREE.DirectionalLight
if (!dlight) {
dlight = new THREE.DirectionalLight()
this.lights.add(dlight)
}
if (item.color) {
dlight.color = new THREE.Color(colorToString(item.color))
}
if (item.position) {
dlight.position.copy(item.position as THREE.Vector3)
}
dlight.intensity = item.intensity ?? 1.0
dlight.matrixAutoUpdate = false
dlight.name = name
dlight.updateMatrix()
dlight.updateMatrixWorld(true)
})
// Remove
this.lights.children.forEach((item) => {
const type = item.name.split('.')[0]
const i = item.name.split('.')[1]
if (i === undefined) return
const index = parseInt(i)
if (isNaN(index)) return
if (type === 'DirectionalLight' && index >= dLights.length) {
this.lights.remove(item)
}
})
}
if (this.props.lights.pointLights) {
const pLights = this.props.lights.pointLights
pLights.forEach((item, index) => {
const name = 'PointLight.' + index
let plight: THREE.PointLight = this.lights.getObjectByName(name) as THREE.PointLight
if (!plight) {
plight = new THREE.PointLight()
this.lights.add(plight)
}
if (item.color) {
plight.color = new THREE.Color(colorToString(item.color))
}
if (item.position) {
plight.position.copy(item.position as THREE.Vector3)
}
plight.intensity = item.intensity ?? 1.0
plight.distance = item.range ?? 0.0
plight.decay = 2 // physical
plight.name = name
plight.matrixAutoUpdate = false
plight.updateMatrix()
plight.updateMatrixWorld(true)
})
// Remove
this.lights.children.forEach((item) => {
const type = item.name.split('.')[0]
const i = item.name.split('.')[1]
if (i === undefined) return
const index = parseInt(i)
if (isNaN(index)) return
if (type === 'PointLight' && index >= pLights.length) {
this.lights.remove(item)
}
})
}
}
}