UNPKG

lingo3d

Version:

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

199 lines 6.83 kB
import { CameraHelper } from "three"; import ObjectManager from "../ObjectManager"; import { ray, euler } from "../../utils/reusables"; import { deg2Rad } from "@lincode/math"; import { MIN_POLAR_ANGLE, MAX_POLAR_ANGLE, PI, PI_HALF } from "../../../globals"; import { Reactive } from "@lincode/reactivity"; import scene from "../../../engine/scene"; import { pushCameraList, pullCameraList } from "../../../states/useCameraList"; import { pullCameraStack, pushCameraStack } from "../../../states/useCameraStack"; import getWorldPosition from "../../../memo/getWorldPosition"; import getWorldDirection from "../../../memo/getWorldDirection"; import HelperSprite from "../utils/HelperSprite"; import { setManager } from "../utils/getManager"; import { getEditorHelper } from "../../../states/useEditorHelper"; import { getCameraRendered } from "../../../states/useCameraRendered"; import { cameraRenderedPtr } from "../../../pointers/cameraRenderedPtr"; import { ssrExcludeSet } from "../../../collections/ssrExcludeSet"; import { cameraTransitionSet } from "../../../collections/cameraTransitionSet"; import { renderCheckExcludeSet } from "../../../collections/renderCheckExcludeSet"; import { configCameraSystem } from "../../../systems/configSystems/configCameraSystem"; import { gyrateResetSystem } from "../../../systems/configSystems/gyrateResetSystem"; export default class CameraBase extends ObjectManager { $camera; midObject3d = this.outerObject3d; constructor($camera) { super(); this.$camera = $camera; this.object3d.add($camera); setManager($camera, this); pushCameraList($camera); this.createEffect(() => { if (!getEditorHelper() || cameraRenderedPtr[0] === $camera || this.$disableSceneGraph) return; const helper = new CameraHelper($camera); ssrExcludeSet.add(helper); renderCheckExcludeSet.add(helper); scene.add(helper); const sprite = new HelperSprite("camera", this); helper.add(sprite.outerObject3d); return () => { helper.dispose(); ssrExcludeSet.delete(helper); renderCheckExcludeSet.delete(helper); scene.remove(helper); sprite.dispose(); }; }, [getEditorHelper, getCameraRendered]); } disposeNode() { super.disposeNode(); pullCameraStack(this.$camera); pullCameraList(this.$camera); } lookAt(a0, a1, a2) { super.lookAt(a0, a1, a2); const angle = euler.setFromQuaternion(this.quaternion); angle.x += PI; angle.z += PI; this.outerObject3d.setRotationFromEuler(angle); } _fov = 75; get fov() { return this._fov; } set fov(val) { this._fov = val; configCameraSystem.add(this); } _zoom = 1; get zoom() { return this._zoom; } set zoom(val) { this._zoom = val; configCameraSystem.add(this); } _active; get active() { return !!this._active; } set active(val) { this._active = val; pullCameraStack(this.$camera); val && pushCameraStack(this.$camera); } get transition() { return cameraTransitionSet.has(this.$camera); } set transition(val) { val ? cameraTransitionSet.add(this.$camera) : cameraTransitionSet.delete(this.$camera); } getRay() { return ray.set(getWorldPosition(this.$camera), getWorldDirection(this.$camera)); } orbitMode; _gyrate(movementX, movementY, inner) { const manager = inner ? this.object3d : this.midObject3d; euler.setFromQuaternion(manager.quaternion); euler.y -= movementX * 0.002; euler.y = Math.max(PI_HALF - this._maxAzimuthAngle * deg2Rad, Math.min(PI_HALF - this._minAzimuthAngle * deg2Rad, euler.y)); euler.x -= movementY * 0.002; euler.x = Math.max(PI_HALF - this._maxPolarAngle * deg2Rad, Math.min(PI_HALF - this._minPolarAngle * deg2Rad, euler.x)); manager.setRotationFromEuler(euler); } gyrate(movementX, movementY) { if (this.orbitMode) { this._gyrate(movementX, movementY); return; } this._gyrate(movementX, 0); this._gyrate(0, movementY, true); } _minPolarAngle = MIN_POLAR_ANGLE; get minPolarAngle() { return this._minPolarAngle; } set minPolarAngle(val) { this._minPolarAngle = val; gyrateResetSystem.add(this); } _maxPolarAngle = MAX_POLAR_ANGLE; get maxPolarAngle() { return this._maxPolarAngle; } set maxPolarAngle(val) { this._maxPolarAngle = val; gyrateResetSystem.add(this); } _minAzimuthAngle = -Infinity; get minAzimuthAngle() { return this._minAzimuthAngle; } set minAzimuthAngle(val) { this._minAzimuthAngle = val; gyrateResetSystem.add(this); } _maxAzimuthAngle = Infinity; get maxAzimuthAngle() { return this._maxAzimuthAngle; } set maxAzimuthAngle(val) { this._maxAzimuthAngle = val; gyrateResetSystem.add(this); } setPolarAngle(angle) { const { _minPolarAngle, _maxPolarAngle } = this; this.minPolarAngle = this.maxPolarAngle = angle; queueMicrotask(() => { if (this.done) return; this.minPolarAngle = _minPolarAngle; this.maxPolarAngle = _maxPolarAngle; }); } setAzimuthAngle(angle) { const { _minAzimuthAngle, _maxAzimuthAngle } = this; this.minAzimuthAngle = this.maxAzimuthAngle = angle; queueMicrotask(() => { if (this.done) return; this.minAzimuthAngle = _minAzimuthAngle; this.maxAzimuthAngle = _maxAzimuthAngle; }); } _polarAngle; get polarAngle() { return this._polarAngle; } set polarAngle(val) { this._polarAngle = val; val && this.setPolarAngle(val); } _azimuthAngle; get azimuthAngle() { return this._azimuthAngle; } set azimuthAngle(val) { this._azimuthAngle = val; val && this.setAzimuthAngle(val); } inertia = false; mouseControlState = new Reactive(false); mouseControlInit; get mouseControl() { return this.mouseControlState.get(); } set mouseControl(val) { this.mouseControlState.set(val); if (!val || this.mouseControlInit) return; this.mouseControlInit = true; import("./enableMouseControl").then((module) => module.default.call(this)); } } //# sourceMappingURL=index.js.map