UNPKG

videx-3d

Version:

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

287 lines (259 loc) 7.39 kB
var f = Object.defineProperty; var m = (n, e, t) => e in n ? f(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; var c = (n, e, t) => m(n, typeof e != "symbol" ? e + "" : e, t); import g from "proj4"; import { ShaderMaterial as v, UniformsUtils as p, ShaderLib as h } from "three"; function H(n, e, t) { const r = /* @__PURE__ */ new Map(), s = {}; e.sort((o, i) => o.id === t ? -1 : i.id === t ? 1 : o.drilled && i.drilled ? i.drilled.getTime() - o.drilled.getTime() : o.name.localeCompare(i.name)); for (let o = 0; o < e.length; o++) { const i = e[o]; if (!i) continue; let a = i.parent && i.kickoffDepthMsl !== null ? i.kickoffDepthMsl : -i.depthReferenceElevation; if (r.has(i.id)) a = r.get(i.id); else { let u = i.parent; for (; u; ) { const l = n[u]; if (!l) break; if (r.has(l.id)) { const d = r.get(l.id); a >= d && (r.set(l.id, a), a = d); break; } else r.set(l.id, a), a = l.parent && l.kickoffDepthMsl !== null ? l.kickoffDepthMsl : -l.depthReferenceElevation; u = l.parent; } } s[i.id] = [a, o], r.set(i.id, i.depthMdMsl); } return s; } const _ = "wellbore-selected", b = "wellbore-added", x = "wellbore-removed"; class L extends CustomEvent { constructor(e) { super(_, { detail: e }); } } class U extends CustomEvent { constructor(e) { super(b, { detail: e }); } } class y extends CustomEvent { constructor(e) { super(x, { detail: e }); } } const w = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"; class z { constructor(e, t, r = "lnglat") { c(this, "utmDef"); c(this, "originWgs84"); c(this, "originUtm"); c(this, "_projection"); this.utmDef = e, this._projection = g(w, e), r === "lnglat" ? (this.originWgs84 = t, this.originUtm = this.wgs84ToUtm(t)) : (this.originWgs84 = this.utmToWgs84(t), this.originUtm = t); } utmToWgs84(e) { return this._projection.inverse(e); } wgs84ToUtm(e) { return this._projection.forward(e); } utmToWorld(e, t, r) { return { x: e - this.originUtm[0], y: r, z: this.originUtm[1] - t }; } worldToUtm(e, t, r) { return { easting: e + this.originUtm[0], altitude: t, northing: this.originUtm[1] - r }; } wgs84ToWorld(e, t, r = 0) { const s = this.wgs84ToUtm([e, t]); return this.utmToWorld(s[0], s[1], r); } worldToWgs84(e, t, r) { const s = this.worldToUtm(e, t, r), o = this.utmToWgs84([s.easting, s.northing]); return { lng: o[0], lat: o[1], alt: t }; } } function G(n) { const [, e, t] = new RegExp(/^([0-9]{2})([N|S]?)$/).exec(n) || []; return `+proj=utm +zone=${e}${t === "S" ? " +south" : ""} +ellps=intl +towgs84=-87,-98,-121,0,0,0,0 +units=m +no_defs`; } function W([n, e]) { if (e > 55 && e < 64 && n > 2 && n < 6) return "32N"; if (e > 71 && n >= 6 && n < 9) return "31N"; if (e > 71 && (n >= 9 && n < 12 || n >= 18 && n < 21)) return "33N"; if (e > 71 && (n >= 21 && n < 24 || n >= 30 && n < 33)) return "35N"; if (n >= -180 && n <= 180) { const t = Math.floor((n + 180) / 6) % 60 + 1; return e < 0 ? `${t}S` : `${t}N`; } throw new Error(`getUtmZoneFromLatLng: Cannot figure out UTM zone from give Lat: ${e}, Lng: ${n}`); } const B = (n) => `#${n.toString(16).padStart(6, "0")}`; function M() { const n = "123456789ABCDEF"; let e = "#"; for (let t = 0; t < 6; t++) e += n[Math.floor(Math.random() * 16)]; return e; } function P(n, e, t) { if (n.length === 0) return []; n.sort((o, i) => e(o) - e(i)); const r = []; let s = { start: e(n[0]), end: t(n[0]) }; for (let o = 1; o < n.length; o += 1) e(n[o]) === s.end ? s.end = t(n[o]) : (r.push(s), s = { start: e(n[o]), end: t(n[o]) }); return r.push(s), r; } var C = `#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 }`, S = `#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 V extends v { constructor(t) { super({ vertexShader: S, fragmentShader: C, uniforms: p.clone(h.basic.uniforms), defines: { DEPTH_SHADE: !0 }, clipping: !0, fog: !0 }); c(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, V as T, U as W, y as a, b, H as c, x as d, L as e, w as f, G as g, W as h, B as i, M as r, P as t, _ as w };