UNPKG

lingo3d

Version:

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

150 lines 4.9 kB
import { Cancellable } from "@lincode/promiselikes"; import { Matrix3 } from "three"; import { OBB } from "three/examples/jsm/math/OBB"; import MeshAppendable from "../MeshAppendable"; import getWorldPosition from "../../../memo/getWorldPosition"; import { vector3_1 } from "../../utils/reusables"; import { reflectionVisibleSet } from "../../../collections/reflectionCollections"; import { clickSet, mouseDownSet, mouseMoveSet, mouseOutSet, mouseOverSet, mouseUpSet } from "../../../collections/mouseSets"; import { idRenderCheckMap } from "../../../collections/idCollections"; import getRendered from "../../../throttle/getRendered"; import { hitTestSystem } from "../../../systems/hitTestSystem"; import { configCastShadowSystem } from "../../../systems/configLoadedSystems/configCastShadowSystem"; import { configOutlineSystem } from "../../../systems/configLoadedSystems/configOutlineSystem"; import { configSelectiveBloomSystem } from "../../../systems/configLoadedSystems/configSelectiveBloomSystem"; const thisOBB = new OBB(); const targetOBB = new OBB(); export default class VisibleMixin extends MeshAppendable { _bloom; get bloom() { return this._bloom; } set bloom(val) { this._bloom = val; configSelectiveBloomSystem.add(this); } _outline; get outline() { return this._outline; } set outline(val) { this._outline = val; configOutlineSystem.add(this); } _visible; get visible() { return this._visible; } set visible(val) { this._visible = val; this.outerObject3d.visible = !!val; } _reflectionVisible; get reflectionVisible() { return this._reflectionVisible; } set reflectionVisible(val) { this._reflectionVisible = val; this.cancelHandle("reflectionVisible", val && (() => { reflectionVisibleSet.add(this); return new Cancellable(() => { reflectionVisibleSet.delete(this); this.outerObject3d.visible = !!this._visible; }); })); } initRenderCheck; get isRendered() { if (!this.initRenderCheck) { this.initRenderCheck = true; idRenderCheckMap.set(this.object3d.id, this); } return getRendered().has(this); } _castShadow; get castShadow() { return (this._castShadow ??= true); } set castShadow(val) { this._castShadow = val; configCastShadowSystem.add(this); } $addToRaycastSet(set) { set.add(this.object3d); return new Cancellable(() => set.delete(this.object3d)); } _onClick; get onClick() { return this._onClick; } set onClick(cb) { this._onClick = cb; this.cancelHandle("onClick", cb && (() => this.$addToRaycastSet(clickSet))); } _onMouseDown; get onMouseDown() { return this._onMouseDown; } set onMouseDown(cb) { this._onMouseDown = cb; this.cancelHandle("onMouseDown", cb && (() => this.$addToRaycastSet(mouseDownSet))); } _onMouseUp; get onMouseUp() { return this._onMouseUp; } set onMouseUp(cb) { this._onMouseUp = cb; this.cancelHandle("onMouseUp", cb && (() => this.$addToRaycastSet(mouseUpSet))); } _onMouseOver; get onMouseOver() { return this._onMouseOver; } set onMouseOver(cb) { this._onMouseOver = cb; this.cancelHandle("onMouseOver", cb && (() => this.$addToRaycastSet(mouseOverSet))); } _onMouseOut; get onMouseOut() { return this._onMouseOut; } set onMouseOut(cb) { this._onMouseOut = cb; this.cancelHandle("onMouseOut", cb && (() => this.$addToRaycastSet(mouseOutSet))); } _onMouseMove; get onMouseMove() { return this._onMouseMove; } set onMouseMove(cb) { this._onMouseMove = cb; this.cancelHandle("onMouseMove", cb && (() => this.$addToRaycastSet(mouseMoveSet))); } hitTest(target) { if (this.done) return false; if (target.done) return false; if (this === target) return false; thisOBB.set(getWorldPosition(this.object3d), vector3_1.clone(), new Matrix3()); thisOBB.applyMatrix4(this.object3d.matrixWorld); targetOBB.set(getWorldPosition(target.object3d), vector3_1.clone(), new Matrix3()); targetOBB.applyMatrix4(target.object3d.matrixWorld); return thisOBB.intersectsOBB(targetOBB); } _hitTarget; get hitTarget() { return this._hitTarget; } set hitTarget(val) { this._hitTarget = val; val ? hitTestSystem.add(this) : hitTestSystem.delete(this); } onHit; onHitStart; onHitEnd; } //# sourceMappingURL=VisibleMixin.js.map