gl-draw 0.17.0-beta.2 → 0.17.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1031 +0,0 @@
1
- var Ce = Object.defineProperty, Ie = Object.defineProperties;
2
- var Pe = Object.getOwnPropertyDescriptors;
3
- var V = Object.getOwnPropertySymbols;
4
- var te = Object.prototype.hasOwnProperty, ie = Object.prototype.propertyIsEnumerable;
5
- var se = Math.pow, ee = (n, e, t) => e in n ? Ce(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, k = (n, e) => {
6
- for (var t in e || (e = {}))
7
- te.call(e, t) && ee(n, t, e[t]);
8
- if (V)
9
- for (var t of V(e))
10
- ie.call(e, t) && ee(n, t, e[t]);
11
- return n;
12
- }, $ = (n, e) => Ie(n, Pe(e));
13
- var ne = (n, e) => {
14
- var t = {};
15
- for (var i in n)
16
- te.call(n, i) && e.indexOf(i) < 0 && (t[i] = n[i]);
17
- if (n != null && V)
18
- for (var i of V(n))
19
- e.indexOf(i) < 0 && ie.call(n, i) && (t[i] = n[i]);
20
- return t;
21
- };
22
- var re = (n, e, t) => new Promise((i, s) => {
23
- var a = (o) => {
24
- try {
25
- r(t.next(o));
26
- } catch (c) {
27
- s(c);
28
- }
29
- }, l = (o) => {
30
- try {
31
- r(t.throw(o));
32
- } catch (c) {
33
- s(c);
34
- }
35
- }, r = (o) => o.done ? i(o.value) : Promise.resolve(o.value).then(a, l);
36
- r((t = t.apply(n, e)).next());
37
- });
38
- import { Material as ae, Object3D as N, Texture as oe, BufferGeometry as Z, Float32BufferAttribute as R, PointsMaterial as Be, Points as J, InstancedMesh as xe, Vector3 as w, Quaternion as De, Group as Te, Mesh as we, Sprite as ce, Box3 as Se, ShaderMaterial as ze, Vector2 as q, Color as le, Vector4 as E, Matrix4 as Oe, Line3 as _e, Sphere as ke, InstancedInterleavedBuffer as Ee, InterleavedBufferAttribute as ue, MathUtils as Le } from "three";
39
- import { CSS2DObject as Ve } from "three/examples/jsm/renderers/CSS2DRenderer";
40
- import { CSS3DObject as Ue, CSS3DSprite as We } from "three/examples/jsm/renderers/CSS3DRenderer";
41
- import { geoBounds as je, geoContains as Ne, geoDistance as Re, geoInterpolate as Ge } from "d3-geo";
42
- import "d3-geo-projection";
43
- import { p as fe, a as Fe } from "./polar2Cartesian.module.js";
44
- import { merge as H, mean as $e, extent as de } from "d3-array";
45
- import qe, { flatten as Ae } from "earcut";
46
- import Ke from "@turf/boolean-clockwise";
47
- import Qe from "delaunator";
48
- import Xe from "@turf/boolean-point-in-polygon";
49
- import { geoVoronoi as Ye } from "d3-geo-voronoi";
50
- import { scaleLinear as he } from "d3-scale";
51
- import { LineSegmentsGeometry as Ze } from "three/examples/jsm/lines/LineSegmentsGeometry";
52
- const Je = 0, Dt = 1, He = 2, Tt = !1;
53
- class et {
54
- constructor() {
55
- this.resources = /* @__PURE__ */ new Set(), this.disposeMaterial = !0, this.disposeVideo = !0;
56
- }
57
- track(e) {
58
- if (!e)
59
- return e;
60
- if (Array.isArray(e))
61
- return e.forEach((t) => this.track(t)), e;
62
- if (!this.disposeMaterial && e instanceof ae)
63
- return e;
64
- if (e instanceof pe ? (e.disposeTrack && e.object3d ? this.track(e.object3d) : this.resources.add(e), Object.values(e.materialList).map((t) => this.track(t))) : (e instanceof N || Reflect.has(e, "dispose")) && this.resources.add(e), e instanceof pe)
65
- e.children.forEach((t) => {
66
- t.disposeTrack = !1;
67
- }), this.track(e.children);
68
- else if (e instanceof N) {
69
- const t = e;
70
- this.track(t.geometry), this.track(t.material), this.track(t.children);
71
- } else if (e instanceof ae) {
72
- for (const i of Object.values(e))
73
- i instanceof oe && this.track(i);
74
- const t = e;
75
- if (t.uniforms) {
76
- for (const i of Object.values(t.uniforms))
77
- if (i) {
78
- const s = i.value;
79
- (s instanceof oe || Array.isArray(s)) && this.track(s);
80
- }
81
- }
82
- } else this.disposeVideo && e.isVideoTexture && e.source.data && this.resources.add(e.source.data);
83
- return e;
84
- }
85
- dispose() {
86
- const e = [];
87
- for (const t of this.resources)
88
- t instanceof N ? e.push(t) : t instanceof HTMLVideoElement && t.pause(), Reflect.has(t, "dispose") && t.dispose();
89
- e.forEach((t) => {
90
- t.removeFromParent();
91
- }), e.length = 0, this.resources.clear();
92
- }
93
- }
94
- const tt = (n, e = 1) => {
95
- const t = new Z();
96
- t.setAttribute(
97
- "position",
98
- new R(new Array(e * 3).fill(0), 3)
99
- ), t.setAttribute(
100
- "scaleAtt",
101
- new R(new Array(e).fill(1), 1)
102
- );
103
- const i = n.material, s = new Be({
104
- size: 10,
105
- map: i.map,
106
- alphaMap: i.alphaMap,
107
- color: i.color,
108
- blending: i.blending,
109
- depthTest: i.depthTest,
110
- depthWrite: !1,
111
- opacity: i.opacity,
112
- transparent: !0,
113
- alphaTest: i.alphaTest,
114
- sizeAttenuation: !1
115
- });
116
- return s.onBeforeCompile = (a) => {
117
- a.vertexShader = `
118
- attribute float scaleAtt;
119
- ${a.vertexShader.replace(
120
- "gl_PointSize = size;",
121
- "gl_PointSize = size * scaleAtt;"
122
- )}
123
- `;
124
- }, new J(t, s);
125
- }, it = (n, e) => {
126
- const t = new N();
127
- e.forEach((i, s) => {
128
- const a = fe(i.position), l = fe(i.scale || [1, 1, 1]);
129
- t.position.copy(a), t.scale.copy(l), t.updateMatrix();
130
- const r = t.matrix.clone();
131
- if (n instanceof xe || n.isInstantiate)
132
- n.setMatrixAt(s, r);
133
- else if (n instanceof J || n.type === "Points") {
134
- const c = n.geometry, m = c.attributes.position.array, u = c.attributes.scaleAtt.array, h = new w(), f = new w(), p = new De(), d = s * 3, v = s * 1;
135
- r.decompose(h, p, f), m[d] = h.x, m[d + 1] = h.y, m[d + 2] = h.z, u[v] = Math.max(f.x, f.y, f.z), c.attributes.position.needsUpdate = !0, c.attributes.scaleAtt.needsUpdate = !0;
136
- }
137
- });
138
- };
139
- class st {
140
- constructor() {
141
- this.onPointerIndex = [];
142
- }
143
- onPointerEvent(e, t) {
144
- const i = this.lead.handlePick([this], e, t);
145
- this.onPointerIndex.push(i);
146
- }
147
- onClick(e) {
148
- this.onPointerEvent("click", e);
149
- }
150
- onPointerEnter(e) {
151
- this.onPointerEvent("enter", e);
152
- }
153
- onPointerLeave(e) {
154
- this.onPointerEvent("leave", e);
155
- }
156
- onPointerMove(e) {
157
- this.onPointerEvent("move", e);
158
- }
159
- onPointerDown(e) {
160
- this.onPointerEvent("down", e);
161
- }
162
- dispose() {
163
- this.onPointerIndex.forEach((e) => {
164
- this.lead.removePick(e);
165
- });
166
- }
167
- }
168
- class nt extends st {
169
- constructor() {
170
- super(...arguments), this.userData = {}, this.materialList = {}, this.useMaterialType = "origin", this.disposeMaterialIfNotUsed = !0;
171
- }
172
- cloneMaterial() {
173
- const e = this.object3d;
174
- if (!e || !e.material)
175
- return;
176
- const t = e.material;
177
- if (Array.isArray(t))
178
- return t.map((i) => {
179
- const s = i.userData;
180
- i.userData = {};
181
- const a = i.clone();
182
- return i.userData = s, a;
183
- });
184
- {
185
- const i = t.userData;
186
- t.userData = {};
187
- const s = t.clone();
188
- return t.userData = i, s;
189
- }
190
- }
191
- setMaterialList(e, t) {
192
- const i = this.object3d;
193
- if (!i || !i.material)
194
- return;
195
- this.materialList.origin || (this.materialList.origin = i.material);
196
- const s = t === "clone" ? this.cloneMaterial() : Array.isArray(t) ? t.slice() : t;
197
- return this.materialList[e] = s, s;
198
- }
199
- useMaterial(e) {
200
- const t = this.object3d;
201
- !t || !t.material || this.useMaterialType === e || !this.materialList[e] || (this.useMaterialType = e, t.material = this.materialList[e]);
202
- }
203
- useMListById(e, t) {
204
- if (!this.mList)
205
- return;
206
- const i = this.mList.get(e);
207
- if (!i)
208
- return;
209
- const s = this.object3d;
210
- Array.isArray(s.material) && t !== void 0 ? s.material[t] = i : s.material = i;
211
- }
212
- useMListByName(e, t) {
213
- if (!this.mList)
214
- return;
215
- const i = this.mList.getKeyByName(e);
216
- i && this.useMListById(i, t);
217
- }
218
- dispose() {
219
- super.dispose(), this.mList.rmBaseObjectMap(
220
- this,
221
- void 0,
222
- this.disposeMaterialIfNotUsed
223
- );
224
- }
225
- }
226
- class pe extends nt {
227
- constructor() {
228
- super(...arguments), this.key = "", this.objectType = "BaseObject", this.userData = {}, this.isPrefab = !1, this.isInstantiate = !1, this.isBloom = !1, this.isBaseObject = !0, this.disposeTrack = !0;
229
- }
230
- get parent() {
231
- const e = this.object3d.parent;
232
- return e && this.lead.objMap.get(e) || null;
233
- }
234
- get children() {
235
- return this.object3d.children.map((e) => this.lead.objMap.get(e)).filter((e) => !!e);
236
- }
237
- get position() {
238
- return this.object3d.position;
239
- }
240
- get rotation() {
241
- return this.object3d.rotation;
242
- }
243
- get scale() {
244
- return this.object3d.scale;
245
- }
246
- lookAt(e) {
247
- const t = e instanceof w ? e : new w(...e);
248
- this.object3d.lookAt(t);
249
- }
250
- add(...e) {
251
- [...e].forEach((t) => {
252
- this.lead.objMap.get(t) ? this.object3d.add(t) : this.lead.createBaseObject(t, {
253
- target: this
254
- });
255
- });
256
- }
257
- remove(...e) {
258
- [...e].forEach((t) => {
259
- var i;
260
- this.lead.objMap.get(t) ? (i = this.lead.objMap.get(t)) == null || i.erase() : this.object3d.remove(t);
261
- });
262
- }
263
- get visible() {
264
- return this.object3d.visible;
265
- }
266
- get visibleWithAncestors() {
267
- if (this.visible) {
268
- let e = this.parent;
269
- for (; e; ) {
270
- if (!e.visible)
271
- return !1;
272
- e = e.parent;
273
- }
274
- return !0;
275
- } else
276
- return !1;
277
- }
278
- create() {
279
- this.createGroup();
280
- }
281
- render() {
282
- }
283
- update(e, t) {
284
- }
285
- resize(e, t) {
286
- }
287
- show() {
288
- return this.object3d.visible = !0, this.object3d.layers.set(Je), this.isBloom && this.enableBloom(), this;
289
- }
290
- hide() {
291
- return this.object3d.visible = !1, this.object3d.layers.set(He), this;
292
- }
293
- createGroup() {
294
- return this.object3d = new Te(), this;
295
- }
296
- createMesh(...e) {
297
- return this.object3d = new we(...e), this;
298
- }
299
- createPoints(...e) {
300
- return this.object3d = new J(...e), this;
301
- }
302
- createCSS2DObject(e) {
303
- return this.object3d = new Ve(e), this;
304
- }
305
- createCSS3DObject(e) {
306
- return this.object3d = new Ue(e), this;
307
- }
308
- createCSS3DSprite(e) {
309
- return this.object3d = new We(e), this;
310
- }
311
- createSprite(e) {
312
- return this.object3d = new ce(e), this;
313
- }
314
- attach(...e) {
315
- return [...e].forEach((t) => {
316
- this.object3d.attach(t.object3d);
317
- }), this;
318
- }
319
- getSize() {
320
- const e = new Se().setFromObject(this.object3d);
321
- return {
322
- min: e.min,
323
- max: e.max,
324
- size: e.getSize(new w()),
325
- center: e.getCenter(new w())
326
- };
327
- }
328
- setTop(e) {
329
- this.object3d && (this.object3d.renderOrder = e);
330
- }
331
- traverse(e) {
332
- e(this), this.children.forEach((t) => {
333
- t.traverse(e);
334
- });
335
- }
336
- instantiate(e) {
337
- return re(this, null, function* () {
338
- var c, m;
339
- const t = (c = e == null ? void 0 : e.recursive) != null ? c : !0, i = (m = e == null ? void 0 : e.cloneMaterial) != null ? m : !1, { objectType: s, objectOptions: a } = this;
340
- let l = e == null ? void 0 : e.create, r, o = (e == null ? void 0 : e.target) || this.parent;
341
- return o === this.lead.prefabGroup && (o = this.lead.group), this.objectType === "BaseObject" ? r = this.lead.createBaseObject(this.object3d.clone(!1), {
342
- target: o
343
- }) : (l === void 0 && (l = (u) => {
344
- var h;
345
- if (this.object3d) {
346
- if ((h = e == null ? void 0 : e.instancedAttr) != null && h.length) {
347
- const f = e.instancedAttr.length;
348
- if (this.object3d instanceof ce)
349
- u.object3d = tt(this.object3d, f);
350
- else {
351
- const p = this.object3d, d = i ? this.cloneMaterial() : p.material;
352
- u.object3d = new xe(
353
- p.geometry,
354
- d,
355
- f
356
- );
357
- }
358
- it(u.object3d, e == null ? void 0 : e.instancedAttr);
359
- } else
360
- u.object3d = this.object3d.clone(!1), i && u.object3d.material && (u.object3d.material = this.cloneMaterial());
361
- u.object3d.userData.prefab && delete u.object3d.userData.prefab;
362
- }
363
- }), r = yield this.lead.draw(s, $(k({}, a || {}), {
364
- create: l,
365
- prefab: !1,
366
- keyType: this.keyType,
367
- key: (e == null ? void 0 : e.key) || this.keyName,
368
- uId: (e == null ? void 0 : e.uId) || this.keyUId,
369
- target: o
370
- }))), this.isBloom && r.enableBloom(), t && (yield Promise.all(
371
- this.children.map(
372
- (u) => u.instantiate({
373
- key: u.keyUId ? `${u.keyName}-${u.keyUId}` : u.keyName,
374
- uId: e == null ? void 0 : e.uId,
375
- cloneMaterial: i,
376
- target: r
377
- })
378
- )
379
- )), r.isInstantiate = !0, r;
380
- });
381
- }
382
- erase() {
383
- this.lead.erase(this);
384
- }
385
- handleMaterialChange(e) {
386
- }
387
- enableBloom() {
388
- var e;
389
- (e = this.pencil.composerController) == null || e.setBloomSelection(this, !0), this.isBloom = !0;
390
- }
391
- disableBloom() {
392
- var e;
393
- (e = this.pencil.composerController) == null || e.setBloomSelection(this, !1), this.isBloom = !1;
394
- }
395
- dispose() {
396
- var e;
397
- if (super.dispose(), (e = this.pencil.composerController) == null || e.bloomSelection.delete(this), this.lead && (this.lead.objects.delete(this.key), this.lead.objectWrapChindIdMap.delete(this), this.object3d && this.lead.objMap.delete(this.object3d)), this.disposeTrack) {
398
- const t = new et();
399
- t.disposeMaterial = !1, t.track(this), t.dispose();
400
- }
401
- }
402
- }
403
- function rt(n, e) {
404
- return n.map((t) => {
405
- const i = [];
406
- let s;
407
- return t.forEach((a) => {
408
- if (s) {
409
- const l = Re(a, s) * 180 / Math.PI;
410
- if (l > e) {
411
- const r = Ge(s, a), o = 1 / Math.ceil(l / e);
412
- let c = o;
413
- for (; c < 1; )
414
- i.push(r(c)), c += o;
415
- }
416
- }
417
- i.push(s = a);
418
- }), i;
419
- });
420
- }
421
- function at(n, { minLng: e, maxLng: t, minLat: i, maxLat: s } = {}) {
422
- const a = Math.round(se(360 / n, 2) / Math.PI), l = (1 + Math.sqrt(5)) / 2, r = (f) => f / l * 360 % 360 - 180, o = (f) => Math.acos(2 * f / a - 1) / Math.PI * 180 - 90, c = (f) => a * (Math.cos((f + 90) * Math.PI / 180) + 1) / 2, m = [
423
- s !== void 0 ? Math.ceil(c(s)) : 0,
424
- i !== void 0 ? Math.floor(c(i)) : a - 1
425
- ], u = e === void 0 && t === void 0 ? () => !0 : e === void 0 ? (f) => f <= t : t === void 0 ? (f) => f >= e : t >= e ? (f) => f >= e && f <= t : (f) => f >= e || f <= t, h = [];
426
- for (let f = m[0]; f <= m[1]; f++) {
427
- const p = r(f);
428
- u(p) && h.push([p, o(f)]);
429
- }
430
- return h;
431
- }
432
- function Y(n, e, t = !1) {
433
- return t ? Ne(e, n) : Xe(n, e);
434
- }
435
- function ot(n, e) {
436
- const t = { type: "Polygon", coordinates: n }, [[i, s], [a, l]] = je(t);
437
- if (Math.min(Math.abs(a - i), Math.abs(l - s)) < e)
438
- return [];
439
- const r = i > a || l >= 89 || s <= -89;
440
- return at(e, {
441
- minLng: i,
442
- maxLng: a,
443
- minLat: s,
444
- maxLat: l
445
- }).filter(
446
- (o) => Y(o, t, r)
447
- );
448
- }
449
- function ct(n, { resolution: e = 1 / 0, bbox: t, projection: i } = {}) {
450
- const s = rt(n, e), a = H(s), l = ot(n, e), r = [...a, ...l], o = { type: "Polygon", coordinates: n }, [[c, m], [u, h]] = je(o), f = c > u || // crosses antimeridian
451
- h >= 89 || // crosses north pole
452
- m <= -89;
453
- let p = [];
454
- if (f) {
455
- const y = Ye(r).triangles(), x = new Map(
456
- r.map(([C, I], O) => [`${C}-${I}`, O])
457
- );
458
- y.features.forEach((C) => {
459
- const I = C.geometry.coordinates[0].slice(0, 3).reverse(), O = [];
460
- if (I.forEach(([P, F]) => {
461
- const L = `${P}-${F}`;
462
- x.has(L) && O.push(x.get(L));
463
- }), O.length === 3) {
464
- if (O.some((P) => P < a.length)) {
465
- const P = C.properties.circumcenter;
466
- if (!Y(
467
- P,
468
- o,
469
- f
470
- ))
471
- return;
472
- }
473
- p.push(...O);
474
- }
475
- });
476
- } else if (l.length) {
477
- const y = Qe.from(r);
478
- for (let x = 0, C = y.triangles.length; x < C; x += 3) {
479
- const I = [2, 1, 0].map((P) => y.triangles[x + P]), O = I.map((P) => r[P]);
480
- if (I.some((P) => P < a.length)) {
481
- const P = [0, 1].map(
482
- (F) => $e(O, (L) => L[F])
483
- );
484
- if (!Y(
485
- P,
486
- o,
487
- f
488
- ))
489
- continue;
490
- }
491
- p.push(...I);
492
- }
493
- } else {
494
- const { vertices: y, holes: x = [] } = Ae(s);
495
- p = qe(y, x, 2);
496
- }
497
- let d = t ? [t[0], t[2]] : de(r, (y) => y[0]), v = t ? [t[1], t[3]] : de(r, (y) => y[1]);
498
- if (i) {
499
- const [y, x] = i([d[0], v[0]]), [C, I] = i([d[1], v[1]]);
500
- d = [y, C], v = [-x, -I];
501
- }
502
- const S = he(d, [0, 1]), j = he(v, [0, 1]), B = r.map(([y, x]) => {
503
- if (i) {
504
- const [C, I] = i([y, x]);
505
- return [S(C), j(-I)];
506
- } else
507
- return [S(y), j(x)];
508
- });
509
- return { contour: s, triangles: { points: r, indices: p, uvs: B } };
510
- }
511
- const me = new Z().setAttribute ? "setAttribute" : "addAttribute";
512
- function G(n, e, t, i) {
513
- const s = n.map(
514
- (a) => a.map(([l, r]) => {
515
- if (i) {
516
- const [o, c] = i([l, r]);
517
- return [o, -c, e];
518
- }
519
- return t ? Fe(l, r, e) : [l, r, e];
520
- })
521
- );
522
- return Ae(s);
523
- }
524
- function lt(n, e, t, i, s) {
525
- const { vertices: a, holes: l } = G(
526
- n,
527
- e,
528
- i,
529
- s
530
- ), { vertices: r } = G(
531
- n,
532
- t,
533
- i,
534
- s
535
- ), o = H([r, a]), c = Math.round(r.length / 3), m = new Set(l);
536
- let u = 0;
537
- const h = [];
538
- for (let p = 0; p < c; p++) {
539
- let d = p + 1;
540
- if (d === c)
541
- d = u;
542
- else if (m.has(d)) {
543
- const v = d;
544
- d = u, u = v;
545
- }
546
- h.push(p, p + c, d + c), h.push(d + c, d, p);
547
- }
548
- const f = [];
549
- for (let p = 1; p >= 0; p--)
550
- for (let d = 0; d < c; d += 1) f.push(d / (c - 1), p);
551
- return { indices: h, vertices: o, uvs: f, topVerts: r };
552
- }
553
- function ve(n, e, t, i, s, a) {
554
- return {
555
- indices: i ? n.indices : n.indices.slice().reverse(),
556
- vertices: G(
557
- [n.points],
558
- e,
559
- s,
560
- a
561
- ).vertices,
562
- uvs: t
563
- };
564
- }
565
- const ut = ({
566
- polygonGeoJson: n,
567
- startHeight: e,
568
- endHeight: t,
569
- curvatureResolution: i = 1,
570
- cartesian: s = !0,
571
- hasSide: a = !0,
572
- hasBottom: l = !1,
573
- hasTop: r = !1,
574
- projection: o,
575
- bbox: c
576
- }) => {
577
- n.forEach((S) => {
578
- Ke(S) || S.reverse();
579
- });
580
- const { contour: m, triangles: u } = ct(n, {
581
- resolution: i,
582
- bbox: c,
583
- projection: o
584
- });
585
- let h = {}, f;
586
- a && (h = lt(
587
- m,
588
- e != null ? e : t,
589
- t != null ? t : e,
590
- s,
591
- o
592
- ), f = h.topVerts);
593
- let p = [];
594
- (l || r) && (p = H(u.uvs));
595
- let d = {};
596
- l && (d = ve(
597
- u,
598
- e,
599
- p,
600
- !1,
601
- s,
602
- o
603
- ));
604
- let v = {};
605
- return r && (v = ve(
606
- u,
607
- t,
608
- p,
609
- !0,
610
- s,
611
- o
612
- )), { contour: m, triangles: u, sideTorso: h, bottomCap: d, topCap: v, topVerts: f };
613
- };
614
- class zt extends Z {
615
- constructor(e, t = {}) {
616
- super(), this.type = "PolygonBufferGeometry", this.parameters = k({
617
- polygonGeoJson: e,
618
- startHeight: 0,
619
- endHeight: 1,
620
- hasTop: !0,
621
- topFirst: !1,
622
- hasBottom: !0,
623
- hasSide: !0,
624
- curvatureResolution: 1,
625
- cartesian: !0,
626
- userDataRsoOffset: 0
627
- }, t);
628
- const {
629
- endHeight: i,
630
- hasTop: s,
631
- topFirst: a,
632
- hasBottom: l,
633
- hasSide: r,
634
- cartesian: o,
635
- userDataRsoOffset: c,
636
- projection: m
637
- } = this.parameters, { contour: u, sideTorso: h, topVerts: f, bottomCap: p, topCap: d } = ut(k({}, this.parameters));
638
- let v = [], S = [], j = [], B = 0;
639
- const A = (y) => {
640
- const x = Math.round(v.length / 3), C = j.length;
641
- v = v.concat(y.vertices), S = S.concat(y.uvs), j = j.concat(
642
- x ? y.indices.map((I) => I + x) : y.indices
643
- ), this.addGroup(C, j.length - C, B++);
644
- };
645
- s && a && A(d), r && (A(h), this.userData.topVerts = c ? G(
646
- u,
647
- i + c,
648
- o,
649
- m
650
- ).vertices : f), l && A(p), s && !a && A(d), this.setIndex(j), this[me]("position", new R(v, 3)), this[me]("uv", new R(S, 2)), this.computeVertexNormals();
651
- }
652
- }
653
- const ft = `
654
- #include <fog_pars_fragment>
655
- #include <logdepthbuf_pars_fragment>
656
-
657
- uniform float useDash;
658
- uniform float dashArray;
659
- uniform float dashOffset;
660
- uniform float dashRatio;
661
- uniform sampler2D alphaMap;
662
- uniform float useAlphaMap;
663
-
664
- varying vec2 vUV;
665
- varying vec4 vColor;
666
- varying float vCounters;
667
-
668
- uniform sampler2D map;
669
- uniform float useMap;
670
- uniform vec2 repeat;
671
- uniform float offsetLoop;
672
- uniform float alphaTest;
673
-
674
-
675
-
676
- void main() {
677
- #include <logdepthbuf_fragment>
678
-
679
- vec4 c = vColor;
680
-
681
- if( useMap == 1. ) c *= texture2D( map, vUV * repeat );
682
- if( useAlphaMap == 1. ) c.a *= texture2D( alphaMap, vUV * repeat ).r;
683
- if(offsetLoop!=1.0){
684
- if(vUV.x>1.0 || vUV.x<0.0){
685
- c.a = 0.0;
686
- }
687
- }
688
- if (c.a < alphaTest) discard;
689
- if( useDash == 1. ){
690
- c.a *= ceil(mod(vCounters + dashOffset, dashArray) - (dashArray * dashRatio));
691
- }
692
- gl_FragColor = c;
693
- #include <fog_fragment>
694
- #include <tonemapping_fragment>
695
- #include <colorspace_fragment>
696
- }
697
- `, dt = `
698
- #include <common>
699
- #include <logdepthbuf_pars_vertex>
700
- #include <fog_pars_vertex>
701
-
702
- attribute vec3 previous;
703
- attribute vec3 next;
704
- attribute float side;
705
- attribute float width;
706
- attribute float counters;
707
-
708
- uniform vec2 resolution;
709
- uniform float lineWidth;
710
- uniform vec3 color;
711
- uniform float opacity;
712
- uniform float sizeAttenuation;
713
- uniform float scaleDown;
714
- uniform vec2 offset;
715
-
716
- varying vec2 vUV;
717
- varying vec4 vColor;
718
- varying float vCounters;
719
-
720
- vec2 intoScreen(vec4 i) {
721
- return resolution * (0.5 * i.xy / i.w + 0.5);
722
- }
723
-
724
- void main() {
725
- float aspect = resolution.y / resolution.x;
726
-
727
- mat4 m = projectionMatrix * modelViewMatrix;
728
-
729
- vec4 currentClip = m * vec4( position, 1.0 );
730
- vec4 prevClip = m * vec4( previous, 1.0 );
731
- vec4 nextClip = m * vec4( next, 1.0 );
732
-
733
- vec4 currentNormed = currentClip / currentClip.w;
734
- vec4 prevNormed = prevClip / prevClip.w;
735
- vec4 nextNormed = nextClip / nextClip.w;
736
-
737
- vec2 currentScreen = intoScreen(currentNormed);
738
- vec2 prevScreen = intoScreen(prevNormed);
739
- vec2 nextScreen = intoScreen(nextNormed);
740
-
741
- float actualWidth = lineWidth * width;
742
-
743
- vec2 dir;
744
- if(nextScreen == currentScreen) {
745
- dir = normalize( currentScreen - prevScreen );
746
- } else if(prevScreen == currentScreen) {
747
- dir = normalize( nextScreen - currentScreen );
748
- } else {
749
- vec2 inDir = currentScreen - prevScreen;
750
- vec2 outDir = nextScreen - currentScreen;
751
- vec2 fullDir = nextScreen - prevScreen;
752
-
753
- if(length(fullDir) > 0.0) {
754
- dir = normalize(fullDir);
755
- } else if(length(inDir) > 0.0){
756
- dir = normalize(inDir);
757
- } else {
758
- dir = normalize(outDir);
759
- }
760
- }
761
-
762
- vec2 normal = vec2(-dir.y, dir.x);
763
-
764
- if(sizeAttenuation != 0.0) {
765
- normal /= currentClip.w;
766
- normal *= min(resolution.x, resolution.y);
767
- }
768
-
769
- if (scaleDown > 0.0) {
770
- float dist = length(nextNormed - prevNormed);
771
- normal *= smoothstep(0.0, scaleDown, dist);
772
- }
773
-
774
- vec2 offsetInScreen = actualWidth * normal * side * 0.5;
775
-
776
- vec2 withOffsetScreen = currentScreen + offsetInScreen;
777
- vec3 withOffsetNormed = vec3((2.0 * withOffsetScreen/resolution - 1.0), currentNormed.z);
778
-
779
- vCounters = counters;
780
- vColor = vec4( color, opacity );
781
- vUV = uv;
782
- vUV=uv+offset;
783
-
784
- gl_Position = currentClip.w * vec4(withOffsetNormed, 1.0);
785
-
786
- #include <logdepthbuf_vertex>
787
- #include <fog_vertex>
788
- }
789
- `;
790
- class Ot extends ze {
791
- constructor(e = {}) {
792
- const j = e, {
793
- lineWidth: t = 1,
794
- color: i = "#ffffff",
795
- opacity: s = 1,
796
- map: a = null,
797
- dashOffset: l = 0,
798
- dashArray: r = 0,
799
- dashRatio: o = 0,
800
- sizeAttenuation: c = !0,
801
- offsetLoop: m = !0,
802
- offset: u = new q(0, 0),
803
- scaleDown: h = 0,
804
- alphaMap: f = void 0,
805
- alphaTest: p = 0,
806
- repeat: d = new q(1, 1),
807
- resolution: v = new q(1, 1)
808
- } = j, S = ne(j, [
809
- "lineWidth",
810
- "color",
811
- "opacity",
812
- "map",
813
- "dashOffset",
814
- "dashArray",
815
- "dashRatio",
816
- "sizeAttenuation",
817
- "offsetLoop",
818
- "offset",
819
- "scaleDown",
820
- "alphaMap",
821
- "alphaTest",
822
- "repeat",
823
- "resolution"
824
- ]);
825
- super($(k({}, S), {
826
- uniforms: {
827
- lineWidth: { value: t },
828
- color: { value: new le(i) },
829
- opacity: { value: s },
830
- map: { value: a },
831
- useMap: { value: a ? 1 : 0 },
832
- resolution: { value: v },
833
- sizeAttenuation: { value: c ? 1 : 0 },
834
- offset: { value: u },
835
- offsetLoop: { value: m ? 1 : 0 },
836
- dashArray: { value: r },
837
- dashOffset: { value: l },
838
- dashRatio: { value: o },
839
- useDash: { value: r > 0 ? 1 : 0 },
840
- scaleDown: { value: h / 10 },
841
- alphaTest: { value: p },
842
- alphaMap: { value: f },
843
- useAlphaMap: { value: f ? 1 : 0 },
844
- repeat: { value: d }
845
- },
846
- vertexShader: dt,
847
- fragmentShader: ft
848
- })), this.type = "MeshLineMaterial";
849
- }
850
- // Getter and setter for color
851
- get color() {
852
- return this.uniforms.color.value;
853
- }
854
- set color(e) {
855
- this.uniforms.color.value = new le(e);
856
- }
857
- get opacity() {
858
- var e;
859
- return ((e = this.uniforms) == null ? void 0 : e.opacity.value) || 1;
860
- }
861
- set opacity(e) {
862
- this.uniforms && (this.uniforms.opacity.value = e);
863
- }
864
- get alphaTest() {
865
- return this.uniforms.alphaTest.value;
866
- }
867
- set alphaTest(e) {
868
- this.uniforms && (this.uniforms.alphaTest.value = e);
869
- }
870
- // Getter and setter for map
871
- get map() {
872
- return this.uniforms.map.value;
873
- }
874
- set map(e) {
875
- this.uniforms.map.value = e, this.uniforms.useMap.value = e ? 1 : 0;
876
- }
877
- get repeat() {
878
- return this.uniforms.repeat.value;
879
- }
880
- set repeat(e) {
881
- this.uniforms.repeat.value.copy(e);
882
- }
883
- // Getter and setter for lineWidth
884
- get lineWidth() {
885
- return this.uniforms.lineWidth.value;
886
- }
887
- set lineWidth(e) {
888
- this.uniforms.lineWidth.value = e;
889
- }
890
- // Getter and setter for sizeAttenuation
891
- get sizeAttenuation() {
892
- return this.uniforms.sizeAttenuation.value === 1;
893
- }
894
- set sizeAttenuation(e) {
895
- this.uniforms.sizeAttenuation.value = e ? 1 : 0;
896
- }
897
- }
898
- const K = new E(), ye = new w(), be = new w(), b = new E(), g = new E(), D = new E(), Q = new w(), X = new Oe(), M = new _e(), ge = new w(), U = new Se(), W = new ke(), T = new E();
899
- let z, _;
900
- function Me(n, e, t) {
901
- return T.set(0, 0, -e, 1).applyMatrix4(n.projectionMatrix), T.multiplyScalar(1 / T.w), T.x = _ / t.width, T.y = _ / t.height, T.applyMatrix4(n.projectionMatrixInverse), T.multiplyScalar(1 / T.w), Math.abs(Math.max(T.x, T.y));
902
- }
903
- function ht(n, e) {
904
- const t = n.matrixWorld, i = n.geometry, s = i.attributes.instanceStart, a = i.attributes.instanceEnd, l = Math.min(i.instanceCount, s.count);
905
- for (let r = 0, o = l; r < o; r++) {
906
- M.start.fromBufferAttribute(s, r), M.end.fromBufferAttribute(a, r), M.applyMatrix4(t);
907
- const c = new w(), m = new w();
908
- z.distanceSqToSegment(M.start, M.end, m, c), m.distanceTo(c) < _ * 0.5 && e.push({
909
- point: m,
910
- pointOnLine: c,
911
- distance: z.origin.distanceTo(m),
912
- object: n,
913
- face: null,
914
- faceIndex: r,
915
- uv: null,
916
- uv1: null
917
- });
918
- }
919
- }
920
- function pt(n, e, t) {
921
- const i = e.projectionMatrix, a = n.material.resolution, l = n.matrixWorld, r = n.geometry, o = r.attributes.instanceStart, c = r.attributes.instanceEnd, m = Math.min(r.instanceCount, o.count), u = -e.near;
922
- z.at(1, D), D.w = 1, D.applyMatrix4(e.matrixWorldInverse), D.applyMatrix4(i), D.multiplyScalar(1 / D.w), D.x *= a.x / 2, D.y *= a.y / 2, D.z = 0, Q.copy(D), X.multiplyMatrices(e.matrixWorldInverse, l);
923
- for (let h = 0, f = m; h < f; h++) {
924
- if (b.fromBufferAttribute(o, h), g.fromBufferAttribute(c, h), b.w = 1, g.w = 1, b.applyMatrix4(X), g.applyMatrix4(X), b.z > u && g.z > u)
925
- continue;
926
- if (b.z > u) {
927
- const B = b.z - g.z, A = (b.z - u) / B;
928
- b.lerp(g, A);
929
- } else if (g.z > u) {
930
- const B = g.z - b.z, A = (g.z - u) / B;
931
- g.lerp(b, A);
932
- }
933
- b.applyMatrix4(i), g.applyMatrix4(i), b.multiplyScalar(1 / b.w), g.multiplyScalar(1 / g.w), b.x *= a.x / 2, b.y *= a.y / 2, g.x *= a.x / 2, g.y *= a.y / 2, M.start.copy(b), M.start.z = 0, M.end.copy(g), M.end.z = 0;
934
- const d = M.closestPointToPointParameter(Q, !0);
935
- M.at(d, ge);
936
- const v = Le.lerp(b.z, g.z, d), S = v >= -1 && v <= 1, j = Q.distanceTo(ge) < _ * 0.5;
937
- if (S && j) {
938
- M.start.fromBufferAttribute(o, h), M.end.fromBufferAttribute(c, h), M.start.applyMatrix4(l), M.end.applyMatrix4(l);
939
- const B = new w(), A = new w();
940
- z.distanceSqToSegment(M.start, M.end, A, B), t.push({
941
- point: A,
942
- pointOnLine: B,
943
- distance: z.origin.distanceTo(A),
944
- object: n,
945
- face: null,
946
- faceIndex: h,
947
- uv: null,
948
- uv1: null
949
- });
950
- }
951
- }
952
- }
953
- class _t extends we {
954
- constructor(e = new Ze(), t) {
955
- super(e, t), this.isLineSegments2 = !0, this.type = "LineSegments2";
956
- }
957
- // for backwards-compatibility, but could be a method of LineSegmentsGeometry...
958
- computeLineDistances() {
959
- const e = this.geometry, t = e.attributes.instanceStart, i = e.attributes.instanceEnd, s = new Float32Array(2 * t.count);
960
- for (let l = 0, r = 0, o = t.count; l < o; l++, r += 2)
961
- ye.fromBufferAttribute(t, l), be.fromBufferAttribute(i, l), s[r] = r === 0 ? 0 : s[r - 1], s[r + 1] = s[r] + ye.distanceTo(be);
962
- const a = new Ee(
963
- s,
964
- 2,
965
- 1
966
- );
967
- return e.setAttribute(
968
- "instanceDistanceStart",
969
- new ue(a, 1, 0)
970
- ), e.setAttribute(
971
- "instanceDistanceEnd",
972
- new ue(a, 1, 1)
973
- ), this;
974
- }
975
- raycast(e, t) {
976
- const i = this.material.worldUnits, s = e.camera;
977
- s === null && !i && console.error(
978
- 'LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.'
979
- );
980
- const a = e.params.Line2 !== void 0 && e.params.Line2.threshold || 0;
981
- z = e.ray;
982
- const l = this.matrixWorld, r = this.geometry, o = this.material;
983
- _ = o.linewidth + a, r.boundingSphere === null && r.computeBoundingSphere(), W.copy(r.boundingSphere).applyMatrix4(l);
984
- let c;
985
- if (i)
986
- c = _ * 0.5;
987
- else {
988
- const u = Math.max(
989
- s.near,
990
- W.distanceToPoint(z.origin)
991
- );
992
- c = Me(
993
- s,
994
- u,
995
- o.resolution
996
- );
997
- }
998
- if (W.radius += c, z.intersectsSphere(W) === !1)
999
- return;
1000
- r.boundingBox === null && r.computeBoundingBox(), U.copy(r.boundingBox).applyMatrix4(l);
1001
- let m;
1002
- if (i)
1003
- m = _ * 0.5;
1004
- else {
1005
- const u = Math.max(
1006
- s.near,
1007
- U.distanceToPoint(z.origin)
1008
- );
1009
- m = Me(
1010
- s,
1011
- u,
1012
- o.resolution
1013
- );
1014
- }
1015
- U.expandByScalar(m), z.intersectsBox(U) !== !1 && (i ? ht(this, t) : pt(this, s, t));
1016
- }
1017
- onBeforeRender(e) {
1018
- const t = this.material.uniforms;
1019
- t && t.resolution && (e.getViewport(K), this.material.uniforms.resolution.value.set(K.z, K.w));
1020
- }
1021
- }
1022
- export {
1023
- Dt as B,
1024
- Tt as I,
1025
- _t as L,
1026
- Ot as M,
1027
- zt as P,
1028
- et as R,
1029
- pe as a,
1030
- ut as g
1031
- };