UNPKG

lingo3d

Version:

Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor

78 lines 2.98 kB
import { ConeGeometry, Mesh, SpotLight as ThreeSpotLight, SpotLightHelper } from "three"; import { spotLightDefaults, spotLightSchema } from "../../../interface/ISpotLight"; import { deg2Rad, rad2Deg } from "@lincode/math"; import { SpotLightMaterial } from "./SpotLightMaterial"; import { Cancellable } from "@lincode/promiselikes"; import { ssrExcludeSet } from "../../../collections/ssrExcludeSet"; import PointLightBase from "../../core/PointLightBase"; import { renderCheckExcludeSet } from "../../../collections/renderCheckExcludeSet"; import unsafeSetValue from "../../../utils/unsafeSetValue"; import { spotLightShadowResolutionSystem } from "../../../systems/spotLightShadowResolutionSystem"; import { volumetricSpotLightSystem } from "../../../systems/volumetricSpotLightSystem"; const coneGeometry = new ConeGeometry(0.5, 1, 256); class SpotLight extends PointLightBase { static componentName = "spotLight"; static defaults = spotLightDefaults; static schema = spotLightSchema; constructor() { super(new ThreeSpotLight(), SpotLightHelper); this.angle = 45; this.penumbra = 0.2; const light = this.object3d; this.outerObject3d.add(light.target); light.position.y = 0; light.target.position.y = -0.1; } get shadows() { return super.shadows; } set shadows(val) { super.shadows = val; val ? spotLightShadowResolutionSystem.add(this) : spotLightShadowResolutionSystem.delete(this); } get angle() { return this.object3d.angle * rad2Deg; } set angle(val) { this.object3d.angle = val * deg2Rad; } get penumbra() { return this.object3d.penumbra; } set penumbra(val) { this.object3d.penumbra = val; } _volumetric = false; get volumetric() { return this._volumetric; } set volumetric(val) { this._volumetric = val; this.cancelHandle("volumetric", val && (() => { const material = new SpotLightMaterial(); unsafeSetValue(material, "lightColor", this.object3d.color); unsafeSetValue(material, "anglePower", 2); const cone = new Mesh(coneGeometry, material); this.outerObject3d.add(cone); ssrExcludeSet.add(cone); renderCheckExcludeSet.add(cone); volumetricSpotLightSystem.add(cone, { light: this, material }); return new Cancellable(() => { material.dispose(); this.outerObject3d.remove(cone); ssrExcludeSet.delete(cone); renderCheckExcludeSet.delete(cone); volumetricSpotLightSystem.delete(cone); }); })); } volumetricDistance = 1; } export default SpotLight; //# sourceMappingURL=index.js.map