UNPKG

@realsee/dnalogel

Version:
327 lines (326 loc) 14.2 kB
var $ = Object.defineProperty, E = Object.defineProperties; var _ = Object.getOwnPropertyDescriptors; var M = Object.getOwnPropertySymbols; var L = Object.prototype.hasOwnProperty, O = Object.prototype.propertyIsEnumerable; var D = (m, e, n) => e in m ? $(m, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : m[e] = n, I = (m, e) => { for (var n in e || (e = {})) L.call(e, n) && D(m, n, e[n]); if (M) for (var n of M(e)) O.call(e, n) && D(m, n, e[n]); return m; }, U = (m, e) => E(m, _(e)); import * as j from "three"; import { is3DTag as z, isMediaModelTag as R } from "../utils/tag/tagCheck.js"; import { getTagCenterPosition as k, getTagPosition as Z } from "../utils/tagPosition.js"; import { checkRange as y } from "../utils/checkRange.js"; import { isPanoramaLike as P, isModelLike as q } 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 "animejs"; import { toArray as F } from "../../shared-utils/util.js"; import { notNil as H } from "../../shared-utils/isNil.js"; import { TagUtil as N } from "./TagUtil.js"; import { getFloorIndex as W } from "../../shared-utils/five/getFloorIndex.js"; import { safeObj as S } from "../../shared-utils/safeObj.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 C = new j.Raycaster(); C.params.Points.threshold = 0.1; class Ye extends N { constructor(e) { super(e); } /** * @description 获取是否可见 */ getVisible(e, n) { const r = I(I({}, this.five.getCurrentState()), n), { panoIndex: t, mode: o } = r, f = P(o) ? this.getPanoIndexCache({ panoIndex: t, id: e.id }) : void 0; if ((f == null ? void 0 : f.visible) !== void 0) return f.visible; { const s = [], d = (() => { var a, c, v, u, b, x, h; const i = (a = this.getTagConfig(e).visibleConfig) != null ? a : {}; if (typeof i == "function") return { value: i(this.five, { tag: e, distance: this.getDistance(e, r) }), checkedList: s, reason: "config function result" }; if (i.keep === "hidden") return { value: !1, checkedList: s, reason: "config.keep is hidden" }; if (i.keep === "visible") return { value: !0, checkedList: s, reason: "config.keep is visible" }; if (i.visibleFiveMode !== void 0) { const l = typeof i.visibleFiveMode == "function" ? i.visibleFiveMode(e) : i.visibleFiveMode; let p = !1; if (Array.isArray(l) ? p = l.includes(o) : l === "ModelLike" ? p = q(o) : l === "PanoramaLike" ? p = !P(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: i.visibleFiveMode, mode: o }; } else if (i.visibleFiveMode === void 0 && ((c = this.five.getCurrentState()) == null ? void 0 : c.mode) !== ((u = (v = e.fiveState) == null ? void 0 : v.mode) != null ? u : "Panorama")) return { value: !1, checkedList: s, reason: "current mode is not equal to tag.fiveState.mode", tagFiveMode: (b = e.fiveState) == null ? void 0 : b.mode, mode: o }; if (i.followModelVisibility === !0 && (o === "Floorplan" || o === "Mapview") && this.getVisibleByFloorIndex(e) === !1) return { value: !1, checkedList: s, reason: "followModelVisibility check failed" }; if (P(o) && i.visiblePanoIndex !== void 0 && i.visiblePanoIndex !== "all" && t !== void 0) { if (s.push("visiblePanoIndex"), Array.isArray(i.visiblePanoIndex) && !i.visiblePanoIndex.includes(t)) return { value: !1, checkedList: s, reason: `current panoIndex is not included in visiblePano. currentPanoIndex: ${t}, visiblePanoIndex: ${i.visiblePanoIndex}` }; if (i.visiblePanoIndex === "current" && t !== ((x = e.fiveState) == null ? void 0 : x.panoIndex)) return { value: !1, checkedList: s, reason: `current panoIndex is not equal to tag.panoIndex. currentPanoIndex: ${t}, tag.panoIndex: ${(h = e.fiveState) == null ? void 0 : h.panoIndex}` }; } if (i.visibleDistance !== void 0 && (s.push("visibleDistance"), i.visibleDistance !== "unLimited")) { const l = this.getDistance(e, r); if (y(l, i.visibleDistance) === !1) return { value: !1, checkedList: s, panoIndex: t, visibleDistance: i.visibleDistance, reason: `distance is not in visibleDistance. distance: ${l}, visibleDistance: ${i.visibleDistance.min} - ${i.visibleDistance.max}` }; } if (P(o) && i.angleRange && z(e)) { s.push("angleRange"); const l = this.getAngle(e, t); if (y(l, i.angleRange) === !1) return { value: !1, checkedList: s, reason: `angle is not in angleRange. angle: ${l}, angleRange: ${i.angleRange}` }; } if (i.intersectRaycaster !== !1 && (typeof i.intersectRaycaster != "object" || i.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 f && d.do_not_cache !== !0 && (f.visible = d.value, f.__debug_visible_reason__ = d), d.value; } } /** * @description 获取是否展开 */ getUnfoldedByPanoIndex(e, n) { if (!this.getCurrentVisibleState(e)) return; const t = this.getPanoIndexCache({ panoIndex: n, id: e.id }); if (t.unfolded !== void 0) return t.unfolded; { const o = this.getTagConfig(e).unfoldedConfig; if (!o) return; const f = (() => { if (typeof o == "function") return o(this.five, { tag: e, distance: this.getDistance(e, { panoIndex: n }) }); if (o.keep === "folded") return !1; if (o.keep === "unfolded") return !0; if (o.unfoldDistance && y(this.getDistance(e, { panoIndex: n }), o.unfoldDistance) === !1) return !1; })(); t.unfolded = f; 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 f = this.getTagProject(e); if (f && y(f.x, t.autoUnfold.autoUnfoldProjectX) === !1) return !1; } if (t.autoUnfold.strategy === "MinimumDistance") { const d = this.filterPointTag.filter((i) => this.getCurrentVisibleState(i)).filter((i) => { const a = this.getTagProject(i); if (!a) return !1; const { x: c, y: v, z: u } = a; return !(Math.abs(u) > 1 || Math.abs(c) > 1 || Math.abs(v) > 1); }).map((i) => ({ tag: i, id: i.id, tagConfig: this.getTagConfig(i).unfoldedConfig })).filter(({ tag: i, tagConfig: a }) => { var c, v; return !(typeof a == "function" || a.keep || a.autoUnfold === !1 || ((c = a.autoUnfold) == null ? void 0 : c.enable) === !1 || ((v = a.autoUnfold) == null ? void 0 : v.strategy) !== "MinimumDistance"); }).map((i) => U(I({}, i), { distance: this.getDistance(i.tag) })).filter(({ distance: i, tagConfig: a }) => { const c = a.autoUnfold.distance; return !(c && y(i, c) === !1); }).sort((i, a) => i.distance - a.distance).findIndex((i) => i.id === e.id); if (d === -1 || d <= ((o = t.autoUnfold.maxNumber) != null ? o : 1) - 1 === !1) return !1; } return t.autoUnfold.strategy !== "FoldWhenMove"; } })() : void 0; } setTagZIndex(e) { return e.forEach((n) => { n.zIndex = this.calculateTagZIndex(n); }); } calculateTagZIndex(e) { const n = this.getDistance(e); return Math.round((1e4 - (n != null ? n : 0)) * 100); } setVisible(e) { (e ? F(e) : this.tags).forEach((r) => { const t = this.getVisible(r); r.state && (r.state.visible = t); }); } setUnfoldedByPanoIndex() { this.tags.forEach((e) => { const n = this.getUnfoldedByPanoIndex(e); if (e.state && (n !== void 0 && (e.state.unfolded = n), n && !e.state.visible)) { const r = this.getTagConfig(e); typeof r.unfoldedConfig == "object" && r.unfoldedConfig.autoFoldWhenHide !== !1 && (e.state.unfolded = !1); } }); } /** * @description 一个点的标签 */ getTagProject(e) { const n = k(e); if (!n) return; const { x: r, y: t, z: o } = n.project(this.five.camera); if (!(o > 1)) return { x: r, y: t, z: o }; } /** 通过射线检测标签可用性 */ getTagEnableByIntersect(e, n) { var g, i, a, c, v; const r = S(S((g = this.getTagConfig(e).visibleConfig) != null ? g : {}).intersectRaycaster), t = n != null ? n : this.five.getCurrentState().panoIndex, o = P(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 f = F( (() => { var b; const u = (b = r.checkPoints) != null ? b : "center"; return u === "center" ? k(e) : u === "corner" ? Z(e) : Array.isArray(u) ? u : []; })() ); let s = 0, d = 0; for (const u of f) { const b = new j.Vector3().subVectors(u, o).normalize(); C.set(o, b); const x = o.distanceTo(u), [h] = this.five.model.intersectRaycaster(C), l = (() => { if (!R(e)) return; const A = this.tags.filter(R).map((B) => { var T; return (T = B.model) == null ? void 0 : T.object; }).filter(H), [w] = C.intersectObjects(A, !0); return w; })(), p = (i = r.distanceAccuracy) != null ? i : 0.01; Math.min((a = h == null ? void 0 : h.distance) != null ? a : 1 / 0, (c = l == null ? void 0 : l.distance) != null ? c : 1 / 0) + p >= x ? s++ : d++; const V = (v = r.needPassed) != null ? v : 1; if (s >= V) return { value: !0 }; } return d === 0 ? { value: !0 } : { value: !1, reason: { type: "intersectRaycaster check failed", passedCount: s, needPassed: r.needPassed } }; } /** 检测是否匹配当前楼层 */ getVisibleByFloorIndex(e) { var o, f, s, d, g, i, a; let n = 0; const r = (o = e.fiveState) == null ? void 0 : o.panoIndex; r !== void 0 ? n = (f = this.workUtil.getObserver(r)) == null ? void 0 : f.floorIndex : n = W(this.workUtil.work, (a = (i = (d = (s = e.model) == null ? void 0 : s.object) == null ? void 0 : d.position) != null ? i : (g = e.mediaPlane) == null ? void 0 : g.position) != null ? a : k(e)); const t = this.five.model.shownFloor; return t === null || t === n; } } export { Ye as TagComputer };