@three3d/tools
Version:
@three3d/tools 提供了 ThreeJS 常用的工具库
1,115 lines (1,114 loc) • 35.5 kB
JavaScript
var zt = Object.defineProperty;
var Ut = (t, n, e) => n in t ? zt(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e;
var j = (t, n, e) => (Ut(t, typeof n != "symbol" ? n + "" : n, e), e);
import { LineCurve3 as K, LineCurve as $, CurvePath as Ot, Vector4 as St, Vector3 as w, Vector2 as z, Matrix3 as ft, Quaternion as S, TextureLoader as qt, Texture as Rt, AlphaFormat as Nt, RedFormat as kt, RedIntegerFormat as jt, RGFormat as Qt, RGIntegerFormat as Ft, RGBAFormat as Wt, RGBAIntegerFormat as Et, LuminanceFormat as Gt, LuminanceAlphaFormat as Xt, DepthFormat as Yt, DepthStencilFormat as Zt, Line3 as Ht, MathUtils as Jt, Color as Q, BufferGeometry as Kt, Float32BufferAttribute as wt, LineBasicMaterial as $t, Line as vt, MirroredRepeatWrapping as xt, ClampToEdgeWrapping as Ct, RepeatWrapping as At } from "three";
import { isBaseType as tn, isIterable as nn } from "type-tls";
import { Axis as Ie, Axis4 as Me } from "type-tls";
import { createLinearGradientImageData as en, getData3DSlice as on, getData3DItemSafe as sn } from "image-tls";
function cn(t) {
const n = t.curves[0].getPoint(0), e = t.curves[t.curves.length - 1].getPoint(1);
if (!n.equals(e)) {
const o = n.isVector3 && e.isVector3 ? K : $;
t.curves.push(new o(e, n));
}
return t;
}
function kn() {
Ot.prototype.closePath = function() {
cn(this);
};
}
function Pt(t) {
return t.w !== void 0 ? [St, 4] : t.z !== void 0 ? [w, 3] : [z, 2];
}
function rn(t) {
return t.w != null ? new St().copy(t) : t.z != null ? new w().copy(t) : new z().copy(t);
}
function H(t, n, e) {
e = e ?? 0;
const o = e + 1;
if (tn(t))
return t;
if (t.x != null && t.y != null)
return rn(t);
if (Array.isArray(t))
return t.map((c) => H(c, n, o));
if (t instanceof Map) {
const c = /* @__PURE__ */ new Map();
for (const r of t.keys()) {
const i = t.get(r), l = H(i, n, o);
c.set(r, l);
}
return c;
}
if (nn(t)) {
const c = [];
for (const r of t) {
const i = H(r, n, o);
c.push(i);
}
return c;
}
if ((n || e === 0) && typeof t == "object") {
const c = {};
for (const r of Object.keys(t))
c[r] = H(t[r], n, o);
return c;
}
return t;
}
function X(t, n, e, o) {
const s = (o == null ? void 0 : o.copy(t)) || t.clone();
return s.cross(n), s.lengthSq() === 0 && (e ? Math.abs(n.z) === 1 ? t.x -= 1e-4 : t.z += 1e-4 : Math.abs(t.x) === 1 ? n.z -= 1e-4 : n.x += 1e-4, n.normalize(), s.crossVectors(t, n)), e ? t.copy(n).cross(s) : n.copy(s).cross(t), s.normalize(), n.normalize(), t.normalize(), { tangent: t, normal: n, binormal: s };
}
function ln(t, n, e, o) {
const { binormal: s } = X(t, n, e, o);
return s.negate(), { front: t, up: n, binormal: s };
}
function jn(t) {
const { tangent: n, normal: e, binormal: o } = t;
return { front: n, up: e, binormal: o.clone().negate() };
}
function Qn(t) {
const { front: n, up: e, binormal: o } = t;
return { tangent: n, normal: e, binormal: o.clone().negate() };
}
function Fn(t, n, e, o) {
const { front: s, up: c, binormal: r } = ln(t.clone().normalize(), n.clone().normalize(), e), i = o ?? new ft(), l = i.elements;
return r.toArray(l, 0), c.toArray(l, 3), s.toArray(l, 6), i;
}
function Wn(t, n, e, o) {
const s = t.clone().projectOnPlane(e).normalize(), c = n.clone().projectOnPlane(e).normalize();
return o = o ?? new S(), o.setFromUnitVectors(s, c), o;
}
function T(t, n) {
const e = n.toArray(), o = e.findIndex((s) => s !== 0);
return e[o] / t.toArray()[o];
}
function at(t, n) {
const e = t.clone().cross(n);
return typeof e == "number" ? e === 0 : e.lengthSq() === 0;
}
function En(t) {
const n = t.length, e = [];
if (n === 0)
return e;
const [o, s] = Pt(t[0]);
for (let c = 0; c < n; c++) {
const r = t[c], i = new o().copy(r), l = r.radius, u = e[c] ?? (e[c] = []);
for (let a = c + 1; a < n; a++) {
const f = t[a];
i.distanceToSquared(f) <= (f.radius + l) ** 2 && (u.push(a), (e[a] = []).push(c));
}
}
return e;
}
let Tt;
function Gn(t) {
if (typeof t == "string")
return (Tt || (Tt = new qt())).load(t);
if (t.isTexture)
return t;
const n = Array.isArray(t) ? en(t, 256, 1) : t, e = new Rt(n);
return n.colorSpace === "srgb" && (e.colorSpace = "srgb"), e.needsUpdate = !0, e;
}
function an(t, n) {
const e = Math.sqrt(t.lengthSq() * n.lengthSq());
if (e === 0)
return 0;
let o = t.dot(n) / e;
return o = Math.max(-1, Math.min(1, o)), Math.acos(o);
}
function J(t, n, e) {
let o = an(t, n);
return o === 0 ? o : t.clone().cross(n).dot(e) < 0 ? -o : o;
}
function un(t, n, e) {
return t = t.clone().projectOnPlane(e), n = n.clone().projectOnPlane(e), J(t, n, e);
}
function fn(t, n, e) {
const o = n.clone().negate(), s = e.clone().projectOnPlane(n), c = t.clone().projectOnPlane(s), r = J(n, c, s), i = n.clone().cross(s), l = t.clone().projectOnPlane(i), u = J(n, l, i), a = t.clone().projectOnPlane(o), f = J(s, a, o);
return { yaw: r, pitch: u, roll: f };
}
const it = 180 / Math.PI, ut = {
yaw: [
{ name: "前", range: [-15, 15] },
{ name: "左", range: [15, 165] },
{ name: "右", range: [-165, -15] },
{ name: "后", range: [-180.1, -165] },
{ name: "后", range: [165, 180.1] }
],
pitch: [
{ name: "前", range: [-15, 15] },
{ name: "上", range: [15, 165] },
{ name: "下", range: [-165, -15] },
{ name: "后", range: [-180.1, -165] },
{ name: "后", range: [165, 180.1] }
],
roll: [
{ name: "上", range: [-15, 15] },
{ name: "左", range: [15, 165] },
{ name: "右", range: [-165, -15] },
{ name: "下", range: [-180.1, -165] },
{ name: "下", range: [165, 180.1] }
]
};
function pn(t) {
const n = {};
for (const [e, o] of Object.entries(t))
n[e] = Array.isArray(o) ? o : Object.entries(o).map(([s, c]) => ({ name: s, range: c }));
return n;
}
const lt = {
degrees: !0,
map: ut,
front: { x: 0, y: 0, z: 1 },
up: { x: 0, y: 1, z: 0 }
};
class It {
constructor(n) {
j(this, "_options");
j(this, "_listMap");
j(this, "_front");
j(this, "_up");
n && (this.options = n);
}
static get options() {
return this._options ?? (this.options = lt);
}
static set options(n) {
this._options = Object.assign({}, structuredClone(ut), n);
}
/**
* 默认选项
*/
get defaultOptions() {
return this.constructor.options;
}
get options() {
return this._options ?? (this.options = this.defaultOptions);
}
set options(n) {
this._options = Object.assign({}, structuredClone(this.defaultOptions), n), this._listMap = null, this._front = null, this._up = null;
}
/**
* 是否使用角度,而非弧度
*/
get degrees() {
return this.options.degrees ?? (this.options.degrees = this.defaultOptions.degrees ?? !0);
}
set degrees(n) {
this.options.degrees = n;
}
get map() {
return this.options.map || (this.map = this.defaultOptions.map), this.options.map;
}
set map(n) {
const e = structuredClone(this.defaultOptions.map), o = structuredClone(ut);
n = n ? {
yaw: n.yaw ?? e.yaw ?? o.yaw,
pitch: n.pitch ?? e.pitch ?? o.pitch,
roll: n.roll ?? e.roll ?? o.roll
} : e, this.options.map = n, this._listMap = null;
}
get listMap() {
return this._listMap ?? (this._listMap = pn(this.map ?? {}));
}
get front() {
return this._front || (this.front = this.options.front ?? this.defaultOptions.front ?? lt.front), this._front;
}
set front(n) {
this._front = new w().copy(n);
}
get up() {
return this._up || (this.up = this.options.up ?? this.defaultOptions.up ?? lt.up), this._up;
}
set up(n) {
this._up = new w().copy(n);
}
/**
* 计算方位
* @param target
* @param front
* @param up
*/
computeAzimuth(n, e, o) {
const s = new w().copy(n), c = new w().copy(e ?? this.front), r = new w().copy(o ?? this.up);
let { yaw: i, pitch: l, roll: u } = fn(s, c, r);
return this.degrees && (i *= it, l *= it, u *= it), {
yaw: {
angle: i,
name: this.findAzimuthNames("yaw", i)
},
pitch: {
angle: l,
name: this.findAzimuthNames("pitch", l)
},
roll: {
angle: u,
name: this.findAzimuthNames("roll", u)
}
};
}
/**
* 查找匹配的方位名字
* @param type - 类型
* @param angle - 角度
* @returns 匹配的名字列表
*/
findAzimuthNames(n, e) {
const o = [], s = this.listMap[n];
if (!s)
return o;
for (const { name: c, range: [r, i] } of s)
(e >= r && e < i || e <= r && e > i) && o.push(c);
return o;
}
}
j(It, "_options");
const Xn = new It(), mn = {
[Nt]: 1,
[kt]: 1,
[jt]: 1,
[Qt]: 3,
[Ft]: 2,
[Wt]: 4,
[Et]: 4,
[Gt]: 1,
[Xt]: 2,
[Yt]: 1,
[Zt]: 2
};
function Mt(t) {
return mn[t];
}
function Yn(t, n, e) {
const { data: o, width: s, height: c, depth: r } = t.image, i = Mt(t.format);
return on({ data: o, size: { x: s, y: c, z: r } }, n, e, i);
}
function Zn(t, n) {
const { data: e, width: o, height: s, depth: c } = t.image, r = Mt(t.format);
return sn({ data: e, size: { x: o, y: s, z: c } }, n, r);
}
var h = /* @__PURE__ */ ((t) => (t.Dissociation = "相离", t.Intersect = "相交", t.Tangency = "相切", t.Contain = "包含", t))(h || {});
function Hn(t, n) {
const [e, o] = t, { center: s, radius: c } = n, r = o.clone().sub(e), i = s.clone().sub(e), l = r.lengthSq(), u = r.dot(i) ** 2, a = l * (i.lengthSq() - c ** 2), f = u - a;
return f < 0 ? h.Dissociation : f === 0 ? h.Tangency : h.Intersect;
}
function Y(t, n) {
const [e, o] = t, { center: s, radius: c } = n, r = o.clone().sub(e), i = e.clone().sub(s), l = r.lengthSq(), u = 2 * r.dot(i), a = i.lengthSq() - c ** 2, f = u ** 2 - 4 * l * a;
if (f < 0)
return [];
const p = l * 2, m = -u / p;
if (f === 0)
return [m];
const d = Math.sqrt(f) / p, y = m - d, b = m + d;
return [y, b];
}
function Jn(t, n) {
const [e, o] = t, s = o.clone().sub(e);
return Y(t, n).map((r) => s.clone().multiplyScalar(r).add(e));
}
function hn(t, n) {
const e = Y(t, n), o = e.length;
if (o === 0)
return h.Dissociation;
let s = 0, c = 0, r = 0;
for (const l of e)
l < 0 ? s++ : l > 1 ? c++ : (l === 0 || l === 1) && r++;
const i = s + c;
return o === 1 && i === 0 ? h.Tangency : s === 1 && c === 1 || r === 2 ? h.Contain : s === 2 || c === 2 ? h.Dissociation : h.Intersect;
}
function gn(t, n) {
const [e, o] = t, s = o.clone().sub(e), c = Y(t, n), r = [];
for (const i of c) {
if (i < 0 || i > 1)
continue;
const l = s.clone().multiplyScalar(i).add(e);
r.push(l);
}
return r;
}
function Kn(t, n) {
const e = Y(t, n), o = e.length;
if (o === 0)
return h.Dissociation;
let s = 0;
for (const c of e)
c < 0 && s++;
return o === 1 && s === 0 ? h.Tangency : s === 2 ? h.Dissociation : h.Intersect;
}
function $n(t, n) {
const [e, o] = t, s = o.clone().sub(e), c = Y(t, n), r = [];
for (const i of c) {
if (i < 0)
continue;
const l = s.clone().multiplyScalar(i).add(e);
r.push(l);
}
return r;
}
function Bt(t, n) {
const [e, o] = t, s = o.clone().sub(e), [c, r] = n, i = r.clone().sub(c);
if (at(i, s)) {
const l = c.clone().sub(e);
return at(l, s) ? h.Tangency : h.Dissociation;
}
return h.Intersect;
}
function v(t, n) {
const [e, o] = t, s = o.clone().sub(e), [c, r] = n, i = r.clone().sub(c), l = s.clone().cross(i), [u, a] = Pt(e);
if (a === 2 ? l === 0 : l.equals(new u()))
return null;
const m = c.clone().sub(e).cross(i), g = a === 2 ? m / l : T(l, m);
return s.clone().multiplyScalar(g).add(e);
}
function dn(t, n) {
const [e, o] = n, [s, c] = t, r = c.clone().sub(s), i = Bt(t, n);
if (i === h.Tangency) {
let p = 0;
return T(r, e.clone().sub(s)) < 0 && p++, T(r, o.clone().sub(s)) < 0 && p++, p === 2 ? h.Dissociation : p === 0 ? h.Contain : h.Tangency;
}
if (i !== h.Intersect)
return i;
const l = v(t, n), u = o.clone().sub(e), a = T(u, l.clone().sub(e));
return a < 0 || a > 1 || T(r, l.clone().sub(s)) < 0 ? h.Dissociation : h.Intersect;
}
function yn(t, n) {
const e = v(t, n);
if (e === null)
return null;
const [o, s] = n, c = s.clone().sub(o), r = T(c, e.clone().sub(o));
if (r < 0 || r > 1)
return null;
const [i, l] = t, u = l.clone().sub(i);
return T(u, e.clone().sub(i)) < 0 ? null : e;
}
function vn(t, n) {
const [e, o] = t, [s, c] = n, r = o.clone().sub(e), i = Bt(t, n);
if (i === h.Tangency) {
let p = 0, m = 0;
const g = T(r, s.clone().sub(e));
g < 0 ? p++ : g > 1 && m++;
const d = T(r, c.clone().sub(e));
return d < 0 ? p++ : d > 1 && m++, p === 2 || m === 2 ? h.Dissociation : p + m === 1 ? h.Tangency : h.Contain;
}
if (i !== h.Intersect)
return i;
const l = v(t, n), u = c.clone().sub(s), a = T(u, l.clone().sub(s));
if (a < 0 || a > 1)
return h.Dissociation;
const f = T(r, l.clone().sub(e));
return f < 0 || f > 1 ? h.Dissociation : h.Intersect;
}
function te(t, n) {
const e = v(t, n);
if (e === null)
return null;
const [o, s] = n, c = s.clone().sub(o), r = T(c, e.clone().sub(o));
if (r < 0 || r > 1)
return null;
const [i, l] = t, u = l.clone().sub(i), a = T(u, e.clone().sub(i));
return a < 0 || a > 1 ? null : e;
}
function bn(t, n) {
const [e, o] = t, s = n.clone().sub(e), c = o.clone().sub(e);
if (at(c, s)) {
const r = T(c, s);
return r < 0 || r > 1 ? h.Tangency : h.Contain;
}
return h.Dissociation;
}
function ne(t, n) {
const e = n.length;
let o, s = !1;
for (let c = 0; c < e; c++) {
const r = n[c];
let i = c + 1;
i === e && (i = 0);
const l = n[i], u = new z().subVectors(l, r), f = new z().subVectors(t, r).cross(u);
f === 0 && (s = !0);
const p = Math.sign(f);
o !== void 0 && o !== p && h.Dissociation, o = p;
}
return s ? h.Tangency : h.Contain;
}
function Ln(t, n) {
const e = [t, t.clone().add(new z(10, 0))], o = n.length;
let s = 0;
for (let c = 0; c < o; c++) {
const r = n[c];
let i = c + 1;
i === o && (i = 0);
const l = n[i], u = [r, l];
if (bn(u, t) === h.Contain)
return h.Tangency;
const f = dn(e, u);
if (f === h.Contain) {
s += 2;
continue;
}
if (f === h.Intersect) {
yn(e, u);
let p = 0;
r.y > t.y && p++, l.y > t.y && p++, p === 1 && s++;
}
}
return s % 2 === 0 ? h.Dissociation : h.Contain;
}
function ee(t, n) {
const e = t.length;
let o = 0, s = 0;
for (let l = 0; l < e; l++) {
const u = t[l];
let a = l + 1;
a === e && (a = 0);
const f = t[a], m = hn([u, f], n);
if (m === h.Intersect)
return h.Intersect;
m === h.Contain ? o++ : m === h.Tangency && s++;
}
if (o === e)
return h.Contain;
if (o > 0)
return h.Intersect;
const { center: c, radius: r } = n, i = Ln(c, t);
return r === 0 ? i : i === h.Contain ? h.Contain : s > 0 ? h.Tangency : h.Dissociation;
}
function oe(t, n) {
const e = t.length;
let o = [];
for (let s = 0; s < e; s++) {
const c = t[s];
let r = s + 1;
r === e && (r = 0);
const i = t[r], u = gn([c, i], n);
o = [...o, ...u];
}
return o;
}
function se(t, n) {
if (n = n ?? t.arcLengthDivisions, t.cacheArcULengths && t.cacheArcULengths.length === n + 1 && !t.needsUpdate) {
const c = t.cacheArcULengths;
return { lengths: c, length: c[n] };
}
t.needsUpdate = !1;
const e = [0];
let o = t.getPoint(0), s = 0;
for (let c = 1; c <= n; c++) {
const r = t.getPointAt(c / n);
s += r.distanceTo(o), e.push(s), o = r;
}
return t.cacheArcULengths = e, { lengths: e, length: s };
}
function ce(t, n, e) {
const o = e ? (l) => t.getPointAt(l) : (l) => t.getPoint(l);
let s = o(0), c = 0;
const r = [], i = n.length;
for (let l = 0; l < i; l++) {
const u = n[l], a = o(u);
c += a.distanceTo(s), r.push(c), s = a;
}
return { lengths: r, length: r[i - 1] };
}
function Vt(t, n) {
let e = t.sampleLength;
if (!e) {
const o = t.sampleNum;
if (o)
return o;
e = 1;
}
return Math.ceil(n / e);
}
function re(t) {
const { curve: n } = t;
let e = n.getLength();
const o = Vt(t, e);
return n.arcLengthDivisions < o && (n.arcLengthDivisions = o, n.updateArcLengths(), e = n.getLength()), { length: e, division: o };
}
var wn = /* @__PURE__ */ ((t) => (t.back = "back", t.front = "front", t))(wn || {});
function ie(t) {
const { curve: n, distance: e, fromU: o = 0, side: s, tolerance: c = e * 0.1 } = t, r = t.length ?? n.getLength(), i = n.getPointAt(o);
let l = e / r;
const u = s === "front" ? -1 : 1;
let a = !0, f = o, p = i, m = 0, g = !0;
do {
f = u * l + o;
let d = !1;
f > 1 ? (f = 1, d = !0) : f < 0 && (f = 0, d = !0), p = n.getPointAt(f), m = p.distanceTo(i), a = Math.abs(e - m) > c;
const y = e / m;
if (d && a && y > 1) {
g = !1;
break;
}
l *= y;
} while (a);
return {
succeed: g,
u: f,
point: p,
distance: m
};
}
function le(t) {
const { curve: n, distance: e, fromU: o = 0, tolerance: s = e * 0.1, origin: c } = t, r = t.length ?? n.getLength(), i = n.getPointAt(o), l = i.distanceTo(c), u = e - l;
let a = u / r, f = !0, p = o, m = i;
do {
p = a + o;
let g = !1;
p > 1 ? (p = 1, g = !0) : p < 0 && (p = 0, g = !0), m = n.getPointAt(p);
const d = m.distanceTo(c);
f = Math.abs(e - d) > s;
const y = u / (d - l);
if (g && f && y > 1)
return null;
a *= y;
} while (f);
return {
u: p,
point: m
};
}
function xn(t, n, e) {
const o = [], s = [], c = [], r = [], i = [];
let l = t.getTangent(0), u = e.clone(), { binormal: a } = X(l, u);
const f = 1 / n, p = new S();
for (let m = 0; m <= n; m++) {
const g = m * f;
i.push(g);
const d = t.getPoint(g);
o.push(d);
const y = t.getTangent(g);
s.push(y), p.setFromUnitVectors(l, y);
const b = u.clone().applyQuaternion(p);
c.push(b);
const C = a.clone().applyQuaternion(p);
r.push(C), l = y, u = b, a = C;
}
return { tangents: s, normals: c, binormals: r, points: o, uts: i };
}
function Cn(t, n, e, o) {
const s = [];
o = o ?? t.autoClose;
const { tangents: c, normals: r, binormals: i } = t.computeFrenetFrames(n, o), l = un(r[0], e, c[0]), u = 1 / n, a = new S(), f = [];
for (let p = 0; p <= n; p++) {
const m = p * u;
f.push(m);
const g = t.getPoint(m);
s.push(g);
const d = c[p], y = r[p], b = i[p];
a.setFromAxisAngle(d, l), y.applyQuaternion(a), b.applyQuaternion(a);
}
return { tangents: c, normals: r, binormals: i, points: s, uts: f };
}
function An(t, n, e, o) {
const s = [], c = [], r = [], i = [], l = [], u = o ? function(f) {
return {
point: t.getPointAt(f),
tangent: t.getTangentAt(f)
};
} : function(f) {
return {
point: t.getPoint(f),
tangent: t.getTangent(f)
};
}, a = 1 / n;
for (let f = 0; f <= n; f++) {
const p = f * a;
l.push(p);
const { point: m, tangent: g } = u(p);
s.push(m), c.push(g);
const d = e.clone(), { binormal: y } = X(g, d);
r.push(d), i.push(y);
}
return { tangents: c, normals: r, binormals: i, points: s, uts: l };
}
function ae(t, n, e, o) {
const { useU: s, fixUp: c, closed: r } = o || {}, i = r ?? !!t.autoClose;
let l;
return c ? l = An(t, n, e, s) : s ? l = Cn(t, n, e, i) : l = xn(t, n, e), l;
}
function ue(t) {
const n = t.count, e = [0];
let o = new w().fromBufferAttribute(t, 0), s = new w(), c = 0;
for (let r = 1; r < n; r++)
s.fromBufferAttribute(t, r), c += s.distanceTo(o), e.push(c), o.copy(s);
return { lengths: e, length: c };
}
function fe(t) {
const n = t.length, e = [0];
let o = t[0], s, c = 0;
for (let r = 1; r < n; r++)
s = t[r], c += s.distanceTo(o), e.push(c), o = s;
return { lengths: e, length: c };
}
function pt(t) {
const n = Tn(t), e = [0], o = n.reduce((s, c) => (s += c.distance(), e.push(s), s), 0);
return { lines: n, lengths: e, length: o };
}
function Tn(t) {
const n = [];
return t.reduce((e, o) => {
const s = new Ht(e, o);
return n.push(s), o;
}), n;
}
function pe(t, n) {
const e = [];
return { lines: n.filter((s, c) => {
const r = s.closestPointToPointParameter(t), i = 0 <= r || r >= 1;
return i && e.push(c), i;
}), indexs: e };
}
function me(t, n) {
const { distSortIndexs: e, clampDists: o, clampPoints: s, ts: c, clampTs: r } = On(t, n), i = e[0];
return { line: n[i], index: i, clampDist: o[i], clampPoint: s[i], t: c[i], clampT: r[i] };
}
function On(t, n) {
const e = {
clampDists: [],
clampPoints: [],
distSortIndexs: [],
ts: [],
clampTs: []
};
return n.forEach((o, s) => {
const c = o.closestPointToPointParameter(t), r = Jt.clamp(c, 0, 1), i = o.at(r, new w()), l = t.distanceTo(i);
e.clampDists.push(l), e.clampPoints.push(i), e.distSortIndexs.push(s), e.ts.push(c), e.clampTs.push(r);
}), e.distSortIndexs.sort((o, s) => e.clampDists[o] - e.clampDists[s]), e;
}
function he(t) {
const n = new Ot(), e = t[0].z == null ? $ : K;
return t.reduce((o, s) => {
const c = new e(o, s);
return n.add(c), s;
}), n;
}
function ge(t, n) {
return t.z == null ? new $(t, n) : new K(t, n);
}
function de(t) {
const n = t[0].z == null ? $ : K, e = [];
return t.reduce((o, s) => {
const c = new n(o, s);
return e.push(c), s;
}), e;
}
function ye(t, n) {
const e = [], o = [], s = [], { lines: c, lengths: r, length: i } = pt(t), l = c.length;
for (let u = 0; u < l; u++) {
const f = c[u].delta(new w()).normalize();
e.push(f);
const p = n.clone(), { binormal: m } = X(f, p);
o.push(p), s.push(m);
}
return e.push(e.at(-1).clone()), o.push(o.at(-1).clone()), s.push(s.at(-1).clone()), { tangents: e, normals: o, binormals: s, lengths: r, length: i, lines: c };
}
function be(t, n) {
const e = [], o = [], s = [], { lines: c, lengths: r, length: i } = pt(t), l = c.length - 1;
let u = c[0].delta(new w()).normalize(), a = n.clone(), { binormal: f } = X(u, a);
const p = new S();
for (let m = 0; m <= l; m++) {
const d = c[m].delta(new w()).normalize();
e.push(d), p.setFromUnitVectors(u, d);
const y = a.clone().applyQuaternion(p);
o.push(y);
const b = f.clone().applyQuaternion(p);
s.push(b), u = d, a = y, f = b;
}
return e.push(u.clone()), o.push(a.clone()), s.push(f.clone()), { tangents: e, normals: o, binormals: s, lengths: r, length: i };
}
function Sn(t, n) {
const e = t.getLength(), o = Vt(n ?? {}, e), s = t.getPoints(o), c = t.getLengths(o);
return _t(s, { ...n, lengths: c });
}
function _t(t, n) {
const { startColor: e, endColor: o, color: s, lengths: c } = n ?? {}, r = s ? new Q(s) : null, i = e ? new Q(e) : r ?? new Q(0, 1, 0), l = o ? new Q(o) : r ?? new Q(0, 0, 1), u = [], a = [];
t[0].toArray(u, 0);
const f = u.length, p = c ?? pt(t).lengths, m = p[p.length - 1], g = new Q();
t.forEach((y, b) => {
y.toArray(u, b * f);
const C = p[b] / m;
g.lerpColors(i, l, C), g.toArray(a, b * 3);
});
const d = new Kt();
return d.setAttribute("position", new wt(u, f)), d.setAttribute("color", new wt(a, 3)), d;
}
function Le(t, n) {
n = n ?? {};
let { material: e, linewidth: o } = n;
o = o ?? 1, e = e ?? new $t({ vertexColors: !0, linewidth: o });
const s = Array.isArray(t) ? _t(t, n) : Sn(t, n);
return new vt(s, e);
}
const tt = 0.1;
function we(t, n = 0, e) {
const o = [];
let s = t / 2 - 1;
if (e)
if (n === 1) {
const c = n - 1, r = n, i = r + 1;
o.push(i, r, c);
} else
n > 1 && (s++, n -= 2);
for (let c = 0; c < s; c++) {
const r = c * 2 + n, i = r + 1, l = r + 2, u = r + 3;
o.push(r, i, l, u, l, i);
}
return o;
}
function xe(t, n = 0, e) {
const o = [];
let s = t.length / 6 - 1;
if (e)
if (n === 1) {
const u = n - 1, a = n, f = a + 1;
o.push(f, a, u);
} else
n > 1 && (s++, n -= 2);
const c = new w(), r = new w(), i = new w(), l = s - 1;
for (let u = 0; u < s; u++) {
const a = u * 2, f = a + 1, p = a + 2, m = a + 3, g = a + n, d = g + 1, y = g + 2, b = g + 3, C = [g, d, y, b, y, d], L = [g, d, b, b, y, g];
if (g >= 0) {
c.fromArray(t, a * 3), r.fromArray(t, p * 3);
const O = u === l;
if (c.equals(r)) {
const A = a + 4;
O || i.fromArray(t, A * 3).equals(r) ? o.push(...L) : o.push(...C);
continue;
}
if (c.fromArray(t, f * 3), r.fromArray(t, m * 3), c.equals(r)) {
const A = a + 5;
O || i.fromArray(t, A * 3).equals(r) ? o.push(...C) : o.push(...L);
continue;
}
}
o.push(...C);
}
return o;
}
var Pn = /* @__PURE__ */ ((t) => (t.bevel = "bevel", t.chamfer = "chamfer", t.round = "round", t.lineSegment = "lineSegment", t))(Pn || {});
function In(t, n, e, o, s = tt) {
const { point: c, length: r, width: i } = t, l = i / 2, { tangent: u, normal: a, binormal: f } = n, { tangent: p, normal: m, binormal: g } = e, { line: d } = Dt(n, e, s);
let y;
if (!d) {
y = f.clone().multiplyScalar(l);
const P = c.clone().sub(y), nt = c.clone().add(y);
y.copy(g).multiplyScalar(l);
const yt = c.clone().sub(y), bt = c.clone().add(y);
return {
points: [P, nt, yt, bt],
normals: [a, a, m, m],
lengths: [r, r, r, r]
};
}
let { tangent: b, normal: C, length: L } = d;
y = b.clone().multiplyScalar(L * l);
const O = Math.abs(y.dot(p)), A = r - O, U = r + O, q = c.clone().sub(y), R = c.clone().add(y);
let N, I, k, V;
const M = f.clone().multiplyScalar(i), W = g.clone().multiplyScalar(i);
if (u.clone().cross(p).dot(a) > 0) {
const P = N = k = q;
I = P.clone().add(M), V = P.clone().add(W);
} else {
const P = V = I = R;
N = P.clone().sub(M), k = P.clone().sub(W);
}
return o ? {
points: [N, I, k, V],
normals: [a, a, m, m],
lengths: [A, A, U, U]
} : {
points: [N, I, q, R, k, V],
normals: [a, a, C, C, m, m],
lengths: [A, A, r, r, U, U]
};
}
var Mn = /* @__PURE__ */ ((t) => (t[t.AllOblique = 0] = "AllOblique", t[t.TangentSame = 1] = "TangentSame", t[t.TangentReverse = 2] = "TangentReverse", t[t.TangentVertical = 4] = "TangentVertical", t[t.NormalSame = 8] = "NormalSame", t[t.NormalReverse = 16] = "NormalReverse", t[t.NormalVertical = 32] = "NormalVertical", t[t.BinormalSame = 64] = "BinormalSame", t[t.BinormalReverse = 128] = "BinormalReverse", t[t.BinormalVertical = 256] = "BinormalVertical", t))(Mn || {});
function Bn(t, n, e = tt) {
const { tangent: o, normal: s, binormal: c } = t, { tangent: r, normal: i, binormal: l } = n;
let u = 0;
const a = o.dot(r), f = Math.abs(a);
f > 1 - e ? u |= a > 0 ? 1 : 2 : f < e && (u |= 4);
const p = s.dot(i), m = Math.abs(p);
m > 1 - e ? u |= p > 0 ? 8 : 16 : m < e && (u |= 32);
const g = c.dot(l), d = Math.abs(g);
return d > 1 - e ? u |= g > 0 ? 64 : 128 : d < e && (u |= 256), u;
}
function Dt(t, n, e = tt) {
const { normal: o, binormal: s } = t, { normal: c, binormal: r } = n, i = Bn(t, n, e);
let l, u;
if (i & 8 && !(i & 2))
u = c, l = s.clone().add(r);
else if (i & 16)
u = c, l = r.clone().negate().add(s);
else {
if (i & 3)
return { relation: i };
if (i & 256)
return { relation: i };
u = o.clone().add(c).normalize(), l = o.clone().cross(c);
}
l.normalize();
let a = l.dot(s);
a < 0 && (l.negate(), a = -a);
const f = 1 / a;
return {
relation: i,
line: {
tangent: l,
normal: u,
length: f
}
};
}
function Vn(t, n, e, o, s = tt) {
const { point: c, length: r, width: i } = t, l = i / 2, { tangent: u, normal: a, binormal: f } = n, { tangent: p, normal: m, binormal: g } = e, { smoothStepAngle: d, smoothStepLength: y } = o || {}, { relation: b, line: C } = Dt(n, e, s);
let L;
if (!C) {
L = f.clone().multiplyScalar(l);
const x = c.clone().sub(L), _ = c.clone().add(L);
L.copy(g).multiplyScalar(l);
const D = c.clone().sub(L), E = c.clone().add(L);
return {
points: [x, _, D, E],
normals: [a, a, m, m],
lengths: [r, r, r, r]
};
}
let { tangent: O, normal: A, length: U } = C;
L = O.clone().multiplyScalar(U * l);
const q = c.clone().sub(L), R = c.clone().add(L);
if (b & 64)
return {
points: [q, R],
normals: [A, A],
lengths: [r, r]
};
const N = f.angleTo(O), I = Math.abs(L.dot(p)), k = r - I, V = 1 / I;
let M = d == null && y ? I / y : N / (d ?? 0.5);
M = Math.max(Math.round(M), 1);
const W = 1 / M, gt = new S().setFromUnitVectors(f, O), dt = new S().setFromUnitVectors(O, g), P = new S().setFromUnitVectors(a, A), nt = new S().setFromUnitVectors(A, m), Lt = u.clone().cross(p).dot(a) > 0 ? function(x) {
return {
left: q,
right: q.clone().add(x)
};
} : function(x) {
return {
left: R.clone().sub(x),
right: R
};
};
L.copy(f).multiplyScalar(i);
const Z = new S(), B = new S(), et = [], ot = [], st = [];
for (let x = 0; x < M; x++) {
const _ = x * W;
B.slerpQuaternions(Z, gt, _);
const D = x * V + k;
st.push(D, D);
const E = L.clone().applyQuaternion(B), { left: ct, right: rt } = Lt(E);
et.push(ct, rt), B.slerpQuaternions(Z, P, _);
const G = a.clone().applyQuaternion(B);
ot.push(G, G);
}
L.copy(O).multiplyScalar(i);
for (let x = 0; x <= M; x++) {
const _ = x * W;
B.slerpQuaternions(Z, dt, _);
const D = x * V + r;
st.push(D, D);
const E = L.clone().applyQuaternion(B), { left: ct, right: rt } = Lt(E);
et.push(ct, rt), B.slerpQuaternions(Z, nt, _);
const G = A.clone().applyQuaternion(B);
ot.push(G, G);
}
return { points: et, normals: ot, lengths: st };
}
function _n(t, n, e) {
const { point: o, length: s, width: c } = t, r = c / 2, { normal: i, binormal: l } = n, { normal: u, binormal: a } = e;
let f = l.clone().multiplyScalar(r);
const p = o.clone().sub(f), m = o.clone().add(f);
let g = a.clone().multiplyScalar(r);
const d = o.clone().sub(g), y = o.clone().add(g);
return {
points: [p, m, d, y],
normals: [i, i, u, u],
lengths: [s, s, s, s]
};
}
function Ce(t, n, e, o) {
const { connectionType: s } = o || {};
switch (s) {
case "round":
return Vn(t, n, e, o);
case "lineSegment":
return _n(t, n, e);
default:
return In(
t,
n,
e,
s === "chamfer"
/* chamfer */
);
}
}
const F = new ft();
function mt(t, n) {
const { wrapS: e, wrapT: o, flipX: s, flipY: c } = n;
if (t.x < 0 || t.x > 1)
switch (e) {
case At:
t.x = t.x - Math.floor(t.x);
break;
case Ct:
t.x = t.x < 0 ? 0 : 1;
break;
case xt:
Math.abs(Math.floor(t.x) % 2) === 1 ? t.x = Math.ceil(t.x) - t.x : t.x = t.x - Math.floor(t.x);
break;
}
if (t.y < 0 || t.y > 1)
switch (o) {
case At:
t.y = t.y - Math.floor(t.y);
break;
case Ct:
t.y = t.y < 0 ? 0 : 1;
break;
case xt:
Math.abs(Math.floor(t.y) % 2) === 1 ? t.y = Math.ceil(t.y) - t.y : t.y = t.y - Math.floor(t.y);
break;
}
return s && (t.x = 1 - t.x), c && (t.y = 1 - t.y), t;
}
function Dn(t, n) {
const e = t.count;
for (let o = 0; o < e; o++) {
const s = t.getX(o), c = t.getY(o), r = mt({ x: s, y: c }, n);
t.setXY(o, r.x, r.y);
}
return t;
}
function zn(t, n) {
const e = new z(), o = t.length;
for (let s = 0; s < o; s++) {
const c = s * 2, r = c + 1;
e.x = t[c], e.y = t[r], mt(e, n), t[c] = e.x, t[r] = e.y;
}
return t;
}
function ht(t, n = new ft()) {
const { offset: e = { x: 0, y: 0 }, repeat: o = { x: 1, y: 1 }, center: s = { x: 0, y: 0 }, rotation: c = 0 } = t;
return n.setUvTransform(e.x, e.y, o.x, o.y, c, s.x, s.y), n;
}
function Ae(t, n, e) {
return ht(n, F), t.applyMatrix3(F), e && mt(t, e), t;
}
function Te(t, n, e) {
return ht(n, F), t.applyMatrix3(F), e && Dn(t, e), t.needsUpdate = !0, t;
}
function Oe(t, n, e) {
ht(n, F);
const o = new z(), s = t.length;
for (let c = 0; c < s; c++) {
const r = c * 2, i = r + 1;
o.x = t[r], o.y = t[i], o.applyMatrix3(F), t[r] = o.x, t[i] = o.y;
}
return e && zn(t, e), t;
}
export {
Ie as Axis,
Me as Axis4,
It as Azimuth,
wn as DirectionSide,
Mn as FrenetFrameRelation,
h as GeometricRelationship,
Pn as LineConnectionType,
X as adjustFrenetFrame,
ln as adjustFrontUpFrame,
Fn as adjustOrientation,
Xn as azimuth,
cn as closeCurvePath,
ae as computeCurveFrenetFrames,
An as computeCurveFrenetFramesByFixUp,
xn as computeCurveFrenetFramesByT,
Cn as computeCurveFrenetFramesByU,
Bn as computeFrenetFrameRelation,
En as computeIntersectSpheres,
Y as computeIntersectionFactorOfLine_Circle,
Dt as computeIntersectionLineOfBands,
gn as computeIntersectionOfLineSegment_Circle,
te as computeIntersectionOfLineSegment_LineSegment,
Jn as computeIntersectionOfLine_Circle,
v as computeIntersectionOfLine_Line,
oe as computeIntersectionOfPolygon_Circle,
$n as computeIntersectionOfRay_Circle,
yn as computeIntersectionOfRay_LineSegment,
be as computePolylineFrenetFrames,
ye as computePolylineFrenetFramesByFixUp,
T as computeVectorScalar,
mt as configUV,
Dn as configUVBufferAttribute,
zn as configUVs,
In as createBevelLineConnection,
Sn as createCurveBufferGeometry,
Ce as createLineConnection,
ge as createLineCurve,
de as createLineCurves,
_n as createLineSegmentConnection,
Le as createLineSegmentsByCurve,
Gn as createLinearGradientTexture,
Tn as createLines,
_t as createPolylineBufferGeometry,
he as createPolylineCurve,
Vn as createRoundLineConnection,
we as createSymmetricSegmentedTrigonometricIndexs,
xe as createSymmetricSegmentedTrigonometricIndexsByVertexs,
ht as createUVTransformMatrix,
lt as defaultAzimuthOptions,
ut as defaultCourseAzimuthMap,
hn as discriminateRelationshipOfLineSegment_Circle,
vn as discriminateRelationshipOfLineSegment_LineSegment,
bn as discriminateRelationshipOfLineSegment_Point,
Hn as discriminateRelationshipOfLine_Circle,
Bt as discriminateRelationshipOfLine_Line,
ne as discriminateRelationshipOfPoint_ConvexPolygon,
Ln as discriminateRelationshipOfPoint_Polygon,
ee as discriminateRelationshipOfPolygon_Circle,
Kn as discriminateRelationshipOfRay_Circle,
dn as discriminateRelationshipOfRay_LineSegment,
pn as formatAzimuthDefineMap,
jn as frenetFrameToFrontUpFrame,
Qn as frontUpFrameToFrenetFrame,
Zn as get3DTextureItem,
Yn as get3DTextureSlice,
un as getAxisRotationAngle,
fn as getAzimuthAngle,
me as getClosestDistanceInfoOfPointToLines,
re as getCurveDivisionLength,
ie as getCurvePointAwayFrom,
le as getCurvePointAwayFromOrigin,
se as getCurveULengths,
On as getDistanceInfoOfPointToLines,
an as getIncludedAngle,
fe as getLengthsOfPoints,
ue as getLengthsOfPositionAttribute,
ce as getLengthsOfTs,
pt as getLinesInfo,
pe as getProjectionLines,
Wn as getQuaternionBetweenVectorsAroundAxis,
J as getRotationAngle,
Vt as getSampleNum,
Mt as getTextureFormatSize,
Pt as getVectorClass,
at as isCollinear,
H as ivectorMemberToVector,
rn as ivectorToVector,
kn as threeBugPatch,
Ae as transformUV,
Te as transformUVBufferAttribute,
Oe as transformUVs,
tt as zeroThreshold_Default
};