UNPKG

videx-3d

Version:

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

718 lines (717 loc) 19.8 kB
import { transfer as L } from "comlink"; import { t as h, k as B, d as M, x as ut, G as mt, H as O, a as W, y as lt, a6 as pt, a1 as gt, h as nt, i as st, A as dt, O as ft, Q as ht, a0 as yt, j as Tt } from "./chunk-CPDkHB2U.js"; import { Vector3 as b, Matrix4 as D, Color as rt, BufferGeometry as Mt, BufferAttribute as X } from "three"; import "three/src/math/MathUtils.js"; import "proj4"; import { clamp as wt } from "curve-interpolator"; import { group as at } from "d3-array"; import { mergeGeometries as _ } from "three/examples/jsm/utils/BufferGeometryUtils.js"; import { c as N, f as vt, d as bt, b as At, t as xt } from "./chunk-BJ3kEVFR.js"; import { b as Bt, d as Lt } from "./chunk-BX-cez1_.js"; async function Qt(e, n, c = 0, a, m = !1) { const t = await h( () => this.get("position-logs", e) ), o = B(e, t); if (!o) return null; const i = a !== void 0 ? M( (a - o.measuredTop) / o.measuredLength, 0, 1 ) : 0, u = ut( o.curve, i, 1, n, c ), s = new Float32Array(u.length * 3), p = m ? new Float32Array(u.length) : null; u.forEach((d, f) => { const v = o.curve.getPointAt(d); s[f * 3] = v[0], s[f * 3 + 1] = v[1], s[f * 3 + 2] = v[2], p && (p[f] = d); }); const r = { position: { array: s, itemSize: 3 } }; p && (r.lengths = { array: p, itemSize: 1 }); const [l, g] = mt({ attributes: r }); return L(l, g); } async function qt(e) { const n = await h(() => this.get("casings", e)); if (!n) return null; const c = await h( () => this.get("position-logs", e) ), a = B(e, c); return a ? n.filter((t) => t.mdBottomMsl > a.measuredTop).map((t) => { const o = M( (t.mdTopMsl + (t.mdBottomMsl - t.mdTopMsl) / 2 - a.measuredTop) / a.measuredLength, 0, 1 ); return { name: `${t.properties.Diameter} ${t.properties.Type}`, data: t.properties, position: a.curve.getPointAt(o), direction: a.curve.getTangentAt(o), priority: t.type === "Shoe" ? 50 : t.innerDiameter }; }) : null; } function $t(e, n, c, a, m = 0) { const t = M( n.mdBottomMsl - n.mdTopMsl, 1e-4, e.measuredLength ), o = 1 / e.measuredLength, i = [], u = M( (n.mdTopMsl - e.measuredTop) / e.measuredLength, 0, 1 ), s = M( (n.mdBottomMsl - e.measuredTop) / e.measuredLength, 0, 1 ), p = c * (n.outerDiameter / 2), r = Math.max( (n.innerDiameter + (n.outerDiameter - n.innerDiameter) / 4) / 2 * c, p * 0.95 ); i.push([u, r]); const l = Math.min((p - r) * 2, t / 3) * o; return i.push([u + l, p]), i.push([s - l, p]), i.push([s, r]), N(e.curve, { ...a, from: Math.max(u, m), to: s, innerRadius: n.innerDiameter / 2 * c, radiusModifier: { type: "linear", steps: i } }); } function Dt(e, n, c, a, m, t = 0) { const o = M( (n.mdTopMsl - e.measuredTop) / e.measuredLength, 0, 1 ), i = M( (n.mdBottomMsl - e.measuredTop) / e.measuredLength, 0, 1 ), u = n.outerDiameter / 2 * c, s = u * m, p = n.innerDiameter / 2 * c; return N(e.curve, { ...a, from: Math.max(o, t), to: i, radiusModifier: { type: "linear", steps: [ [o, u], [o + (i - o) / 4, u], [i, s] ] }, innerRadius: p }); } async function Jt(e, n, c = 16, a = 1, m = 2, t = 0.1, o = 0) { const i = await h(() => this.get("casings", e)); if (!i) return null; const u = await h( () => this.get("position-logs", e) ), s = B(e, u); if (!s) return null; const p = n !== void 0 ? M( (n - s.measuredTop) / s.measuredLength, 0, 1 ) : 0, r = { startCap: !0, endCap: !0, radialSegments: c, addGroups: !0, computeNormals: !0, computeUvs: !0, simplificationThreshold: o, segmentsPerMeter: t }, l = [], g = [], d = i.filter( (w) => w.mdBottomMsl > s.measuredTop && (n === void 0 || w.mdBottomMsl > n) ).sort((w, y) => w.outerDiameter - y.outerDiameter); if (d.length === 0) return null; at(d, (w) => ({ category: ["Shoe", "Casing"].includes(w.type) ? w.type : "Generic", dimmension: w.outerDiameter })).forEach((w, y) => { const $ = w.map((P) => { let V; return y.category === "Shoe" ? V = Dt( s, P, a, r, m, p ) : V = $t( s, P, a, r, p ), V; }); g.push(Bt[y.category]), l.push(_($, !1)); }); const v = _(l, !0); v.groups.forEach((w, y) => { w.materialIndex = g[y]; }); const [A, T] = O(v); return L({ geometry: A }, T); } async function Kt(e) { const n = await this.get("completion-tools", e); if (!n) return null; const c = await h( () => this.get("position-logs", e) ), a = B(e, c); return a ? n.filter((t) => t.mdBottomMsl > a.measuredTop).map((t) => { const o = M( (t.mdTopMsl + t.length / 2 - a.measuredTop) / a.measuredLength, 0, 1 ); return { name: t.name, //data: d, position: a.curve.getPointAt(o), direction: a.curve.getTangentAt(o), priority: t.diameterMax }; }) : null; } function Pt(e, n, c, a, m) { const t = M(n.length, 1e-4, e.measuredLength), o = 1 / e.measuredLength, i = [], u = M( (n.mdTopMsl - e.measuredTop) / e.measuredLength, 0, 1 ), s = M( (n.mdBottomMsl - e.measuredTop) / e.measuredLength, 0, 1 ), p = c * ((n.diameterTop || n.diameterBottom) / 2), r = c * ((n.diameterBottom || n.diameterTop) / 2), l = c * ((n.diameterMax || n.diameterTop) / 2), g = Math.min(p, r, l); i.push([u, p]); const d = Math.min((l - g) * 2, t / 3) * o; return l > g && (i.push([u + d, l]), i.push([s - d, l])), i.push([s, r]), N(e.curve, { ...m, from: Math.max(u, a), to: s, computeLengths: !0, radiusModifier: { type: "linear", steps: i } }); } async function Zt(e, n, c = 16, a = 1, m = 0.1, t = 0) { const o = await h(() => this.get("completion-tools", e)); if (!o) return null; const i = await h( () => this.get("position-logs", e) ), u = B(e, i); if (!u) return null; const s = n !== void 0 ? M( (n - u.measuredTop) / u.measuredLength, 0, 1 ) : 0, p = o.filter( (T) => T.mdBottomMsl > u.measuredTop && (n === void 0 || T.mdBottomMsl > n) ).sort((T, x) => T.mdTopMsl - x.mdTopMsl), r = at(p, (T) => T.category), l = { startCap: !0, endCap: !0, radialSegments: c, computeNormals: !0, computeUvs: !0, segmentsPerMeter: m, simplificationThreshold: t, radius: 0 }, g = [], d = []; if (r.forEach((T, x) => { const w = T.map((y) => Pt( u, y, a, s, l )); d.push(Lt[x]), g.push(_(w, !1)); }), !g.length) return null; const f = _(g, !0); f.groups.forEach((T, x) => { T.materialIndex = d[x]; }); const [v, A] = O(f); return L(v, A); } async function zt(e, n, c = "MSL", a) { const m = await h( () => this.get("position-logs", e) ); if (!m || m.length < 8) return null; let t = 0; if (c === "RT") { const g = await h( () => this.get("wellbore-headers", e) ); g && (t = g.depthReferenceElevation); } const o = B(e, m); if (!o) return null; const i = m[m.length - 1] + t, s = Math.max( o.measuredTop, a && Number.isFinite(a) ? a : o.measuredTop ) + t, p = [s]; let r = Math.floor(s / n) * n; for (r <= s && (r += n); r < i; ) p.push(r), r += n; return p.push(i), p.map((g) => { const d = M( (g - t - o.measuredTop) / o.measuredLength, 0, 1 ), f = o.curve.getPointAt(d), v = o.curve.getTangentAt(d); return { id: `${e}_${g}`, name: (Math.round(g * 10) / 10).toString(), direction: v, position: f }; }); } const F = new b(), q = new b(), H = new b(), Vt = new b(0, 1, 0), k = new D(), Ft = new D().makeRotationX(W); async function te(e, n, c = 1) { const a = await h( () => this.get("perforations", e) ); if (!a) return null; const m = await h( () => this.get("position-logs", e) ), t = B(e, m); if (!t) return null; H.set( Math.max(1, c / 2), c, Math.max(1, c / 2) ); const o = [], i = a.filter( (r) => r.status === "Open" && r.mdBottomMsl > t.measuredTop && (n === void 0 || r.mdBottomMsl > n) ).sort((r, l) => r.mdTopMsl - l.mdTopMsl); for (let r = 0; r < i.length; r++) { const l = i[r]; l.mdBottomMsl <= t.measuredTop || (!o.length || o[o.length - 1].bottom !== l.mdTopMsl ? o.push({ type: l.type, top: Math.max(t.measuredTop, l.mdTopMsl), bottom: l.mdBottomMsl, density: vt(l.density || 0), phase: l.phase || 0, innerDiameter: 0, outerDiameter: 0 }) : o.length && (o[o.length - 1].bottom = l.mdBottomMsl)); } const u = []; for (let r = 0; r < o.length; r++) { const l = o[r], g = l.bottom - l.top, d = Math.max( 1, Math.floor(g * l.density) ), f = M( (l.top - t.measuredTop) / t.measuredLength, 0, 1 ), A = (M( (l.bottom - t.measuredTop) / t.measuredLength, 0, 1 ) - f) / d, T = []; for (let y = 0; y < d; y++) T.push(f + A * y); const x = lt(t.curve, T); let w = W; for (let y = 0; y < x.length; y++) { const $ = x[y], P = pt( gt($.tangent, [0, -1, 0]), $.tangent, w ); u.push({ name: l.type, position: $.position, normal: P, tangent: $.tangent }), w += bt(l.phase); } } const s = new Float32Array(u.length * 16 * 3), p = []; for (let r = 0; r < u.length; r++) { const l = u[r]; F.set(...l.position), q.set( F.x + l.normal[0], F.y + l.normal[1], F.z + l.normal[2] ), H.setY( c + c * (Math.random() - 0.5) * 0.25 ), k.identity(), k.lookAt(F, q, Vt), k.multiply(Ft), k.setPosition(F), k.scale(H), k.toArray(s, r * 16), p[r] = { id: `${e}_${r}`, name: l.name, direction: l.tangent }; } return L( { data: p, transformations: s }, [s.buffer] ); } async function ee(e, n, c = 0.1, a = 0) { const m = await h( () => this.get("position-logs", e) ), t = B(e, m); if (!t) return null; const o = { from: 0, to: 1, startCap: !1, endCap: !1, radialSegments: 32, computeLengths: !0, computeUvs: !0, segmentsPerMeter: c, simplificationThreshold: a, radius: n }, i = N(t.curve, o), [u, s] = O(i); return L(u, s); } const C = new b(), J = new b(), K = new b(), kt = new b(0, 1, 0), G = new D(), Ct = new D().makeRotationX(W), Z = new rt(); async function oe(e, n, c, a = 10) { const m = await nt(e, n, this, !0, c); if (!m) return null; const t = st(m.matched, m.wellbore.depthMdMsl), o = dt(t); if (!o.length) return null; const i = await h( () => this.get("position-logs", e) ), u = B(e, i); if (!u) return null; const s = o.map((g) => { const d = wt( (g.mdMsl - u.measuredTop) / u.measuredLength, 0, 1 ); return { ...g, position: u.curve.getPointAt(d), direction: u.curve.getTangentAt(d) }; }), p = new Float32Array(s.length * 16 * 3), r = new Float32Array(s.length * 3 * 3), l = []; return s.forEach((g, d) => { C.set(...g.position), G.identity(); const f = a; K.set(f, f, f), J.set( C.x + g.direction[0], C.y + g.direction[1], C.z + g.direction[2] ), G.lookAt(C, J, kt), G.multiply(Ct), G.setPosition(C), G.scale(K), G.toArray(p, d * 16), Z.set(g.color), Z.toArray(r, d * 3), l[d] = { id: `${e}_${d}`, name: `${g.name} ${At(g.type)}`, depth: g.mdMsl, tvd: g.tvdMsl, level: g.level, direction: g.direction }; }), L( { data: l, transformations: p, colors: r }, [p.buffer] ); } const R = new b(), z = new b(), tt = new b(), Gt = new b(0, 1, 0), S = new D(), Rt = new D().makeRotationX(W); async function ne(e, n, c, a) { const m = await h( () => this.get("position-logs", e) ), t = B(e, m); if (!t) return null; const o = t.measuredBottom, i = t.measuredLength, s = Math.max( t.measuredTop, a && Number.isFinite(a) ? a : t.measuredTop ), p = [s]; let r = Math.floor(s / c) * c; for (r <= s && (r += c); r < o; ) p.push(r), r += c; p.push(o); const l = new Float32Array(p.length * 16 * 3), g = []; return p.forEach((d, f) => { const v = M((d - t.measuredTop) / i, 0, 1), A = t.curve.getPointAt(v), T = t.curve.getTangentAt(v); R.set(...A), S.identity(); const x = n + 2 / n; tt.set(x, x, x), z.set( R.x + T[0], R.y + T[1], R.z + T[2] ), S.lookAt(R, z, Gt), S.multiply(Rt), S.setPosition(R), S.scale(tt), S.toArray(l, f * 16), g[f] = { id: `${e}_${f}`, depth: d, position: A }; }), L( { data: g, transformations: l }, [l.buffer] ); } const E = new b(), et = new b(), ot = new b(), St = new b(0, 1, 0), I = new D(), Et = new D().makeRotationX(W); async function se(e, n, c) { const a = await h(() => this.get("casings", e)); if (!a) return null; const m = await h( () => this.get("position-logs", e) ), t = B(e, m); if (!t) return null; const o = a.filter( (s) => s.type === "Shoe" && s.mdBottomMsl > t.measuredTop && (n === void 0 || s.mdBottomMsl > n) ).map((s) => { const p = M( (s.mdBottomMsl - t.measuredTop) / t.measuredLength, 0, 1 ); return { name: `${s.properties.Diameter} ${s.properties.Type}`, data: s.properties, position: t.curve.getPointAt(p), direction: t.curve.getTangentAt(p), radius: s.outerDiameter / 2 }; }), i = new Float32Array(o.length * 16 * 3), u = []; return o.forEach((s, p) => { E.set(...s.position), I.identity(); const r = s.radius * (c || 1); ot.set(r, r, r), et.set( E.x + s.direction[0], E.y + s.direction[1], E.z + s.direction[2] ), I.lookAt(E, et, St), I.multiply(Et), I.setPosition(E), I.scale(ot), I.toArray(i, p * 16), u[p] = { id: `${e}_${p}`, name: s.name, direction: s.direction }; }), L( { data: u, transformations: i }, [i.buffer] ); } const Y = -1; async function re(e) { const n = await h(() => this.get("surface-meta", e)); if (!n) return null; const c = await h( () => this.get("surface-values", e) ); if (!c) return null; const a = ft(c, Y), m = ht( c, n.header.nx, n.header.xinc, n.header.yinc, n.header.rot, Y ); return L({ elevationImageBuffer: a, normalsImageBuffer: m }, [a.buffer, m.buffer]); } async function ae(e, n = 5) { const c = await h(() => this.get("surface-meta", e)); if (!c) return null; const a = c.max, m = await h( () => this.get("surface-values", e) ); if (!m) return null; const { header: t } = c, o = new Mt(), { positions: i, uvs: u, indices: s } = xt( m, t.nx, t.xinc, t.yinc, Y, n ); o.setAttribute("position", new X(i, 3)), o.setAttribute("uv", new X(u, 2)), o.setIndex(new X(s, 1)), o.translate(0, 0, -t.ny * t.yinc), o.rotateY(t.rot * (Math.PI / 180)), o.translate(0, -a, 0); const [p, r] = O(o); return L(p, r); } async function ie(e, n, c = 0, a, m = 0.5, t = 16, o = !1) { const i = await h( () => this.get("position-logs", e) ), u = B(e, i); if (!u) return null; const p = { from: a !== void 0 ? M( (a - u.measuredTop) / u.measuredLength, 0, 1 ) : 0, radius: m, startCap: !0, endCap: !0, segmentsPerMeter: n, simplificationThreshold: c, computeNormals: !0, computeUvs: !0, computeLengths: !!o, radialSegments: t }, r = N(u.curve, p), [l, g] = O(r); return L(l, g); } async function ce(e, n, c = 250) { const a = await h( () => this.get("position-logs", e) ), m = { main: { center: [0, 0, 0], radius: 10 }, sampled: [] }; if (a) { const i = B(e, a); if (i) { const u = n !== void 0 ? M( (n - i.measuredTop) / i.measuredLength, 0, 1 ) : 0, s = i.curve.getBoundingBox(u), p = (s.max[0] - s.min[0]) / 2, r = (s.max[1] - s.min[1]) / 2, l = (s.max[2] - s.min[2]) / 2, g = yt([p, r, l]) + c * 2, d = [ s.min[0] + p, s.min[1] + r, s.min[2] + l ]; if (m.main.center = d, m.main.radius = g, c > 0) { const f = Math.ceil( (1 - u) * i.curve.length / c ), v = i.curve.getPoints(f, u, 1), A = []; v.forEach((T) => { A.push({ center: T, radius: c }); }), m.sampled = A; } } } const t = new Float32Array(4 + m.sampled.length * 4); let o = 0; t[o] = m.main.center[0], t[o + 1] = m.main.center[1], t[o + 2] = m.main.center[2], t[o + 3] = m.main.radius, o = 4; for (let i = 0; i < m.sampled.length; i++, o += 4) t[o] = m.sampled[i].center[0], t[o + 1] = m.sampled[i].center[1], t[o + 2] = m.sampled[i].center[2], t[o + 3] = m.sampled[i].radius; return L(t, [t.buffer]); } async function ue(e, n, c, a, m, t, o = 0.5, i = 2, u = !0, s = 16, p = 0) { const r = await nt(e, n, this, !0); if (!r) return null; const l = st(r.matched, r.wellbore.depthMdMsl).filter( (y) => (t === void 0 || t.includes(y.unit.unitType)) && (m === void 0 || m.includes(y.unit.name)) ); if (!l.length) return null; const g = Tt(l), d = await h( () => this.get("position-logs", e) ), f = B(e, d); if (!f) return null; const v = { startCap: u, endCap: u, segmentsPerMeter: c, simplificationThreshold: p, radialSegments: s, computeRelativeLengths: !0 }, A = []; if (g.forEach((y) => { if (a === void 0 || y.mdMslBottom > a) { let $ = y.mdMslTop; a !== void 0 && a > $ && ($ = a); const P = f.getPositionAtDepth($, !0), V = f.getPositionAtDepth(y.mdMslBottom, !0); if (P !== null && V !== null) { const it = i + o, ct = new rt(y.unit.color), U = N(f.curve, { ...v, radius: it, from: P, to: V }); if (U.attributes.position.count) { const Q = new Float32Array( U.attributes.position.count * 3 ); for (let j = 0; j < U.attributes.position.count; j++) ct.toArray(Q, j * 3); U.attributes.color = new X(Q, 3), A.push(U); } } } }), !A.length) return null; const T = _(A, !1), [x, w] = O(T); return L(x, w); } async function me(e, n, c) { const a = await h( () => this.get("wellbore-headers", e) ); if (!a) return null; const m = await h( () => this.get("position-logs", e) ), t = B(e, m); if (!t) return null; let o = 1; const { measuredTop: i, measuredLength: u, curve: s } = t; if (n === "top") o = M(((c || i) - i) / u, 0, 1); else if (n === "center") { const r = (c || i) + (u - (c || i)) / 2; o = M((r - i) / u, 0, 1); } return [{ id: e, name: `${a.name.replace("NO ", "")}`, position: s.getPointAt(o), direction: s.getTangentAt(o) }]; } export { ce as calculateWellboreBounds, Qt as generateBasicTrajectory, qt as generateCasingAnnotations, Jt as generateCasings, Kt as generateCompletionToolAnnotations, Zt as generateCompletionTools, zt as generateDepthMarkers, te as generatePerforations, ee as generatePerimeterGeometry, oe as generatePicks, ne as generatePositionMarkers, se as generateShoes, ae as generateSurfaceGeometry, re as generateSurfaceTexturesData, ie as generateTubeTrajectory, ue as generateWellboreFormationColumnGeometries, me as generateWellboreLabel };