UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

98 lines (75 loc) 2.36 kB
import { Color } from "../../../../../core/color/Color.js"; import Vector1 from "../../../../../core/geom/Vector1.js"; import Vector3 from "../../../../../core/geom/Vector3.js"; import { AbstractLight } from "./AbstractLight.js"; export class PointLight extends AbstractLight { /** * @readonly * @type {Vector3} */ position = new Vector3(); /** * @readonly * @type {Vector1} */ radius = new Vector1(1); /** * @readonly * @type {Color} */ color = new Color(1, 1, 1); /** * @readonly * @type {Vector1} */ intensity = new Vector1(1); getCenter(result) { this.position.writeToArray(result, 0); } getAABB(result) { const r = this.radius.getValue(); const p = this.position; const center_x = p.x; const center_y = p.y; const center_z = p.z; result[0] = center_x - r; result[1] = center_y - r; result[2] = center_z - r; result[3] = center_x + r; result[4] = center_y + r; result[5] = center_z + r; } onDimensionChanged(listener, context) { this.position.onChanged.add(listener, context); this.radius.onChanged.add(listener, context); } offDimensionChanged(listener, context) { this.position.onChanged.remove(listener, context); this.radius.onChanged.remove(listener, context); } /** * * @param {number[]|Float32Array|Float64Array} destination * @param {number} address * @returns {number} number of used slots */ toArray(destination, address) { const position = this.position; destination[address] = position.x; destination[address + 1] = position.y; destination[address + 2] = position.z; destination[address + 3] = this.radius.getValue(); const color = this.color; destination[address + 4] = color.r; destination[address + 5] = color.g; destination[address + 6] = color.b; destination[address + 7] = this.intensity.getValue(); return 8; } } /** * @readonly * @type {boolean} */ PointLight.prototype.isPointLight = true; PointLight.prototype.ENCODED_SLOT_COUNT = 8;