UNPKG

videx-3d

Version:

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

349 lines (321 loc) 9.12 kB
var b = Object.defineProperty; var C = (e, n, t) => n in e ? b(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t; var p = (e, n, t) => C(e, typeof n != "symbol" ? n + "" : n, t); import T from "proj4"; import { UniformsGroup as R, Uniform as g, Vector4 as S, Vector3 as E, Vector2 as H, DataTexture as y, RedIntegerFormat as U, UnsignedShortType as G, ShaderMaterial as L, UniformsUtils as z, ShaderLib as M } from "three"; function Q(e, n, t) { const o = /* @__PURE__ */ new Map(), a = {}; n.sort((r, s) => r.id === t ? -1 : s.id === t ? 1 : r.drilled && s.drilled ? s.drilled.getTime() - r.drilled.getTime() : r.name.localeCompare(s.name)); for (let r = 0; r < n.length; r++) { const s = n[r]; if (!s) continue; let d = s.parent && s.kickoffDepthMsl !== null ? s.kickoffDepthMsl : -s.depthReferenceElevation; if (o.has(s.id)) d = o.get(s.id); else { let h = s.parent; for (; h; ) { const l = e[h]; if (!l) break; if (o.has(l.id)) { const i = o.get(l.id); d >= i && (o.set(l.id, d), d = i); break; } else o.set(l.id, d), d = l.parent && l.kickoffDepthMsl !== null ? l.kickoffDepthMsl : -l.depthReferenceElevation; h = l.parent; } } a[s.id] = [d, r], o.set(s.id, s.depthMdMsl); } return a; } const P = "wellbore-selected", V = "wellbore-added", W = "wellbore-removed"; class $ extends CustomEvent { constructor(n) { super(P, { detail: n }); } } class O extends CustomEvent { constructor(n) { super(V, { detail: n }); } } class I extends CustomEvent { constructor(n) { super(W, { detail: n }); } } const A = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"; class Z { constructor(n, t, o = "lnglat") { p(this, "utmDef"); p(this, "originWgs84"); p(this, "originUtm"); p(this, "_projection"); this.utmDef = n, this._projection = T(A, n), o === "lnglat" ? (this.originWgs84 = t, this.originUtm = this.wgs84ToUtm(t)) : (this.originWgs84 = this.utmToWgs84(t), this.originUtm = t); } utmToWgs84(n) { return this._projection.inverse(n); } wgs84ToUtm(n) { return this._projection.forward(n); } utmToWorld(n, t, o) { return { x: n - this.originUtm[0], y: o, z: this.originUtm[1] - t }; } worldToUtm(n, t, o) { return { easting: n + this.originUtm[0], altitude: t, northing: this.originUtm[1] - o }; } wgs84ToWorld(n, t, o = 0) { const a = this.wgs84ToUtm([n, t]); return this.utmToWorld(a[0], a[1], o); } worldToWgs84(n, t, o) { const a = this.worldToUtm(n, t, o), r = this.utmToWgs84([a.easting, a.northing]); return { lng: r[0], lat: r[1], alt: t }; } } function j(e) { const [, n, t] = new RegExp(/^([0-9]{2})([N|S]?)$/).exec(e) || []; return `+proj=utm +zone=${n}${t === "S" ? " +south" : ""} +ellps=intl +towgs84=-87,-98,-121,0,0,0,0 +units=m +no_defs`; } function J([e, n]) { if (n > 55 && n < 64 && e > 2 && e < 6) return "32N"; if (n > 71 && e >= 6 && e < 9) return "31N"; if (n > 71 && (e >= 9 && e < 12 || e >= 18 && e < 21)) return "33N"; if (n > 71 && (e >= 21 && e < 24 || e >= 30 && e < 33)) return "35N"; if (e >= -180 && e <= 180) { const t = Math.floor((e + 180) / 6) % 60 + 1; return n < 0 ? `${t}S` : `${t}N`; } throw new Error(`getUtmZoneFromLatLng: Cannot figure out UTM zone from give Lat: ${n}, Lng: ${e}`); } const Y = (e) => `#${e.toString(16).padStart(6, "0")}`; function q() { const e = "123456789ABCDEF"; let n = "#"; for (let t = 0; t < 6; t++) n += e[Math.floor(Math.random() * 16)]; return n; } function K(e) { const n = new Map( e.chars.map((i, f) => [i.id, { index: f, spacing: i.xadvance }]) ), t = 32, o = (i) => { const f = []; let c = 0; for (let v = 0; v < i.length; v++) { let m = i.charCodeAt(v); n.has(m) || (m = t); const u = n.get(m); u && (f.push(u.index), c += u.spacing); } return { indices: f, width: c }; }, a = (i) => { i = Array.isArray(i) ? i : [i]; const f = [], c = []; for (let u = 0; u < i.length; u++) { const w = i[u], _ = o(w), x = c.length; c.push(..._.indices), f.push([ x, c.length, _.width ]); } c.length || c.push(0); const v = c.length; f.forEach((u) => c.push(...u)); const m = new y( new Uint16Array(c), c.length, 1, U, G ); return m.needsUpdate = !0, { texture: m, textPointersOffset: v, textPointersCount: f.length }; }, r = new R(); r.setName("GlyphData"); const s = [], d = []; e.chars.forEach((i) => { s.push( new g(new S(i.x, i.y, i.width, i.height)) ), d.push( new g(new E(i.xoffset, i.yoffset, i.xadvance)) ); }), r.add(s), r.add(d), r.add( new g(new H(e.common.scaleW, e.common.scaleH)) ), r.add(new g(e.info.size)), r.add(new g(e.distanceField.distanceRange)), r.add(new g(e.common.lineHeight)), r.add(new g(e.common.base)); const h = () => { r.dispose(); }; return { glyphsCount: e.chars.length, glyphData: r, encodeText: o, encodeTextTexture: a, dispose: h }; } function X(e, n, t) { if (e.length === 0) return []; e.sort((r, s) => n(r) - n(s)); const o = []; let a = { start: n(e[0]), end: t(e[0]) }; for (let r = 1; r < e.length; r += 1) n(e[r]) === a.end ? a.end = t(e[r]) : (o.push(a), a = { start: n(e[r]), end: t(e[r]) }); return o.push(a), o; } var D = `#define TRAJECTORY_MATERIAL uniform vec3 diffuse; uniform float opacity; #ifndef FLAT_SHADED varying vec3 vNormal; #endif varying vec3 vViewPosition; varying vec3 vColor; #include <common> #include <uv_pars_fragment> #include <map_pars_fragment> #include <fog_pars_fragment> #include <logdepthbuf_pars_fragment> #include <clipping_planes_pars_fragment> vec3 hue2rgb(in float H) { float R = abs(H * 6. - 3.) - 1.; float G = 2. - abs(H * 6. - 2.); float B = 2. - abs(H * 6. - 4.); return saturate(vec3(R, G, B)); } vec3 hsl2rgb(in vec3 HSL) { vec3 RGB = hue2rgb(HSL.x); float C = (1. - abs(2. * HSL.z - 1.)) * HSL.y; return (RGB - 0.5) * C + HSL.z; } vec3 rgb2hsv(in vec3 RGB) { vec4 P = (RGB.g < RGB.b) ? vec4(RGB.bg, -1.0, 2.0 / 3.0) : vec4(RGB.gb, 0.0, -1.0 / 3.0); vec4 Q = (RGB.r < P.x) ? vec4(P.xyw, RGB.r) : vec4(RGB.r, P.yzx); float C = Q.x - min(Q.w, Q.y); float H = abs((Q.w - Q.y) / (6. * C + EPSILON) + Q.z); return vec3(H, C, Q.x); } vec3 rgb2hsl(in vec3 RGB) { vec3 HCV = rgb2hsv(RGB); float L = HCV.z - HCV.y * 0.5; float S = HCV.y / (1. - abs(L * 2. - 1.) + EPSILON); return vec3(HCV.x, S, L); } vec3 hsv2rgb(in vec3 HSV) { vec3 RGB = hue2rgb(HSV.x); return ((RGB - 1.) * HSV.y + 1.) * HSV.z; } void main() { #include <clipping_planes_fragment> vec3 color = diffuse.rgb; vec4 diffuseColor = vec4(color.rgb, opacity); #include <logdepthbuf_fragment> #include <map_fragment> #include <color_fragment> #include <normal_fragment_begin> #ifdef DEPTH_SHADE float depthFactor = clamp(dot(normalize(vNormal), normalize(vViewPosition)), 0.0, 1.0); float darkenFactor = clamp(vViewPosition.z / 5000.0, 0.1, 0.8); vec3 hsv = rgb2hsv(diffuseColor.rgb); hsv.z = hsv.z * darkenFactor; vec3 mixColor = hsv2rgb(hsv); diffuseColor.rgb = mix(mixColor, diffuseColor.rgb, pow(depthFactor, 0.8)); #else float alphaFactor = clamp(vViewPosition.z / 100000.0, 0.0, 0.9); diffuseColor.a = 1.0 - alphaFactor; #endif gl_FragColor = diffuseColor.rgba; #include <tonemapping_fragment> #include <colorspace_fragment> #include <fog_fragment> #ifdef OPAQUE gl_FragColor.a = 1.0; #endif }`, B = `#define TRAJECTORY_MATERIAL varying vec3 vViewPosition; #include <common> #include <batching_pars_vertex> #include <uv_pars_vertex> #include <envmap_pars_vertex> #include <color_pars_vertex> #include <fog_pars_vertex> #include <normal_pars_fragment> #include <logdepthbuf_pars_vertex> #include <clipping_planes_pars_vertex> void main() { #include <uv_vertex> #include <color_vertex> #include <batching_vertex> #include <beginnormal_vertex> #include <defaultnormal_vertex> #include <normal_vertex> #include <begin_vertex> #include <project_vertex> #include <logdepthbuf_vertex> #include <clipping_planes_vertex> vViewPosition = - mvPosition.xyz; #include <worldpos_vertex> #include <fog_vertex> }`; class ee extends L { constructor(t) { super({ vertexShader: B, fragmentShader: D, uniforms: z.clone(M.basic.uniforms), defines: { DEPTH_SHADE: !0 }, clipping: !0, fog: !0 }); p(this, "isTubeMaterial", !0); t && this.setValues(t); } get color() { return this.uniforms.diffuse.value; } set color(t) { this.uniforms.diffuse.value.set(t); } } export { Z as C, ee as T, O as W, I as a, K as b, Q as c, V as d, W as e, $ as f, j as g, A as h, Y as i, J as j, q as r, X as t, P as w };