videx-3d
Version:
React 3D component library designed for sub surface visualizations in the browser
469 lines (468 loc) • 18.7 kB
JavaScript
var Q = Object.defineProperty;
var X = (d, t, s) => t in d ? Q(d, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : d[t] = s;
var k = (d, t, s) => X(d, typeof t != "symbol" ? t + "" : t, s);
import { wrap as Y } from "comlink";
import { K as dt, ad as ut, b as ft, a as gt, P as pt, c as wt, T as yt, a9 as xt, Z as mt, a5 as vt, y as bt, M as Mt, d as At, a4 as It, o as Ft, i as Vt, p as kt, a1 as Et, a2 as Lt, e as Bt, Q as Tt, O as _t, x as Gt, g as Wt, A as jt, B as Pt, k as Dt, E as St, D as zt, h as Nt, a7 as Ut, X as qt, S as Ht, ac as Zt, a0 as Jt, R as $t, t as Kt, j as Ot, m as Qt, a3 as Xt, aa as Yt, W as Ct, n as Rt, f as te, F as ee, I as se, H as re, G as ne, q as ie, r as ae, U as le, a6 as oe, ab as he, $ as ce, a8 as de, Y as ue, s as fe, _ as ge, V as pe, N as we, J as ye, u as xe, ae as me } from "./chunk-CPDkHB2U.js";
import { d as $, e as K } from "./chunk-Bv7spTT9.js";
import { C as be, T as Me, c as Ae, b as Ie, g as Fe, j as Ve, i as ke, r as Ee, t as Le, h as Be } from "./chunk-Bv7spTT9.js";
import { D as _e, a as Ge, c as We, d as je, f as Pe, b as De, t as Se } from "./chunk-BJ3kEVFR.js";
class et {
constructor(t) {
k(this, "store", null);
k(this, "generators", /* @__PURE__ */ new Map());
t && (this.store = t);
}
add(t, s) {
this.generators.set(t, s);
}
setStore(t) {
this.store = t;
}
async connectRemoteStore(t) {
const s = Y(t);
this.store = s;
}
async invoke(t, ...s) {
if (!this.store) throw Error("No available store!");
if (!this.generators.has(t))
throw Error(`Generator with key '${t}' not found!`);
return this.generators.get(t).bind(this.store)(...s);
}
}
function st(d, t, s = 1, r = 1, n = (i) => i) {
console.time("triangulate");
const i = [], e = [], a = [], c = [], h = d.length / t;
let l, o, f, g, b, y, x, M, I, E, v, L, A, F, V, S, u, q, W, j, P, p, m, H, O = 0, Z = 0, J = 0, T = new Array(t).fill(null), z = new Array(t).fill(null);
const w = new Array(t - 1).fill(null);
function N(B, G, D) {
return i.push({ x: B * s, y: D, z: G * r, edge: null }), a.push(B / (t - 1), 1 - G / (h - 1)), O++;
}
function _(B, G, D) {
W = { index: Z++, tail: B, head: G, twin: null, prev: null, next: null }, j = { index: Z++, tail: G, head: D, twin: null, prev: null, next: null }, P = { index: Z++, tail: D, head: B, twin: null, prev: null, next: null }, W.next = j, j.next = P, P.next = W, W.prev = P, j.prev = W, P.prev = j, i[B].edge || (i[B].edge = W), i[G].edge || (i[G].edge = j), i[D].edge || (i[D].edge = P), e.push(W, j, P), c.push(B, G, D);
}
for (S = 1; S < h - 1; S++) {
H = !1;
const B = T;
for (T = z, z = B.fill(null), p = null, q = S - 1, J += t, V = 1; V < t - 1; V++)
u = V - 1, E = J + V, I = E - 1, M = E - t, x = M - 1, v = n(d[x]), L = n(d[M]), A = n(d[I]), F = n(d[E]), v !== null && L !== null && A !== null && F !== null ? m = 1 : v !== null && L !== null && A !== null ? m = 2 : v !== null && L !== null && F !== null ? m = 3 : v !== null && A !== null && F !== null ? m = 4 : L !== null && A !== null && F !== null ? m = 5 : m = 0, f = null, g = null, m !== 0 ? (H ? (l = T[u], f = z[u]) : (m !== 5 && (T[u] === null ? (l = N(u, q, v), T[u] = l) : l = T[u]), m !== 3 && (f = N(u, S, A)), z[u] = f), m !== 4 && (T[V] === null ? (o = N(V, q, L), T[V] = o) : o = T[V]), m !== 2 && (g = N(V, S, F)), m === 1 ? (b = Math.abs(i[l].y - i[g].y), y = Math.abs(i[o].y - i[f].y), b < y ? (_(l, f, g), p !== null && (e[e.length - 3].twin = p, p.twin = e[e.length - 3]), _(g, o, l), w[u] !== null && (e[e.length - 2].twin = w[u], w[u].twin = e[e.length - 2]), e[e.length - 4].twin = e[e.length - 1], e[e.length - 1].twin = e[e.length - 4], w[u] = e[e.length - 5], p = e[e.length - 3]) : (_(l, f, o), w[u] !== null && (e[e.length - 1].twin = w[u], w[u].twin = e[e.length - 1]), p !== null && (e[e.length - 3].twin = p, p.twin = e[e.length - 3]), _(o, f, g), e[e.length - 5].twin = e[e.length - 3], e[e.length - 3].twin = e[e.length - 5], w[u] = e[e.length - 2], p = e[e.length - 1])) : m === 2 ? (_(l, f, o), w[u] !== null && (e[e.length - 1].twin = w[u], w[u].twin = e[e.length - 1]), p !== null && (e[e.length - 3].twin = p, p.twin = e[e.length - 3]), w[u] = null, p = null) : m === 5 ? (_(o, f, g), w[u] = e[e.length - 2], p = e[e.length - 1]) : m === 3 ? (_(o, l, g), w[u] !== null && (e[e.length - 3].twin = w[u], w[u].twin = e[e.length - 3]), w[u] = null, p = e[e.length - 1]) : (_(l, f, g), p !== null && (e[e.length - 3].twin = p, p.twin = e[e.length - 3]), w[u] = e[e.length - 2], p = null)) : (w[u] = null, p = null), z[V] = g, H = !!m;
}
return console.timeEnd("triangulate"), console.log(c.length / 3), { vertices: i, indices: c, uvs: a, edges: e };
}
class rt {
constructor() {
k(this, "map", /* @__PURE__ */ new Map());
this.onWellboreAdded = this.onWellboreAdded.bind(this), this.onWellboreRemoved = this.onWellboreRemoved.bind(this), addEventListener($, this.onWellboreAdded), addEventListener(K, this.onWellboreRemoved);
}
onWellboreAdded(t) {
this.map.set(t.detail.id, {
wellboreId: t.detail.id,
position: t.detail.position,
objectId: t.detail.objectId,
objectUuid: t.detail.objectUuid
});
}
onWellboreRemoved(t) {
this.map.delete(t.detail.id);
}
getInfo(t) {
return this.map.get(t);
}
getAll() {
return this.map.values();
}
dispose() {
removeEventListener($, this.onWellboreAdded), removeEventListener(K, this.onWellboreRemoved);
}
}
async function nt(d, t = -1, s = null) {
const r = await d.arrayBuffer(), n = new DataView(r), i = {
ny: n.getInt32(8, !1),
xori: n.getFloat32(12, !1),
xmax: n.getFloat32(16, !1),
yori: n.getFloat32(20, !1),
ymax: n.getFloat32(24, !1),
xinc: n.getFloat32(28, !1),
yinc: n.getFloat32(32, !1),
nx: n.getInt32(44, !1),
rot: n.getFloat32(48, !1)
}, e = 1e30, a = 1e-30, c = new Float32Array(i.nx * i.ny);
let h, l, o, f, g, b = 0, y = 100;
for (; y < n.byteLength; ) {
l = n.getInt32(y), y += 4;
for (let x = 0; x < l; x += 4)
h = n.getFloat32(y + x, !1), o = b % i.nx, f = i.ny - Math.floor(b / i.nx), g = (f - 1) * i.nx + o, c[g] = h < a || h > e ? t : s ? s - h : h, b++;
y += l + 4;
}
return { header: i, data: c };
}
function it(d) {
return d.map((t) => -t);
}
function at(d, t) {
return d.map((s) => s * t);
}
function lt(d, t, s) {
const r = (n) => {
if (n.userData[d] && n.userData[d] === t)
return n;
if (n.children && n.children.length)
for (let i = 0; i < n.children.length; i++) {
const e = r(n.children[i]);
if (e)
return e;
}
return null;
};
return r(s);
}
class U {
constructor(t, s, r = 1) {
k(this, "data");
k(this, "columns");
k(this, "rows");
k(this, "stride");
k(this, "_rowLength");
k(this, "_lerpFn", []);
k(this, "arrayConstructor");
this.data = t, this.columns = s, this.stride = r, this._rowLength = s * r, this.rows = this.data.length / this._rowLength, this.arrayConstructor = (n) => new this.data.constructor(n);
}
static readWriteBlock(t, s, r, n, i, e, a, c, h, l, o = null) {
if (!(t instanceof U && e instanceof U))
throw Error("Source and target must be of type Typed2dArray");
if (a < 0 || a + h > e.columns || c < 0 || c + l > e.rows)
throw Error("Invalid target block dimensions!");
if (s < 0 || s + n > t.columns || r < 0 || r + i > t.rows)
throw Error("Invalid source block dimensions!");
const f = Math.max(1, h - 1), g = Math.max(1, l - 1), b = Math.max(1, n - 1), y = Math.max(1, i - 1);
for (let x = 0; x < l; x++) {
const M = e.index(0, x + c), I = x / g * y + r;
for (let E = 0; E < h; E++) {
const v = M + (E + a) * e.stride, L = E / f * b + s;
let A = t.valueAt(L, I);
if (o && (A = o(A)), e.stride === 1)
e.data[v] = A;
else if (Array.isArray(A))
for (let F = 0; F < A.length; F++)
e.data[v + F] = A[F];
}
}
return this;
}
// built-in interpolation methods
static logInterp(t, s, r, n, i, e) {
const a = (s * s - t * t) * i + t * t, c = (n * n - r * r) * i + r * r;
return Math.sqrt((c - a) * e + a);
}
static linearInterp(t, s, r, n, i, e) {
const a = (s - t) * i + t;
return ((n - r) * i + r - a) * e + a;
}
static nearestInterp(t, s, r, n, i, e) {
const a = i <= 0.5 ? t : s, c = i <= 0.5 ? r : n;
return e <= 0.5 ? a : c;
}
// // create a new Typed2DArray instance using an existing data array
// static from<ArrayType>(source: ArrayType, columns: number, stride = 1, copyData = false) {
// const data = source instanceof Typed2DArray ? source.data : source;
// const array = new Typed2DArray(data.constructor, columns, data.length / (columns * stride), stride, false);
// array.data = copyData ? new array.type(data) : data;
// if (source instanceof Typed2DArray) {
// array.setInterpolator(...source._lerpFn);
// }
// return array;
// }
// alias for columns
get width() {
return this.columns;
}
// alias for rows
get height() {
return this.rows;
}
// get the array index to the first component from the provided column and row indices
index(t, s) {
if (t < 0 || s < 0 || t >= this.columns || s >= this.rows) throw Error("Index out of bounds!");
return s * this._rowLength + t * this.stride;
}
// get the column and row at the beginning of the item according to stride from an index into the data array
positionOf(t) {
if (t < 0 || t > this.data.length) return;
const s = t % this.stride, r = Math.floor((t - s) / this._rowLength), n = Math.floor((t - r * this._rowLength) / this.stride);
return { row: r, col: n };
}
// allow you to set a custom interpolation function per component, which are used when interpolating values
setInterpolator(...t) {
return this._lerpFn = t, this;
}
// get the configured interpolation function for the given component index
getInterpolator(t) {
return this._lerpFn.length > 0 ? this._lerpFn[Math.min(t, this._lerpFn.length - 1)] : U.linearInterp;
}
// convenience function for reading an entire column
col(t, s) {
return this.readBlock(Math.floor(t), 0, 1, this.rows, void 0, void 0, s);
}
// convenience function for reading an entire row
row(t, s) {
const r = this.index(0, Math.floor(t));
if (s) {
for (let n = 0; n < this._rowLength; n++)
s[n] = this.data[r + n];
return s;
}
return this.data.subarray(r, r + this._rowLength);
}
// set a single value into the provided column and row
setValue(t, s, ...r) {
const n = this.index(t, s);
for (let i = 0; i < Math.min(r.length, this.stride); i++)
this.data[n + i] = r[i];
return this;
}
// read all the values within the provided block dimension
readBlock(t, s, r, n, i, e, a) {
if (t < 0 || t + r > this.columns || s < 0 || s + n > this.rows) throw Error("Invalid block dimensions!");
i = Number.isFinite(i) ? i : r, e = Number.isFinite(e) ? e : n, a = a || this.arrayConstructor(i * e * this.stride);
const c = Math.max(1, i - 1), h = Math.max(1, e - 1), l = Math.max(1, r - 1), o = Math.max(1, n - 1);
let f = 0;
for (let g = 0; g < e; g++) {
const b = g / h * o + s;
for (let y = 0; y < i; y++) {
const x = y / c * l + t, M = this.valueAt(x, b);
if (this.stride === 1)
a[f++] = M;
else if (Array.isArray(M))
for (let I = 0; I < M.length; I++)
a[f++] = M[I];
}
}
return a;
}
// upscale grid using the current interpolation method
upscale(t, s) {
if (t < this.columns || s < this.rows) throw Error("New column and row size must be equal or bigger than the current sizes!");
const r = this.readBlock(0, 0, this.columns, this.rows, t, s);
return this.columns = t, this.rows = s, this._rowLength = t * this.stride, this.data = r, this;
}
// write values into a given block dimension
writeBlock(t, s, r, n, i) {
if (i.length !== r * n * this.stride) throw Error("Incorrect number of values");
if (t < 0 || t + r > this.columns || s < 0 || s + n > this.rows) throw Error("Invalid block dimensions!");
let e = 0;
for (let a = s; a < s + n; a++) {
const c = this.index(t, a);
for (let h = 0; h < r; h++) {
const l = c + h * this.stride;
for (let o = 0; o < this.stride; o++)
this.data[l + o] = i[e++];
}
}
return this;
}
// fills the block with a single value
fillBlock(t, s, r, n, i) {
if (t < 0 || t + r > this.columns || s < 0 || s + n > this.rows) throw Error("Invalid block dimensions!");
let e = (a, c, h) => {
this.data[h] = i;
};
typeof i == "function" ? e = (a, c, h) => {
const l = i(a, c, h);
if (Array.isArray(l) && l.length && l.length > 0)
for (let o = 0; o < Math.min(l.length, this.stride); o++)
this.data[h + o] = l[o];
else
this.data[h] = l;
} : this.stride > 1 && Array.isArray(i) && (e = (a, c, h) => {
for (let l = 0; l < Math.min(i.length, this.stride); l++)
this.data[h + l] = i[l];
});
for (let a = s; a < s + n; a++) {
const c = this.index(t, a);
for (let h = 0; h < r; h++) {
const l = c + h * this.stride;
e(h, a, l);
}
}
return this;
}
// get the value corresponding to the specified index according to stride
valueOf(t, s) {
const { stride: r, data: n } = this;
if (r > 1) {
t = t % r, s = s || this.arrayConstructor(r);
for (let i = 0; i < r; i++)
s[i] = n[t + i];
return s;
}
return n[t];
}
// get the calue at the requested column and row, which may be given as fractions, which in case
// bilinear filtering will be applied to interpolate values (for each component) in between columns and rows
valueAt(t, s, r) {
const { columns: n, rows: i, stride: e, data: a } = this, c = t % 1, h = s % 1;
if (c > 0 || h > 0) {
const o = (t < 0 ? 0 : t >= n ? n - 1 : t) | 0, f = (s < 0 ? 0 : s >= i ? i - 1 : s) | 0, g = o === n - 1 ? o : o + 1, b = f === i - 1 ? f : f + 1;
let y = this.index(o, f), x = this.index(g, f), M = this.index(o, b), I = this.index(g, b);
if (e > 1) {
r = r || this.arrayConstructor(e);
for (let v = 0; v < e; v++) {
const L = this.getInterpolator(v);
r[v] = L(a[y++], a[x++], a[M++], a[I++], c, h);
}
return r;
}
return this.getInterpolator(0)(a[y], a[x], a[M], a[I], c, h);
}
const l = this.index(t, s);
if (e > 1) {
r = r || this.arrayConstructor(e);
for (let o = 0; o < e; o++)
r[o] = a[l + o];
return r;
}
return a[l];
}
// swap all values from one row with all values from another row
swapRows(t, s, r) {
r = r || this.arrayConstructor(this._rowLength), this.row(t, r);
const n = this.index(0, t), i = this.index(0, s);
for (let e = 0; e < this._rowLength; e++)
this.data[n + e] = this.data[i + e], this.data[i + e] = r[e];
return this;
}
// invert all rows (top-bottom to bottom-top)
invertRows() {
const t = Math.floor(this.rows / 2), s = this.arrayConstructor(this._rowLength);
for (let r = this.rows - 1, n = 0; r > t; r--, n++)
this.swapRows(r, n, s);
return this;
}
copyInto(t, s = 0, r = 0, n = this.columns - s, i = this.rows - r) {
if (t.length !== n * i * this.stride) throw Error("Target is not of the correct size!");
let e = 0;
for (let a = r; a < r + i; a++) {
const c = this.index(0, a);
for (let h = s; h < s + n; h++) {
const l = c + h * this.stride;
for (let o = 0; o < this.stride; o++)
t[e++] = this.data[l + o];
}
}
return this;
}
// return a multi-dimensional javascript array of the data (main purpose for debugging)
toJsArray() {
const t = new Array(this.rows);
for (let s = 0; s < this.rows; s++) {
const r = this.index(0, s);
t[s] = new Array(this.columns);
for (let n = 0; n < this.columns; n++)
if (this.stride > 1) {
t[s][n] = new Array(this.stride);
for (let i = 0; i < this.stride; i++)
t[s][n][i] = this.data[r + n * this.stride + i];
} else
t[s][n] = this.data[r + n * this.stride];
}
return t;
}
}
function ot(d) {
const t = new Float32Array(d.length * 3);
for (let s = 0; s < d.length; s++) {
const r = s * 3;
t[r + 0] = d[s][0], t[r + 1] = d[s][1], t[r + 2] = d[s][2];
}
return t;
}
export {
be as CRS,
dt as CameraManager,
_e as Delatin,
ut as DepthReadMaterial,
et as GeneratorRegistry,
ft as PI,
gt as PI2,
pt as PI4,
wt as PI8,
yt as TAU,
Me as TubeMaterial,
U as Typed2DArray,
rt as WellboreManager,
xt as addVec2,
mt as addVec3,
vt as angleVec3,
bt as calculateFrenetFrames,
Ge as calculateHashValue,
Ae as calculateWellSegments,
Mt as cameraManager,
At as clamp,
It as copyVec3,
Ie as createConfig,
Ft as createElevationTexture,
Vt as createFormationIntervals,
kt as createNormalTexture,
We as createTubeGeometry,
Et as crossVec3,
je as degreesToRadians,
Lt as dotVec3,
Bt as edgeOfRectangle,
Tt as elevationMapNormalsToRGBA,
_t as elevationMapToRGBA,
Pe as feetToMeters,
Gt as getCurvePositions,
Wt as getDepthBuffer,
jt as getFormationMarkers,
lt as getObjectByCustomProperty,
Fe as getProjectionDefFromUtmZone,
Pt as getSplineCurve,
Dt as getTrajectory,
St as getTypedArrayFromBuffer,
zt as getTypedArrayType,
Nt as getUnitPicks,
Ve as getUtmZoneFromLatLng,
Ut as getVec2,
qt as getVec3,
ke as idToHexColor,
Ht as inverseLerp,
Zt as lengthVec2,
Jt as lengthVec3,
$t as lerp,
Kt as limit,
Ot as mergeFormationIntervals,
Qt as mixVec2,
Xt as mixVec3,
at as multiply,
it as negate,
Yt as negateVec2,
Ct as negateVec3,
Rt as normalizeVec2,
te as normalizeVec3,
ee as packAttribute,
se as packBufferGeometries,
re as packBufferGeometry,
ne as packBufferGeometryLike,
nt as parseIrapbin,
ie as queue,
Ee as randomColor,
ae as readDepth,
le as remap,
oe as rotateVec3,
he as scaleVec2,
ce as scaleVec3,
de as setVec2,
ue as setVec3,
fe as subVec2,
ge as subVec3,
De as titleCase,
ot as toFloat32Array,
pe as toRGB,
Le as toSegments,
we as triangleNormal,
st as triangulateGrid,
Se as triangulateGridDelaunay,
ye as unpackBufferGeometries,
xe as unpackBufferGeometry,
me as uvMaterial,
Be as wgs84Def
};