@realsee/dnalogel
Version:
274 lines (273 loc) • 9.83 kB
JavaScript
var ne = Object.defineProperty;
var J = Object.getOwnPropertySymbols;
var oe = Object.prototype.hasOwnProperty, se = Object.prototype.propertyIsEnumerable;
var Q = (t, n, e) => n in t ? ne(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e, B = (t, n) => {
for (var e in n || (n = {}))
oe.call(n, e) && Q(t, e, n[e]);
if (J)
for (var e of J(n))
se.call(n, e) && Q(t, e, n[e]);
return t;
};
var X = (t, n, e) => new Promise(($, h) => {
var S = (x) => {
try {
u(e.next(x));
} catch (v) {
h(v);
}
}, l = (x) => {
try {
u(e.throw(x));
} catch (v) {
h(v);
}
}, u = (x) => x.done ? $(x.value) : Promise.resolve(x.value).then(S, l);
u((e = e.apply(t, n)).next());
});
import { Five as re } from "@realsee/five";
import { Vector3 as L, Raycaster as ie } from "three";
import { intersectionOfLine as le } from "../shared-utils/math/planimetry.js";
import { nextFrame as ae } from "../shared-utils/nextFrame.js";
import ce from "./style.js";
const ue = (t, n) => Math.sqrt(Math.pow(t.z - n.z, 2) + Math.pow(t.x - n.x, 2)), de = (t, n) => {
const e = {}, $ = new ie(), h = n.work;
if (!h)
return e;
const S = t.observers;
h.observers.forEach((l, u) => {
const { standingPosition: x } = l, v = new L(x.x, x.y, x.z);
$.set(v, new L(0, 1, 0));
const [I] = n.model.intersectRaycaster($), q = I ? I.point.y : 2.7, k = S[u];
if (!k)
return e;
const A = t.rooms[k].name;
e[A] === void 0 ? e[A] = {
__roof: [q],
__floor: [v.y]
} : (e[A].__roof.push(q), e[A].__floor.push(v.y));
});
for (const l in e) {
const u = e[l];
u.__roof.sort(), u.__floor.sort(), u.floor = u.__floor[~~(u.__floor.length / 2)], u.roof = u.__roof[u.__roof.length - 1];
}
return e;
}, Pe = (t, n) => {
const e = {
enable: !1,
loaded: !1,
options: n.options || {
distanceText: (r) => `${r.toFixed(1)}m`
}
}, $ = (r, a) => {
const c = `
<div class="PanoRulerPlugin-rule-line">
<em></em>
<div class="PanoRulerPlugin-rule-label">
<div class="PanoRulerPlugin-rule-label-name">${e.options.distanceText(a)}</div>
</div>
</div>
`, o = document.createElement("div");
return o.setAttribute("class", "PanoRulerPlugin-rule"), o.setAttribute("data-name", r), o.setAttribute("style", "display: none"), o.innerHTML = c, o;
}, h = document.createElement("div");
h.setAttribute(
"style",
"position: absolute;pointer-events: none;width: 100%;height: 100%;left: 0;top: 0;overflow: hidden;"
);
const S = document.createElement("div");
S.innerHTML = ce, h.appendChild(S);
const l = {}, u = (r, a) => {
if (e.loaded)
throw new Error("标尺被重复初始化!");
const c = de(r, t), o = t.work;
if (!o)
return !1;
for (const i in a) {
const y = a[i], { standingPosition: p } = o.observers[0], m = y.map(({ x: d, z: f, observers: b }) => {
const s = b.length > 0 ? r.rooms[r.observers[b[0]]].name : "", P = c[s] ? c[s].floor : null;
let g = 1 / 0, w = {
index: 0,
x: p.x,
y: p.y,
z: p.z
};
b.forEach((C) => {
if (!o.observers[C])
return;
const { standingPosition: Y } = o.observers[C], O = {
index: C,
x: Y.x,
y: Y.y,
z: Y.z
}, R = ue({ x: d, z: f }, O);
P ? R < g && Math.abs(O.y - P) < 0.3 && (g = R, w = O) : R < g && (g = R, w = O);
});
const _ = new L(d, w.y, f);
Object.assign(_, { observers: b });
const T = c[s] ? c[s].roof : null, j = T ? new L(d, T, f) : null;
return j && Object.assign(j, { observers: b }), { origin: _, vertical: j };
});
l[i] = {
origins: m.map((d) => d.origin),
rules: []
};
for (const { origin: d, vertical: f } of m) {
if (!f)
continue;
const b = $(i, d.distanceTo(f));
h.append(b), l[i].rules.push({ vertical: !0, rule: [d, f], $element: b });
}
for (let d = 0; d < m.length; d++) {
let f = d + 1;
f >= m.length && (f = 0);
const { origin: b } = m[d], { origin: s } = m[f], P = $(i, b.distanceTo(s));
h.append(P), l[i].rules.push({ vertical: !1, rule: [b, s], $element: P });
}
}
return e.loaded = !0, !0;
}, x = (r, a, c) => X(void 0, null, function* () {
const o = r || n.roomInfo, i = a || n.roomRules;
if (!o || !i)
throw new Error("标尺数据依赖不齐全!");
return e.loaded = !1, e.options = B(B({}, e.options), c || {}), t.model.loaded ? u(o, i) : yield new Promise(
(y) => t.once("modelLoaded", () => y(u(o, i)))
);
});
n.roomInfo && n.roomRules && x(n.roomInfo, n.roomRules);
const v = (r, a, c, o) => {
const i = [
[
{ x: 0, y: 0 },
{ x: c, y: 0 }
],
[
{ x: 0, y: 0 },
{ x: 0, y: o }
],
[
{ x: c, y: 0 },
{ x: c, y: o }
],
[
{ x: 0, y: o },
{ x: c, y: o }
]
], y = [];
for (let p = 0; p < i.length; p++) {
const m = le([r, a], [i[p][0], i[p][1]], !0);
m && y.push(m);
}
return y.length === 0 ? !1 : y;
}, I = () => {
var b;
const r = (b = t.getElement()) == null ? void 0 : b.parentElement;
if (!r || !e.loaded || Object.keys(l).length <= 0)
return;
const { panoIndex: a, camera: c, currentMode: o } = t;
if (a === void 0)
return;
let i;
for (const s in l)
s.split(",").indexOf(a.toString()) >= 0 && (i = s);
if (!i) {
for (const s in l)
for (const { $element: P } of l[s].rules)
P.style.display = "none";
return;
}
const y = c.position, p = c.getWorldDirection(new L()), m = r.clientWidth, d = r.clientHeight;
if (o !== re.Mode.Panorama) {
for (const s in l)
for (const { $element: P } of l[s].rules)
P.style.display = "none";
return;
}
for (const s in l)
for (const { $element: P } of l[s].rules)
P.style.display = s === i ? "block" : "none";
const [f] = l[i].origins.slice().filter((s) => s.observers.indexOf(a) >= 0).sort((s, P) => {
const g = s.clone().setY(0).sub(y).normalize().angleTo(p.clone().setY(0)), w = P.clone().setY(0).sub(y).normalize().angleTo(p.clone().setY(0));
return g - w;
});
for (const { rule: s, vertical: P, $element: g } of l[i].rules) {
const [w, _] = s, T = g.querySelector(".PanoRulerPlugin-rule-line");
if (!T)
return;
if (!f) {
g.style.display = "none";
continue;
}
if (w !== f && _ !== f) {
g.style.display = "none";
continue;
}
if (w.distanceTo(_) < 0.3) {
g.style.display = "none";
continue;
}
if (w.observers.indexOf(a) === -1 || _.observers.indexOf(a) === -1) {
g.style.display = "none";
continue;
}
if (w.clone().sub(y).normalize().angleTo(p) > Math.PI / 2) {
g.style.display = "none";
continue;
}
if (_.clone().sub(y).normalize().angleTo(p) > Math.PI / 2) {
g.style.display = "none";
continue;
}
const K = w.distanceTo(_);
if (_.clone().sub(_.clone().sub(w).divide(new L(2, 2, 2))).distanceTo(y) / K > 8) {
g.style.display = "none";
continue;
}
const O = w.clone().project(c), R = (O.x + 1) / 2 * m, F = (-O.y + 1) / 2 * d, V = _.clone().project(c), N = (V.x + 1) / 2 * m, D = (-V.y + 1) / 2 * d, E = Math.sqrt(Math.pow(N - R, 2) + Math.pow(D - F, 2));
let H = E, z = 50;
const M = v({ x: ~~R, y: ~~F }, {
x: ~~N,
y: ~~D
}, m, d);
if (M && M.length === 1 && (f === w ? (H = Math.sqrt(Math.pow(M[0].x - R, 2) + Math.pow(M[0].y - F, 2)), z = H / E * 50) : f === _ && (H = Math.sqrt(Math.pow(M[0].x - N, 2) + Math.pow(M[0].y - D, 2)), z = 100 - H / E * 50)), M && M.length === 2) {
const G = {
x: (M[0].x + M[1].x) / 2,
y: (M[0].y + M[1].y) / 2
};
z = Math.sqrt(
Math.pow(G.x - R, 2) + Math.pow(G.y - F, 2)
) / E * 100;
}
const te = (Math.PI / 2 - Math.atan2(N - R, F - D)) / Math.PI * 180, W = T.querySelector(".PanoRulerPlugin-rule-label"), U = W.children[0].clientWidth;
U >= E || U / 2 >= z / 100 * E || U / 2 >= (1 - z / 100) * E ? T.style.display = "none" : (T.style.display = "block", T.style.width = E + "px", T.style.left = R + "px", T.style.top = F + "px", T.style.transform = `rotate(${-te}deg)`, W.style.left = `${z}%`);
}
}, q = () => ae(I), k = () => {
var r, a;
return e.loaded ? (e.enable || (h.setAttribute("class", "PanoRulerPlugin" + (e.options.className ? " " + e.options.className : "")), (a = (r = t.getElement()) == null ? void 0 : r.parentElement) == null || a.append(h), I(), t.on("modeChange", I), t.on("cameraUpdate", q), e.enable = !0), !0) : !1;
}, A = () => (e.enable && (t.off("modeChange", I), t.off("cameraUpdate", q), h && h.remove(), e.enable = !1), !0);
function Z(r) {
if (r.distanceText && r.distanceText !== e.options.distanceText) {
const a = r.distanceText;
e.options.distanceText = a, Object.values(l).forEach((c) => {
c.rules.forEach((o) => {
const [i, y] = o.rule, p = i.distanceTo(y), m = o.$element.querySelector(".PanoRulerPlugin-rule-label-name");
m && (m.innerText = a(p));
});
});
}
}
return {
enable: k,
disable: A,
load: x,
state: e,
changeConfigs: Z
};
}, we = {
name: "PanoRulerPlugin",
version: 0
};
export {
Pe as PanoRulerPlugin,
Pe as default,
we as panoRulerPluginServerParams
};