videx-3d
Version:
React 3D component library designed for sub surface visualizations in the browser
359 lines (332 loc) • 9.93 kB
JavaScript
import Q from "proj4";
import { DataTexture as z, RedFormat as $, FloatType as I, LinearFilter as T, UniformsGroup as O, Uniform as h, Vector4 as Y, Vector3 as Z, Vector2 as J, RedIntegerFormat as j, UnsignedShortType as q, ShaderMaterial as K, UniformsUtils as X, ShaderLib as ee } from "three";
import "comlink";
import "p-limit";
import "curve-interpolator";
import { a3 as B, aa as ne, ah as A, F as te } from "./chunk-iY0wQ9Z6.js";
import "three/src/math/MathUtils.js";
function ge(e, n, r) {
const t = /* @__PURE__ */ new Map(), l = {};
n.sort((o, s) => o.id === r ? -1 : s.id === r ? 1 : o.drilled && s.drilled ? s.drilled.getTime() - o.drilled.getTime() : o.name.localeCompare(s.name));
for (let o = 0; o < n.length; o++) {
const s = n[o];
if (!s) continue;
let u = s.parent && s.kickoffDepthMsl !== null ? s.kickoffDepthMsl : -s.depthReferenceElevation;
if (t.has(s.id))
u = t.get(s.id);
else {
let m = s.parent;
for (; m; ) {
const a = e[m];
if (!a) break;
if (t.has(a.id)) {
const i = t.get(a.id);
u >= i && (t.set(a.id, u), u = i);
break;
} else
t.set(a.id, u), u = a.parent && a.kickoffDepthMsl !== null ? a.kickoffDepthMsl : -a.depthReferenceElevation;
m = a.parent;
}
}
l[s.id] = [u, o], t.set(s.id, s.depthMdMsl);
}
return l;
}
const re = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
class me {
utmDef;
originWgs84;
originUtm;
_projection;
constructor(n, r, t = "lnglat") {
this.utmDef = n, this._projection = Q(re, n), t === "lnglat" ? (this.originWgs84 = r, this.originUtm = this.wgs84ToUtm(r)) : (this.originWgs84 = this.utmToWgs84(r), this.originUtm = r);
}
utmToWgs84(n) {
return this._projection.inverse(n);
}
wgs84ToUtm(n) {
return this._projection.forward(n);
}
utmToWorld(n, r, t) {
return {
x: n - this.originUtm[0],
y: t,
z: this.originUtm[1] - r
};
}
worldToUtm(n, r, t) {
return {
easting: n + this.originUtm[0],
altitude: r,
northing: this.originUtm[1] - t
};
}
wgs84ToWorld(n, r, t = 0) {
const l = this.wgs84ToUtm([n, r]);
return this.utmToWorld(l[0], l[1], t);
}
worldToWgs84(n, r, t) {
const l = this.worldToUtm(n, r, t), o = this.utmToWgs84([l.easting, l.northing]);
return {
lng: o[0],
lat: o[1],
alt: r
};
}
}
function pe(e) {
const [, n, r] = new RegExp(/^([0-9]{2})([N|S]?)$/).exec(e) || [];
return `+proj=utm +zone=${n}${r === "S" ? " +south" : ""} +ellps=intl +towgs84=-87,-98,-121,0,0,0,0 +units=m +no_defs`;
}
function he([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 r = Math.floor((e + 180) / 6) % 60 + 1;
return n < 0 ? `${r}S` : `${r}N`;
}
throw new Error(
`getUtmZoneFromLatLng: Cannot figure out UTM zone from give Lat: ${n}, Lng: ${e}`
);
}
function b(e, n, r) {
const t = A(e, n), l = A(e, r);
return B(te(t, l));
}
function ve(e, n, r, t, l = 0, o = -1) {
const s = e.length / n, u = n - 1, m = s - 1, a = new Uint8Array(u * m * 4);
let i = 0;
const d = (c, g) => e[g * n + c];
for (let c = 0; c < m; c++) {
const g = c + 1, p = c + 0.5;
for (let f = 0; f < u; f++) {
const v = f + 1, w = f + 0.5, _ = d(f, c);
if (_ !== o) {
const V = d(f, g), F = d(v, c), M = d(v, g), D = (_ + V + F + M) / 4, G = [f * r, c * t, _], L = [f * r, g * t, V], P = [v * r, c * t, F], E = [v * r, g * t, M], x = [w * r, p * t, D], C = b(x, G, P), R = b(x, P, E), H = b(x, E, L), U = b(x, L, G), S = B([
C[0] + R[0] + H[0] + U[0],
C[2] + R[2] + H[2] + U[2],
C[1] + R[1] + H[1] + U[1]
]), y = ne(S, [0, 1, 0], l * (Math.PI / 180)), W = Math.floor((y[0] + 1) / 2 * 255), N = Math.floor((y[1] + 1) / 2 * 255), k = Math.floor((y[2] + 1) / 2 * 255);
a[i] = W, a[i + 1] = N, a[i + 2] = k, a[i + 3] = 255;
} else
a[i] = 0, a[i + 1] = 0, a[i + 2] = 0, a[i + 3] = 0;
i += 4;
}
}
return a;
}
function _e(e, n, r) {
const t = new z(e, n, r);
return t.minFilter = T, t.magFilter = T, t.flipY = !0, t.anisotropy = 4, t.needsUpdate = !0, t;
}
function we(e, n, r) {
const t = new z(
e,
n,
r,
$,
I
);
return t.minFilter = T, t.magFilter = T, t.needsUpdate = !0, t.flipY = !0, t;
}
function xe(e) {
const n = new Map(
e.chars.map((i, d) => [i.id, { index: d, spacing: i.xadvance }])
), r = 32, t = (i) => {
const d = [];
let c = 0;
for (let g = 0; g < i.length; g++) {
let p = i.charCodeAt(g);
n.has(p) || (p = r);
const f = n.get(p);
f && (d.push(f.index), c += f.spacing);
}
return {
indices: d,
width: c
};
}, l = (i) => {
i = Array.isArray(i) ? i : [i];
const d = [], c = [];
for (let f = 0; f < i.length; f++) {
const v = i[f], w = t(v), _ = c.length;
c.push(...w.indices), d.push([_, c.length, w.width]);
}
c.length || c.push(0);
const g = c.length;
d.forEach((f) => c.push(...f));
const p = new z(
new Uint16Array(c),
c.length,
1,
j,
q
);
return p.needsUpdate = !0, { texture: p, textPointersOffset: g, textPointersCount: d.length };
}, o = new O();
o.setName("GlyphData");
const s = [], u = [];
e.chars.forEach((i) => {
s.push(
new h(new Y(i.x, i.y, i.width, i.height))
), u.push(
new h(new Z(i.xoffset, i.yoffset, i.xadvance))
);
}), o.add(s), o.add(u), o.add(
new h(new J(e.common.scaleW, e.common.scaleH))
), o.add(new h(e.info.size)), o.add(new h(e.distanceField.distanceRange)), o.add(new h(e.common.lineHeight)), o.add(new h(e.common.base));
const m = () => {
o.dispose();
};
return {
glyphsCount: e.chars.length,
glyphData: o,
encodeText: t,
encodeTextTexture: l,
dispose: m
};
}
function be(e, n, r) {
if (e.length === 0) return [];
e.sort((o, s) => n(o) - n(s));
const t = [];
let l = { start: n(e[0]), end: r(e[0]) };
for (let o = 1; o < e.length; o += 1)
n(e[o]) === l.end ? l.end = r(e[o]) : (t.push(l), l = { start: n(e[o]), end: r(e[o]) });
return t.push(l), t;
}
var oe = `
uniform vec3 diffuse;
uniform float opacity;
varying vec3 vNormal;
varying vec3 vViewPosition;
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() {
vec3 color = diffuse.rgb;
vec4 diffuseColor = vec4(color.rgb, opacity);
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));
float alphaFactor = clamp(vViewPosition.z / 100000.0, 0.0, 0.9);
diffuseColor.a = 1.0 - alphaFactor;
gl_FragColor = diffuseColor.rgba;
gl_FragColor.a = 1.0;
}`, ie = `
varying vec3 vViewPosition;
void main() {
vViewPosition = - mvPosition.xyz;
}`;
class Te extends K {
isTubeMaterial = !0;
constructor(n) {
super({
vertexShader: ie,
fragmentShader: oe,
uniforms: X.clone(ee.basic.uniforms),
defines: {
DEPTH_SHADE: !0
},
clipping: !0,
fog: !0
}), n && this.setValues(n);
}
get color() {
return this.uniforms.diffuse.value;
}
set color(n) {
this.uniforms.diffuse.value.set(n);
}
}
export {
me as C,
Te as T,
we as a,
xe as b,
ge as c,
_e as d,
ve as e,
he as f,
pe as g,
b as h,
be as t,
re as w
};