UNPKG

@realsee/dnalogel

Version:
342 lines (341 loc) 13.3 kB
var q = Object.defineProperty, K = Object.defineProperties; var Q = Object.getOwnPropertyDescriptors; var x = Object.getOwnPropertySymbols; var Y = Object.prototype.hasOwnProperty, Z = Object.prototype.propertyIsEnumerable; var w = (l, s, e) => s in l ? q(l, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[s] = e, k = (l, s) => { for (var e in s || (s = {})) Y.call(s, e) && w(l, e, s[e]); if (x) for (var e of x(s)) Z.call(s, e) && w(l, e, s[e]); return l; }, R = (l, s) => K(l, Q(s)); var p = (l, s, e) => (w(l, typeof s != "symbol" ? s + "" : s, e), e); import { defaultGlobalConfig as ee } from "../typings/tag/TagConfig.js"; import { objectAssignDeepExports as y } from "../../vendor/object-assign-deep/objectAssignDeep.js"; import * as ie from "three"; import { DefaultConfig as te } from "../tag.config.js"; import { anyPositionToVector3 as C } from "../../shared-utils/positionToVector3.js"; import { planeNormal as E } from "../utils/planeNormal.js"; import { getTagCenterPosition as _ } from "../utils/tagPosition.js"; import { normalPositionToPositions as oe } from "../utils/normalPositionToPositions.js"; import { TagCache as re } from "./TagCache.js"; import { writable as ne } from "../../vendor/svelte/store/index.js"; import { isIOSWX as se } from "../../shared-utils/device.js"; import { Five as fe } from "@realsee/five"; import { isMediaPlaneTag as le, isMediaModelTag as B, isPlaneTag as ce, isPoint3DTag as ae } from "../utils/tag/tagCheck.js"; import { VideoPlane as de } from "../utils/model/mediaPlane.js"; import { FiveDomEvents as ue } from "../../shared-utils/five/FiveDomEvents.js"; import N from "../utils/tag/adaptConfig.js"; import { isPanoramaLike as A, isModelLike as $ } from "../../shared-utils/five/mode.js"; import "hammerjs"; import "../../vendor/@tweenjs/tween/dist/tween.esm.js.js"; import "../../CSS3DRenderPlugin/utils/three/CSS3DRender.js"; import "../../CSS3DRenderPlugin/utils/generateBehindFiveElement.js"; import { entries as z } from "../../shared-utils/typescript/entries.js"; import { getUrlExt as H } from "../../shared-utils/url/getUrl.js"; import { transformPosition as J } from "../../shared-utils/five/transformPosition.js"; import { WorkUtil as me } from "../../shared-utils/Utils/WorkUtil.js"; import "../../shared-utils/three/centerPoint.js"; import "../../base/BasePlugin.js"; import "../../shared-utils/Subscribe.js"; import "../../shared-utils/url/absoluteUrl.js"; import "../../CSS3DRenderPlugin/utils/three/CSS3DRenderer.js"; import "three/examples/jsm/renderers/CSS3DRenderer"; import "../../CSS3DRenderPlugin/utils/getAllCSS3DObject.js"; import "../../shared-utils/util.js"; import "../../CSS3DRenderPlugin/utils/createResizeObserver.js"; import "../../CSS3DRenderPlugin/utils/even.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 "../../vendor/svelte/internal/index.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/calculateThreeMouse.js"; import "../../shared-utils/Utils/BaseUtil.js"; class di extends re { constructor(e) { super(e); p(this, "tags", []); p(this, "config", te); p(this, "workUtil", new me(this.five)); p(this, "mediaStore", ne({ currentMediaElement: null })); /** css3DRenderPlugin */ p(this, "css3DRenderPlugin"); p(this, "store", { disposers: [], disposed: !1, resizeObserverDisposerAdding: !1, css3DRenderDisposer: /* @__PURE__ */ new Map() }); p(this, "domEvents", new ue(this.five)); p(this, "loadVideoFirstFrame", () => { se && this.hooks.emit("loadVideoFirstFrame"); }); this.mediaStore.subscribe(({ currentMediaElement: i }) => { this.tags.forEach((o) => { var t; if (o.mediaPlane instanceof de && i !== o.mediaPlane.videoInstance) { if (!((t = o.mediaPlane.videoInstance) != null && t.src) || i === o.mediaPlane.videoInstance) return; o.mediaPlane.pause(); } }); }); } set workCode(e) { this.workUtil.workCode = e; } get workCode() { return this.workUtil.workCode; } getTagById(e) { const i = this.tags.find((o) => o.id === e); if (!i) { console.warn(`getTagById Error: can't find tag id: ${e}`); return; } return i; } /** 暂停当前标签内进行的所有多媒体 */ pauseCurrentMedia() { this.mediaStore.set({ currentMediaElement: null }); } /** * @description: 获取标签配置 */ getTagConfig(e, i) { var n, f, c; const o = this.calculateTagConfig(e, { useCache: i == null ? void 0 : i.useCache }), t = (n = i == null ? void 0 : i.fiveMode) != null ? n : this.five.getCurrentState().mode, r = (f = o.configWithFiveMode) == null ? void 0 : f[t]; return (c = r != null ? r : o) != null ? c : {}; } /** * @description 获取标签当前状态 */ getCurrentVisibleState(e) { return !(!this.state.enabled || !this.state.visible || !e.enabled || !e.state.visible); } updateTagConfig() { this.clearCache(), this.tags.forEach((e) => { var t; const i = this.getTagConfig(e, { useCache: !1 }); e.computedConfig = i; const o = this.getTagConfig(e); if (e.config = o, e.config.initialData) { const r = JSON.parse(JSON.stringify(e.data)); e.data = (t = o.initialData) != null && t.important ? y(e.data, r, o.initialData) : y(e.data, o.initialData, r); } }); } can(e, i) { const o = i, t = this.getTagConfig(o); if (!t || typeof t != "object") return !0; if (e === "show" || e === "hide") { if (!t.visibleConfig || typeof t.visibleConfig != "object") return !0; if (e === "show" && t.visibleConfig.keep === "hidden" || e === "hide" && (t.visibleConfig.keep === "visible" || t.visibleConfig.alwaysShowWhenMovePano)) return !1; } if (e === "fold" || e === "unfold") { if (!t.unfoldedConfig || typeof t.unfoldedConfig != "object") return !0; if (e === "fold" && t.unfoldedConfig.keep === "unfolded" || e === "unfold" && t.unfoldedConfig.keep === "folded") return !1; } return !0; } getRenderType(e) { const i = (() => { if (e.stickType === "3DPoint") return "Dom"; const o = this.getTagConfig(e); if (!o || typeof o != "object" || !o.renderType) return; const t = e.data.mediaData; if (!(!t || t.length === 0) && o.renderType === "Mesh") { if (le(e)) { if (t.length === 1) { if (t[0].type === "Video") return "Mesh"; if (t[0].type === "Image") return H(t[0].url) === "gif" ? "Dom" : "Mesh"; } } else if (B(e)) return t.length === 1 && t[0].type === "Image" ? H(t[0].url) === "gif" ? "Dom" : "Mesh" : "BehindDom"; } })(); return i != null ? i : "Dom"; } /** * @description: 获取角度 */ getAngle(e, i) { const o = i != null ? i : this.five.getCurrentState().panoIndex; if (o === void 0) throw new Error(`getAngle(): fivePanoIndex is ${o}`); const t = this.getPanoIndexCache({ panoIndex: i, id: e.id }); if (t.angle !== void 0) return t.angle; { const r = this.workUtil.getObserverPosition(o); if (r === void 0) throw new Error(`getAngle(): observerPosition is ${r}`); const n = (() => e.stickType === "3DPoint" ? C(e.normal) : E(e.position))(); if (!n) return; const f = _(e); if (!f) return; const c = new ie.Vector3().copy(r).sub(f), g = n.angleTo(c) * 180 / Math.PI; return t.angle = g, t.angle; } } /** * @description: 获取距离 */ getDistance(e, i) { const o = k(k({}, this.five.getCurrentState()), i), { panoIndex: t, mode: r } = o, n = A(r) ? this.getPanoIndexCache({ panoIndex: t, id: e.id }) : void 0; if ((n == null ? void 0 : n.distance) !== void 0) return n.distance; const f = _(e); if (!f) return -1; if (A(r)) { const c = this.workUtil.getObserverPosition(t); if (c === void 0) return -1; const g = c.distanceTo(f); return n && (n.distance = g), g; } if ($(r)) return this.five.camera.position.distanceTo(f); } getPositions(e) { if (ce(e)) return e.position; if (B(e)) return e.data.mediaPosition; if (ae(e)) return oe(this.five.camera.position, C(e.position), C(e.normal)); } addObjectClickHandler(e, i, o) { if (!i || !this.domEvents) return () => { }; const t = () => !(!this.getCurrentVisibleState(e) || e.loading), r = (n) => { if (!t()) return !1; o(n.origDomEvent); }; return this.domEvents.addEventListener(i, "click", r), () => { var n; (n = this.domEvents) == null || n.removeEventListener(i, "click", r); }; } getTagNormal(e) { if (e.normal) return C(e.normal); if (e.stickType === "Plane") return E(e.position); if (e.stickType === "Model") return E(this.getPositions(e)); } // TODO: 优化点:下面这些函数,调用比较频繁,可以按点位加缓存 get filterPointTag() { return this.tags.filter((e) => e.stickType === "2DPoint" || e.stickType === "3DPoint").filter((e) => e.position); } get filter2DPointTag() { return this.tags.filter((e) => e.stickType === "2DPoint").filter((e) => e.position); } get filterImagePlane() { return this.tags.filter( (e) => e.contentType === "MediaPlane" && e.stickType === "Plane" && this.getRenderType(e) === "Mesh" ); } get filterMediaModel() { return this.tags.filter((e) => e.stickType === "Model" && e.contentType === "MediaModel"); } get filterCSS3DTag() { return this.tags.filter( (i) => i.stickType === "3DPoint" || i.stickType === "Plane" || i.stickType === "Model" && i.contentType === "MediaModel" ).filter((i) => { const o = this.getRenderType(i); return o === "BehindDom" || o === "Dom"; }); } getTransformedPostion(e) { if (!e) return; const i = this.workUtil.transform; return Array.isArray(e) && e.length === 4 ? e.map(C).map((o) => J(o, i)) : J(C(e), i); } /** * @description 检查是否已经销毁 * @returns isDisposed; 已经销毁返回 true,否则返回 false */ checkDisposed() { return this.store.disposed ? (console.error("PanoTagPluginController has been disposed"), !0) : !1; } /** * @description: 获取merge后的配置 */ calculateTagConfig(e, i) { var O, j, S, I, W; const o = (O = i == null ? void 0 : i.useCache) != null ? O : !0; if (!e) return (j = this.config.globalConfig) != null ? j : {}; if (o) { if ((S = e == null ? void 0 : e.computedConfig) != null && S._isMerged) return e.computedConfig; if ((I = e == null ? void 0 : e.config) != null && I._isMerged) return e.config; } const t = {}, r = {}, n = {}; this.config.contentTypeConfig && Object.entries(this.config.contentTypeConfig).forEach(([d, u]) => { var V, L; const a = d, D = a.split("-"), F = d.startsWith("["), T = F ? D[0].slice(1, -1) : void 0, h = F ? D.slice(1) : D, v = T ? ["PanoramaLike", "ModelLike"].includes(T) ? (V = r[T]) != null ? V : r[T] = {} : (L = n[T]) != null ? L : n[T] = {} : t; if (!v[a]) { if (h.length === 0 && (v[a] = u), h.length === 1) { const [m] = h; (e.contentType === m || m === "Any") && (v[a] = u); } if (h.length === 2) { const [m = "Any", P = "Any"] = h; m === "Mixin" && e.contentType === P && (v[a] = u), (e.stickType === m || m === "Any") && (e.contentType === P || P === "Any") && (v[a] = u); } if (h.length === 3) { const [m = "Any", P, X] = h; if (P === "Audio" && e.contentType === "Audio") { const U = e; (U.stickType === m || m === "Any") && U.data.appearance === X && (v[a] = u); } } } }); const f = (W = e.initialConfig) != null ? W : {}, c = y({}, ee, this.config.globalConfig, ...Object.values(t)), g = y({}, c, f), M = {}, G = Object.values(fe.Mode); z(r).forEach(([d, u]) => { G.forEach((a) => { (d === "PanoramaLike" && A(a) || d === "ModelLike" && $(a)) && (M[a] = y({}, c, ...Object.values(u), f, { _isMerged: !0 })); }); }), z(n).forEach(([d, u]) => { M[d] = y({}, c, ...Object.values(u), f, { _isMerged: !0 }); }); const b = R(k({}, g), { configWithFiveMode: M }); return N(b), Object.values(M).forEach((d) => N(d)), b._isMerged = !0, b; } } export { di as TagUtil };