@realsee/dnalogel
Version:
90 lines (89 loc) • 3.12 kB
JavaScript
var p = Object.defineProperty;
var a = (e, o, t) => o in e ? p(e, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[o] = t;
var n = (e, o, t) => (a(e, typeof o != "symbol" ? o + "" : o, t), t);
import { IObject3D as d } from "../../shared-utils/three/IObject3D.js";
import { anyPositionToVector3 as c } from "../../shared-utils/positionToVector3.js";
import "hammerjs";
import "three";
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 r } from "../../shared-utils/isNil.js";
import { RectangleWithEdgeMesh as P } from "./RectangleWithEdge.js";
import { RectangleMesh as m } from "./Rectangle.js";
class w extends d {
constructor(t) {
super();
n(this, "name", "BoxMesh");
n(this, "bottomPlane");
n(this, "topPlane");
n(this, "heightPoint");
n(this, "edgePlanes", []);
this.bottomPlane = new P(t), this.topPlane = new P(t), this.add(this.bottomPlane), t != null && t.points && this.setPoints(t);
}
get planes() {
return this.children.filter((t) => t instanceof m);
}
get color() {
var t;
return (t = this.bottomPlane) == null ? void 0 : t.color;
}
get lineColor() {
var t;
return (t = this.bottomPlane) == null ? void 0 : t.lineColor;
}
get lineWidth() {
var t;
return (t = this.bottomPlane) == null ? void 0 : t.lineWidth;
}
get occlusionVisibility() {
var t;
return (t = this.bottomPlane) == null ? void 0 : t.occlusionVisibility;
}
setPoints(t) {
r(t.heightPoint) && this.setTopHeightPoint(t.heightPoint), r(t.points) && this.setBottomPoints(t.points);
}
setBottomPoints(t) {
const i = t.map(c).filter(r);
if (i.length < 3) {
console.error("Invalid position");
return;
}
this.bottomPlane.setPoints(i), this.heightPoint && this.setTopHeightPoint(this.heightPoint);
}
setTopHeightPoint(t) {
if (!this.bottomPlane.points.length)
return;
const i = c(t);
this.heightPoint = i, this.addIfNotExists(this.topPlane);
const h = this.bottomPlane.projectPoint(i), s = i.clone().sub(h), l = this.bottomPlane.points.map((g) => g.clone().add(s));
this.topPlane.setPoints(l), this.up.copy(s.clone().normalize()), this.setEdgePlanes();
}
setEdgePlanes() {
for (let t = 0; t < 4; t++) {
let i = this.edgePlanes[t];
i || (this.edgePlanes[t] = new P({
color: this.color,
lineColor: this.lineColor,
lineWidth: this.lineWidth,
occlusionVisibility: this.occlusionVisibility
}), i = this.edgePlanes[t]);
const h = this.topPlane.sortedPoint, s = this.bottomPlane.sortedPoint, l = t === 3 ? 0 : t + 1;
i.setPoints([h[t], s[l], s[t]]), this.addIfNotExists(i);
}
}
setStyle(t) {
this.planes.forEach((i) => i.setStyle(t));
}
highlight() {
this.planes.forEach((t) => t.highlight());
}
unhighlight() {
this.planes.forEach((t) => t.unhighlight());
}
}
export {
w as BoxMesh
};