UNPKG

mylingo3d

Version:

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

127 lines 4.3 kB
import { Color, RectAreaLight } from "three"; import { RectAreaLightHelper } from "three/examples/jsm/helpers/RectAreaLightHelper"; import { areaLightDefaults, areaLightSchema } from "../../interface/IAreaLight"; import { lazy } from "@lincode/utils"; import ObjectManager from "../core/ObjectManager"; import mainCamera from "../../engine/mainCamera"; import scene from "../../engine/scene"; import { scaleDown } from "../../engine/constants"; import { onTransformControls } from "../../events/onTransformControls"; import { Reactive } from "@lincode/reactivity"; import { getSelectionTarget } from "../../states/useSelectionTarget"; import { getCameraRendered } from "../../states/useCameraRendered"; import { getEditorModeComputed } from "../../states/useEditorModeComputed"; const lazyInit = lazy(async () => { const { RectAreaLightUniformsLib } = await import("three/examples/jsm/lights/RectAreaLightUniformsLib"); RectAreaLightUniformsLib.init(); }); export default class AreaLight extends ObjectManager { static componentName = "areaLight"; static defaults = areaLightDefaults; static schema = areaLightSchema; light; constructor() { super(); lazyInit().then(() => { if (this.done) return; const light = (this.light = new RectAreaLight(this._color, this._intensity, this.width * this.scaleX * scaleDown, this.height * this.scaleY * scaleDown)); this.object3d.add(light); this.then(() => light.dispose()); this.createEffect(() => { if (getEditorModeComputed() !== "scale" || getSelectionTarget() !== this) return; const handle = onTransformControls(() => { const { x, y } = this.outerObject3d.scale; this.scaleX = x; this.scaleY = y; }); return () => { handle.cancel(); }; }, [getEditorModeComputed, getSelectionTarget]); this.createEffect(() => { if (getCameraRendered() !== mainCamera || !this.helperState.get()) return; const helper = new RectAreaLightHelper(light); scene.add(helper); return () => { helper.dispose(); scene.remove(helper); }; }, [getCameraRendered, this.helperState.get]); }); } shadowResolution; shadowBias; get castShadow() { return false; } set castShadow(_) { } helperState = new Reactive(true); get helper() { return this.helperState.get(); } set helper(val) { this.helperState.set(val); } _color; get color() { return this._color ?? "#ffffff"; } set color(val) { this._color = val; this.light && (this.light.color = new Color(val)); } _intensity; get intensity() { return this._intensity ?? 1; } set intensity(val) { this._intensity = val; this.light && (this.light.intensity = val); } _width; get width() { return this._width ?? 100; } set width(val) { this._width = val; this.light && (this.light.width = val * this.scaleX * scaleDown); } _height; get height() { return this._height ?? 100; } set height(val) { this._height = val; this.light && (this.light.height = val * this.scaleY * scaleDown); } _scaleX; get scaleX() { return this._scaleX ?? 1; } set scaleX(val) { this._scaleX = val; this.light && (this.light.width = val * this.width * scaleDown); } _scaleY; get scaleY() { return this._scaleY ?? 1; } set scaleY(val) { this._scaleY = val; this.light && (this.light.height = val * this.height * scaleDown); } get depth() { return 0; } set depth(_) { } get scaleZ() { return 0; } set scaleZ(_) { } } //# sourceMappingURL=AreaLight.js.map