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