@realsee/dnalogel
Version:
149 lines (148 loc) • 6.41 kB
JavaScript
var C = Object.defineProperty, P = Object.defineProperties;
var b = Object.getOwnPropertyDescriptors;
var y = Object.getOwnPropertySymbols;
var k = Object.prototype.hasOwnProperty, O = Object.prototype.propertyIsEnumerable;
var u = (r, e, t) => e in r ? C(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, d = (r, e) => {
for (var t in e || (e = {}))
k.call(e, t) && u(r, t, e[t]);
if (y)
for (var t of y(e))
O.call(e, t) && u(r, t, e[t]);
return r;
}, c = (r, e) => P(r, b(e));
var f = (r, e, t) => (u(r, typeof e != "symbol" ? e + "" : e, t), t);
var S = (r, e, t) => new Promise((s, h) => {
var o = (i) => {
try {
n(t.next(i));
} catch (a) {
h(a);
}
}, p = (i) => {
try {
n(t.throw(i));
} catch (a) {
h(a);
}
}, n = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(o, p);
n((t = t.apply(r, e)).next());
});
import w from "./BaseController.js";
import { objectAssignDeepExports as l } from "../vendor/object-assign-deep/objectAssignDeep.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 { uuid as x } from "../shared-utils/uuid.js";
import { getFiveStateOnCurve as g } from "./utils/getFiveStateOnCurve.js";
import "../base/BasePlugin.js";
import "../shared-utils/Subscribe.js";
import "../shared-utils/url/absoluteUrl.js";
import "../shared-utils/equal.js";
import "../shared-utils/isTruelyObject.js";
import "../shared-utils/Utils/FiveUtil.js";
import "../shared-utils/Utils/BaseUtil.js";
import "../shared-utils/Utils/WorkUtil.js";
import "../shared-utils/five/transformPosition.js";
import "../shared-utils/positionToVector3.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/centerPoint.js";
import "../shared-utils/three/getObjectVisible.js";
import "../CSS3DRenderPlugin/utils/three/CSS3DScene.js";
import "../CSS3DRenderPlugin/utils/three/CSS3DGroup.js";
import "../shared-utils/vectorToCoordinate.js";
import "../shared-utils/formatRad.js";
class nt extends w {
constructor(t, s) {
var p;
super(t, s);
f(this, "curve");
f(this, "baseCurveOffset");
f(this, "curveOffset");
f(this, "playStartedTime", performance.now());
f(this, "duration");
f(this, "changeSpeed", (t, s = !0) => {
this.state.speed = t, this.hooks.emit("speedChange", t, { userAction: s });
});
f(this, "moveToStart", () => {
this.five.setState(c(d({}, g(this.curve, 0, this.curveOffset)), { mode: "Model" }));
});
f(this, "playFromStart", () => {
this.clearPauseData(), this.setState({ playing: !0 });
});
f(this, "getDuration", () => this.getSpeededDuration(this.duration));
f(this, "getProgress", () => {
var i;
const t = this.getPauseData();
let s = (i = t == null ? void 0 : t.playedProgress) != null ? i : 0;
(s < 0 || s >= 1) && (s = 0);
const h = 1 - s, o = this.getDuration(), n = (performance.now() - this.playStartedTime) / o;
return 1 - h + n;
});
const h = {
config: {
speedConfig: {
moveSpeed: 2,
moveSpeedUnit: "m/s"
}
}
}, o = {
allowBroke: !0
};
this.state = l({}, h, this.state), this.config = l({}, o, this.config), this.baseCurveOffset = l({ x: 0, y: 0, z: 0 }, { y: 2 }, (p = this.config) == null ? void 0 : p.offset);
}
load(t, s) {
var p, n, i, a, m, v;
if (this.handlePause(), this.clear(), this.data = d({ id: x() }, t), this.curve = this.data.path.curves[0], this.curveOffset = {
x: this.baseCurveOffset.x + ((n = (p = this.data.offset) == null ? void 0 : p.x) != null ? n : 0),
y: this.baseCurveOffset.y + ((a = (i = this.data.offset) == null ? void 0 : i.y) != null ? a : 0),
z: this.baseCurveOffset.z + ((v = (m = this.data.offset) == null ? void 0 : m.z) != null ? v : 0)
}, !this.curve)
throw new Error("curve is not defined");
const h = this.curve.getLength(), o = this.state.config.speedConfig.moveSpeedUnit === "m/ms" ? 1 : 1e3;
return this.duration = h / (this.state.config.speedConfig.moveSpeed / o), s ? this.setState(s) : (this.setState({ playing: !1 }), this.handleVisible(this.state.visible), this.handleEnable(this.state.enabled), this.changePlayState(this.state.playing), this.changeSpeed(this.state.speed)), Promise.resolve();
}
handlePlay() {
return new Promise((t, s) => S(this, null, function* () {
var i;
this.hooks.emit("play", { userAction: !0 });
const h = this.getPauseData();
let o = (i = h == null ? void 0 : h.playedProgress) != null ? i : 0;
(o < 0 || o >= 1) && (o = 0);
const p = g(this.curve, o, this.curveOffset);
if (this.hooks.emit("progressChange", o), this.five.setState(c(d({}, p), { mode: "Model" })), yield this.five.ready(), this.playStartedTime = performance.now(), this.config.allowBroke) {
const a = this.addInterruptListener(() => {
this.state.playing && (this.hooks.emit("broke"), this.handlePause(), a(), s(new Error("broke")));
});
}
const n = () => {
const a = this.getProgress();
if (a >= 1)
this.five.off("renderFrame", n), this.setState({ playing: !1 }, { userAction: !1 }), this.hooks.emit("end"), this.hooks.emit("progressChange", 1), t("end");
else if (this.state.playing === !1)
this.five.off("renderFrame", n);
else if (a >= 0) {
const m = g(this.curve, a, this.curveOffset);
this.hooks.emit("progressChange", a), this.five.setState(m, !0);
}
};
this.five.on("renderFrame", n);
}));
}
handlePause(t) {
var s;
this.state.playing = !1, this.hooks.emit("pause", { userAction: (s = t == null ? void 0 : t.userAction) != null ? s : !0 }), this.setPauseData();
}
}
export {
nt as default
};