UNPKG

videx-3d

Version:

React 3D component library designed for sub surface visualizations in the browser

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