@realsee/dnalogel
Version:
110 lines (109 loc) • 4.81 kB
JavaScript
var k = Object.defineProperty;
var E = (h, o, e) => o in h ? k(h, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : h[o] = e;
var l = (h, o, e) => (E(h, typeof o != "symbol" ? o + "" : o, e), e);
import * as r from "three";
import { DEFAULT_LINE_COLOR as g, DEFAULT_LINE_WIDTH as w, DEFAULT_HIGHLIGHT_OPACITY as L } from "../utils/color.js";
import { LineGeometry as y, LineMaterial as a, THREE_Line2 as H } from "@realsee/five/line";
import { anyPositionToVector3 as C } from "../../shared-utils/positionToVector3.js";
import { IObject3D as D } from "../../shared-utils/three/IObject3D.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 { notNil as s } from "../../shared-utils/isNil.js";
class b extends a {
constructor(e) {
var t, i;
super(e);
l(this, "_three_color");
s(e == null ? void 0 : e.color) && (this.three_color = (t = e == null ? void 0 : e.color) != null ? t : 16777215), Object.keys(e).forEach((n) => {
["color", "dashed", "dashScale", "dashSize", "gapSize", "resolution"].includes(n) || n in this && (this[n] = e[n]);
}), this.setDashed((i = e == null ? void 0 : e.dashed) != null ? i : !1);
}
get three_color() {
return this._three_color;
}
set three_color(e) {
this._three_color = e, this.color = e;
}
setDashed(e) {
e ? this.defines.USE_DASH = "" : delete this.defines.USE_DASH, this.needsUpdate = !0;
}
}
class _ extends H {
constructor(e, t) {
super(e, t);
l(this, "name", "Line3");
}
}
class G extends D {
constructor(e) {
var c, d, f, u;
super();
l(this, "name", "LineMesh");
l(this, "points");
l(this, "highlighted", !1);
l(this, "line");
l(this, "backLine");
l(this, "opacityBeforeHighlight");
const t = new y(), i = new b({
color: new r.Color((c = e == null ? void 0 : e.lineColor) != null ? c : g),
linewidth: (d = e == null ? void 0 : e.lineWidth) != null ? d : w,
dashScale: 40,
opacity: 1,
transparent: !0,
dashed: (f = e == null ? void 0 : e.dashed) != null ? f : !1
}), n = new b({
color: new r.Color((u = e == null ? void 0 : e.lineColor) != null ? u : g),
linewidth: i == null ? void 0 : i.linewidth,
dashScale: i.dashScale,
depthTest: !1,
depthWrite: !1,
transparent: !0,
opacity: 0.2,
dashed: i.dashed,
resolution: i.resolution
});
this.line = new _(t, i), this.backLine = new _(t, n), this.line.renderOrder = 1, this.backLine.renderOrder = 0, this.line.name = "lineFrontMaterial", this.backLine.name = "lineBackMaterial", e && this.setStyle(e), e != null && e.points && this.setPoints(e.points);
}
get lineWidth() {
return this.line.material.linewidth;
}
get color() {
return new r.Color(this.line.material.three_color);
}
get dashed() {
return this.line.material.dashed;
}
get occlusionVisibility() {
return this.backLine.visible;
}
setPoints(e) {
const t = e.map(C).filter(s);
if (this.points = t, t.length < 2)
return;
this.addIfNotExists(this.line, this.backLine);
const i = t.flatMap((n) => [n.x, n.y, n.z]);
i.length > 2 && (this.line.geometry.dispose(), this.line.geometry = new y(), this.backLine.geometry = this.line.geometry), this.line.geometry.setPositions(i), this.line.computeLineDistances(), this.needsRender = !0;
}
setResolution(e, t) {
const i = this.line.material.resolution;
(i.x !== e || i.y !== t) && (i.set(e, t), this.needsRender = !0);
const n = this.backLine.material.resolution;
(n.x !== e || n.y !== t) && (n.set(e, t), this.needsRender = !0);
}
setStyle(e) {
s(e.lineColor) && (this.line.material.three_color = new r.Color(e.lineColor), this.backLine.material.three_color = new r.Color(e.lineColor)), s(e.lineWidth) && (this.line.material.linewidth = e.lineWidth, this.backLine.material.linewidth = e.lineWidth), s(e.dashed) && (this.line.material.setDashed(e.dashed), this.backLine.material.setDashed(e.dashed)), s(e.occlusionVisibility) && (this.backLine.visible = e.occlusionVisibility), this.needsRender = !0;
}
highlight() {
this.highlighted || (this.highlighted = !0, this.opacityBeforeHighlight = this.line.material.opacity, this.line.material.opacity = this.opacityBeforeHighlight * L, this.backLine.material.opacity = this.backLine.material.opacity * L, this.needsRender = !0);
}
unhighlight() {
this.highlighted && (this.highlighted = !1, this.line.material.opacity = this.opacityBeforeHighlight, this.backLine.material.opacity = 0.2, this.needsRender = !0);
}
}
export {
G as LineMesh
};