UNPKG

@realsee/dnalogel

Version:
320 lines (319 loc) 14 kB
var A = Object.defineProperty, $ = Object.defineProperties; var E = Object.getOwnPropertyDescriptors; var T = Object.getOwnPropertySymbols; var L = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable; var M = (b, e, i) => e in b ? A(b, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : b[e] = i, x = (b, e) => { for (var i in e || (e = {})) L.call(e, i) && M(b, i, e[i]); if (T) for (var i of T(e)) _.call(e, i) && M(b, i, e[i]); return b; }, U = (b, e) => $(b, E(e)); import * as F from "three"; import { is3DTag as O, isMediaModelTag as D } from "../utils/tag/tagCheck.js"; import { getTagCenterPosition as C, getTagPosition as z } from "../utils/tagPosition.js"; import { checkRange as h } from "../utils/checkRange.js"; import { isPanoramaLike as y, isModelLike as Z } from "../../shared-utils/five/mode.js"; import "hammerjs"; import "@realsee/five"; import "../../vendor/@tweenjs/tween/dist/tween.esm.js.js"; import "../../CSS3DRenderPlugin/utils/three/CSS3DRender.js"; import "../../CSS3DRenderPlugin/utils/generateBehindFiveElement.js"; import { notNil as q } from "../../shared-utils/isNil.js"; import { TagUtil as H } from "./TagUtil.js"; import { getFloorIndex as N } from "../../shared-utils/five/getFloorIndex.js"; import { safeObj as R } from "../../shared-utils/safeObj.js"; import { toArray as W } from "../../shared-utils/util.js"; import "../../shared-utils/three/centerPoint.js"; import "../../shared-utils/positionToVector3.js"; import "../../CSS3DRenderPlugin/utils/three/CSS3DRenderer.js"; import "three/examples/jsm/renderers/CSS3DRenderer"; import "../../CSS3DRenderPlugin/utils/getAllCSS3DObject.js"; import "../../CSS3DRenderPlugin/utils/createResizeObserver.js"; import "../../CSS3DRenderPlugin/utils/even.js"; import "../../shared-utils/Subscribe.js"; import "../../CSS3DRenderPlugin/utils/three/CSS3DObject.js"; import "../../CSS3DRenderPlugin/utils/three/OpacityMesh.js"; import "../../shared-utils/three/getObjectVisible.js"; import "../../CSS3DRenderPlugin/utils/three/CSS3DScene.js"; import "../../CSS3DRenderPlugin/utils/three/CSS3DGroup.js"; import "../typings/tag/TagConfig.js"; import "../../vendor/object-assign-deep/objectAssignDeep.js"; import "../tag.config.js"; import "../utils/planeNormal.js"; import "../utils/normalPositionToPositions.js"; import "./TagCache.js"; import "../../base/BasePlugin.js"; import "../../shared-utils/url/absoluteUrl.js"; import "../../vendor/svelte/store/index.js"; import "../../vendor/svelte/internal/index.js"; import "../../shared-utils/device.js"; import "../utils/model/mediaPlane.js"; import "../../shared-utils/three/loadTexture.js"; import "../../shared-utils/three/Quadrangle.js"; import "../../shared-utils/math/pointIsRectangle.js"; import "../../shared-utils/three/loadVideoTexture.js"; import "../Assets/Icon.js"; import "../../shared-utils/three/getPositionsByObjectFit.js"; import "../../shared-utils/three/FragmentTransparencyMaterial.js"; import "../../shared-utils/three/getNormal.js"; import "../../shared-utils/five/FiveDomEvents.js"; import "../../shared-utils/five/calculateThreeMouse.js"; import "../utils/tag/adaptConfig.js"; import "../../shared-utils/typescript/entries.js"; import "../../shared-utils/url/getUrl.js"; import "../../shared-utils/five/transformPosition.js"; import "../../shared-utils/Utils/WorkUtil.js"; import "../../shared-utils/Utils/BaseUtil.js"; const I = new F.Raycaster(); I.params.Points.threshold = 0.1; class Qe extends H { constructor(e) { super(e); } /** * @description: 获取是否可见 */ getVisible(e, i) { const f = x(x({}, this.five.getCurrentState()), i), { panoIndex: t, mode: o } = f, d = y(o) ? this.getPanoIndexCache({ panoIndex: t, id: e.id }) : void 0; if ((d == null ? void 0 : d.visible) !== void 0) return d.visible; { const s = [], c = (() => { var r, a, u, m, v, g, P; const n = (r = this.getTagConfig(e).visibleConfig) != null ? r : {}; if (typeof n == "function") return { value: n(this.five, { tag: e, distance: this.getDistance(e) }), checkedList: s, reason: "config function result" }; if (n.keep === "hidden") return { value: !1, checkedList: s, reason: "config.keep is hidden" }; if (n.keep === "visible") return { value: !0, checkedList: s, reason: "config.keep is visible" }; if (n.visibleFiveMode !== void 0) { const l = typeof n.visibleFiveMode == "function" ? n.visibleFiveMode(e) : n.visibleFiveMode; let p = !1; if (Array.isArray(l) ? p = l.includes(o) : l === "ModelLike" ? p = Z(o) : l === "PanoramaLike" ? p = !y(o) : l === "all" ? p = !0 : typeof l == "string" && (p = l === o), p === !1) return { value: !1, checkedList: s, reason: "current mode is not included in visibleFiveMode", visibleFiveMode: n.visibleFiveMode, mode: o }; } else if (n.visibleFiveMode === void 0 && ((a = this.five.getCurrentState()) == null ? void 0 : a.mode) !== ((m = (u = e.fiveState) == null ? void 0 : u.mode) != null ? m : "Panorama")) return { value: !1, checkedList: s, reason: "current mode is not equal to tag.fiveState.mode", tagFiveMode: (v = e.fiveState) == null ? void 0 : v.mode, mode: o }; if (n.followModelVisibility === !0 && (o === "Floorplan" || o === "Mapview") && this.getVisibleByFloorIndex(e) === !1) return { value: !1, checkedList: s, reason: "followModelVisibility check failed" }; if (y(o) && n.visiblePanoIndex !== void 0 && n.visiblePanoIndex !== "all" && t !== void 0) { if (s.push("visiblePanoIndex"), Array.isArray(n.visiblePanoIndex) && !n.visiblePanoIndex.includes(t)) return { value: !1, checkedList: s, reason: `current panoIndex is not included in visiblePano. currentPanoIndex: ${t}, visiblePanoIndex: ${n.visiblePanoIndex}` }; if (n.visiblePanoIndex === "current" && t !== ((g = e.fiveState) == null ? void 0 : g.panoIndex)) return { value: !1, checkedList: s, reason: `current panoIndex is not equal to tag.panoIndex. currentPanoIndex: ${t}, tag.panoIndex: ${(P = e.fiveState) == null ? void 0 : P.panoIndex}` }; } if (n.visibleDistance !== void 0 && (s.push("visibleDistance"), n.visibleDistance !== "unLimited")) { const l = this.getDistance(e); if (h(l, n.visibleDistance) === !1) return { value: !1, checkedList: s, reason: `distance is not in visibleDistance. distance: ${l}, visibleDistance: ${n.visibleDistance}` }; } if (y(o) && n.angleRange && O(e)) { s.push("angleRange"); const l = this.getAngle(e); if (h(l, n.angleRange) === !1) return { value: !1, checkedList: s, reason: `angle is not in angleRange. angle: ${l}, angleRange: ${n.angleRange}` }; } if (n.intersectRaycaster !== !1 && (typeof n.intersectRaycaster != "object" || n.intersectRaycaster.enabled !== !1)) { if (s.push("intersectRaycaster"), t === void 0) return { value: !1, checkedList: s, reason: `intersectRaycaster check failed: panoIndex is ${t}` }; const l = this.getTagEnableByIntersect(e, t); if (l.value === !1) return Object.assign(l, { checkedList: s }); } return { value: !0, checkedList: s, reason: "all check passed" }; })(); return d && (d.visible = c.value, d.__debug_visible_reason__ = c), c.value; } } /** * @description: 获取是否展开 */ getUnfoldedByPanoIndex(e, i) { if (!this.getCurrentVisibleState(e)) return; const t = this.getPanoIndexCache({ panoIndex: i, id: e.id }); if (t.unfolded !== void 0) return t.unfolded; { const o = this.getTagConfig(e).unfoldedConfig; if (!o) return; const d = (() => { if (typeof o == "function") return o(this.five, { tag: e, distance: this.getDistance(e) }); if (o.keep === "folded") return !1; if (o.keep === "unfolded") return !0; if (o.unfoldDistance && h(this.getDistance(e), o.unfoldDistance) === !1) return !1; })(); t.unfolded = d; const s = this.getUnfoldedByCamera(e); return s !== void 0 ? s : t.unfolded; } } /** * @description: 获取是否展开 */ getUnfoldedByCamera(e) { return this.getCurrentVisibleState(e) ? (() => { var o; const t = this.getTagConfig(e).unfoldedConfig; if (t) { if (typeof t == "function") return t(this.five, { tag: e, distance: this.getDistance(e) }); if (t.keep === "folded") return !1; if (t.keep === "unfolded") return !0; if (t.autoUnfold === void 0 || t.autoUnfold === !1 || t.autoUnfold.enable === !1 || !t.autoUnfold.strategy) return; if (t.autoUnfold.strategy === "ScreenPostion") { const d = this.getTagProject(e); if (d && h(d.x, t.autoUnfold.autoUnfoldProjectX) === !1) return !1; } if (t.autoUnfold.strategy === "MinimumDistance") { const c = this.filterPointTag.filter((r) => this.getCurrentVisibleState(r)).filter((r) => { const a = this.getTagProject(r); if (!a) return !1; const { x: u, y: m, z: v } = a; return !(Math.abs(v) > 1 || Math.abs(u) > 1 || Math.abs(m) > 1); }).map((r) => ({ tag: r, id: r.id, tagConfig: this.getTagConfig(r).unfoldedConfig })).filter(({ tag: r, tagConfig: a }) => { var u, m; return !(typeof a == "function" || a.keep || a.autoUnfold === !1 || ((u = a.autoUnfold) == null ? void 0 : u.enable) === !1 || ((m = a.autoUnfold) == null ? void 0 : m.strategy) !== "MinimumDistance"); }).map((r) => U(x({}, r), { distance: this.getDistance(r.tag) })).filter(({ distance: r, tagConfig: a }) => { const u = a.autoUnfold.distance; return !(u && h(r, u) === !1); }).sort((r, a) => r.distance - a.distance).findIndex((r) => r.id === e.id); if (c === -1 || c <= ((o = t.autoUnfold.maxNumber) != null ? o : 1) - 1 === !1) return !1; } return !0; } })() : void 0; } setTagZIndex(e) { return e.forEach((i) => { i.zIndex = this.calculateTagZIndex(i); }); } calculateTagZIndex(e) { const i = this.getDistance(e); return Math.round((1e4 - (i != null ? i : 0)) * 100); } setVisible(e) { (e != null ? e : this.tags).forEach((i) => { const f = this.getVisible(i); i.state && (i.state.visible = f); }); } setUnfoldedByPanoIndex() { this.tags.forEach((e) => { const i = this.getUnfoldedByPanoIndex(e); if (e.state && (i !== void 0 && (e.state.unfolded = i), i && !e.state.visible)) { const f = this.getTagConfig(e); typeof f.unfoldedConfig == "object" && f.unfoldedConfig.autoFoldWhenHide !== !1 && (e.state.unfolded = !1); } }); } /** * @description 一个点的标签 */ getTagProject(e) { const i = C(e); if (!i) return; const { x: f, y: t, z: o } = i.project(this.five.camera); if (!(o > 1)) return { x: f, y: t, z: o }; } /** 通过射线检测标签可用性 */ getTagEnableByIntersect(e, i) { var n, r, a, u, m; const f = R(R((n = this.getTagConfig(e).visibleConfig) != null ? n : {}).intersectRaycaster), t = i != null ? i : this.five.getCurrentState().panoIndex, o = y(this.five.getCurrentState().mode) ? this.workUtil.getObserverPosition(t) : this.five.camera.position; if (o === void 0) return { value: !1, reason: { type: "startPosition is undefined", fivePanoIndex: t } }; const d = W( (() => { var g; const v = (g = f.checkPoints) != null ? g : "center"; return v === "center" ? C(e) : v === "corner" ? z(e) : Array.isArray(v) ? v : []; })() ); let s = 0, c = 0; for (const v of d) { const g = new F.Vector3().subVectors(v, o).normalize(); I.set(o, g); const P = o.distanceTo(v), [l] = this.five.model.intersectRaycaster(I), p = (() => { if (!D(e)) return; const V = this.tags.filter(D).map((B) => { var k; return (k = B.model) == null ? void 0 : k.object; }).filter(q), [w] = I.intersectObjects(V, !0); return w; })(), S = (r = f.distanceAccuracy) != null ? r : 0.01; Math.min((a = l == null ? void 0 : l.distance) != null ? a : 1 / 0, (u = p == null ? void 0 : p.distance) != null ? u : 1 / 0) + S >= P ? s++ : c++; const j = (m = f.needPassed) != null ? m : 1; if (s >= j) return { value: !0 }; } return c === 0 ? { value: !0 } : { value: !1, reason: { type: "intersectRaycaster check failed", passedCount: s, needPassed: f.needPassed } }; } /** 检测是否匹配当前楼层 */ getVisibleByFloorIndex(e) { var o, d, s, c, n, r, a; let i = 0; const f = (o = e.fiveState) == null ? void 0 : o.panoIndex; f !== void 0 ? i = (d = this.workUtil.getObserver(f)) == null ? void 0 : d.floorIndex : i = N(this.workUtil.work, (a = (r = (c = (s = e.model) == null ? void 0 : s.object) == null ? void 0 : c.position) != null ? r : (n = e.mediaPlane) == null ? void 0 : n.position) != null ? a : C(e)); const t = this.five.model.shownFloor; return t === null || t === i; } } export { Qe as TagComputer };