build-dxf 0.0.32 → 0.0.33
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.
- package/package.json +1 -1
- package/src/build.js +1290 -1180
- package/src/index.css +1 -1
- package/src/index3.js +697 -660
- package/src/utils/DxfSystem/components/Dxf.d.ts +13 -2
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/CommandFlowComponent.d.ts +1 -1
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/MergeLine.d.ts +3 -1
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/VerticalCorrection.d.ts +6 -3
- package/src/utils/PointVirtualGrid/index.d.ts +7 -2
- package/src/utils/Quadtree/Point.d.ts +6 -0
- package/src/utils/Quadtree/Quadtree.d.ts +6 -0
package/src/build.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { EventDispatcher as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { OBJExporter as
|
|
6
|
-
function
|
|
1
|
+
import * as U from "three";
|
|
2
|
+
import { EventDispatcher as Pe, Color as ve, Matrix4 as Ae, Vector3 as ee, Quaternion as Ne, BufferAttribute as H, REVISION as Ce, CompressedTexture as ie, Source as Be, NoColorSpace as Oe, MathUtils as ce, RGBAFormat as Fe, ImageUtils as Ue, DoubleSide as Ge, PropertyBinding as te, InterpolateDiscrete as _e, Scene as fe, SRGBColorSpace as ze, NearestFilter as qe, NearestMipmapNearestFilter as je, NearestMipmapLinearFilter as Ye, LinearFilter as Xe, LinearMipmapNearestFilter as ke, LinearMipmapLinearFilter as Ve, ClampToEdgeWrapping as We, RepeatWrapping as He, MirroredRepeatWrapping as Je, InterpolateLinear as Ke } from "three";
|
|
3
|
+
import pe from "clipper-lib";
|
|
4
|
+
import Q from "dxf-writer";
|
|
5
|
+
import { OBJExporter as $e } from "three/examples/jsm/exporters/OBJExporter.js";
|
|
6
|
+
function le() {
|
|
7
7
|
return "xxxx-xxxx-4xxx-yxxx-xxxx".replace(/[xy]/g, function(d) {
|
|
8
8
|
var e = Math.random() * 16 | 0, t = d == "x" ? e : e & 3 | 8;
|
|
9
9
|
return t.toString(16);
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
class
|
|
13
|
-
uuid =
|
|
12
|
+
class Ee extends Pe {
|
|
13
|
+
uuid = le();
|
|
14
14
|
addEventListener(e, t, n) {
|
|
15
15
|
const { once: s = !1 } = n ?? {}, i = (o) => {
|
|
16
16
|
t(o), s && r();
|
|
@@ -30,7 +30,7 @@ class Le extends Ie {
|
|
|
30
30
|
t && (t.forEach((n) => n()), this.eventRecordStack.delete(e));
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
class
|
|
33
|
+
class J extends Ee {
|
|
34
34
|
parent;
|
|
35
35
|
destroyed = !1;
|
|
36
36
|
constructor(...e) {
|
|
@@ -48,7 +48,7 @@ class W extends Le {
|
|
|
48
48
|
this.destroyed = !0;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
class
|
|
51
|
+
class Ze extends Ee {
|
|
52
52
|
static EventType = {
|
|
53
53
|
ADD_COMPONENT: "addComponent"
|
|
54
54
|
};
|
|
@@ -71,7 +71,7 @@ class Ke extends Le {
|
|
|
71
71
|
* @param component
|
|
72
72
|
*/
|
|
73
73
|
removeComponent(e) {
|
|
74
|
-
if (e instanceof
|
|
74
|
+
if (e instanceof J) {
|
|
75
75
|
const t = this.components.indexOf(e);
|
|
76
76
|
t > -1 && (this.components.splice(t, 1), this.dispatchEvent({
|
|
77
77
|
type: "removeComponent",
|
|
@@ -116,214 +116,6 @@ class Ke extends Le {
|
|
|
116
116
|
return t || null;
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
class w {
|
|
120
|
-
x;
|
|
121
|
-
y;
|
|
122
|
-
get X() {
|
|
123
|
-
return this.x;
|
|
124
|
-
}
|
|
125
|
-
get Y() {
|
|
126
|
-
return this.y;
|
|
127
|
-
}
|
|
128
|
-
userData = {};
|
|
129
|
-
/**
|
|
130
|
-
*
|
|
131
|
-
* @param x
|
|
132
|
-
* @param y
|
|
133
|
-
*/
|
|
134
|
-
constructor(e = 0, t = 0) {
|
|
135
|
-
this.x = e, this.y = t;
|
|
136
|
-
}
|
|
137
|
-
set(e, t) {
|
|
138
|
-
return this.x = e, this.y = t, this;
|
|
139
|
-
}
|
|
140
|
-
setX(e) {
|
|
141
|
-
return this.x = e, this;
|
|
142
|
-
}
|
|
143
|
-
setY(e) {
|
|
144
|
-
return this.y = e, this;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
*
|
|
148
|
-
* @param point
|
|
149
|
-
* @returns
|
|
150
|
-
*/
|
|
151
|
-
equal(e) {
|
|
152
|
-
return Math.abs(e.x - this.x) < 1e-9 && Math.abs(e.y - this.y) < 1e-9;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
*
|
|
156
|
-
* @param arr
|
|
157
|
-
*/
|
|
158
|
-
setByArray(e) {
|
|
159
|
-
return this.x = e[0], this.y = e[1], this;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
*
|
|
163
|
-
*/
|
|
164
|
-
toArray() {
|
|
165
|
-
return [this.x, this.y];
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* multiplyScalar
|
|
169
|
-
* @param scalar
|
|
170
|
-
*/
|
|
171
|
-
mutiplyScalar(e) {
|
|
172
|
-
return this.x *= e, this.y *= e, this;
|
|
173
|
-
}
|
|
174
|
-
multiplyScalar(e) {
|
|
175
|
-
return this.x *= e, this.y *= e, this;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
*
|
|
179
|
-
* @param scalar
|
|
180
|
-
* @returns
|
|
181
|
-
*/
|
|
182
|
-
divisionScalar(e) {
|
|
183
|
-
return this.x /= e, this.y /= e, this;
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* 减法
|
|
187
|
-
* @description 将当前点的坐标减去指定点的坐标
|
|
188
|
-
* @param point
|
|
189
|
-
* @returns
|
|
190
|
-
*/
|
|
191
|
-
division(e) {
|
|
192
|
-
return this.x -= e.x, this.y -= e.y, this;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* 加法
|
|
196
|
-
* @description 将当前点的坐标加上指定点的坐标
|
|
197
|
-
* @param point
|
|
198
|
-
* @returns
|
|
199
|
-
*/
|
|
200
|
-
add(e) {
|
|
201
|
-
return this.x += e.x, this.y += e.y, this;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* 绕point旋转angle
|
|
205
|
-
* @param point
|
|
206
|
-
* @param angle 旋转角度,单位为弧度
|
|
207
|
-
*/
|
|
208
|
-
rotate(e, t) {
|
|
209
|
-
const n = this.x - e.x, s = this.y - e.y, i = Math.cos(t), r = Math.sin(t), o = n * i - s * r, a = n * r + s * i;
|
|
210
|
-
return this.x = o + e.x, this.y = a + e.y, this;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* 保留小数位数
|
|
214
|
-
* @param count
|
|
215
|
-
*/
|
|
216
|
-
fixed(e) {
|
|
217
|
-
return this.x = Number(this.x.toFixed(e)), this.y = Number(this.y.toFixed(e)), this;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* 归一化
|
|
221
|
-
* @description 将当前点的坐标归一化为单位向量
|
|
222
|
-
* @returns
|
|
223
|
-
*/
|
|
224
|
-
normalize() {
|
|
225
|
-
const e = Math.sqrt(this.x * this.x + this.y * this.y);
|
|
226
|
-
return e === 0 ? this : (this.x /= e, this.y /= e, this);
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* 获取单位法向量
|
|
230
|
-
* @description 计算当前点到指定点的方向向量,并返回逆时针旋转90度后的单位法向量
|
|
231
|
-
* @param point
|
|
232
|
-
* @returns
|
|
233
|
-
*/
|
|
234
|
-
normal(e) {
|
|
235
|
-
const t = this.x - e.x, n = this.y - e.y, s = Math.sqrt(t * t + n * n), i = -n / s, r = t / s;
|
|
236
|
-
return new w(i, r);
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* 获取由传入的点到该点的单位方向向量
|
|
240
|
-
* @description 计算当前点到指定点的方向向量,并返回单位方向
|
|
241
|
-
* @param point
|
|
242
|
-
* @returns
|
|
243
|
-
*/
|
|
244
|
-
direction(e) {
|
|
245
|
-
const t = this.x - e.x, n = this.y - e.y, s = Math.sqrt(t * t + n * n);
|
|
246
|
-
return s === 0 ? new w(0, 0) : new w(t / s, n / s);
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* 计算模长
|
|
250
|
-
* @returns
|
|
251
|
-
*/
|
|
252
|
-
magnitude() {
|
|
253
|
-
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* 计算点点积
|
|
257
|
-
* @param point
|
|
258
|
-
* @returns
|
|
259
|
-
*/
|
|
260
|
-
dot(e) {
|
|
261
|
-
return this.x * e.x + this.y * e.y;
|
|
262
|
-
}
|
|
263
|
-
/** 求两个点叉积
|
|
264
|
-
* @description 如果叉积大于 0,a 到 b 为逆时针方向。
|
|
265
|
-
* @description 如果叉积小于 0,a 到 b 为顺时针方向。
|
|
266
|
-
* @param point
|
|
267
|
-
* @returns
|
|
268
|
-
*/
|
|
269
|
-
cross(e) {
|
|
270
|
-
return this.x * e.y - this.y * this.x;
|
|
271
|
-
}
|
|
272
|
-
/** 计算两个向量夹角
|
|
273
|
-
* @description 公式:a · b = |a| × |b| × cosθ
|
|
274
|
-
* @description 结果为0(0度),两个向量方向一致,结果为3.1415926(180度, PI),两个向量方向相反
|
|
275
|
-
* @param point
|
|
276
|
-
* @returns
|
|
277
|
-
*/
|
|
278
|
-
angleBetween(e, t = "radian", n = "180") {
|
|
279
|
-
const s = this.dot(e), i = this.magnitude(), r = e.magnitude();
|
|
280
|
-
if (i === 0 || r === 0) return 0;
|
|
281
|
-
const o = s / (i * r), a = Math.max(-1, Math.min(1, o));
|
|
282
|
-
return t === "radian" ? Math.acos(a) : t === "cos" ? a : n === "180" || this.cross(e) < 0 ? Math.acos(a) / (Math.PI / 180) : 360 - Math.acos(a) / (Math.PI / 180);
|
|
283
|
-
}
|
|
284
|
-
/** 获取向量长度
|
|
285
|
-
*/
|
|
286
|
-
length() {
|
|
287
|
-
const e = Math.sqrt(this.x * this.x + this.y * this.y);
|
|
288
|
-
return Math.abs(e - Math.round(e)) < 1e-9 ? Math.round(e) : e;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* 获取两个点长度
|
|
292
|
-
* @param point
|
|
293
|
-
*/
|
|
294
|
-
distance(e) {
|
|
295
|
-
return Math.sqrt(
|
|
296
|
-
(this.x - e.x) * (this.x - e.x) + (this.y - e.y) * (this.y - e.y)
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* 克隆
|
|
301
|
-
* @returns
|
|
302
|
-
*/
|
|
303
|
-
clone() {
|
|
304
|
-
return new w(this.x, this.y);
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* 克隆
|
|
308
|
-
* @returns
|
|
309
|
-
*/
|
|
310
|
-
copy(e) {
|
|
311
|
-
return this.x = e.x ?? 0, this.y = e.y ?? 0, this;
|
|
312
|
-
}
|
|
313
|
-
toJson(e = 0) {
|
|
314
|
-
return {
|
|
315
|
-
x: this.x,
|
|
316
|
-
y: this.y,
|
|
317
|
-
z: e
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
static from(e) {
|
|
321
|
-
return Array.isArray(e) ? new w(e[0], e[1]) : "x" in e && "y" in e ? new w(e.x, e.y) : "X" in e && "Y" in e ? new w(e.X, e.Y) : this.zero();
|
|
322
|
-
}
|
|
323
|
-
static zero() {
|
|
324
|
-
return new w(0, 0);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
119
|
class _ {
|
|
328
120
|
minX = 0;
|
|
329
121
|
maxX = 0;
|
|
@@ -411,8 +203,8 @@ class _ {
|
|
|
411
203
|
for (let l = 0; l < 4; l++) {
|
|
412
204
|
const c = o[l], h = o[(l + 1) % 4];
|
|
413
205
|
for (let f = 0; f < 4; f++) {
|
|
414
|
-
const u = t[f], p = t[(f + 1) % 4], y = (h.x - c.x) * (u.y - c.y) - (h.y - c.y) * (u.x - c.x), x = (h.x - c.x) * (p.y - c.y) - (h.y - c.y) * (p.x - c.x), S = (p.x - u.x) * (c.y - u.y) - (p.y - u.y) * (c.x - u.x),
|
|
415
|
-
if (y * x < 0 && S *
|
|
206
|
+
const u = t[f], p = t[(f + 1) % 4], y = (h.x - c.x) * (u.y - c.y) - (h.y - c.y) * (u.x - c.x), x = (h.x - c.x) * (p.y - c.y) - (h.y - c.y) * (p.x - c.x), S = (p.x - u.x) * (c.y - u.y) - (p.y - u.y) * (c.x - u.x), R = (p.x - u.x) * (h.y - u.y) - (p.y - u.y) * (h.x - u.x);
|
|
207
|
+
if (y * x < 0 && S * R < 0 || y === 0 && Math.min(c.x, h.x) <= u.x && u.x <= Math.max(c.x, h.x) && Math.min(c.y, h.y) <= u.y && u.y <= Math.max(c.y, h.y) || x === 0 && Math.min(c.x, h.x) <= p.x && p.x <= Math.max(c.x, h.x) && Math.min(c.y, h.y) <= p.y && p.y <= Math.max(c.y, h.y) || S === 0 && Math.min(u.x, p.x) <= c.x && c.x <= Math.max(u.x, p.x) && Math.min(u.y, p.y) <= c.y && c.y <= Math.max(u.y, p.y) || R === 0 && Math.min(u.x, p.x) <= h.x && h.x <= Math.max(u.x, p.x) && Math.min(u.y, p.y) <= h.y && h.y <= Math.max(u.y, p.y))
|
|
416
208
|
return !0;
|
|
417
209
|
}
|
|
418
210
|
}
|
|
@@ -544,146 +336,25 @@ class _ {
|
|
|
544
336
|
);
|
|
545
337
|
}
|
|
546
338
|
}
|
|
547
|
-
class
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
this.gridSize = e;
|
|
339
|
+
class se {
|
|
340
|
+
points;
|
|
341
|
+
get p0() {
|
|
342
|
+
return this.points[0];
|
|
552
343
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
* @param point
|
|
556
|
-
* @param userData
|
|
557
|
-
*/
|
|
558
|
-
insert(e, t) {
|
|
559
|
-
if (!e || isNaN(e.x) || isNaN(e.y))
|
|
560
|
-
throw new Error("无效的点坐标");
|
|
561
|
-
const n = this.getGridId(e);
|
|
562
|
-
this.map.has(n) || this.map.set(n, /* @__PURE__ */ new Set());
|
|
563
|
-
const s = this.map.get(n), i = { point: e, userData: t };
|
|
564
|
-
s.add(i), e.userData.pointVirtualGrid = { set: s, target: i };
|
|
344
|
+
get p1() {
|
|
345
|
+
return this.points[1];
|
|
565
346
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
* @param points
|
|
569
|
-
*/
|
|
570
|
-
insertBatch(e) {
|
|
571
|
-
for (const { point: t, userData: n } of e)
|
|
572
|
-
this.insert(t, n);
|
|
347
|
+
get p2() {
|
|
348
|
+
return this.points[2];
|
|
573
349
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
*/
|
|
577
|
-
remove(e) {
|
|
578
|
-
const { set: t, target: n } = e?.userData?.pointVirtualGrid ?? {};
|
|
579
|
-
t && (t.delete(n), delete e?.userData?.pointVirtualGridMap);
|
|
350
|
+
get p3() {
|
|
351
|
+
return this.points[3];
|
|
580
352
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
getGridId(e) {
|
|
587
|
-
const t = Math.ceil(e.x / this.gridSize), n = Math.ceil(e.y / this.gridSize);
|
|
588
|
-
return `${t}.${n}`;
|
|
589
|
-
}
|
|
590
|
-
/**
|
|
591
|
-
*
|
|
592
|
-
* @param gridId
|
|
593
|
-
* @returns
|
|
594
|
-
*/
|
|
595
|
-
decodeGridId(e) {
|
|
596
|
-
const [t, n] = e.split(".").map(Number);
|
|
597
|
-
return new w(t, n);
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* 查询与矩形相交的点
|
|
601
|
-
* @param rectangle 矩形
|
|
602
|
-
* @returns 相交的节点数组
|
|
603
|
-
*/
|
|
604
|
-
queryRect(e) {
|
|
605
|
-
const t = e.toBox(), n = Math.ceil(t.minX / this.gridSize), s = Math.ceil(t.maxX / this.gridSize), i = Math.ceil(t.minY / this.gridSize), r = Math.ceil(t.maxY / this.gridSize);
|
|
606
|
-
for (let o = n; o <= s; o++)
|
|
607
|
-
for (let a = i; a <= r; a++) {
|
|
608
|
-
const l = `${o}.${a}`;
|
|
609
|
-
if (!this.map.has(l)) continue;
|
|
610
|
-
this.map.get(l)?.forEach((h) => {
|
|
611
|
-
e.containsPoint(h.point);
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* 查询与圆形区域相交的点
|
|
617
|
-
* @param pos 圆心
|
|
618
|
-
* @param radius 半径
|
|
619
|
-
* @returns 相交的节点数组
|
|
620
|
-
*/
|
|
621
|
-
queryCircle(e, t) {
|
|
622
|
-
const n = new _(e.x - t, e.x + t, e.y - t, e.y + t), s = Math.ceil(n.minX / this.gridSize), i = Math.ceil(n.maxX / this.gridSize), r = Math.ceil(n.minY / this.gridSize), o = Math.ceil(n.maxY / this.gridSize), a = [];
|
|
623
|
-
for (let l = s; l <= i; l++)
|
|
624
|
-
for (let c = r; c <= o; c++) {
|
|
625
|
-
const h = `${l}.${c}`;
|
|
626
|
-
if (!this.map.has(h)) continue;
|
|
627
|
-
this.map.get(h)?.forEach((u) => {
|
|
628
|
-
e.distance(u.point) <= t && a.push(u);
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
return a;
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* 查询与包围盒相交的点
|
|
635
|
-
* @param box2 包围盒
|
|
636
|
-
* @returns 相交的节点数组
|
|
637
|
-
*/
|
|
638
|
-
queryBox(e) {
|
|
639
|
-
const t = Math.ceil(e.minX / this.gridSize), n = Math.ceil(e.maxX / this.gridSize), s = Math.ceil(e.minY / this.gridSize), i = Math.ceil(e.maxY / this.gridSize), r = [];
|
|
640
|
-
for (let o = t; o <= n; o++)
|
|
641
|
-
for (let a = s; a <= i; a++) {
|
|
642
|
-
const l = `${o}.${a}`;
|
|
643
|
-
if (!this.map.has(l)) continue;
|
|
644
|
-
this.map.get(l)?.forEach((h) => {
|
|
645
|
-
e.containsPoint(h.point) && r.push(h);
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
return r;
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* 查找相同点
|
|
652
|
-
* @param point
|
|
653
|
-
*/
|
|
654
|
-
queryPoint(e) {
|
|
655
|
-
const t = this.getGridId(e), n = [];
|
|
656
|
-
return this.map.has(t) && this.map.get(t)?.forEach((i) => {
|
|
657
|
-
e.equal(i.point) && n.push(i);
|
|
658
|
-
}), n;
|
|
659
|
-
}
|
|
660
|
-
/**
|
|
661
|
-
* 查找点自己
|
|
662
|
-
* @param point
|
|
663
|
-
*/
|
|
664
|
-
queryPointSelf(e) {
|
|
665
|
-
return e.userData.pointVirtualGrid && e.userData.pointVirtualGrid.target ? e.userData.pointVirtualGrid.target : null;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
class te {
|
|
669
|
-
points;
|
|
670
|
-
get p0() {
|
|
671
|
-
return this.points[0];
|
|
672
|
-
}
|
|
673
|
-
get p1() {
|
|
674
|
-
return this.points[1];
|
|
675
|
-
}
|
|
676
|
-
get p2() {
|
|
677
|
-
return this.points[2];
|
|
678
|
-
}
|
|
679
|
-
get p3() {
|
|
680
|
-
return this.points[3];
|
|
681
|
-
}
|
|
682
|
-
get path() {
|
|
683
|
-
return this.points.flatMap((e, t) => {
|
|
684
|
-
const n = this.points[(t + 1) % this.points.length];
|
|
685
|
-
return [e.x, e.y, 0, n.x, n.y, 0];
|
|
686
|
-
});
|
|
353
|
+
get path() {
|
|
354
|
+
return this.points.flatMap((e, t) => {
|
|
355
|
+
const n = this.points[(t + 1) % this.points.length];
|
|
356
|
+
return [e.x, e.y, 0, n.x, n.y, 0];
|
|
357
|
+
});
|
|
687
358
|
}
|
|
688
359
|
path2D(e) {
|
|
689
360
|
return this.points.flatMap((t, n) => {
|
|
@@ -799,32 +470,554 @@ class te {
|
|
|
799
470
|
return t === 4 || n === 4;
|
|
800
471
|
}
|
|
801
472
|
/**
|
|
802
|
-
*
|
|
473
|
+
*
|
|
474
|
+
* @returns
|
|
475
|
+
*/
|
|
476
|
+
toBox() {
|
|
477
|
+
let e = 1 / 0, t = -1 / 0, n = 1 / 0, s = -1 / 0;
|
|
478
|
+
return this.points.forEach((i) => {
|
|
479
|
+
t = Math.max(i.x, t), e = Math.min(i.x, e), s = Math.max(i.x, s), n = Math.min(i.x, n);
|
|
480
|
+
}), new _(e, t, n, s);
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
*
|
|
484
|
+
* @param line
|
|
485
|
+
* @param width
|
|
486
|
+
* @returns
|
|
487
|
+
*/
|
|
488
|
+
static fromByLineSegment(e, t = 0.1, n = !1, s = 0.5) {
|
|
489
|
+
const i = e.points[0], r = e.points[1], o = r.normal(i), a = n ? r.direction(i).mutiplyScalar(t * s) : w.zero(), l = n ? i.direction(r).mutiplyScalar(t * s) : w.zero(), c = o.x * t * 0.5, h = o.y * t * 0.5;
|
|
490
|
+
return new se([
|
|
491
|
+
new w(i.x + c, i.y + h).add(l),
|
|
492
|
+
new w(r.x + c, r.y + h).add(a),
|
|
493
|
+
new w(r.x - c, r.y - h).add(a),
|
|
494
|
+
new w(i.x - c, i.y - h).add(l)
|
|
495
|
+
]);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
class B {
|
|
499
|
+
points = [new w(), new w()];
|
|
500
|
+
userData = {};
|
|
501
|
+
// line: any
|
|
502
|
+
get center() {
|
|
503
|
+
return new w(
|
|
504
|
+
this.points[0].x + (this.points[1].x - this.points[0].x) * 0.5,
|
|
505
|
+
this.points[0].y + (this.points[1].y - this.points[0].y) * 0.5
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
get start() {
|
|
509
|
+
return this.points[0];
|
|
510
|
+
}
|
|
511
|
+
get end() {
|
|
512
|
+
return this.points[1];
|
|
513
|
+
}
|
|
514
|
+
constructor(e = new w(), t = new w()) {
|
|
515
|
+
this.points = [e, t];
|
|
516
|
+
}
|
|
517
|
+
set(e, t) {
|
|
518
|
+
return this.start.copy(e), this.end.copy(t), this;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* 是否有相同端点
|
|
522
|
+
* @param line
|
|
523
|
+
* @returns
|
|
524
|
+
*/
|
|
525
|
+
sameEndpoint(e) {
|
|
526
|
+
return this.start.equal(e.start) || this.start.equal(e.end) || this.end.equal(e.start) || this.end.equal(e.end);
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* 相同端点是否为开始
|
|
530
|
+
* @param line
|
|
531
|
+
* @returns
|
|
532
|
+
*/
|
|
533
|
+
sameEndpointAsStart(e) {
|
|
534
|
+
return this.start.equal(e.start) || this.start.equal(e.end);
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* 获取共线点
|
|
538
|
+
* @param line
|
|
539
|
+
* @returns
|
|
540
|
+
*/
|
|
541
|
+
getSameEndpoint(e) {
|
|
542
|
+
return this.start.equal(e.start) ? [this.start, e.start] : this.start.equal(e.end) ? [this.start, e.end] : this.end.equal(e.start) ? [this.end, e.start] : this.end.equal(e.end) ? [this.end, e.end] : null;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* 判断一个点是否在当前线段上(包含端点)
|
|
546
|
+
* @param point 要判断的点
|
|
547
|
+
* @returns 如果点在当前线段上则返回 true,否则返回 false
|
|
548
|
+
*/
|
|
549
|
+
isPointOnSegment(e) {
|
|
550
|
+
const { start: t, end: n } = this, s = (e.y - t.y) * (n.x - t.x) - (e.x - t.x) * (n.y - t.y);
|
|
551
|
+
return Math.abs(s) > 1e-10 ? !1 : (e.x - t.x) * (e.x - n.x) + (e.y - t.y) * (e.y - n.y) <= 1e-10;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* 相同端点是否为结束
|
|
555
|
+
* @param line
|
|
556
|
+
* @returns
|
|
557
|
+
*/
|
|
558
|
+
sameEndpointAsEnd(e) {
|
|
559
|
+
return this.end.equal(e.start) || this.end.equal(e.end);
|
|
560
|
+
}
|
|
561
|
+
/** 膨胀
|
|
562
|
+
* @description 向线段的两个端点分别膨胀 width
|
|
563
|
+
* @param width
|
|
564
|
+
*/
|
|
565
|
+
expansion(e, t = "all") {
|
|
566
|
+
const n = this.direction().multiplyScalar(e);
|
|
567
|
+
return (t === "end" || t === "all") && this.end.add(n), (t === "start" || t === "all") && this.start.add(n.multiplyScalar(-1)), this;
|
|
568
|
+
}
|
|
569
|
+
/** 向前
|
|
570
|
+
* @description 向前移动 width
|
|
571
|
+
* @param width
|
|
572
|
+
*/
|
|
573
|
+
forward(e) {
|
|
574
|
+
const t = this.direction().multiplyScalar(e);
|
|
575
|
+
return this.start.add(t), this.end.add(t), this;
|
|
576
|
+
}
|
|
577
|
+
/** 向前
|
|
578
|
+
* @description 向前移动 width
|
|
579
|
+
* @param width
|
|
580
|
+
*/
|
|
581
|
+
backward(e) {
|
|
582
|
+
const t = this.direction().multiplyScalar(-e);
|
|
583
|
+
return this.start.add(t), this.end.add(t), this;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* 向指定方向平移
|
|
587
|
+
* @param direct
|
|
588
|
+
* @param size
|
|
589
|
+
*/
|
|
590
|
+
directionMove(e, t) {
|
|
591
|
+
const n = e.clone().multiplyScalar(t);
|
|
592
|
+
return this.start.add(n), this.end.add(n), this;
|
|
593
|
+
}
|
|
594
|
+
/** 膨胀为矩形
|
|
595
|
+
*
|
|
596
|
+
* @param width
|
|
597
|
+
* @returns {Rectangle}
|
|
598
|
+
*/
|
|
599
|
+
expandToRectangle(e = 0.1, t = "all") {
|
|
600
|
+
const n = this.start, s = this.end, i = s.normal(n), r = t === "bothSides" ? w.zero() : s.direction(n).mutiplyScalar(e * 0.5), o = t === "bothSides" ? w.zero() : n.direction(s).mutiplyScalar(e * 0.5), a = i.x * e * 0.5, l = i.y * e * 0.5, c = [
|
|
601
|
+
// 第一条线
|
|
602
|
+
new w(n.x + a, n.y + l).add(o),
|
|
603
|
+
new w(s.x + a, s.y + l).add(r),
|
|
604
|
+
// 第二条线
|
|
605
|
+
new w(n.x - a, n.y - l).add(o),
|
|
606
|
+
new w(s.x - a, s.y - l).add(r)
|
|
607
|
+
];
|
|
608
|
+
return new se([0, 1, 3, 2].map((h) => c[h]));
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* 计算线段的长度
|
|
612
|
+
* @returns 线段的长度
|
|
613
|
+
*/
|
|
614
|
+
getLength() {
|
|
615
|
+
return this.points[0].distance(this.points[1]);
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* 获取方向
|
|
619
|
+
* @returns
|
|
620
|
+
*/
|
|
621
|
+
direction() {
|
|
622
|
+
return this.points[1].direction(this.points[0]);
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* 获取发向量
|
|
626
|
+
*/
|
|
627
|
+
normal() {
|
|
628
|
+
return this.points[1].normal(this.points[0]);
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* 线段长度
|
|
632
|
+
* @returns
|
|
633
|
+
*/
|
|
634
|
+
length() {
|
|
635
|
+
return this.points[1].distance(this.points[0]);
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* 计算一条线段在另一条直线上的投影,并裁剪超出目标线段的部分
|
|
639
|
+
* @param line 要投影的线段
|
|
640
|
+
* @returns 投影并裁剪后的线段
|
|
641
|
+
*/
|
|
642
|
+
projectLineSegment(e) {
|
|
643
|
+
if (e.points.length !== 2 || this.points.length !== 2)
|
|
644
|
+
throw new Error("每条线段必须由两个点定义");
|
|
645
|
+
const [t, n] = e.points, [s, i] = this.points, r = new w(i.x - s.x, i.y - s.y);
|
|
646
|
+
if (r.x === 0 && r.y === 0)
|
|
647
|
+
throw new Error("投影目标线段的两个点不能重合");
|
|
648
|
+
const o = (p) => {
|
|
649
|
+
const y = new w(p.x - s.x, p.y - s.y), x = r.x * r.x + r.y * r.y, R = (y.x * r.x + y.y * r.y) / x, F = s.x + R * r.x, A = s.y + R * r.y;
|
|
650
|
+
return new w(F, A);
|
|
651
|
+
};
|
|
652
|
+
let a = o(t), l = o(n);
|
|
653
|
+
const c = (p) => {
|
|
654
|
+
const y = new w(p.x - s.x, p.y - s.y), x = r.x * r.x + r.y * r.y;
|
|
655
|
+
return (y.x * r.x + y.y * r.y) / x;
|
|
656
|
+
};
|
|
657
|
+
let h = c(a), f = c(l);
|
|
658
|
+
const u = (p) => {
|
|
659
|
+
const y = Math.max(0, Math.min(1, p)), x = s.x + y * r.x, S = s.y + y * r.y;
|
|
660
|
+
return new w(x, S);
|
|
661
|
+
};
|
|
662
|
+
return (h < 0 || h > 1) && (a = u(h)), (f < 0 || f > 1) && (l = u(f)), a.x === l.x && a.y === l.y ? new B(a, a) : new B(a, l);
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* 计算一条线段在另一条直线上的投影
|
|
666
|
+
* @param p1 要投影的点
|
|
667
|
+
* @param clip 是否裁剪超出目标线段的部分,默认裁剪
|
|
668
|
+
* @returns 投影并裁剪后的线段
|
|
669
|
+
*/
|
|
670
|
+
projectPoint(e, t = !0) {
|
|
671
|
+
const [n, s] = this.points, i = new w(s.x - n.x, s.y - n.y);
|
|
672
|
+
if (i.x === 0 && i.y === 0)
|
|
673
|
+
throw new Error("投影目标线段的两个点不能重合");
|
|
674
|
+
let o = ((c) => {
|
|
675
|
+
const h = new w(c.x - n.x, c.y - n.y), f = i.x * i.x + i.y * i.y, p = (h.x * i.x + h.y * i.y) / f, y = n.x + p * i.x, x = n.y + p * i.y;
|
|
676
|
+
return new w(y, x);
|
|
677
|
+
})(e);
|
|
678
|
+
if (!t) return o;
|
|
679
|
+
let l = ((c) => {
|
|
680
|
+
const h = new w(c.x - n.x, c.y - n.y), f = i.x * i.x + i.y * i.y;
|
|
681
|
+
return (h.x * i.x + h.y * i.y) / f;
|
|
682
|
+
})(o);
|
|
683
|
+
return l < 0 || l > 1 ? null : o;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* 判断线段是否与另一条线段相交(包含共用端点或部分重合的情况)
|
|
687
|
+
* @param line
|
|
688
|
+
* @param endpoint 是否包含端点相交
|
|
689
|
+
* @returns
|
|
690
|
+
*/
|
|
691
|
+
intersectLineSegment(e, t = !0) {
|
|
692
|
+
const n = this.start, s = this.end, i = e.start, r = e.end;
|
|
693
|
+
function o(u, p, y) {
|
|
694
|
+
return (p.x - u.x) * (y.y - u.y) - (p.y - u.y) * (y.x - u.x);
|
|
695
|
+
}
|
|
696
|
+
function a(u, p, y) {
|
|
697
|
+
return Math.min(p.x, y.x) - 1e-10 <= u.x && u.x <= Math.max(p.x, y.x) + 1e-10 && Math.min(p.y, y.y) - 1e-10 <= u.y && u.y <= Math.max(p.y, y.y) + 1e-10;
|
|
698
|
+
}
|
|
699
|
+
const l = o(n, s, i), c = o(n, s, r), h = o(i, r, n), f = o(i, r, s);
|
|
700
|
+
return !!(l * c < 0 && h * f < 0 || t && (Math.abs(l) < 1e-10 && a(i, n, s) || Math.abs(c) < 1e-10 && a(r, n, s) || Math.abs(h) < 1e-10 && a(n, i, r) || Math.abs(f) < 1e-10 && a(s, i, r)));
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* 判断一个点是否在线段上(含端点)
|
|
704
|
+
* @param pt 要判断的点
|
|
705
|
+
* @returns 如果点在当前线段上返回 true,否则返回 false
|
|
706
|
+
*/
|
|
707
|
+
containsPoint(e) {
|
|
708
|
+
const t = e.distance(this.start), n = e.distance(this.end), s = this.getLength();
|
|
709
|
+
return Math.abs(t + n - s) < 1e-10;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* 获取交点
|
|
713
|
+
* @param line
|
|
714
|
+
* @returns
|
|
715
|
+
*/
|
|
716
|
+
getIntersection(e) {
|
|
717
|
+
const t = this.start, n = this.end, s = e.start, i = e.end, r = (t.x - n.x) * (s.y - i.y) - (t.y - n.y) * (s.x - i.x);
|
|
718
|
+
if (Math.abs(r) < 1e-10)
|
|
719
|
+
return null;
|
|
720
|
+
const o = ((t.x - s.x) * (s.y - i.y) - (t.y - s.y) * (s.x - i.x)) / r, a = t.x + o * (n.x - t.x), l = t.y + o * (n.y - t.y);
|
|
721
|
+
return new w(a, l);
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* 获取两条线段夹角
|
|
725
|
+
* @param line
|
|
726
|
+
*/
|
|
727
|
+
includedAngle(e) {
|
|
728
|
+
const t = this.direction(), n = e.direction();
|
|
729
|
+
return t.angleBetween(n) / (Math.PI / 180);
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* 两条线段方向是否一致
|
|
733
|
+
* @param line
|
|
734
|
+
*/
|
|
735
|
+
directionEqual(e, t = 0.1) {
|
|
736
|
+
return this.includedAngle(e) < t;
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* 两条线段是否平行
|
|
740
|
+
* @param line
|
|
741
|
+
*/
|
|
742
|
+
parallel(e, t = 1) {
|
|
743
|
+
const n = this.includedAngle(e);
|
|
744
|
+
return n < t || n > 180 - t;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* 两条线段方向相反否一致
|
|
748
|
+
* @param line
|
|
749
|
+
*/
|
|
750
|
+
directionOpposite(e, t = 0.1) {
|
|
751
|
+
return 180 - this.includedAngle(e) < t;
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* 判断两条线是否平行
|
|
755
|
+
* @param line
|
|
756
|
+
*/
|
|
757
|
+
isParallel(e, t = 4) {
|
|
758
|
+
const n = this.includedAngle(e);
|
|
759
|
+
return n < t || n > 180 - t;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* 判断两条直线是否重合
|
|
763
|
+
* @param line
|
|
764
|
+
* @returns
|
|
765
|
+
*/
|
|
766
|
+
areLinesCoincident(e) {
|
|
767
|
+
const t = this.start, n = this.end, s = e.start, i = e.end, r = (n.y - t.y) / (n.x - t.x), o = t.y - r * t.x, a = (i.y - s.y) / (i.x - s.x), l = s.y - a * s.x;
|
|
768
|
+
return !isFinite(r) && !isFinite(a) ? t.x === s.x && n.x === s.x : Math.abs(r - a) < 1e-3 && Math.abs(o - l) < 1e-3;
|
|
769
|
+
}
|
|
770
|
+
clone() {
|
|
771
|
+
const e = new B(
|
|
772
|
+
this.points[0].clone(),
|
|
773
|
+
this.points[1].clone()
|
|
774
|
+
);
|
|
775
|
+
return e.userData = { ...this.userData }, e;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* 获取最长线段
|
|
779
|
+
* @param lines
|
|
780
|
+
*/
|
|
781
|
+
static maxLengthLineIndex(e, t) {
|
|
782
|
+
let n = 0, s = -1;
|
|
783
|
+
for (let i = 0; i < e.length; i++) {
|
|
784
|
+
if (t && t(e[i])) continue;
|
|
785
|
+
const r = e[i].length();
|
|
786
|
+
r > n && (n = r, s = i);
|
|
787
|
+
}
|
|
788
|
+
return s;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
class w {
|
|
792
|
+
x;
|
|
793
|
+
y;
|
|
794
|
+
get X() {
|
|
795
|
+
return this.x;
|
|
796
|
+
}
|
|
797
|
+
get Y() {
|
|
798
|
+
return this.y;
|
|
799
|
+
}
|
|
800
|
+
userData = {};
|
|
801
|
+
/**
|
|
802
|
+
*
|
|
803
|
+
* @param x
|
|
804
|
+
* @param y
|
|
805
|
+
*/
|
|
806
|
+
constructor(e = 0, t = 0) {
|
|
807
|
+
this.x = e, this.y = t;
|
|
808
|
+
}
|
|
809
|
+
set(e, t) {
|
|
810
|
+
return this.x = e, this.y = t, this;
|
|
811
|
+
}
|
|
812
|
+
setX(e) {
|
|
813
|
+
return this.x = e, this;
|
|
814
|
+
}
|
|
815
|
+
setY(e) {
|
|
816
|
+
return this.y = e, this;
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
*
|
|
820
|
+
* @param point
|
|
821
|
+
* @returns
|
|
822
|
+
*/
|
|
823
|
+
equal(e) {
|
|
824
|
+
return Math.abs(e.x - this.x) < 1e-9 && Math.abs(e.y - this.y) < 1e-9;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
*
|
|
828
|
+
* @param arr
|
|
829
|
+
*/
|
|
830
|
+
setByArray(e) {
|
|
831
|
+
return this.x = e[0], this.y = e[1], this;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
*
|
|
835
|
+
*/
|
|
836
|
+
toArray() {
|
|
837
|
+
return [this.x, this.y];
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* multiplyScalar
|
|
841
|
+
* @param scalar
|
|
842
|
+
*/
|
|
843
|
+
mutiplyScalar(e) {
|
|
844
|
+
return this.x *= e, this.y *= e, this;
|
|
845
|
+
}
|
|
846
|
+
multiplyScalar(e) {
|
|
847
|
+
return this.x *= e, this.y *= e, this;
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
*
|
|
851
|
+
* @param scalar
|
|
852
|
+
* @returns
|
|
853
|
+
*/
|
|
854
|
+
divisionScalar(e) {
|
|
855
|
+
return this.x /= e, this.y /= e, this;
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* 减法
|
|
859
|
+
* @description 将当前点的坐标减去指定点的坐标
|
|
860
|
+
* @param point
|
|
861
|
+
* @returns
|
|
862
|
+
*/
|
|
863
|
+
division(e) {
|
|
864
|
+
return this.x -= e.x, this.y -= e.y, this;
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* 加法
|
|
868
|
+
* @description 将当前点的坐标加上指定点的坐标
|
|
869
|
+
* @param point
|
|
870
|
+
* @returns
|
|
871
|
+
*/
|
|
872
|
+
add(e) {
|
|
873
|
+
return this.x += e.x, this.y += e.y, this;
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* 绕point旋转angle
|
|
877
|
+
* @param point
|
|
878
|
+
* @param angle 旋转角度,单位为弧度
|
|
879
|
+
*/
|
|
880
|
+
rotate(e, t) {
|
|
881
|
+
const n = this.x - e.x, s = this.y - e.y, i = Math.cos(t), r = Math.sin(t), o = n * i - s * r, a = n * r + s * i;
|
|
882
|
+
return this.x = o + e.x, this.y = a + e.y, this;
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* 保留小数位数
|
|
886
|
+
* @param count
|
|
887
|
+
*/
|
|
888
|
+
fixed(e) {
|
|
889
|
+
return this.x = Number(this.x.toFixed(e)), this.y = Number(this.y.toFixed(e)), this;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* 归一化
|
|
893
|
+
* @description 将当前点的坐标归一化为单位向量
|
|
894
|
+
* @returns
|
|
895
|
+
*/
|
|
896
|
+
normalize() {
|
|
897
|
+
const e = Math.sqrt(this.x * this.x + this.y * this.y);
|
|
898
|
+
return e === 0 ? this : (this.x /= e, this.y /= e, this);
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* 获取单位法向量
|
|
902
|
+
* @description 计算当前点到指定点的方向向量,并返回逆时针旋转90度后的单位法向量
|
|
903
|
+
* @param point
|
|
904
|
+
* @returns
|
|
905
|
+
*/
|
|
906
|
+
normal(e) {
|
|
907
|
+
const t = this.x - e.x, n = this.y - e.y, s = Math.sqrt(t * t + n * n), i = -n / s, r = t / s;
|
|
908
|
+
return new w(i, r);
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* 获取由传入的点到该点的单位方向向量
|
|
912
|
+
* @description 计算当前点到指定点的方向向量,并返回单位方向
|
|
913
|
+
* @param point
|
|
914
|
+
* @returns
|
|
915
|
+
*/
|
|
916
|
+
direction(e) {
|
|
917
|
+
const t = this.x - e.x, n = this.y - e.y, s = Math.sqrt(t * t + n * n);
|
|
918
|
+
return s === 0 ? new w(0, 0) : new w(t / s, n / s);
|
|
919
|
+
}
|
|
920
|
+
/** 展开为线
|
|
921
|
+
* @param direction
|
|
922
|
+
* @param length
|
|
923
|
+
*/
|
|
924
|
+
expandAsLine(e, t) {
|
|
925
|
+
return new B(
|
|
926
|
+
this.clone(),
|
|
927
|
+
this.clone().add(e.clone().multiplyScalar(t))
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* 计算模长
|
|
932
|
+
* @returns
|
|
933
|
+
*/
|
|
934
|
+
magnitude() {
|
|
935
|
+
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* 计算点点积
|
|
939
|
+
* @param point
|
|
940
|
+
* @returns
|
|
941
|
+
*/
|
|
942
|
+
dot(e) {
|
|
943
|
+
return this.x * e.x + this.y * e.y;
|
|
944
|
+
}
|
|
945
|
+
/** 求两个点叉积
|
|
946
|
+
* @description 如果叉积大于 0,a 到 b 为逆时针方向。
|
|
947
|
+
* @description 如果叉积小于 0,a 到 b 为顺时针方向。
|
|
948
|
+
* @param point
|
|
949
|
+
* @returns
|
|
950
|
+
*/
|
|
951
|
+
cross(e) {
|
|
952
|
+
return this.x * e.y - this.y * this.x;
|
|
953
|
+
}
|
|
954
|
+
/** 计算两个向量夹角
|
|
955
|
+
* @description 公式:a · b = |a| × |b| × cosθ
|
|
956
|
+
* @description 结果为0(0度),两个向量方向一致,结果为3.1415926(180度, PI),两个向量方向相反
|
|
957
|
+
* @param point
|
|
958
|
+
* @returns
|
|
959
|
+
*/
|
|
960
|
+
angleBetween(e, t = "radian", n = "180") {
|
|
961
|
+
const s = this.dot(e), i = this.magnitude(), r = e.magnitude();
|
|
962
|
+
if (i === 0 || r === 0) return 0;
|
|
963
|
+
const o = s / (i * r), a = Math.max(-1, Math.min(1, o));
|
|
964
|
+
return t === "radian" ? Math.acos(a) : t === "cos" ? a : n === "180" || this.cross(e) < 0 ? Math.acos(a) / (Math.PI / 180) : 360 - Math.acos(a) / (Math.PI / 180);
|
|
965
|
+
}
|
|
966
|
+
/** 获取向量长度
|
|
967
|
+
*/
|
|
968
|
+
length() {
|
|
969
|
+
const e = Math.sqrt(this.x * this.x + this.y * this.y);
|
|
970
|
+
return Math.abs(e - Math.round(e)) < 1e-9 ? Math.round(e) : e;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* 获取两个点长度
|
|
974
|
+
* @param point
|
|
975
|
+
*/
|
|
976
|
+
distance(e) {
|
|
977
|
+
return Math.sqrt(
|
|
978
|
+
(this.x - e.x) * (this.x - e.x) + (this.y - e.y) * (this.y - e.y)
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* 克隆
|
|
803
983
|
* @returns
|
|
804
984
|
*/
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
return this.points.forEach((i) => {
|
|
808
|
-
t = Math.max(i.x, t), e = Math.min(i.x, e), s = Math.max(i.x, s), n = Math.min(i.x, n);
|
|
809
|
-
}), new _(e, t, n, s);
|
|
985
|
+
clone() {
|
|
986
|
+
return new w(this.x, this.y);
|
|
810
987
|
}
|
|
811
988
|
/**
|
|
812
|
-
*
|
|
813
|
-
* @param line
|
|
814
|
-
* @param width
|
|
989
|
+
* 克隆
|
|
815
990
|
* @returns
|
|
816
991
|
*/
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
992
|
+
copy(e) {
|
|
993
|
+
return this.x = e.x ?? 0, this.y = e.y ?? 0, this;
|
|
994
|
+
}
|
|
995
|
+
toJson(e = 0) {
|
|
996
|
+
return {
|
|
997
|
+
x: this.x,
|
|
998
|
+
y: this.y,
|
|
999
|
+
z: e
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
static from(e) {
|
|
1003
|
+
return Array.isArray(e) ? new w(e[0], e[1]) : "x" in e && "y" in e ? new w(e.x, e.y) : "X" in e && "Y" in e ? new w(e.X, e.Y) : this.zero();
|
|
1004
|
+
}
|
|
1005
|
+
static zero() {
|
|
1006
|
+
return new w(0, 0);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
async function K(d, e = !0) {
|
|
1010
|
+
if (typeof global < "u" && typeof require < "u")
|
|
1011
|
+
return require(d);
|
|
1012
|
+
{
|
|
1013
|
+
let t = await import(
|
|
1014
|
+
/* @vite-ignore */
|
|
1015
|
+
d
|
|
1016
|
+
);
|
|
1017
|
+
return e && (t = t.default), t;
|
|
825
1018
|
}
|
|
826
1019
|
}
|
|
827
|
-
class
|
|
1020
|
+
class X {
|
|
828
1021
|
bounds;
|
|
829
1022
|
// 包围盒
|
|
830
1023
|
capacity;
|
|
@@ -890,22 +1083,22 @@ class Y {
|
|
|
890
1083
|
if (!this.isLeaf) return;
|
|
891
1084
|
this.isLeaf = !1, this.children = [];
|
|
892
1085
|
const e = (this.bounds.minX + this.bounds.maxX) / 2, t = (this.bounds.minY + this.bounds.maxY) / 2;
|
|
893
|
-
this.children[0] = new
|
|
1086
|
+
this.children[0] = new X(
|
|
894
1087
|
new _(this.bounds.minX, e, this.bounds.minY, t),
|
|
895
1088
|
this.capacity,
|
|
896
1089
|
this.maxDepth,
|
|
897
1090
|
this.depth + 1
|
|
898
|
-
), this.children[1] = new
|
|
1091
|
+
), this.children[1] = new X(
|
|
899
1092
|
new _(e, this.bounds.maxX, this.bounds.minY, t),
|
|
900
1093
|
this.capacity,
|
|
901
1094
|
this.maxDepth,
|
|
902
1095
|
this.depth + 1
|
|
903
|
-
), this.children[2] = new
|
|
1096
|
+
), this.children[2] = new X(
|
|
904
1097
|
new _(this.bounds.minX, e, t, this.bounds.maxY),
|
|
905
1098
|
this.capacity,
|
|
906
1099
|
this.maxDepth,
|
|
907
1100
|
this.depth + 1
|
|
908
|
-
), this.children[3] = new
|
|
1101
|
+
), this.children[3] = new X(
|
|
909
1102
|
new _(e, this.bounds.maxX, t, this.bounds.maxY),
|
|
910
1103
|
this.capacity,
|
|
911
1104
|
this.maxDepth,
|
|
@@ -955,6 +1148,22 @@ class Y {
|
|
|
955
1148
|
n.push(...i.queryCircle(e, t));
|
|
956
1149
|
return n.sort((i) => i.line.length()), n;
|
|
957
1150
|
}
|
|
1151
|
+
/**
|
|
1152
|
+
* 查询与点相交的线段节点
|
|
1153
|
+
* @param point 圆心
|
|
1154
|
+
* @returns 相交的节点数组
|
|
1155
|
+
*/
|
|
1156
|
+
queryPoint(e) {
|
|
1157
|
+
const t = [];
|
|
1158
|
+
if (e.x < this.bounds.minX || e.x > this.bounds.maxX || e.y < this.bounds.minY || e.y > this.bounds.maxY)
|
|
1159
|
+
return t;
|
|
1160
|
+
for (const n of this.nodes)
|
|
1161
|
+
n.line.isPointOnSegment(e) && t.push(n);
|
|
1162
|
+
if (!this.isLeaf)
|
|
1163
|
+
for (const n of this.children)
|
|
1164
|
+
t.push(...n.queryPoint(e));
|
|
1165
|
+
return t;
|
|
1166
|
+
}
|
|
958
1167
|
/**
|
|
959
1168
|
* 查询与矩形相交的线段节点
|
|
960
1169
|
* @param rectangle 矩形
|
|
@@ -985,326 +1194,151 @@ class Y {
|
|
|
985
1194
|
if (!this.isLeaf)
|
|
986
1195
|
for (const s of this.children)
|
|
987
1196
|
n.push(...s.queryLineSegment(e));
|
|
988
|
-
return n;
|
|
989
|
-
}
|
|
990
|
-
/**
|
|
991
|
-
* 包围盒转换为数组
|
|
992
|
-
* @param array
|
|
993
|
-
* @param colors
|
|
994
|
-
* @returns
|
|
995
|
-
*/
|
|
996
|
-
boundsToArray(e = [], t, n = !0) {
|
|
997
|
-
return !this.isLeaf && n && this.children?.forEach((s) => s.boundsToArray(e, t)), e.push(...this.bounds.points.flatMap((s, i, r) => {
|
|
998
|
-
const o = r[(i + 1) % r.length];
|
|
999
|
-
return t?.push(...this.color), t?.push(...this.color), [s.x, s.y, 0, o.x, o.y, 0];
|
|
1000
|
-
})), e;
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
class B {
|
|
1004
|
-
points = [new w(), new w()];
|
|
1005
|
-
userData = {};
|
|
1006
|
-
// line: any
|
|
1007
|
-
get center() {
|
|
1008
|
-
return new w(
|
|
1009
|
-
this.points[0].x + (this.points[1].x - this.points[0].x) * 0.5,
|
|
1010
|
-
this.points[0].y + (this.points[1].y - this.points[0].y) * 0.5
|
|
1011
|
-
);
|
|
1012
|
-
}
|
|
1013
|
-
get start() {
|
|
1014
|
-
return this.points[0];
|
|
1015
|
-
}
|
|
1016
|
-
get end() {
|
|
1017
|
-
return this.points[1];
|
|
1018
|
-
}
|
|
1019
|
-
constructor(e = new w(), t = new w()) {
|
|
1020
|
-
this.points = [e, t];
|
|
1021
|
-
}
|
|
1022
|
-
set(e, t) {
|
|
1023
|
-
return this.start.copy(e), this.end.copy(t), this;
|
|
1024
|
-
}
|
|
1025
|
-
/**
|
|
1026
|
-
* 是否有相同端点
|
|
1027
|
-
* @param line
|
|
1028
|
-
* @returns
|
|
1029
|
-
*/
|
|
1030
|
-
sameEndpoint(e) {
|
|
1031
|
-
return this.start.equal(e.start) || this.start.equal(e.end) || this.end.equal(e.start) || this.end.equal(e.end);
|
|
1032
|
-
}
|
|
1033
|
-
/**
|
|
1034
|
-
* 相同端点是否为开始
|
|
1035
|
-
* @param line
|
|
1036
|
-
* @returns
|
|
1037
|
-
*/
|
|
1038
|
-
sameEndpointAsStart(e) {
|
|
1039
|
-
return this.start.equal(e.start) || this.start.equal(e.end);
|
|
1040
|
-
}
|
|
1041
|
-
/**
|
|
1042
|
-
* 获取共线点
|
|
1043
|
-
* @param line
|
|
1044
|
-
* @returns
|
|
1045
|
-
*/
|
|
1046
|
-
getSameEndpoint(e) {
|
|
1047
|
-
return this.start.equal(e.start) ? [this.start, e.start] : this.start.equal(e.end) ? [this.start, e.end] : this.end.equal(e.start) ? [this.end, e.start] : this.end.equal(e.end) ? [this.end, e.end] : null;
|
|
1048
|
-
}
|
|
1049
|
-
/**
|
|
1050
|
-
* 判断一个点是否在当前线段上(包含端点)
|
|
1051
|
-
* @param point 要判断的点
|
|
1052
|
-
* @returns 如果点在当前线段上则返回 true,否则返回 false
|
|
1053
|
-
*/
|
|
1054
|
-
isPointOnSegment(e) {
|
|
1055
|
-
const { start: t, end: n } = this, s = (e.y - t.y) * (n.x - t.x) - (e.x - t.x) * (n.y - t.y);
|
|
1056
|
-
return Math.abs(s) > 1e-10 ? !1 : (e.x - t.x) * (e.x - n.x) + (e.y - t.y) * (e.y - n.y) <= 1e-10;
|
|
1057
|
-
}
|
|
1058
|
-
/**
|
|
1059
|
-
* 相同端点是否为结束
|
|
1060
|
-
* @param line
|
|
1061
|
-
* @returns
|
|
1062
|
-
*/
|
|
1063
|
-
sameEndpointAsEnd(e) {
|
|
1064
|
-
return this.end.equal(e.start) || this.end.equal(e.end);
|
|
1065
|
-
}
|
|
1066
|
-
/** 膨胀
|
|
1067
|
-
* @description 向线段的两个端点分别膨胀 width
|
|
1068
|
-
* @param width
|
|
1069
|
-
*/
|
|
1070
|
-
expansion(e, t = "all") {
|
|
1071
|
-
const n = this.direction().multiplyScalar(e);
|
|
1072
|
-
return (t === "end" || t === "all") && this.end.add(n), (t === "start" || t === "all") && this.start.add(n.multiplyScalar(-1)), this;
|
|
1073
|
-
}
|
|
1074
|
-
/** 向前
|
|
1075
|
-
* @description 向前移动 width
|
|
1076
|
-
* @param width
|
|
1077
|
-
*/
|
|
1078
|
-
forward(e) {
|
|
1079
|
-
const t = this.direction().multiplyScalar(e);
|
|
1080
|
-
return this.start.add(t), this.end.add(t), this;
|
|
1081
|
-
}
|
|
1082
|
-
/** 向前
|
|
1083
|
-
* @description 向前移动 width
|
|
1084
|
-
* @param width
|
|
1085
|
-
*/
|
|
1086
|
-
backward(e) {
|
|
1087
|
-
const t = this.direction().multiplyScalar(-e);
|
|
1088
|
-
return this.start.add(t), this.end.add(t), this;
|
|
1089
|
-
}
|
|
1090
|
-
/**
|
|
1091
|
-
* 向指定方向平移
|
|
1092
|
-
* @param direct
|
|
1093
|
-
* @param size
|
|
1094
|
-
*/
|
|
1095
|
-
directionMove(e, t) {
|
|
1096
|
-
const n = e.clone().multiplyScalar(t);
|
|
1097
|
-
return this.start.add(n), this.end.add(n), this;
|
|
1098
|
-
}
|
|
1099
|
-
/** 膨胀为矩形
|
|
1100
|
-
*
|
|
1101
|
-
* @param width
|
|
1102
|
-
* @returns {Rectangle}
|
|
1103
|
-
*/
|
|
1104
|
-
expandToRectangle(e = 0.1, t = "all") {
|
|
1105
|
-
const n = this.start, s = this.end, i = s.normal(n), r = t === "bothSides" ? w.zero() : s.direction(n).mutiplyScalar(e * 0.5), o = t === "bothSides" ? w.zero() : n.direction(s).mutiplyScalar(e * 0.5), a = i.x * e * 0.5, l = i.y * e * 0.5, c = [
|
|
1106
|
-
// 第一条线
|
|
1107
|
-
new w(n.x + a, n.y + l).add(o),
|
|
1108
|
-
new w(s.x + a, s.y + l).add(r),
|
|
1109
|
-
// 第二条线
|
|
1110
|
-
new w(n.x - a, n.y - l).add(o),
|
|
1111
|
-
new w(s.x - a, s.y - l).add(r)
|
|
1112
|
-
];
|
|
1113
|
-
return new te([0, 1, 3, 2].map((h) => c[h]));
|
|
1114
|
-
}
|
|
1115
|
-
/**
|
|
1116
|
-
* 计算线段的长度
|
|
1117
|
-
* @returns 线段的长度
|
|
1118
|
-
*/
|
|
1119
|
-
getLength() {
|
|
1120
|
-
return this.points[0].distance(this.points[1]);
|
|
1121
|
-
}
|
|
1122
|
-
/**
|
|
1123
|
-
* 获取方向
|
|
1124
|
-
* @returns
|
|
1125
|
-
*/
|
|
1126
|
-
direction() {
|
|
1127
|
-
return this.points[1].direction(this.points[0]);
|
|
1128
|
-
}
|
|
1129
|
-
/**
|
|
1130
|
-
* 获取发向量
|
|
1131
|
-
*/
|
|
1132
|
-
normal() {
|
|
1133
|
-
return this.points[1].normal(this.points[0]);
|
|
1134
|
-
}
|
|
1135
|
-
/**
|
|
1136
|
-
* 线段长度
|
|
1137
|
-
* @returns
|
|
1138
|
-
*/
|
|
1139
|
-
length() {
|
|
1140
|
-
return this.points[1].distance(this.points[0]);
|
|
1141
|
-
}
|
|
1142
|
-
/**
|
|
1143
|
-
* 计算一条线段在另一条直线上的投影,并裁剪超出目标线段的部分
|
|
1144
|
-
* @param line 要投影的线段
|
|
1145
|
-
* @returns 投影并裁剪后的线段
|
|
1146
|
-
*/
|
|
1147
|
-
projectLineSegment(e) {
|
|
1148
|
-
if (e.points.length !== 2 || this.points.length !== 2)
|
|
1149
|
-
throw new Error("每条线段必须由两个点定义");
|
|
1150
|
-
const [t, n] = e.points, [s, i] = this.points, r = new w(i.x - s.x, i.y - s.y);
|
|
1151
|
-
if (r.x === 0 && r.y === 0)
|
|
1152
|
-
throw new Error("投影目标线段的两个点不能重合");
|
|
1153
|
-
const o = (p) => {
|
|
1154
|
-
const y = new w(p.x - s.x, p.y - s.y), x = r.x * r.x + r.y * r.y, b = (y.x * r.x + y.y * r.y) / x, C = s.x + b * r.x, m = s.y + b * r.y;
|
|
1155
|
-
return new w(C, m);
|
|
1156
|
-
};
|
|
1157
|
-
let a = o(t), l = o(n);
|
|
1158
|
-
const c = (p) => {
|
|
1159
|
-
const y = new w(p.x - s.x, p.y - s.y), x = r.x * r.x + r.y * r.y;
|
|
1160
|
-
return (y.x * r.x + y.y * r.y) / x;
|
|
1161
|
-
};
|
|
1162
|
-
let h = c(a), f = c(l);
|
|
1163
|
-
const u = (p) => {
|
|
1164
|
-
const y = Math.max(0, Math.min(1, p)), x = s.x + y * r.x, S = s.y + y * r.y;
|
|
1165
|
-
return new w(x, S);
|
|
1166
|
-
};
|
|
1167
|
-
return (h < 0 || h > 1) && (a = u(h)), (f < 0 || f > 1) && (l = u(f)), a.x === l.x && a.y === l.y ? new B(a, a) : new B(a, l);
|
|
1168
|
-
}
|
|
1169
|
-
/**
|
|
1170
|
-
* 计算一条线段在另一条直线上的投影
|
|
1171
|
-
* @param p1 要投影的点
|
|
1172
|
-
* @param clip 是否裁剪超出目标线段的部分,默认裁剪
|
|
1173
|
-
* @returns 投影并裁剪后的线段
|
|
1174
|
-
*/
|
|
1175
|
-
projectPoint(e, t = !0) {
|
|
1176
|
-
const [n, s] = this.points, i = new w(s.x - n.x, s.y - n.y);
|
|
1177
|
-
if (i.x === 0 && i.y === 0)
|
|
1178
|
-
throw new Error("投影目标线段的两个点不能重合");
|
|
1179
|
-
let o = ((c) => {
|
|
1180
|
-
const h = new w(c.x - n.x, c.y - n.y), f = i.x * i.x + i.y * i.y, p = (h.x * i.x + h.y * i.y) / f, y = n.x + p * i.x, x = n.y + p * i.y;
|
|
1181
|
-
return new w(y, x);
|
|
1182
|
-
})(e);
|
|
1183
|
-
if (!t) return o;
|
|
1184
|
-
let l = ((c) => {
|
|
1185
|
-
const h = new w(c.x - n.x, c.y - n.y), f = i.x * i.x + i.y * i.y;
|
|
1186
|
-
return (h.x * i.x + h.y * i.y) / f;
|
|
1187
|
-
})(o);
|
|
1188
|
-
return l < 0 || l > 1 ? null : o;
|
|
1197
|
+
return n;
|
|
1189
1198
|
}
|
|
1190
1199
|
/**
|
|
1191
|
-
*
|
|
1192
|
-
* @param
|
|
1193
|
-
* @param
|
|
1200
|
+
* 包围盒转换为数组
|
|
1201
|
+
* @param array
|
|
1202
|
+
* @param colors
|
|
1194
1203
|
* @returns
|
|
1195
1204
|
*/
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
return (
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1205
|
+
boundsToArray(e = [], t, n = !0) {
|
|
1206
|
+
return !this.isLeaf && n && this.children?.forEach((s) => s.boundsToArray(e, t)), e.push(...this.bounds.points.flatMap((s, i, r) => {
|
|
1207
|
+
const o = r[(i + 1) % r.length];
|
|
1208
|
+
return t?.push(...this.color), t?.push(...this.color), [s.x, s.y, 0, o.x, o.y, 0];
|
|
1209
|
+
})), e;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
class he {
|
|
1213
|
+
map = /* @__PURE__ */ new Map();
|
|
1214
|
+
targetMap = /* @__PURE__ */ new Map();
|
|
1215
|
+
gridSize;
|
|
1216
|
+
constructor(e = 2) {
|
|
1217
|
+
this.gridSize = e;
|
|
1206
1218
|
}
|
|
1207
1219
|
/**
|
|
1208
|
-
*
|
|
1209
|
-
* @param
|
|
1210
|
-
* @
|
|
1220
|
+
* 插入
|
|
1221
|
+
* @param point
|
|
1222
|
+
* @param userData
|
|
1211
1223
|
*/
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1224
|
+
insert(e, t) {
|
|
1225
|
+
if (!e || isNaN(e.x) || isNaN(e.y))
|
|
1226
|
+
throw new Error("无效的点坐标");
|
|
1227
|
+
this.targetMap.has(e) && this.remove(e);
|
|
1228
|
+
const n = this.getGridId(e);
|
|
1229
|
+
this.map.has(n) || this.map.set(n, /* @__PURE__ */ new Set());
|
|
1230
|
+
const s = this.map.get(n), i = { point: e, userData: t };
|
|
1231
|
+
s.add(i), e.userData.pointVirtualGrid = { set: s, target: i }, this.targetMap.set(e, { set: s, target: i });
|
|
1215
1232
|
}
|
|
1216
1233
|
/**
|
|
1217
|
-
*
|
|
1218
|
-
* @param
|
|
1219
|
-
* @returns
|
|
1234
|
+
* 批量加入
|
|
1235
|
+
* @param points
|
|
1220
1236
|
*/
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
return null;
|
|
1225
|
-
const o = ((t.x - s.x) * (s.y - i.y) - (t.y - s.y) * (s.x - i.x)) / r, a = t.x + o * (n.x - t.x), l = t.y + o * (n.y - t.y);
|
|
1226
|
-
return new w(a, l);
|
|
1237
|
+
insertBatch(e) {
|
|
1238
|
+
for (const { point: t, userData: n } of e)
|
|
1239
|
+
this.insert(t, n);
|
|
1227
1240
|
}
|
|
1228
|
-
/**
|
|
1229
|
-
*
|
|
1230
|
-
* @param line
|
|
1241
|
+
/** 移除点
|
|
1242
|
+
* @param point
|
|
1231
1243
|
*/
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1244
|
+
remove(e) {
|
|
1245
|
+
if (this.targetMap.has(e)) {
|
|
1246
|
+
const { target: t, set: n } = this.targetMap.get(e);
|
|
1247
|
+
n && (n.delete(t), delete e?.userData?.pointVirtualGridMap, this.targetMap.delete(e));
|
|
1248
|
+
}
|
|
1235
1249
|
}
|
|
1236
1250
|
/**
|
|
1237
|
-
*
|
|
1238
|
-
* @param
|
|
1251
|
+
* 获取通过坐标,获取唯一网格索引
|
|
1252
|
+
* @param point
|
|
1253
|
+
* @returns
|
|
1239
1254
|
*/
|
|
1240
|
-
|
|
1241
|
-
|
|
1255
|
+
getGridId(e) {
|
|
1256
|
+
const t = Math.ceil(e.x / this.gridSize), n = Math.ceil(e.y / this.gridSize);
|
|
1257
|
+
return `${t}.${n}`;
|
|
1242
1258
|
}
|
|
1243
1259
|
/**
|
|
1244
|
-
*
|
|
1245
|
-
* @param
|
|
1260
|
+
*
|
|
1261
|
+
* @param gridId
|
|
1262
|
+
* @returns
|
|
1246
1263
|
*/
|
|
1247
|
-
|
|
1248
|
-
const n =
|
|
1249
|
-
return
|
|
1264
|
+
decodeGridId(e) {
|
|
1265
|
+
const [t, n] = e.split(".").map(Number);
|
|
1266
|
+
return new w(t, n);
|
|
1250
1267
|
}
|
|
1251
1268
|
/**
|
|
1252
|
-
*
|
|
1253
|
-
* @param
|
|
1269
|
+
* 查询与矩形相交的点
|
|
1270
|
+
* @param rectangle 矩形
|
|
1271
|
+
* @returns 相交的节点数组
|
|
1254
1272
|
*/
|
|
1255
|
-
|
|
1256
|
-
|
|
1273
|
+
queryRect(e) {
|
|
1274
|
+
const t = e.toBox(), n = Math.ceil(t.minX / this.gridSize), s = Math.ceil(t.maxX / this.gridSize), i = Math.ceil(t.minY / this.gridSize), r = Math.ceil(t.maxY / this.gridSize);
|
|
1275
|
+
for (let o = n; o <= s; o++)
|
|
1276
|
+
for (let a = i; a <= r; a++) {
|
|
1277
|
+
const l = `${o}.${a}`;
|
|
1278
|
+
if (!this.map.has(l)) continue;
|
|
1279
|
+
this.map.get(l)?.forEach((h) => {
|
|
1280
|
+
e.containsPoint(h.point);
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1257
1283
|
}
|
|
1258
1284
|
/**
|
|
1259
|
-
*
|
|
1260
|
-
* @param
|
|
1285
|
+
* 查询与圆形区域相交的点
|
|
1286
|
+
* @param pos 圆心
|
|
1287
|
+
* @param radius 半径
|
|
1288
|
+
* @returns 相交的节点数组
|
|
1261
1289
|
*/
|
|
1262
|
-
|
|
1263
|
-
const n = this.
|
|
1264
|
-
|
|
1290
|
+
queryCircle(e, t) {
|
|
1291
|
+
const n = new _(e.x - t, e.x + t, e.y - t, e.y + t), s = Math.ceil(n.minX / this.gridSize), i = Math.ceil(n.maxX / this.gridSize), r = Math.ceil(n.minY / this.gridSize), o = Math.ceil(n.maxY / this.gridSize), a = [];
|
|
1292
|
+
for (let l = s; l <= i; l++)
|
|
1293
|
+
for (let c = r; c <= o; c++) {
|
|
1294
|
+
const h = `${l}.${c}`;
|
|
1295
|
+
if (!this.map.has(h)) continue;
|
|
1296
|
+
this.map.get(h)?.forEach((u) => {
|
|
1297
|
+
e.distance(u.point) <= t && a.push(u);
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
return a;
|
|
1265
1301
|
}
|
|
1266
1302
|
/**
|
|
1267
|
-
*
|
|
1268
|
-
* @param
|
|
1269
|
-
* @returns
|
|
1303
|
+
* 查询与包围盒相交的点
|
|
1304
|
+
* @param box2 包围盒
|
|
1305
|
+
* @returns 相交的节点数组
|
|
1270
1306
|
*/
|
|
1271
|
-
|
|
1272
|
-
const t =
|
|
1273
|
-
|
|
1307
|
+
queryBox(e) {
|
|
1308
|
+
const t = Math.ceil(e.minX / this.gridSize), n = Math.ceil(e.maxX / this.gridSize), s = Math.ceil(e.minY / this.gridSize), i = Math.ceil(e.maxY / this.gridSize), r = [];
|
|
1309
|
+
for (let o = t; o <= n; o++)
|
|
1310
|
+
for (let a = s; a <= i; a++) {
|
|
1311
|
+
const l = `${o}.${a}`;
|
|
1312
|
+
if (!this.map.has(l)) continue;
|
|
1313
|
+
this.map.get(l)?.forEach((h) => {
|
|
1314
|
+
e.containsPoint(h.point) && r.push(h);
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
return r;
|
|
1274
1318
|
}
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1319
|
+
/**
|
|
1320
|
+
* 查找相同点
|
|
1321
|
+
* @param point
|
|
1322
|
+
*/
|
|
1323
|
+
queryPoint(e) {
|
|
1324
|
+
const t = this.getGridId(e), n = [];
|
|
1325
|
+
return this.map.has(t) && this.map.get(t)?.forEach((i) => {
|
|
1326
|
+
e.equal(i.point) && n.push(i);
|
|
1327
|
+
}), n;
|
|
1281
1328
|
}
|
|
1282
1329
|
/**
|
|
1283
|
-
*
|
|
1284
|
-
* @param
|
|
1330
|
+
* 查找点自己
|
|
1331
|
+
* @param point
|
|
1285
1332
|
*/
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
const r = e[i].length();
|
|
1291
|
-
r > n && (n = r, s = i);
|
|
1333
|
+
queryPointSelf(e) {
|
|
1334
|
+
if (this.targetMap.has(e)) {
|
|
1335
|
+
const { target: t } = this.targetMap.get(e);
|
|
1336
|
+
return t;
|
|
1292
1337
|
}
|
|
1293
|
-
return
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
|
-
async function H(d, e = !0) {
|
|
1297
|
-
if (typeof global < "u" && typeof require < "u")
|
|
1298
|
-
return require(d);
|
|
1299
|
-
{
|
|
1300
|
-
let t = await import(
|
|
1301
|
-
/* @vite-ignore */
|
|
1302
|
-
d
|
|
1303
|
-
);
|
|
1304
|
-
return e && (t = t.default), t;
|
|
1338
|
+
return null;
|
|
1305
1339
|
}
|
|
1306
1340
|
}
|
|
1307
|
-
const
|
|
1341
|
+
const Qe = {
|
|
1308
1342
|
Unitless: 1,
|
|
1309
1343
|
// 无单位,1米 = 1(无单位)
|
|
1310
1344
|
Inches: 39.37007874015748,
|
|
@@ -1348,7 +1382,7 @@ const $e = {
|
|
|
1348
1382
|
Parsecs: 3240779289666404e-32
|
|
1349
1383
|
// 秒差距,1米 ≈ 0.00000000000000003240779289666404秒差距
|
|
1350
1384
|
};
|
|
1351
|
-
function
|
|
1385
|
+
function xe(d) {
|
|
1352
1386
|
const e = [];
|
|
1353
1387
|
for (let t = 0; t < d.length; t++)
|
|
1354
1388
|
e.push(new B(
|
|
@@ -1357,10 +1391,10 @@ function fe(d) {
|
|
|
1357
1391
|
));
|
|
1358
1392
|
return e;
|
|
1359
1393
|
}
|
|
1360
|
-
function
|
|
1394
|
+
function ye(d) {
|
|
1361
1395
|
return d.flatMap((e, t) => (t === d.length - 1 && [...e.points, d[0].points[0]], [e.points[0]]));
|
|
1362
1396
|
}
|
|
1363
|
-
class
|
|
1397
|
+
class V extends J {
|
|
1364
1398
|
static name = "Dxf";
|
|
1365
1399
|
shortLine = 0.04;
|
|
1366
1400
|
width = 0.04;
|
|
@@ -1407,19 +1441,21 @@ class X extends W {
|
|
|
1407
1441
|
preprocessing(e, t = !1) {
|
|
1408
1442
|
const n = [];
|
|
1409
1443
|
let s = -1;
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1444
|
+
const i = [];
|
|
1445
|
+
e.forEach(({ start: o, end: a, ...l }, c) => {
|
|
1446
|
+
i.push(o.z ?? 0, a.z ?? 0);
|
|
1447
|
+
const h = new B(
|
|
1448
|
+
w.from(o),
|
|
1449
|
+
w.from(a)
|
|
1414
1450
|
);
|
|
1415
|
-
|
|
1416
|
-
}), s === -1 && (s = B.maxLengthLineIndex(n, (
|
|
1417
|
-
const
|
|
1418
|
-
if (
|
|
1419
|
-
|
|
1420
|
-
return
|
|
1421
|
-
lineSegments:
|
|
1422
|
-
data: this.lineDataToOriginalData(
|
|
1451
|
+
h.userData = l, n.push(h), l.isVerticalReferenceLine && (s = c);
|
|
1452
|
+
}), this.originalZAverage = i.reduce((o, a) => o + a, 0) / i.length, s === -1 && (s = B.maxLengthLineIndex(n, (o) => !o.userData.insetionArr?.length));
|
|
1453
|
+
const r = n[s];
|
|
1454
|
+
if (r.userData.isVerticalReferenceLine = !0, e[s].isVerticalReferenceLine = !0, t) {
|
|
1455
|
+
let o = V.axisAlignmentCorrection.call(this, n, r);
|
|
1456
|
+
return {
|
|
1457
|
+
lineSegments: o,
|
|
1458
|
+
data: this.lineDataToOriginalData(o)
|
|
1423
1459
|
};
|
|
1424
1460
|
}
|
|
1425
1461
|
return {
|
|
@@ -1568,7 +1604,7 @@ class X extends W {
|
|
|
1568
1604
|
break;
|
|
1569
1605
|
}
|
|
1570
1606
|
}
|
|
1571
|
-
const t = this.mergeSameDirectionLine(
|
|
1607
|
+
const t = this.mergeSameDirectionLine(xe(e)), n = [t[0]];
|
|
1572
1608
|
for (let s = 1; s < t.length; s++) {
|
|
1573
1609
|
const i = t[s], r = t[(t.length + s - 1) % t.length];
|
|
1574
1610
|
if (i.length() > this.width * 0.9) {
|
|
@@ -1583,7 +1619,7 @@ class X extends W {
|
|
|
1583
1619
|
const a = t[s + 2];
|
|
1584
1620
|
a && r.includedAngle(a) < 2 ? (s = s + 2, n.push(a)) : n.push(i);
|
|
1585
1621
|
}
|
|
1586
|
-
return n.length > 3 ?
|
|
1622
|
+
return n.length > 3 ? ye(this.mergeSameDirectionLine(n)) : [];
|
|
1587
1623
|
}
|
|
1588
1624
|
/**
|
|
1589
1625
|
* 移除短线段
|
|
@@ -1591,7 +1627,7 @@ class X extends W {
|
|
|
1591
1627
|
* @param path
|
|
1592
1628
|
*/
|
|
1593
1629
|
removeShortLine(e, t = this.shortLine) {
|
|
1594
|
-
const n =
|
|
1630
|
+
const n = xe(e), s = [], i = Math.PI / 180;
|
|
1595
1631
|
for (let r = 0; r < n.length; r++) {
|
|
1596
1632
|
const o = n[r], a = o.length(), l = r;
|
|
1597
1633
|
if (a > t || s.length === 0) {
|
|
@@ -1619,20 +1655,20 @@ class X extends W {
|
|
|
1619
1655
|
} else
|
|
1620
1656
|
r = l;
|
|
1621
1657
|
}
|
|
1622
|
-
return s.length > 3 ?
|
|
1658
|
+
return s.length > 3 ? ye(s) : [];
|
|
1623
1659
|
}
|
|
1624
1660
|
/** 线偏移
|
|
1625
1661
|
* @description 使用 ClipperLib 对每个点组进行线偏移处理,生成具有指定宽度的墙体路径
|
|
1626
1662
|
*/
|
|
1627
|
-
lineOffset(e =
|
|
1628
|
-
let s = new
|
|
1629
|
-
const i = new
|
|
1663
|
+
lineOffset(e = V.EndType.etOpenSquare, t = V.JoinType.jtMiter, n = 1e4) {
|
|
1664
|
+
let s = new pe.Paths();
|
|
1665
|
+
const i = new pe.ClipperOffset(20, 0.25);
|
|
1630
1666
|
return this.pointsGroups.forEach((r) => {
|
|
1631
1667
|
const o = this.lineTopology(r).map((a) => a.map((l) => l.clone().mutiplyScalar(n)));
|
|
1632
1668
|
i.AddPaths(o, t, e);
|
|
1633
1669
|
}), i.Execute(s, this.width / 2 * n), this.wallsGroup = s.map((r) => {
|
|
1634
1670
|
let o = r.map((a) => w.from(a).divisionScalar(n));
|
|
1635
|
-
return o = this.lineSegmentStraightening(o), e ==
|
|
1671
|
+
return o = this.lineSegmentStraightening(o), e == V.EndType.etOpenSquare && (o = this.squareRemoveBurr(o)), o;
|
|
1636
1672
|
}), this.dispatchEvent({
|
|
1637
1673
|
type: "lineOffset",
|
|
1638
1674
|
wallsGroup: this.wallsGroup
|
|
@@ -1667,7 +1703,7 @@ class X extends W {
|
|
|
1667
1703
|
* 线段数据转为原始json数据
|
|
1668
1704
|
*/
|
|
1669
1705
|
lineDataToOriginalData(e, t) {
|
|
1670
|
-
return t || (t = new
|
|
1706
|
+
return t || (t = new X(_.fromByLineSegment(...e)), e.forEach((n) => t?.insert({ line: n, userData: void 0 }))), e.map((n) => {
|
|
1671
1707
|
const s = n.userData, i = s.drawWindow, r = t.queryLineSegment(n).filter((o) => o.line !== n && !o.userData?.isDoor).map((o) => ({ index: e.indexOf(o.line) }));
|
|
1672
1708
|
return {
|
|
1673
1709
|
start: n.start.toJson(this.originalZAverage),
|
|
@@ -1691,7 +1727,7 @@ class X extends W {
|
|
|
1691
1727
|
* 转为绘制数据
|
|
1692
1728
|
*/
|
|
1693
1729
|
toDrawDataJson(e = "Millimeters") {
|
|
1694
|
-
const t =
|
|
1730
|
+
const t = Qe[e], n = {
|
|
1695
1731
|
unit: e,
|
|
1696
1732
|
line: [],
|
|
1697
1733
|
arc: [],
|
|
@@ -1740,24 +1776,24 @@ class X extends W {
|
|
|
1740
1776
|
c.start.clone().add(h.clone().multiplyScalar(c.length()))
|
|
1741
1777
|
);
|
|
1742
1778
|
const u = f.clone().directionMove(f.normal(), c.length() * -0.5).expandToRectangle(c.length(), "bothSides");
|
|
1743
|
-
for (let
|
|
1744
|
-
if (a[
|
|
1779
|
+
for (let A = 0; A < a.length; A++)
|
|
1780
|
+
if (a[A].intersectRectangle(u)) {
|
|
1745
1781
|
f = new B(
|
|
1746
1782
|
c.start.clone(),
|
|
1747
1783
|
c.start.clone().add(h.clone().multiplyScalar(-c.length()))
|
|
1748
1784
|
);
|
|
1749
1785
|
break;
|
|
1750
1786
|
}
|
|
1751
|
-
f.expansion(-o * 0.5).expandToRectangle(this.width * 0.2, "bothSides").path2D((
|
|
1752
|
-
const p = c.length(), y = f.length(), x = (p ** 2 + y ** 2) / (2 * y), S = f.end.clone().add(f.direction().multiplyScalar(-x)), [
|
|
1753
|
-
r(S, x, Math.min(
|
|
1787
|
+
f.expansion(-o * 0.5).expandToRectangle(this.width * 0.2, "bothSides").path2D((A, P) => i(A, P));
|
|
1788
|
+
const p = c.length(), y = f.length(), x = (p ** 2 + y ** 2) / (2 * y), S = f.end.clone().add(f.direction().multiplyScalar(-x)), [R, F] = this.getArcAngleRange(S, c.end, f.end);
|
|
1789
|
+
r(S, x, Math.min(R, F), Math.max(R, F)), a.push(u);
|
|
1754
1790
|
} else
|
|
1755
1791
|
c.clone().expansion(-this.width * 0.5).expandToRectangle(this.width).path2D((h, f) => i(h, f)), c.clone().directionMove(c.normal(), o * 0.5).directionMove(c.direction(), o * 0.5).expansion(-c.length() * 0.45, "end").forward(o * 0.5).expandToRectangle(o).path2D((h, f) => i(h, f)), c.clone().directionMove(c.normal(), -o * 0.5).directionMove(c.direction(), -o * 0.5).expansion(-c.length() * 0.45, "start").forward(-o * 0.5).expandToRectangle(o).path2D((h, f) => i(h, f));
|
|
1756
1792
|
}), s = "yellow", this.lineSegments.forEach((l) => {
|
|
1757
1793
|
if (!l.userData.isWindow) return !1;
|
|
1758
1794
|
Array.isArray(l.userData.drawWindow) && l.userData.drawWindow.forEach((c) => {
|
|
1759
1795
|
const { p: h, width: f } = c, u = w.from(h), p = u.clone().add(l.direction().multiplyScalar(f * 0.5)), y = u.clone().add(l.direction().multiplyScalar(-f * 0.5)), x = new B(p, y);
|
|
1760
|
-
i(x.start, x.end), x.expandToRectangle(this.width, "bothSides").path2D((S,
|
|
1796
|
+
i(x.start, x.end), x.expandToRectangle(this.width, "bothSides").path2D((S, R) => i(S, R));
|
|
1761
1797
|
});
|
|
1762
1798
|
}), n;
|
|
1763
1799
|
}
|
|
@@ -1771,7 +1807,7 @@ class X extends W {
|
|
|
1771
1807
|
if (typeof window < "u")
|
|
1772
1808
|
i = document.createElement("canvas");
|
|
1773
1809
|
else if (typeof global < "u") {
|
|
1774
|
-
const { createCanvas: l } = await
|
|
1810
|
+
const { createCanvas: l } = await K("canvas");
|
|
1775
1811
|
i = l();
|
|
1776
1812
|
} else
|
|
1777
1813
|
throw new Error("创建画布失败");
|
|
@@ -1800,8 +1836,8 @@ class X extends W {
|
|
|
1800
1836
|
* 将点json结构转换为Dxf string
|
|
1801
1837
|
*/
|
|
1802
1838
|
toDxfString(e = "Millimeters") {
|
|
1803
|
-
const t = new
|
|
1804
|
-
t.setUnits(e), t.addLayer("cyan",
|
|
1839
|
+
const t = new Q();
|
|
1840
|
+
t.setUnits(e), t.addLayer("cyan", Q.ACI.CYAN, "DOTTED"), t.addLayer("yellow", Q.ACI.YELLOW, "DOTTED"), t.addLayer("white", Q.ACI.WHITE, "DOTTED");
|
|
1805
1841
|
const n = this.toDrawDataJson();
|
|
1806
1842
|
return n.line.forEach((s) => {
|
|
1807
1843
|
let [i, r, o, a, l] = s;
|
|
@@ -1827,7 +1863,7 @@ class X extends W {
|
|
|
1827
1863
|
if (typeof window < "u") {
|
|
1828
1864
|
const n = new Blob([t], { type: "application/json" }), s = document.createElement("a");
|
|
1829
1865
|
s.href = URL.createObjectURL(n), s.download = e, s.click();
|
|
1830
|
-
} else typeof global < "u" && (await
|
|
1866
|
+
} else typeof global < "u" && (await K("fs", !1)).writeFileSync(e, t);
|
|
1831
1867
|
}
|
|
1832
1868
|
/**
|
|
1833
1869
|
* 下载
|
|
@@ -1837,7 +1873,7 @@ class X extends W {
|
|
|
1837
1873
|
if (typeof window < "u") {
|
|
1838
1874
|
const n = this.toDxfBlob(t), s = document.createElement("a");
|
|
1839
1875
|
s.href = URL.createObjectURL(n), s.download = e + ".dxf", s.click();
|
|
1840
|
-
} else typeof global < "u" && (await
|
|
1876
|
+
} else typeof global < "u" && (await K("fs", !1)).writeFileSync(e, this.toDxfString(t));
|
|
1841
1877
|
}
|
|
1842
1878
|
/**
|
|
1843
1879
|
* 下载
|
|
@@ -1849,7 +1885,7 @@ class X extends W {
|
|
|
1849
1885
|
if (typeof window < "u") {
|
|
1850
1886
|
const i = document.createElement("a");
|
|
1851
1887
|
i.href = URL.createObjectURL(s), i.download = e, i.click();
|
|
1852
|
-
} else typeof global < "u" ? (await
|
|
1888
|
+
} else typeof global < "u" ? (await K("fs", !1)).writeFileSync(e, s) : console.error("图片下载失败");
|
|
1853
1889
|
return !0;
|
|
1854
1890
|
}
|
|
1855
1891
|
/**
|
|
@@ -1891,217 +1927,291 @@ class X extends W {
|
|
|
1891
1927
|
* @returns
|
|
1892
1928
|
*/
|
|
1893
1929
|
static axisAlignmentCorrection(e, t) {
|
|
1894
|
-
function n(
|
|
1895
|
-
const
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
if (
|
|
1906
|
-
const
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
const N = D.get(R.point), F = D.get(I.point);
|
|
1912
|
-
return N - F;
|
|
1930
|
+
function n(M, L) {
|
|
1931
|
+
const g = [];
|
|
1932
|
+
for (let b = 0; b < M.length; b++) {
|
|
1933
|
+
const m = M[b], E = /* @__PURE__ */ new Map();
|
|
1934
|
+
m.userData.isDoor || m.points.forEach((T) => {
|
|
1935
|
+
if (L.queryPoint(T).length > 1) return;
|
|
1936
|
+
const I = L.queryCircle(T, 0.4).filter((D) => {
|
|
1937
|
+
const v = D.userData;
|
|
1938
|
+
if (v === m || !m.parallel(v, 25)) return !1;
|
|
1939
|
+
if (L.queryPoint(D.point).length > 1) return;
|
|
1940
|
+
const O = new B(T, D.point), q = new B(m.start === T ? m.end : m.start, v.start === D.point ? v.end : v.start);
|
|
1941
|
+
if (!O.intersectLineSegment(q)) return !1;
|
|
1942
|
+
const G = T.distance(D.point);
|
|
1943
|
+
return G < 1e-3 ? !1 : (E.set(D.point, G), !0);
|
|
1944
|
+
}).sort((D, v) => {
|
|
1945
|
+
const O = E.get(D.point), q = E.get(v.point);
|
|
1946
|
+
return O - q;
|
|
1913
1947
|
});
|
|
1914
|
-
if (
|
|
1915
|
-
const
|
|
1916
|
-
|
|
1948
|
+
if (I.length === 0) return;
|
|
1949
|
+
const N = I[0].userData;
|
|
1950
|
+
g.push(new B(m.projectLineSegment(N).center, N.projectLineSegment(m).center));
|
|
1917
1951
|
});
|
|
1918
1952
|
}
|
|
1919
|
-
return [...
|
|
1953
|
+
return [...M, ...g];
|
|
1920
1954
|
}
|
|
1921
|
-
function s(
|
|
1922
|
-
const L =
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1955
|
+
function s(M) {
|
|
1956
|
+
const L = new he(), g = new X(_.fromByLineSegment(...M)), b = [];
|
|
1957
|
+
return M.forEach((m) => {
|
|
1958
|
+
m.userData.isDoor ? b.push(m) : (m.points.forEach((E) => L.insert(E, m)), g.insert({ line: m, userData: void 0 }));
|
|
1959
|
+
}), b.forEach((m) => {
|
|
1960
|
+
const E = L.queryPoint(m.start), T = L.queryPoint(m.end);
|
|
1961
|
+
E.length ? m.userData.startIntersection = E[0].userData : m.userData.startIntersection = g.queryPoint(m.start)[0]?.line, T.length ? m.userData.endIntersection = T[0].userData : m.userData.endIntersection = g.queryPoint(m.end)[0]?.line;
|
|
1962
|
+
}), M = n(M, L), M;
|
|
1963
|
+
}
|
|
1964
|
+
function i(M, L) {
|
|
1965
|
+
const g = [M], b = [], m = [], E = [];
|
|
1966
|
+
for (let T = 0; T < L.length; T++) {
|
|
1967
|
+
const I = L[T];
|
|
1968
|
+
if (M !== I)
|
|
1969
|
+
if (I.userData.isWindow && E.push(I), I.parallel(M, 45)) {
|
|
1970
|
+
const N = Math.atan2(I.end.y - I.start.y, I.end.x - I.start.x);
|
|
1971
|
+
let v = Math.atan2(M.end.y - M.start.y, M.end.x - M.start.x) - N;
|
|
1972
|
+
for (; v > Math.PI; ) v -= 2 * Math.PI;
|
|
1973
|
+
for (; v < -Math.PI; ) v += 2 * Math.PI;
|
|
1974
|
+
const O = I.center;
|
|
1975
|
+
I.start.rotate(O, v), I.end.rotate(O, v), I.userData.isDoor ? m.push(I) : g.push(I);
|
|
1937
1976
|
} else {
|
|
1938
|
-
const
|
|
1939
|
-
let
|
|
1940
|
-
for (;
|
|
1941
|
-
for (;
|
|
1942
|
-
for (;
|
|
1943
|
-
for (;
|
|
1944
|
-
const
|
|
1945
|
-
|
|
1977
|
+
const N = Math.atan2(I.end.y - I.start.y, I.end.x - I.start.x), D = Math.atan2(M.end.y - M.start.y, M.end.x - M.start.x);
|
|
1978
|
+
let v = D + Math.PI / 2 - N, O = D - Math.PI / 2 - N;
|
|
1979
|
+
for (; v > Math.PI; ) v -= 2 * Math.PI;
|
|
1980
|
+
for (; v < -Math.PI; ) v += 2 * Math.PI;
|
|
1981
|
+
for (; O > Math.PI; ) O -= 2 * Math.PI;
|
|
1982
|
+
for (; O < -Math.PI; ) O += 2 * Math.PI;
|
|
1983
|
+
const q = Math.abs(v) < Math.abs(O) ? v : O, G = I.center;
|
|
1984
|
+
I.start.rotate(G, q), I.end.rotate(G, q), I.userData.isDoor ? m.push(I) : b.push(I);
|
|
1946
1985
|
}
|
|
1947
|
-
}
|
|
1948
1986
|
}
|
|
1949
|
-
return { parallelLines:
|
|
1987
|
+
return { parallelLines: g, verticalLines: b, doorLines: m, windowLines: E };
|
|
1950
1988
|
}
|
|
1951
|
-
function
|
|
1952
|
-
const
|
|
1953
|
-
|
|
1954
|
-
const
|
|
1955
|
-
|
|
1956
|
-
}),
|
|
1957
|
-
const T = [],
|
|
1958
|
-
for (let
|
|
1959
|
-
const
|
|
1960
|
-
if (
|
|
1961
|
-
|
|
1989
|
+
function r(M, L, g, b = 0.3, m = 0.1) {
|
|
1990
|
+
const E = [];
|
|
1991
|
+
M.forEach((N) => {
|
|
1992
|
+
const D = g.projectPoint(N.start, !1);
|
|
1993
|
+
D && (D.userData = N, E.push(D));
|
|
1994
|
+
}), E.sort((N, D) => D.distance(g.start) - N.distance(g.start));
|
|
1995
|
+
const T = [], I = [];
|
|
1996
|
+
for (let N = 0; N < E.length; N++) {
|
|
1997
|
+
const D = E[N];
|
|
1998
|
+
if (N === 0) {
|
|
1999
|
+
I.push(D);
|
|
1962
2000
|
continue;
|
|
1963
2001
|
}
|
|
1964
|
-
|
|
2002
|
+
E[N - 1].distance(D) < m || (T.push([...I]), I.length = 0), I.push(D), N === E.length - 1 && T.push(I);
|
|
1965
2003
|
}
|
|
1966
|
-
return T.flatMap((
|
|
1967
|
-
const
|
|
1968
|
-
const
|
|
1969
|
-
return
|
|
1970
|
-
const
|
|
1971
|
-
return
|
|
2004
|
+
return T.flatMap((N) => {
|
|
2005
|
+
const D = N.flatMap((G) => {
|
|
2006
|
+
const j = G.userData;
|
|
2007
|
+
return j.points.map((k) => {
|
|
2008
|
+
const z = L.projectPoint(k, !1);
|
|
2009
|
+
return z.userData = j, z;
|
|
1972
2010
|
});
|
|
1973
2011
|
});
|
|
1974
|
-
|
|
1975
|
-
const
|
|
1976
|
-
return
|
|
1977
|
-
|
|
1978
|
-
for (const
|
|
1979
|
-
|
|
1980
|
-
}),
|
|
2012
|
+
D.sort((G, j) => G.distance(L.start) - j.distance(L.start));
|
|
2013
|
+
const v = /* @__PURE__ */ new Map(), O = [], q = [];
|
|
2014
|
+
return D.forEach((G, j) => {
|
|
2015
|
+
v.size === 0 && j > 0 && D[j - 1].distance(G) > b && (O.push([...q]), q.length = 0), v.set(G.userData, (v.get(G.userData) ?? 0) + 1);
|
|
2016
|
+
for (const k of v.values()) if (k !== 2) return;
|
|
2017
|
+
q.push(...v.keys()), v.clear();
|
|
2018
|
+
}), O.push([...q]), O;
|
|
1981
2019
|
});
|
|
1982
2020
|
}
|
|
1983
|
-
function
|
|
1984
|
-
return
|
|
1985
|
-
if (
|
|
1986
|
-
if (
|
|
1987
|
-
const
|
|
1988
|
-
|
|
1989
|
-
|
|
2021
|
+
function o(M, L = 0.1) {
|
|
2022
|
+
return M.map((g) => {
|
|
2023
|
+
if (g.length === 0) return;
|
|
2024
|
+
if (g.length === 1) return g[0];
|
|
2025
|
+
const b = [];
|
|
2026
|
+
g.forEach((z) => {
|
|
2027
|
+
b.push(z.start.clone(), z.end.clone());
|
|
1990
2028
|
});
|
|
1991
|
-
const
|
|
1992
|
-
let
|
|
1993
|
-
|
|
1994
|
-
const
|
|
1995
|
-
|
|
2029
|
+
const m = g[0].direction().normalize();
|
|
2030
|
+
let E = 1 / 0, T = -1 / 0, I = 0, N = 0;
|
|
2031
|
+
b.forEach((z) => {
|
|
2032
|
+
const $ = z.x * m.x + z.y * m.y;
|
|
2033
|
+
E = Math.min(E, $), T = Math.max(T, $), I += z.x, N += z.y;
|
|
1996
2034
|
});
|
|
1997
|
-
const
|
|
1998
|
-
|
|
1999
|
-
const
|
|
2000
|
-
|
|
2035
|
+
const D = new w(I / b.length, N / b.length), v = D.x * m.x + D.y * m.y, O = new w(D.x + (E - v) * m.x, D.y + (E - v) * m.y), q = new w(D.x + (T - v) * m.x, D.y + (T - v) * m.y), G = new B(O, q), j = g[0].normal().normalize();
|
|
2036
|
+
E = 1 / 0, T = -1 / 0, b.forEach((z) => {
|
|
2037
|
+
const $ = z.x * j.x + z.y * j.y;
|
|
2038
|
+
E = Math.min(E, $), T = Math.max(T, $);
|
|
2001
2039
|
});
|
|
2002
|
-
const
|
|
2003
|
-
return
|
|
2004
|
-
}).filter((
|
|
2040
|
+
const k = T - E;
|
|
2041
|
+
return k >= L && (G.userData.wallWidth = k), g.forEach((z) => z.userData.fittedLine = G), G;
|
|
2042
|
+
}).filter((g) => !!g);
|
|
2005
2043
|
}
|
|
2006
|
-
function
|
|
2007
|
-
const
|
|
2008
|
-
|
|
2009
|
-
|
|
2044
|
+
function a(M, L = 0.2) {
|
|
2045
|
+
const g = new X(_.fromByLineSegment(...M)), b = /* @__PURE__ */ new Map();
|
|
2046
|
+
M.forEach((E) => {
|
|
2047
|
+
b.set(E, { line: E, userData: void 0 }), g.insert(b.get(E));
|
|
2010
2048
|
});
|
|
2011
|
-
const
|
|
2012
|
-
for (let
|
|
2013
|
-
const T =
|
|
2049
|
+
const m = new B();
|
|
2050
|
+
for (let E = 0; E < M.length; E++) {
|
|
2051
|
+
const T = M[E];
|
|
2014
2052
|
if (T.userData.isAdsorbed) continue;
|
|
2015
|
-
const
|
|
2016
|
-
|
|
2017
|
-
const
|
|
2018
|
-
const
|
|
2019
|
-
return
|
|
2020
|
-
}).sort((
|
|
2021
|
-
const
|
|
2022
|
-
return
|
|
2053
|
+
const I = T.direction().multiplyScalar(L), [N, D] = T.points.map((v) => {
|
|
2054
|
+
m.set(v, v), m.start.add(I), m.end.add(I.multiplyScalar(-1));
|
|
2055
|
+
const O = /* @__PURE__ */ new Map(), q = g.queryRect(m.expandToRectangle(0.1, "bothSides")).filter((G) => G.line !== T).map((G) => {
|
|
2056
|
+
const j = G.line.getIntersection(m);
|
|
2057
|
+
return O.set(G.line, j), G.line;
|
|
2058
|
+
}).sort((G, j) => {
|
|
2059
|
+
const k = O.get(G), z = O.get(j);
|
|
2060
|
+
return k && z ? k.distance(v) - z.distance(v) : 0;
|
|
2023
2061
|
});
|
|
2024
|
-
return
|
|
2062
|
+
return q.length ? O.get(q[0]) : void 0;
|
|
2025
2063
|
});
|
|
2026
|
-
if (
|
|
2027
|
-
if (
|
|
2028
|
-
const
|
|
2029
|
-
|
|
2064
|
+
if (N && D) {
|
|
2065
|
+
if (N.equal(D)) {
|
|
2066
|
+
const v = T.start.distance(N), O = T.end.distance(D);
|
|
2067
|
+
v < O ? T.directionMove(T.start.direction(T.end), v) : T.directionMove(T.end.direction(T.start), O);
|
|
2030
2068
|
} else
|
|
2031
|
-
T.start.copy(
|
|
2069
|
+
T.start.copy(N), T.end.copy(D);
|
|
2032
2070
|
T.userData.isAdsorbed = !0;
|
|
2033
|
-
} else
|
|
2034
|
-
|
|
2071
|
+
} else N ? T.start.copy(N) : D && T.end.copy(D);
|
|
2072
|
+
g.remove(b.get(T)), g.insert(b.get(T));
|
|
2035
2073
|
}
|
|
2036
|
-
return
|
|
2074
|
+
return M.filter((E) => E.length() > 1e-3);
|
|
2037
2075
|
}
|
|
2038
|
-
function
|
|
2039
|
-
for (let
|
|
2040
|
-
const
|
|
2041
|
-
if (
|
|
2042
|
-
const
|
|
2043
|
-
|
|
2044
|
-
const T = w.from(
|
|
2045
|
-
T.clone().add(
|
|
2046
|
-
),
|
|
2047
|
-
T.clone().add(
|
|
2048
|
-
),
|
|
2049
|
-
|
|
2050
|
-
p: new
|
|
2051
|
-
width:
|
|
2052
|
-
full:
|
|
2076
|
+
function l(M) {
|
|
2077
|
+
for (let L = 0; L < M.length; L++) {
|
|
2078
|
+
const g = M[L], b = g.userData.fittedLine;
|
|
2079
|
+
if (b) {
|
|
2080
|
+
const m = g.direction();
|
|
2081
|
+
b.userData.isWindow = !0, b.userData.drawWindow = b.userData.drawWindow ?? [], g.userData.drawWindow?.forEach((E) => {
|
|
2082
|
+
const T = w.from(E.p), I = b.projectPoint(
|
|
2083
|
+
T.clone().add(m.clone().multiplyScalar(E.width * 0.5))
|
|
2084
|
+
), N = b.projectPoint(
|
|
2085
|
+
T.clone().add(m.clone().multiplyScalar(E.width * -0.5))
|
|
2086
|
+
), D = new B(I, N), v = D.center;
|
|
2087
|
+
b.userData.drawWindow?.push({
|
|
2088
|
+
p: new U.Vector3(v?.x ?? 0, v?.y ?? 0, E.p.z),
|
|
2089
|
+
width: D.length(),
|
|
2090
|
+
full: E.full
|
|
2053
2091
|
});
|
|
2054
2092
|
});
|
|
2055
2093
|
}
|
|
2056
2094
|
}
|
|
2057
2095
|
}
|
|
2058
|
-
function
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2096
|
+
function c(M) {
|
|
2097
|
+
for (let L = 0; L < M.length; L++) {
|
|
2098
|
+
const g = M[L];
|
|
2099
|
+
let { endIntersection: b, startIntersection: m } = g.userData;
|
|
2100
|
+
if (!(!b || !m)) {
|
|
2101
|
+
if (m.userData.fittedLine && (m = m.userData.fittedLine), b.userData.fittedLine && (b = b.userData.fittedLine), g.isParallel(m))
|
|
2102
|
+
g.start.distance(m.start) < g.start.distance(m.end) ? g.start.copy(m.start) : g.start.copy(m.end);
|
|
2103
|
+
else {
|
|
2104
|
+
const E = m.projectPoint(g.start);
|
|
2105
|
+
E && g.start.copy(E);
|
|
2106
|
+
}
|
|
2107
|
+
if (g.isParallel(b))
|
|
2108
|
+
g.end.distance(b.start) < g.end.distance(b.end) ? g.end.copy(b.start) : g.end.copy(b.end);
|
|
2109
|
+
else {
|
|
2110
|
+
const E = b.projectPoint(g.end);
|
|
2111
|
+
E && g.end.copy(E);
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
return M;
|
|
2116
|
+
}
|
|
2117
|
+
function h(M) {
|
|
2118
|
+
const L = new X(_.fromByLineSegment(...M));
|
|
2119
|
+
return M.forEach((g) => L.insert({ line: g, userData: void 0 })), M.flatMap((g) => {
|
|
2120
|
+
const b = L.queryLineSegment(g, !0).map((m) => {
|
|
2121
|
+
if (m.line === g) return;
|
|
2122
|
+
const E = m.line.getIntersection(g);
|
|
2123
|
+
if (!(!E || g.start.equal(E) || g.end.equal(E)))
|
|
2124
|
+
return E;
|
|
2125
|
+
}).filter((m) => !!m);
|
|
2126
|
+
if (b.length) {
|
|
2127
|
+
const m = g.clone();
|
|
2128
|
+
b.sort((T, I) => m.start.distance(T) - m.start.distance(I));
|
|
2129
|
+
const E = b.map((T) => {
|
|
2130
|
+
const I = m.clone();
|
|
2131
|
+
return I.set(m.start.clone(), T), m.start.copy(T), m.userData.isWindow && (I.userData.isWindow = !0, I.userData.drawWindow = m.userData.drawWindow?.filter((N) => I.isPointOnSegment(w.from(N.p))) ?? []), I;
|
|
2073
2132
|
});
|
|
2074
|
-
return
|
|
2133
|
+
return m.userData.drawWindow = m.userData.drawWindow?.filter((T) => m.isPointOnSegment(w.from(T.p))) ?? [], [...E, m];
|
|
2075
2134
|
}
|
|
2076
|
-
return
|
|
2077
|
-
}).filter((
|
|
2135
|
+
return g;
|
|
2136
|
+
}).filter((g) => g.length() > 0.03);
|
|
2078
2137
|
}
|
|
2079
|
-
e =
|
|
2080
|
-
const { parallelLines:
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
),
|
|
2084
|
-
|
|
2085
|
-
|
|
2138
|
+
e = s(e.map((M) => M.clone()));
|
|
2139
|
+
const { parallelLines: f, verticalLines: u, doorLines: p, windowLines: y } = i(t, e), x = t.normal(), S = t.center, R = t.direction(), F = new B(
|
|
2140
|
+
S.clone().add(x.clone().multiplyScalar(-1e3)),
|
|
2141
|
+
S.clone().add(x.clone().multiplyScalar(1e3))
|
|
2142
|
+
), A = new B(
|
|
2143
|
+
S.clone().add(R.clone().multiplyScalar(-1e3)),
|
|
2144
|
+
S.clone().add(R.clone().multiplyScalar(1e3))
|
|
2086
2145
|
);
|
|
2087
|
-
let
|
|
2088
|
-
...
|
|
2089
|
-
...
|
|
2146
|
+
let P = o([
|
|
2147
|
+
...r.call(this, f, A, F),
|
|
2148
|
+
...r.call(this, u, F, A)
|
|
2090
2149
|
]);
|
|
2091
|
-
return
|
|
2150
|
+
return P = a.call(this, P), P = a.call(this, P), l(y), c(p), P = h.call(this, P), P.push(...p), P;
|
|
2151
|
+
}
|
|
2152
|
+
/**
|
|
2153
|
+
* @param lines
|
|
2154
|
+
* @param trajectoryPositions
|
|
2155
|
+
* @returns
|
|
2156
|
+
*/
|
|
2157
|
+
static excessLineSegments(e, t) {
|
|
2158
|
+
const n = new X(_.fromByLineSegment(...e));
|
|
2159
|
+
return e.forEach((s) => n.insert({ line: s, userData: void 0 })), e = e.filter((s) => {
|
|
2160
|
+
const i = s.center;
|
|
2161
|
+
for (const r of t) {
|
|
2162
|
+
const o = new B(i, r);
|
|
2163
|
+
if (!n.queryLineSegment(o).filter((l) => l.line !== s).length) return !1;
|
|
2164
|
+
}
|
|
2165
|
+
return !0;
|
|
2166
|
+
}), e.filter((s) => {
|
|
2167
|
+
const i = n.queryLineSegment(s).filter((r) => r.line !== s);
|
|
2168
|
+
for (let r = 0; r < i.length; r++) {
|
|
2169
|
+
const o = i[r];
|
|
2170
|
+
if (e.indexOf(o.line) === -1) return !1;
|
|
2171
|
+
}
|
|
2172
|
+
return !0;
|
|
2173
|
+
});
|
|
2174
|
+
}
|
|
2175
|
+
/** 边线外扩
|
|
2176
|
+
* @param lines
|
|
2177
|
+
* @param trajectory
|
|
2178
|
+
*/
|
|
2179
|
+
static boundaryExtension(e, t) {
|
|
2180
|
+
const s = this.parent?.findComponentByName("Renderer"), i = V.excessLineSegments(e, t);
|
|
2181
|
+
e = e.filter((o) => i.indexOf(o) === -1);
|
|
2182
|
+
const r = new X(_.fromByLineSegment(...e));
|
|
2183
|
+
e.forEach((o) => o.userData.isDoor || r.insert({ line: o, userData: void 0 }));
|
|
2184
|
+
for (let o = 0; o < e.length; o++) {
|
|
2185
|
+
if (e[o].userData.isDoor) continue;
|
|
2186
|
+
const a = e[o], l = a.direction(), c = a.normal(), h = a.center, f = 20;
|
|
2187
|
+
if ([
|
|
2188
|
+
h.expandAsLine(c, f),
|
|
2189
|
+
h.expandAsLine(c, -f),
|
|
2190
|
+
a.start.expandAsLine(l, -f),
|
|
2191
|
+
a.start.expandAsLine(c, f),
|
|
2192
|
+
a.start.expandAsLine(c, -f),
|
|
2193
|
+
a.end.expandAsLine(l, f),
|
|
2194
|
+
a.end.expandAsLine(c, f),
|
|
2195
|
+
a.end.expandAsLine(c, -f)
|
|
2196
|
+
].filter((y) => (y.directionMove(y.direction(), 1e-3), r.queryLineSegment(y, !1).filter((x) => x.line !== a).length === 0)).length) {
|
|
2197
|
+
const y = s.createLineSegments([a], 0, { color: 16711680 });
|
|
2198
|
+
y.position.z = 1e-3;
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
return e;
|
|
2092
2202
|
}
|
|
2093
2203
|
}
|
|
2094
|
-
function
|
|
2204
|
+
function ue(d) {
|
|
2095
2205
|
if (d === null || typeof d != "object") return d;
|
|
2096
2206
|
if (d instanceof Date) return new Date(d.getTime());
|
|
2097
|
-
if (Array.isArray(d)) return d.map(
|
|
2207
|
+
if (Array.isArray(d)) return d.map(ue);
|
|
2098
2208
|
const e = {};
|
|
2099
2209
|
for (const t in d)
|
|
2100
|
-
Object.prototype.hasOwnProperty.call(d, t) && (e[t] =
|
|
2210
|
+
Object.prototype.hasOwnProperty.call(d, t) && (e[t] = ue(d[t]));
|
|
2101
2211
|
return e;
|
|
2102
2212
|
}
|
|
2103
|
-
const
|
|
2104
|
-
class
|
|
2213
|
+
const W = new B();
|
|
2214
|
+
class et extends V {
|
|
2105
2215
|
static name = "AngleCorrectionDxf";
|
|
2106
2216
|
angle = 0;
|
|
2107
2217
|
onAddFromParent(e) {
|
|
@@ -2112,12 +2222,12 @@ class Ze extends X {
|
|
|
2112
2222
|
let s = 0, i = null;
|
|
2113
2223
|
for (let l = 0; l < t.originalData.length; l++) {
|
|
2114
2224
|
const c = t.originalData[l];
|
|
2115
|
-
if (
|
|
2116
|
-
const [h, f] = c.start.y < c.end.y ? [
|
|
2225
|
+
if (W.start.copy(c.start), W.end.copy(c.end), c.isVerticalReferenceLine) {
|
|
2226
|
+
const [h, f] = c.start.y < c.end.y ? [W.start, W.end] : [W.end, W.start];
|
|
2117
2227
|
s = -new B(h, f).direction().angleBetween(new w(0, 1), "angle", "360"), i = null;
|
|
2118
2228
|
break;
|
|
2119
2229
|
}
|
|
2120
|
-
(!i ||
|
|
2230
|
+
(!i || W.length() > i.length()) && (i = W.clone(), i.userData.index = l);
|
|
2121
2231
|
}
|
|
2122
2232
|
if (i) {
|
|
2123
2233
|
t.originalData[i.userData.index].isVerticalReferenceLine = !0;
|
|
@@ -2125,7 +2235,7 @@ class Ze extends X {
|
|
|
2125
2235
|
s = -new B(l, c).direction().angleBetween(new w(0, 1), "angle", "360");
|
|
2126
2236
|
}
|
|
2127
2237
|
const r = t.originalBox.center, o = w.zero(), a = t.originalData.map((l) => {
|
|
2128
|
-
const c = o.copy(l.start).division(r).rotate(w.zero(), s * (Math.PI / 180)).toJson(l.start.z), h = o.copy(l.end).division(r).rotate(w.zero(), s * (Math.PI / 180)).toJson(l.end.z), f = Object.assign(
|
|
2238
|
+
const c = o.copy(l.start).division(r).rotate(w.zero(), s * (Math.PI / 180)).toJson(l.start.z), h = o.copy(l.end).division(r).rotate(w.zero(), s * (Math.PI / 180)).toJson(l.end.z), f = Object.assign(ue(l), { start: c, end: h });
|
|
2129
2239
|
return f.drawWindow && f.drawWindow.forEach((u) => {
|
|
2130
2240
|
u.p = o.copy(u.p).division(r).rotate(w.zero(), s * (Math.PI / 180)).toJson(u.p.z);
|
|
2131
2241
|
}), f;
|
|
@@ -2146,7 +2256,7 @@ class Ze extends X {
|
|
|
2146
2256
|
});
|
|
2147
2257
|
}
|
|
2148
2258
|
}
|
|
2149
|
-
class
|
|
2259
|
+
class Te extends J {
|
|
2150
2260
|
static name = "Variable";
|
|
2151
2261
|
originalLineVisible = !0;
|
|
2152
2262
|
dxfVisible = !0;
|
|
@@ -2173,13 +2283,13 @@ class Ee extends W {
|
|
|
2173
2283
|
if (e in this) return this[e];
|
|
2174
2284
|
}
|
|
2175
2285
|
}
|
|
2176
|
-
class
|
|
2286
|
+
class tt {
|
|
2177
2287
|
// 所有可查找的点位
|
|
2178
2288
|
possibleDoorPoints = [];
|
|
2179
2289
|
doorPoint = [];
|
|
2180
2290
|
dxf;
|
|
2181
2291
|
// 包含所有点的虚拟网格
|
|
2182
|
-
pointVirtualGrid = new
|
|
2292
|
+
pointVirtualGrid = new he();
|
|
2183
2293
|
// 只包含可查找点的虚拟网格
|
|
2184
2294
|
findPointVirtualGrid;
|
|
2185
2295
|
quadtree;
|
|
@@ -2192,7 +2302,7 @@ class Qe {
|
|
|
2192
2302
|
lineAnalysis;
|
|
2193
2303
|
continueFind = !0;
|
|
2194
2304
|
constructor(e) {
|
|
2195
|
-
if (this.lineAnalysis = e, this.dxf = e.Dxf, this.findPointVirtualGrid = new
|
|
2305
|
+
if (this.lineAnalysis = e, this.dxf = e.Dxf, this.findPointVirtualGrid = new he(), this.quadtree = e.quadtree, this.resultList = e.resultList, this.lineSegments = e.lineSegmentList, this.dxf.doorLineSegment.length = 0, this.lineSegments.forEach((n) => {
|
|
2196
2306
|
this.pointVirtualGrid.insert(n.start, n), this.pointVirtualGrid.insert(n.end, n);
|
|
2197
2307
|
}), this.doorPoint = this.getDoorPoint(), !this.continueFind) return;
|
|
2198
2308
|
const t = this.searchDoubleLinePoint();
|
|
@@ -2250,7 +2360,7 @@ class Qe {
|
|
|
2250
2360
|
return this.lineSegments.forEach((t) => {
|
|
2251
2361
|
t.points.forEach((n, s) => {
|
|
2252
2362
|
for (let r = 0; r < this._pointsExcludeRule.length; r++) if (this._pointsExcludeRule[r](t, n, s)) return;
|
|
2253
|
-
this.pointVirtualGrid.queryPoint(n).filter((r) => r.userData !== t).length === 0 && e.push({ line: t, point: n, uuid:
|
|
2363
|
+
this.pointVirtualGrid.queryPoint(n).filter((r) => r.userData !== t).length === 0 && e.push({ line: t, point: n, uuid: le() });
|
|
2254
2364
|
});
|
|
2255
2365
|
}), e;
|
|
2256
2366
|
}
|
|
@@ -2272,7 +2382,7 @@ class Qe {
|
|
|
2272
2382
|
l.length && e.push({
|
|
2273
2383
|
line: l[0].userData,
|
|
2274
2384
|
point: o,
|
|
2275
|
-
uuid:
|
|
2385
|
+
uuid: le()
|
|
2276
2386
|
});
|
|
2277
2387
|
} else if (r.doorDirectConnection) {
|
|
2278
2388
|
this.continueFind = !1;
|
|
@@ -2306,56 +2416,56 @@ class Qe {
|
|
|
2306
2416
|
*/
|
|
2307
2417
|
searchNearby(e, t = [], n = this.doorSearchDistance, s = this.doorSearchNearAngle) {
|
|
2308
2418
|
const i = this.findPointVirtualGrid, r = this.quadtree;
|
|
2309
|
-
function o({ point: x, line: S },
|
|
2310
|
-
const
|
|
2311
|
-
S.start === x &&
|
|
2312
|
-
const
|
|
2313
|
-
for (let
|
|
2314
|
-
const g = t.findIndex((
|
|
2315
|
-
if (
|
|
2316
|
-
|
|
2317
|
-
const
|
|
2318
|
-
if (
|
|
2319
|
-
const
|
|
2320
|
-
|
|
2321
|
-
findData:
|
|
2322
|
-
findUuid:
|
|
2323
|
-
doorLine:
|
|
2324
|
-
doorUuid:
|
|
2419
|
+
function o({ point: x, line: S }, R, F) {
|
|
2420
|
+
const A = S.direction();
|
|
2421
|
+
S.start === x && A.multiplyScalar(-1);
|
|
2422
|
+
const P = i.queryCircle(x, n).filter((L) => L.userData !== S).sort((L, g) => L.point.distance(x) - g.point.distance(x)), M = [];
|
|
2423
|
+
for (let L = 0; L < P.length; L++) {
|
|
2424
|
+
const g = t.findIndex((N) => N.point === P[L].point), b = e[R].uuid, m = t[g].uuid;
|
|
2425
|
+
if (F.has(`${b}.${m}`)) continue;
|
|
2426
|
+
F.add(`${b}.${m}`), F.add(`${m}.${b}`);
|
|
2427
|
+
const E = P[L].point, T = new B(x.clone(), E.clone());
|
|
2428
|
+
if (T.direction().angleBetween(A, "angle") < s) {
|
|
2429
|
+
const N = e[g].line.direction();
|
|
2430
|
+
P[L].userData.start.equal(P[L].point) && N.multiplyScalar(-1), T.direction().multiplyScalar(-1).angleBetween(N, "angle") < s && (r.queryLineSegment(T).length || M.push({
|
|
2431
|
+
findData: P[L],
|
|
2432
|
+
findUuid: m,
|
|
2433
|
+
doorLine: T,
|
|
2434
|
+
doorUuid: b
|
|
2325
2435
|
}));
|
|
2326
2436
|
}
|
|
2327
2437
|
}
|
|
2328
|
-
return
|
|
2438
|
+
return M;
|
|
2329
2439
|
}
|
|
2330
|
-
function a(x, S,
|
|
2331
|
-
|
|
2332
|
-
const
|
|
2333
|
-
|
|
2334
|
-
for (let
|
|
2335
|
-
const
|
|
2336
|
-
if (S.has(
|
|
2337
|
-
const g = S.get(
|
|
2338
|
-
a(
|
|
2339
|
-
} else
|
|
2440
|
+
function a(x, S, R, F, A) {
|
|
2441
|
+
F.add(x);
|
|
2442
|
+
const P = [];
|
|
2443
|
+
A && P.push(A);
|
|
2444
|
+
for (let M = 0; M < R.length; M++) {
|
|
2445
|
+
const L = R[M];
|
|
2446
|
+
if (S.has(L.findUuid)) {
|
|
2447
|
+
const g = S.get(L.findUuid);
|
|
2448
|
+
a(L.findUuid, S, g, F, L) && P.push(L);
|
|
2449
|
+
} else P.push(L);
|
|
2340
2450
|
}
|
|
2341
|
-
return
|
|
2451
|
+
return P.sort((M, L) => M.doorLine.length() - L.doorLine.length()), A && P[0] === A ? (R.splice(0), !0) : (R.splice(1), !1);
|
|
2342
2452
|
}
|
|
2343
2453
|
const l = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Map();
|
|
2344
2454
|
e.map((x, S) => {
|
|
2345
|
-
const
|
|
2346
|
-
|
|
2455
|
+
const R = o(x, S, l);
|
|
2456
|
+
R.length && c.set(x.uuid, R);
|
|
2347
2457
|
}), l.clear();
|
|
2348
2458
|
const h = /* @__PURE__ */ new Map();
|
|
2349
2459
|
c.forEach((x, S) => {
|
|
2350
2460
|
if (!l.has(S) && x.length && a(S, c, x, l), x.length) {
|
|
2351
|
-
const
|
|
2352
|
-
h.has(
|
|
2461
|
+
const R = x[0];
|
|
2462
|
+
h.has(R.doorUuid) || h.set(R.doorUuid, []), h.get(R.doorUuid)?.push(R), h.has(R.findUuid) || h.set(R.findUuid, []), h.get(R.findUuid)?.push(R);
|
|
2353
2463
|
}
|
|
2354
2464
|
});
|
|
2355
2465
|
const f = /* @__PURE__ */ new Set();
|
|
2356
2466
|
h.forEach((x) => {
|
|
2357
2467
|
if (x.length > 1) {
|
|
2358
|
-
x.sort((S,
|
|
2468
|
+
x.sort((S, R) => S.doorLine.length() - R.doorLine.length());
|
|
2359
2469
|
for (let S = 1; S < x.length; S++) f.add(x[S]);
|
|
2360
2470
|
}
|
|
2361
2471
|
});
|
|
@@ -2368,21 +2478,21 @@ class Qe {
|
|
|
2368
2478
|
});
|
|
2369
2479
|
const y = [];
|
|
2370
2480
|
return u.forEach((x) => {
|
|
2371
|
-
const S = e.findIndex((g) => g.uuid === x.doorUuid),
|
|
2372
|
-
if (
|
|
2373
|
-
|
|
2374
|
-
const g = new B(
|
|
2375
|
-
(
|
|
2376
|
-
start:
|
|
2377
|
-
end:
|
|
2481
|
+
const S = e.findIndex((g) => g.uuid === x.doorUuid), R = t.findIndex((g) => g.uuid === x.findUuid), F = e[S].point.clone(), A = t[R].point.clone(), P = this.findLongLineSegment(e[S].line), M = this.findLongLineSegment(t[R].line), L = P.projectPoint(A);
|
|
2482
|
+
if (L) {
|
|
2483
|
+
F.copy(L);
|
|
2484
|
+
const g = new B(F, A), b = M.includedAngle(g);
|
|
2485
|
+
(b < 10 || b > 170 || Math.abs(90 - b) < 10) && y.push({
|
|
2486
|
+
start: F,
|
|
2487
|
+
end: A
|
|
2378
2488
|
});
|
|
2379
2489
|
} else {
|
|
2380
|
-
const g =
|
|
2381
|
-
g &&
|
|
2382
|
-
const
|
|
2383
|
-
(
|
|
2384
|
-
start:
|
|
2385
|
-
end:
|
|
2490
|
+
const g = M.projectPoint(F);
|
|
2491
|
+
g && A.copy(g);
|
|
2492
|
+
const b = new B(F, A), m = P.includedAngle(b);
|
|
2493
|
+
(m < 10 || m > 170 || Math.abs(90 - m) < 10) && y.push({
|
|
2494
|
+
start: F,
|
|
2495
|
+
end: A
|
|
2386
2496
|
});
|
|
2387
2497
|
}
|
|
2388
2498
|
}), t.splice(
|
|
@@ -2464,12 +2574,12 @@ class Qe {
|
|
|
2464
2574
|
return t;
|
|
2465
2575
|
}
|
|
2466
2576
|
}
|
|
2467
|
-
class
|
|
2577
|
+
class nt extends J {
|
|
2468
2578
|
static name = "LineAnalysis";
|
|
2469
2579
|
Dxf = null;
|
|
2470
2580
|
Variable = null;
|
|
2471
2581
|
lineSegmentList = [];
|
|
2472
|
-
container = new
|
|
2582
|
+
container = new U.Group();
|
|
2473
2583
|
// 误差角度
|
|
2474
2584
|
errorAngle = 4;
|
|
2475
2585
|
width = 0.4;
|
|
@@ -2478,7 +2588,7 @@ class et extends W {
|
|
|
2478
2588
|
* @param parent
|
|
2479
2589
|
*/
|
|
2480
2590
|
onAddFromParent(e) {
|
|
2481
|
-
this.Dxf = e.findComponentByType(
|
|
2591
|
+
this.Dxf = e.findComponentByType(V), this.Variable = this.parent?.findComponentByType(Te), this.Dxf.addEventListener("setDta", this.lineAnalysis.bind(this)), this.Dxf.addEventListener("createGroup", this.doorsAnalysis.bind(this));
|
|
2482
2592
|
}
|
|
2483
2593
|
/**
|
|
2484
2594
|
*
|
|
@@ -2520,12 +2630,12 @@ class et extends W {
|
|
|
2520
2630
|
n.includedAngle(s) > 135 && (s.points = [s.points[1], s.points[0]]), this.addData(n.points[0], s.points[0]), this.addData(n.points[1], s.points[1]);
|
|
2521
2631
|
const i = n.points[0].distance(s.points[0]), r = n.points[1].distance(s.points[1]), o = Math.ceil(Math.max(i, r) / t.width), a = i / o, l = r / o, c = s.points[0].direction(n.points[0]), h = s.points[1].direction(n.points[1]), f = n.points[0].clone(), u = n.points[1].clone(), p = u.direction(f);
|
|
2522
2632
|
p.multiplyScalar(t.width * 0.5);
|
|
2523
|
-
const y = f.clone().add(p), x = u.clone().add(p.multiplyScalar(-1)), S = f.direction(u),
|
|
2524
|
-
if (!(S.x > 0 &&
|
|
2633
|
+
const y = f.clone().add(p), x = u.clone().add(p.multiplyScalar(-1)), S = f.direction(u), R = y.direction(x);
|
|
2634
|
+
if (!(S.x > 0 && R.x < 0 || S.x < 0 && R.x > 0 || S.y > 0 && R.y < 0 || S.y < 0 && R.y > 0)) {
|
|
2525
2635
|
f.set(y.x, y.y), u.set(x.x, x.y);
|
|
2526
|
-
for (let
|
|
2527
|
-
const
|
|
2528
|
-
this.addData(
|
|
2636
|
+
for (let F = 1; F < o; F++) {
|
|
2637
|
+
const A = c.clone().multiplyScalar(a * F), P = h.clone().multiplyScalar(l * F), M = f.clone().add(A), L = u.clone().add(P);
|
|
2638
|
+
this.addData(M, L);
|
|
2529
2639
|
}
|
|
2530
2640
|
}
|
|
2531
2641
|
}
|
|
@@ -2535,7 +2645,7 @@ class et extends W {
|
|
|
2535
2645
|
*/
|
|
2536
2646
|
buildQuadtree() {
|
|
2537
2647
|
const e = this.Dxf, t = [];
|
|
2538
|
-
this.quadtree = new
|
|
2648
|
+
this.quadtree = new X(e.originalBox, 2), e.lineSegments.forEach((n) => {
|
|
2539
2649
|
n.userData?.isDoor || (this.quadtree?.insert({
|
|
2540
2650
|
line: n,
|
|
2541
2651
|
userData: t.length
|
|
@@ -2552,7 +2662,7 @@ class et extends W {
|
|
|
2552
2662
|
this.buildQuadtree();
|
|
2553
2663
|
const e = this.quadtree, t = this.lineSegmentList, n = /* @__PURE__ */ new Set(), s = [];
|
|
2554
2664
|
t.forEach((i, r) => {
|
|
2555
|
-
const o = t[r], a =
|
|
2665
|
+
const o = t[r], a = se.fromByLineSegment(o, this.width * 2, !1, -0.01);
|
|
2556
2666
|
e.queryRect(a).map((c) => c.userData).filter((c) => c !== r).forEach((c) => {
|
|
2557
2667
|
try {
|
|
2558
2668
|
if (n.has(`${r}-${c}`) || n.has(`${c}-${r}`)) return;
|
|
@@ -2596,12 +2706,12 @@ class et extends W {
|
|
|
2596
2706
|
doors = [];
|
|
2597
2707
|
DoorsAnalysis;
|
|
2598
2708
|
doorsAnalysis() {
|
|
2599
|
-
this.DoorsAnalysis = new
|
|
2709
|
+
this.DoorsAnalysis = new tt(this), this.dispatchEvent({
|
|
2600
2710
|
type: "analysisCompleted"
|
|
2601
2711
|
});
|
|
2602
2712
|
}
|
|
2603
2713
|
}
|
|
2604
|
-
class
|
|
2714
|
+
class st extends J {
|
|
2605
2715
|
static name = "ThreeVJia";
|
|
2606
2716
|
lineSegments = [];
|
|
2607
2717
|
onAddFromParent() {
|
|
@@ -2723,10 +2833,10 @@ class tt extends W {
|
|
|
2723
2833
|
if (typeof window < "u") {
|
|
2724
2834
|
const t = new Blob([JSON.stringify(this.toJson())]), n = document.createElement("a");
|
|
2725
2835
|
n.href = URL.createObjectURL(t), n.download = e, n.click();
|
|
2726
|
-
} else typeof global < "u" && (await
|
|
2836
|
+
} else typeof global < "u" && (await K("fs", !1)).writeFileSync(e, JSON.stringify(this.toJson()));
|
|
2727
2837
|
}
|
|
2728
2838
|
}
|
|
2729
|
-
class
|
|
2839
|
+
class it extends Ze {
|
|
2730
2840
|
Dxf;
|
|
2731
2841
|
AngleCorrectionDxf;
|
|
2732
2842
|
Variable;
|
|
@@ -2737,7 +2847,7 @@ class nt extends Ke {
|
|
|
2737
2847
|
* @param scale 原始数据缩放比例
|
|
2738
2848
|
*/
|
|
2739
2849
|
constructor(e = 0.1, t = 1) {
|
|
2740
|
-
super(), this.environment = typeof window < "u" ? "browser" : typeof global < "u" ? "node" : "unknown", this.wallWidth = e, this.Dxf = new
|
|
2850
|
+
super(), this.environment = typeof window < "u" ? "browser" : typeof global < "u" ? "node" : "unknown", this.wallWidth = e, this.Dxf = new V(this.wallWidth, t), this.AngleCorrectionDxf = new et(), this.Variable = new Te(), this.addComponent(this.Variable), this.addComponent(this.Dxf), this.addComponent(new nt()), this.addComponent(this.AngleCorrectionDxf), this.addComponent(new st());
|
|
2741
2851
|
}
|
|
2742
2852
|
usePlugin(e) {
|
|
2743
2853
|
return typeof e == "function" && e.call(this, this), this;
|
|
@@ -2750,7 +2860,7 @@ class nt extends Ke {
|
|
|
2750
2860
|
});
|
|
2751
2861
|
}
|
|
2752
2862
|
}
|
|
2753
|
-
const
|
|
2863
|
+
const me = {
|
|
2754
2864
|
POSITION: [
|
|
2755
2865
|
"byte",
|
|
2756
2866
|
"byte normalized",
|
|
@@ -2778,36 +2888,36 @@ const xe = {
|
|
|
2778
2888
|
"unsigned short"
|
|
2779
2889
|
]
|
|
2780
2890
|
};
|
|
2781
|
-
class
|
|
2891
|
+
class ne {
|
|
2782
2892
|
constructor() {
|
|
2783
2893
|
this.textureUtils = null, this.pluginCallbacks = [], this.register(function(e) {
|
|
2784
|
-
return new
|
|
2785
|
-
}), this.register(function(e) {
|
|
2786
|
-
return new pt(e);
|
|
2787
|
-
}), this.register(function(e) {
|
|
2788
|
-
return new gt(e);
|
|
2894
|
+
return new xt(e);
|
|
2789
2895
|
}), this.register(function(e) {
|
|
2790
|
-
return new
|
|
2896
|
+
return new yt(e);
|
|
2791
2897
|
}), this.register(function(e) {
|
|
2792
2898
|
return new Mt(e);
|
|
2793
2899
|
}), this.register(function(e) {
|
|
2794
|
-
return new
|
|
2900
|
+
return new Lt(e);
|
|
2795
2901
|
}), this.register(function(e) {
|
|
2796
|
-
return new
|
|
2902
|
+
return new St(e);
|
|
2797
2903
|
}), this.register(function(e) {
|
|
2798
|
-
return new
|
|
2904
|
+
return new At(e);
|
|
2799
2905
|
}), this.register(function(e) {
|
|
2800
2906
|
return new mt(e);
|
|
2801
2907
|
}), this.register(function(e) {
|
|
2802
|
-
return new
|
|
2908
|
+
return new gt(e);
|
|
2909
|
+
}), this.register(function(e) {
|
|
2910
|
+
return new wt(e);
|
|
2803
2911
|
}), this.register(function(e) {
|
|
2804
2912
|
return new Et(e);
|
|
2805
2913
|
}), this.register(function(e) {
|
|
2806
2914
|
return new Tt(e);
|
|
2807
|
-
}), this.register(function(e) {
|
|
2808
|
-
return new At(e);
|
|
2809
2915
|
}), this.register(function(e) {
|
|
2810
2916
|
return new Dt(e);
|
|
2917
|
+
}), this.register(function(e) {
|
|
2918
|
+
return new bt(e);
|
|
2919
|
+
}), this.register(function(e) {
|
|
2920
|
+
return new It(e);
|
|
2811
2921
|
});
|
|
2812
2922
|
}
|
|
2813
2923
|
register(e) {
|
|
@@ -2820,7 +2930,7 @@ class ee {
|
|
|
2820
2930
|
return this.textureUtils = e, this;
|
|
2821
2931
|
}
|
|
2822
2932
|
parse(e, t, n, s) {
|
|
2823
|
-
const i = new
|
|
2933
|
+
const i = new pt(), r = [];
|
|
2824
2934
|
for (let o = 0, a = this.pluginCallbacks.length; o < a; o++)
|
|
2825
2935
|
r.push(this.pluginCallbacks[o](i));
|
|
2826
2936
|
i.setPlugins(r), i.setTextureUtils(this.textureUtils), i.writeAsync(e, t, s).catch(n);
|
|
@@ -2832,7 +2942,7 @@ class ee {
|
|
|
2832
2942
|
});
|
|
2833
2943
|
}
|
|
2834
2944
|
}
|
|
2835
|
-
const
|
|
2945
|
+
const C = {
|
|
2836
2946
|
POINTS: 0,
|
|
2837
2947
|
LINES: 1,
|
|
2838
2948
|
LINE_LOOP: 2,
|
|
@@ -2856,34 +2966,34 @@ const v = {
|
|
|
2856
2966
|
CLAMP_TO_EDGE: 33071,
|
|
2857
2967
|
MIRRORED_REPEAT: 33648,
|
|
2858
2968
|
REPEAT: 10497
|
|
2859
|
-
},
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
const
|
|
2969
|
+
}, re = "KHR_mesh_quantization", Y = {};
|
|
2970
|
+
Y[qe] = C.NEAREST;
|
|
2971
|
+
Y[je] = C.NEAREST_MIPMAP_NEAREST;
|
|
2972
|
+
Y[Ye] = C.NEAREST_MIPMAP_LINEAR;
|
|
2973
|
+
Y[Xe] = C.LINEAR;
|
|
2974
|
+
Y[ke] = C.LINEAR_MIPMAP_NEAREST;
|
|
2975
|
+
Y[Ve] = C.LINEAR_MIPMAP_LINEAR;
|
|
2976
|
+
Y[We] = C.CLAMP_TO_EDGE;
|
|
2977
|
+
Y[He] = C.REPEAT;
|
|
2978
|
+
Y[Je] = C.MIRRORED_REPEAT;
|
|
2979
|
+
const ge = {
|
|
2870
2980
|
scale: "scale",
|
|
2871
2981
|
position: "translation",
|
|
2872
2982
|
quaternion: "rotation",
|
|
2873
2983
|
morphTargetInfluences: "weights"
|
|
2874
|
-
},
|
|
2875
|
-
function
|
|
2984
|
+
}, rt = new ve(), we = 12, ot = 1179937895, at = 2, Me = 8, ct = 1313821514, lt = 5130562;
|
|
2985
|
+
function Z(d, e) {
|
|
2876
2986
|
return d.length === e.length && d.every(function(t, n) {
|
|
2877
2987
|
return t === e[n];
|
|
2878
2988
|
});
|
|
2879
2989
|
}
|
|
2880
|
-
function
|
|
2990
|
+
function ht(d) {
|
|
2881
2991
|
return new TextEncoder().encode(d).buffer;
|
|
2882
2992
|
}
|
|
2883
|
-
function
|
|
2884
|
-
return
|
|
2993
|
+
function ut(d) {
|
|
2994
|
+
return Z(d.elements, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
2885
2995
|
}
|
|
2886
|
-
function
|
|
2996
|
+
function dt(d, e, t) {
|
|
2887
2997
|
const n = {
|
|
2888
2998
|
min: new Array(d.itemSize).fill(Number.POSITIVE_INFINITY),
|
|
2889
2999
|
max: new Array(d.itemSize).fill(Number.NEGATIVE_INFINITY)
|
|
@@ -2891,15 +3001,15 @@ function ht(d, e, t) {
|
|
|
2891
3001
|
for (let s = e; s < e + t; s++)
|
|
2892
3002
|
for (let i = 0; i < d.itemSize; i++) {
|
|
2893
3003
|
let r;
|
|
2894
|
-
d.itemSize > 4 ? r = d.array[s * d.itemSize + i] : (i === 0 ? r = d.getX(s) : i === 1 ? r = d.getY(s) : i === 2 ? r = d.getZ(s) : i === 3 && (r = d.getW(s)), d.normalized === !0 && (r =
|
|
3004
|
+
d.itemSize > 4 ? r = d.array[s * d.itemSize + i] : (i === 0 ? r = d.getX(s) : i === 1 ? r = d.getY(s) : i === 2 ? r = d.getZ(s) : i === 3 && (r = d.getW(s)), d.normalized === !0 && (r = ce.normalize(r, d.array))), n.min[i] = Math.min(n.min[i], r), n.max[i] = Math.max(n.max[i], r);
|
|
2895
3005
|
}
|
|
2896
3006
|
return n;
|
|
2897
3007
|
}
|
|
2898
|
-
function
|
|
3008
|
+
function De(d) {
|
|
2899
3009
|
return Math.ceil(d / 4) * 4;
|
|
2900
3010
|
}
|
|
2901
|
-
function
|
|
2902
|
-
const t =
|
|
3011
|
+
function oe(d, e = 0) {
|
|
3012
|
+
const t = De(d.byteLength);
|
|
2903
3013
|
if (t !== d.byteLength) {
|
|
2904
3014
|
const n = new Uint8Array(t);
|
|
2905
3015
|
if (n.set(new Uint8Array(d)), e !== 0)
|
|
@@ -2909,10 +3019,10 @@ function ie(d, e = 0) {
|
|
|
2909
3019
|
}
|
|
2910
3020
|
return d;
|
|
2911
3021
|
}
|
|
2912
|
-
function
|
|
3022
|
+
function Le() {
|
|
2913
3023
|
return typeof document > "u" && typeof OffscreenCanvas < "u" ? new OffscreenCanvas(1, 1) : document.createElement("canvas");
|
|
2914
3024
|
}
|
|
2915
|
-
function
|
|
3025
|
+
function ft(d, e) {
|
|
2916
3026
|
if (typeof OffscreenCanvas < "u" && d instanceof OffscreenCanvas) {
|
|
2917
3027
|
let t;
|
|
2918
3028
|
return e === "image/jpeg" ? t = 0.92 : e === "image/webp" && (t = 0.8), d.convertToBlob({
|
|
@@ -2922,12 +3032,12 @@ function ut(d, e) {
|
|
|
2922
3032
|
} else
|
|
2923
3033
|
return new Promise((t) => d.toBlob(t, e));
|
|
2924
3034
|
}
|
|
2925
|
-
class
|
|
3035
|
+
class pt {
|
|
2926
3036
|
constructor() {
|
|
2927
3037
|
this.plugins = [], this.options = {}, this.pending = [], this.buffers = [], this.byteOffset = 0, this.buffers = [], this.nodeMap = /* @__PURE__ */ new Map(), this.skins = [], this.extensionsUsed = {}, this.extensionsRequired = {}, this.uids = /* @__PURE__ */ new Map(), this.uid = 0, this.json = {
|
|
2928
3038
|
asset: {
|
|
2929
3039
|
version: "2.0",
|
|
2930
|
-
generator: "THREE.GLTFExporter r" +
|
|
3040
|
+
generator: "THREE.GLTFExporter r" + Ce
|
|
2931
3041
|
}
|
|
2932
3042
|
}, this.cache = {
|
|
2933
3043
|
meshes: /* @__PURE__ */ new Map(),
|
|
@@ -2964,26 +3074,26 @@ class dt {
|
|
|
2964
3074
|
const s = this, i = s.buffers, r = s.json;
|
|
2965
3075
|
n = s.options;
|
|
2966
3076
|
const o = s.extensionsUsed, a = s.extensionsRequired, l = new Blob(i, { type: "application/octet-stream" }), c = Object.keys(o), h = Object.keys(a);
|
|
2967
|
-
c.length > 0 && (r.extensionsUsed = c), h.length > 0 && (r.extensionsRequired = h), r.buffers && r.buffers.length > 0 && (r.buffers[0].byteLength = l.size), n.binary === !0 ?
|
|
2968
|
-
const u =
|
|
2969
|
-
p.setUint32(0, u.byteLength, !0), p.setUint32(4,
|
|
2970
|
-
const y =
|
|
2971
|
-
x.setUint32(0, y.byteLength, !0), x.setUint32(4,
|
|
2972
|
-
const S = new ArrayBuffer(
|
|
2973
|
-
|
|
2974
|
-
const
|
|
2975
|
-
|
|
2976
|
-
const
|
|
3077
|
+
c.length > 0 && (r.extensionsUsed = c), h.length > 0 && (r.extensionsRequired = h), r.buffers && r.buffers.length > 0 && (r.buffers[0].byteLength = l.size), n.binary === !0 ? ae(l).then(function(f) {
|
|
3078
|
+
const u = oe(f), p = new DataView(new ArrayBuffer(Me));
|
|
3079
|
+
p.setUint32(0, u.byteLength, !0), p.setUint32(4, lt, !0);
|
|
3080
|
+
const y = oe(ht(JSON.stringify(r)), 32), x = new DataView(new ArrayBuffer(Me));
|
|
3081
|
+
x.setUint32(0, y.byteLength, !0), x.setUint32(4, ct, !0);
|
|
3082
|
+
const S = new ArrayBuffer(we), R = new DataView(S);
|
|
3083
|
+
R.setUint32(0, ot, !0), R.setUint32(4, at, !0);
|
|
3084
|
+
const F = we + x.byteLength + y.byteLength + p.byteLength + u.byteLength;
|
|
3085
|
+
R.setUint32(8, F, !0);
|
|
3086
|
+
const A = new Blob([
|
|
2977
3087
|
S,
|
|
2978
3088
|
x,
|
|
2979
3089
|
y,
|
|
2980
3090
|
p,
|
|
2981
3091
|
u
|
|
2982
3092
|
], { type: "application/octet-stream" });
|
|
2983
|
-
|
|
2984
|
-
t(
|
|
3093
|
+
ae(A).then((P) => {
|
|
3094
|
+
t(P);
|
|
2985
3095
|
});
|
|
2986
|
-
}) : r.buffers && r.buffers.length > 0 ?
|
|
3096
|
+
}) : r.buffers && r.buffers.length > 0 ? Rt(l).then((f) => {
|
|
2987
3097
|
r.buffers[0].uri = f, t(r);
|
|
2988
3098
|
}) : t(r);
|
|
2989
3099
|
}
|
|
@@ -3031,7 +3141,7 @@ class dt {
|
|
|
3031
3141
|
*/
|
|
3032
3142
|
isNormalizedNormalAttribute(e) {
|
|
3033
3143
|
if (this.cache.attributesNormalized.has(e)) return !1;
|
|
3034
|
-
const n = new
|
|
3144
|
+
const n = new ee();
|
|
3035
3145
|
for (let s = 0, i = e.count; s < i; s++)
|
|
3036
3146
|
if (Math.abs(n.fromBufferAttribute(e, s).length() - 1) > 5e-4) return !1;
|
|
3037
3147
|
return !0;
|
|
@@ -3046,7 +3156,7 @@ class dt {
|
|
|
3046
3156
|
createNormalizedNormalAttribute(e) {
|
|
3047
3157
|
const t = this.cache;
|
|
3048
3158
|
if (t.attributesNormalized.has(e)) return t.attributesNormalized.get(e);
|
|
3049
|
-
const n = e.clone(), s = new
|
|
3159
|
+
const n = e.clone(), s = new ee();
|
|
3050
3160
|
for (let i = 0, r = n.count; i < r; i++)
|
|
3051
3161
|
s.fromBufferAttribute(n, i), s.x === 0 && s.y === 0 && s.z === 0 ? s.setX(1) : s.normalize(), n.setXYZ(i, s.x, s.y, s.z);
|
|
3052
3162
|
return t.attributesNormalized.set(e, n), n;
|
|
@@ -3066,14 +3176,14 @@ class dt {
|
|
|
3066
3176
|
async buildMetalRoughTextureAsync(e, t) {
|
|
3067
3177
|
if (e === t) return e;
|
|
3068
3178
|
function n(u) {
|
|
3069
|
-
return u.colorSpace ===
|
|
3179
|
+
return u.colorSpace === ze ? function(y) {
|
|
3070
3180
|
return y < 0.04045 ? y * 0.0773993808 : Math.pow(y * 0.9478672986 + 0.0521327014, 2.4);
|
|
3071
3181
|
} : function(y) {
|
|
3072
3182
|
return y;
|
|
3073
3183
|
};
|
|
3074
3184
|
}
|
|
3075
|
-
e instanceof
|
|
3076
|
-
const s = e ? e.image : null, i = t ? t.image : null, r = Math.max(s ? s.width : 0, i ? i.width : 0), o = Math.max(s ? s.height : 0, i ? i.height : 0), a =
|
|
3185
|
+
e instanceof ie && (e = await this.decompressTextureAsync(e)), t instanceof ie && (t = await this.decompressTextureAsync(t));
|
|
3186
|
+
const s = e ? e.image : null, i = t ? t.image : null, r = Math.max(s ? s.width : 0, i ? i.width : 0), o = Math.max(s ? s.height : 0, i ? i.height : 0), a = Le();
|
|
3077
3187
|
a.width = r, a.height = o;
|
|
3078
3188
|
const l = a.getContext("2d", {
|
|
3079
3189
|
willReadFrequently: !0
|
|
@@ -3094,7 +3204,7 @@ class dt {
|
|
|
3094
3204
|
}
|
|
3095
3205
|
l.putImageData(c, 0, 0);
|
|
3096
3206
|
const f = (e || t).clone();
|
|
3097
|
-
return f.source = new
|
|
3207
|
+
return f.source = new Be(a), f.colorSpace = Oe, f.channel = (e || t).channel, e && t && e.channel !== t.channel && console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match."), console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures."), f;
|
|
3098
3208
|
}
|
|
3099
3209
|
async decompressTextureAsync(e, t = 1 / 0) {
|
|
3100
3210
|
if (this.textureUtils === null)
|
|
@@ -3124,25 +3234,25 @@ class dt {
|
|
|
3124
3234
|
r.bufferViews || (r.bufferViews = []);
|
|
3125
3235
|
let o;
|
|
3126
3236
|
switch (t) {
|
|
3127
|
-
case
|
|
3128
|
-
case
|
|
3237
|
+
case C.BYTE:
|
|
3238
|
+
case C.UNSIGNED_BYTE:
|
|
3129
3239
|
o = 1;
|
|
3130
3240
|
break;
|
|
3131
|
-
case
|
|
3132
|
-
case
|
|
3241
|
+
case C.SHORT:
|
|
3242
|
+
case C.UNSIGNED_SHORT:
|
|
3133
3243
|
o = 2;
|
|
3134
3244
|
break;
|
|
3135
3245
|
default:
|
|
3136
3246
|
o = 4;
|
|
3137
3247
|
}
|
|
3138
3248
|
let a = e.itemSize * o;
|
|
3139
|
-
i ===
|
|
3140
|
-
const l =
|
|
3249
|
+
i === C.ARRAY_BUFFER && (a = Math.ceil(a / 4) * 4);
|
|
3250
|
+
const l = De(s * a), c = new DataView(new ArrayBuffer(l));
|
|
3141
3251
|
let h = 0;
|
|
3142
3252
|
for (let p = n; p < n + s; p++) {
|
|
3143
3253
|
for (let y = 0; y < e.itemSize; y++) {
|
|
3144
3254
|
let x;
|
|
3145
|
-
e.itemSize > 4 ? x = e.array[p * e.itemSize + y] : (y === 0 ? x = e.getX(p) : y === 1 ? x = e.getY(p) : y === 2 ? x = e.getZ(p) : y === 3 && (x = e.getW(p)), e.normalized === !0 && (x =
|
|
3255
|
+
e.itemSize > 4 ? x = e.array[p * e.itemSize + y] : (y === 0 ? x = e.getX(p) : y === 1 ? x = e.getY(p) : y === 2 ? x = e.getZ(p) : y === 3 && (x = e.getW(p)), e.normalized === !0 && (x = ce.normalize(x, e.array))), t === C.FLOAT ? c.setFloat32(h, x, !0) : t === C.INT ? c.setInt32(h, x, !0) : t === C.UNSIGNED_INT ? c.setUint32(h, x, !0) : t === C.SHORT ? c.setInt16(h, x, !0) : t === C.UNSIGNED_SHORT ? c.setUint16(h, x, !0) : t === C.BYTE ? c.setInt8(h, x) : t === C.UNSIGNED_BYTE && c.setUint8(h, x), h += o;
|
|
3146
3256
|
}
|
|
3147
3257
|
h % a !== 0 && (h += a - h % a);
|
|
3148
3258
|
}
|
|
@@ -3151,7 +3261,7 @@ class dt {
|
|
|
3151
3261
|
byteOffset: this.byteOffset,
|
|
3152
3262
|
byteLength: l
|
|
3153
3263
|
};
|
|
3154
|
-
return i !== void 0 && (f.target = i), i ===
|
|
3264
|
+
return i !== void 0 && (f.target = i), i === C.ARRAY_BUFFER && (f.byteStride = a), this.byteOffset += l, r.bufferViews.push(f), {
|
|
3155
3265
|
id: r.bufferViews.length - 1,
|
|
3156
3266
|
byteLength: 0
|
|
3157
3267
|
};
|
|
@@ -3164,8 +3274,8 @@ class dt {
|
|
|
3164
3274
|
processBufferViewImage(e) {
|
|
3165
3275
|
const t = this, n = t.json;
|
|
3166
3276
|
return n.bufferViews || (n.bufferViews = []), new Promise(async function(s) {
|
|
3167
|
-
|
|
3168
|
-
const r =
|
|
3277
|
+
ae(e).then((i) => {
|
|
3278
|
+
const r = oe(i), o = {
|
|
3169
3279
|
buffer: t.processBuffer(r),
|
|
3170
3280
|
byteOffset: t.byteOffset,
|
|
3171
3281
|
byteLength: r.byteLength
|
|
@@ -3193,25 +3303,25 @@ class dt {
|
|
|
3193
3303
|
};
|
|
3194
3304
|
let o;
|
|
3195
3305
|
if (e.array.constructor === Float32Array)
|
|
3196
|
-
o =
|
|
3306
|
+
o = C.FLOAT;
|
|
3197
3307
|
else if (e.array.constructor === Int32Array)
|
|
3198
|
-
o =
|
|
3308
|
+
o = C.INT;
|
|
3199
3309
|
else if (e.array.constructor === Uint32Array)
|
|
3200
|
-
o =
|
|
3310
|
+
o = C.UNSIGNED_INT;
|
|
3201
3311
|
else if (e.array.constructor === Int16Array)
|
|
3202
|
-
o =
|
|
3312
|
+
o = C.SHORT;
|
|
3203
3313
|
else if (e.array.constructor === Uint16Array)
|
|
3204
|
-
o =
|
|
3314
|
+
o = C.UNSIGNED_SHORT;
|
|
3205
3315
|
else if (e.array.constructor === Int8Array)
|
|
3206
|
-
o =
|
|
3316
|
+
o = C.BYTE;
|
|
3207
3317
|
else if (e.array.constructor === Uint8Array)
|
|
3208
|
-
o =
|
|
3318
|
+
o = C.UNSIGNED_BYTE;
|
|
3209
3319
|
else
|
|
3210
3320
|
throw new Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: " + e.array.constructor.name);
|
|
3211
3321
|
if (n === void 0 && (n = 0), (s === void 0 || s === 1 / 0) && (s = e.count), s === 0) return null;
|
|
3212
|
-
const a =
|
|
3322
|
+
const a = dt(e, n, s);
|
|
3213
3323
|
let l;
|
|
3214
|
-
t !== void 0 && (l = e === t.index ?
|
|
3324
|
+
t !== void 0 && (l = e === t.index ? C.ELEMENT_ARRAY_BUFFER : C.ARRAY_BUFFER);
|
|
3215
3325
|
const c = this.processBufferView(e, o, n, s, l), h = {
|
|
3216
3326
|
bufferView: c.id,
|
|
3217
3327
|
byteOffset: c.byteOffset,
|
|
@@ -3238,13 +3348,13 @@ class dt {
|
|
|
3238
3348
|
const c = r.images.get(e), h = s + ":flipY/" + n.toString();
|
|
3239
3349
|
if (c[h] !== void 0) return c[h];
|
|
3240
3350
|
o.images || (o.images = []);
|
|
3241
|
-
const f = { mimeType: s }, u =
|
|
3351
|
+
const f = { mimeType: s }, u = Le();
|
|
3242
3352
|
u.width = Math.min(e.width, a.maxTextureSize), u.height = Math.min(e.height, a.maxTextureSize);
|
|
3243
3353
|
const p = u.getContext("2d", {
|
|
3244
3354
|
willReadFrequently: !0
|
|
3245
3355
|
});
|
|
3246
3356
|
if (n === !0 && (p.translate(0, u.height), p.scale(1, -1)), e.data !== void 0) {
|
|
3247
|
-
t !==
|
|
3357
|
+
t !== Fe && console.error("GLTFExporter: Only RGBAFormat is supported.", t), (e.width > a.maxTextureSize || e.height > a.maxTextureSize) && console.warn("GLTFExporter: Image size is bigger than maxTextureSize", e);
|
|
3248
3358
|
const x = new Uint8ClampedArray(e.height * e.width * 4);
|
|
3249
3359
|
for (let S = 0; S < x.length; S += 4)
|
|
3250
3360
|
x[S + 0] = e.data[S + 0], x[S + 1] = e.data[S + 1], x[S + 2] = e.data[S + 2], x[S + 3] = e.data[S + 3];
|
|
@@ -3254,10 +3364,10 @@ class dt {
|
|
|
3254
3364
|
else
|
|
3255
3365
|
throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");
|
|
3256
3366
|
a.binary === !0 ? l.push(
|
|
3257
|
-
|
|
3367
|
+
ft(u, s).then((x) => i.processBufferViewImage(x)).then((x) => {
|
|
3258
3368
|
f.bufferView = x;
|
|
3259
3369
|
})
|
|
3260
|
-
) : f.uri =
|
|
3370
|
+
) : f.uri = Ue.getDataURL(u, s);
|
|
3261
3371
|
const y = o.images.push(f) - 1;
|
|
3262
3372
|
return c[h] = y, y;
|
|
3263
3373
|
} else
|
|
@@ -3272,10 +3382,10 @@ class dt {
|
|
|
3272
3382
|
const t = this.json;
|
|
3273
3383
|
t.samplers || (t.samplers = []);
|
|
3274
3384
|
const n = {
|
|
3275
|
-
magFilter:
|
|
3276
|
-
minFilter:
|
|
3277
|
-
wrapS:
|
|
3278
|
-
wrapT:
|
|
3385
|
+
magFilter: Y[e.magFilter],
|
|
3386
|
+
minFilter: Y[e.minFilter],
|
|
3387
|
+
wrapS: Y[e.wrapS],
|
|
3388
|
+
wrapT: Y[e.wrapT]
|
|
3279
3389
|
};
|
|
3280
3390
|
return t.samplers.push(n) - 1;
|
|
3281
3391
|
}
|
|
@@ -3287,7 +3397,7 @@ class dt {
|
|
|
3287
3397
|
async processTextureAsync(e) {
|
|
3288
3398
|
const n = this.options, s = this.cache, i = this.json;
|
|
3289
3399
|
if (s.textures.has(e)) return s.textures.get(e);
|
|
3290
|
-
i.textures || (i.textures = []), e instanceof
|
|
3400
|
+
i.textures || (i.textures = []), e instanceof ie && (e = await this.decompressTextureAsync(e, n.maxTextureSize));
|
|
3291
3401
|
let r = e.userData.mimeType;
|
|
3292
3402
|
r === "image/webp" && (r = "image/png");
|
|
3293
3403
|
const o = {
|
|
@@ -3314,7 +3424,7 @@ class dt {
|
|
|
3314
3424
|
const s = { pbrMetallicRoughness: {} };
|
|
3315
3425
|
e.isMeshStandardMaterial !== !0 && e.isMeshBasicMaterial !== !0 && console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");
|
|
3316
3426
|
const i = e.color.toArray().concat([e.opacity]);
|
|
3317
|
-
if (
|
|
3427
|
+
if (Z(i, [1, 1, 1, 1]) || (s.pbrMetallicRoughness.baseColorFactor = i), e.isMeshStandardMaterial ? (s.pbrMetallicRoughness.metallicFactor = e.metalness, s.pbrMetallicRoughness.roughnessFactor = e.roughness) : (s.pbrMetallicRoughness.metallicFactor = 0, s.pbrMetallicRoughness.roughnessFactor = 1), e.metalnessMap || e.roughnessMap) {
|
|
3318
3428
|
const o = await this.buildMetalRoughTextureAsync(e.metalnessMap, e.roughnessMap), a = {
|
|
3319
3429
|
index: await this.processTextureAsync(o),
|
|
3320
3430
|
texCoord: o.channel
|
|
@@ -3366,15 +3476,15 @@ class dt {
|
|
|
3366
3476
|
async processMeshAsync(e) {
|
|
3367
3477
|
const t = this.cache, n = this.json, s = [e.geometry.uuid];
|
|
3368
3478
|
if (Array.isArray(e.material))
|
|
3369
|
-
for (let
|
|
3370
|
-
s.push(e.material[
|
|
3479
|
+
for (let A = 0, P = e.material.length; A < P; A++)
|
|
3480
|
+
s.push(e.material[A].uuid);
|
|
3371
3481
|
else
|
|
3372
3482
|
s.push(e.material.uuid);
|
|
3373
3483
|
const i = s.join(":");
|
|
3374
3484
|
if (t.meshes.has(i)) return t.meshes.get(i);
|
|
3375
3485
|
const r = e.geometry;
|
|
3376
3486
|
let o;
|
|
3377
|
-
e.isLineSegments ? o =
|
|
3487
|
+
e.isLineSegments ? o = C.LINES : e.isLineLoop ? o = C.LINE_LOOP : e.isLine ? o = C.LINE_STRIP : e.isPoints ? o = C.POINTS : o = e.material.wireframe ? C.LINES : C.TRIANGLES;
|
|
3378
3488
|
const a = {}, l = {}, c = [], h = [], f = {
|
|
3379
3489
|
uv: "TEXCOORD_0",
|
|
3380
3490
|
uv1: "TEXCOORD_1",
|
|
@@ -3386,76 +3496,76 @@ class dt {
|
|
|
3386
3496
|
}, u = r.getAttribute("normal");
|
|
3387
3497
|
u !== void 0 && !this.isNormalizedNormalAttribute(u) && (console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one."), r.setAttribute("normal", this.createNormalizedNormalAttribute(u)));
|
|
3388
3498
|
let p = null;
|
|
3389
|
-
for (let
|
|
3390
|
-
if (
|
|
3391
|
-
const
|
|
3392
|
-
if (
|
|
3393
|
-
l[
|
|
3499
|
+
for (let A in r.attributes) {
|
|
3500
|
+
if (A.slice(0, 5) === "morph") continue;
|
|
3501
|
+
const P = r.attributes[A];
|
|
3502
|
+
if (A = f[A] || A.toUpperCase(), /^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/.test(A) || (A = "_" + A), t.attributes.has(this.getUID(P))) {
|
|
3503
|
+
l[A] = t.attributes.get(this.getUID(P));
|
|
3394
3504
|
continue;
|
|
3395
3505
|
}
|
|
3396
3506
|
p = null;
|
|
3397
|
-
const
|
|
3398
|
-
|
|
3399
|
-
const g = this.processAccessor(p ||
|
|
3400
|
-
g !== null && (
|
|
3507
|
+
const L = P.array;
|
|
3508
|
+
A === "JOINTS_0" && !(L instanceof Uint16Array) && !(L instanceof Uint8Array) ? (console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.'), p = new H(new Uint16Array(L), P.itemSize, P.normalized)) : (L instanceof Uint32Array || L instanceof Int32Array) && !A.startsWith("_") && (console.warn(`GLTFExporter: Attribute "${A}" converted to type FLOAT.`), p = ne.Utils.toFloat32BufferAttribute(P));
|
|
3509
|
+
const g = this.processAccessor(p || P, r);
|
|
3510
|
+
g !== null && (A.startsWith("_") || this.detectMeshQuantization(A, P), l[A] = g, t.attributes.set(this.getUID(P), g));
|
|
3401
3511
|
}
|
|
3402
3512
|
if (u !== void 0 && r.setAttribute("normal", u), Object.keys(l).length === 0) return null;
|
|
3403
3513
|
if (e.morphTargetInfluences !== void 0 && e.morphTargetInfluences.length > 0) {
|
|
3404
|
-
const
|
|
3514
|
+
const A = [], P = [], M = {};
|
|
3405
3515
|
if (e.morphTargetDictionary !== void 0)
|
|
3406
|
-
for (const
|
|
3407
|
-
|
|
3408
|
-
for (let
|
|
3516
|
+
for (const L in e.morphTargetDictionary)
|
|
3517
|
+
M[e.morphTargetDictionary[L]] = L;
|
|
3518
|
+
for (let L = 0; L < e.morphTargetInfluences.length; ++L) {
|
|
3409
3519
|
const g = {};
|
|
3410
|
-
let
|
|
3411
|
-
for (const
|
|
3412
|
-
if (
|
|
3413
|
-
|
|
3520
|
+
let b = !1;
|
|
3521
|
+
for (const m in r.morphAttributes) {
|
|
3522
|
+
if (m !== "position" && m !== "normal") {
|
|
3523
|
+
b || (console.warn("GLTFExporter: Only POSITION and NORMAL morph are supported."), b = !0);
|
|
3414
3524
|
continue;
|
|
3415
3525
|
}
|
|
3416
|
-
const
|
|
3417
|
-
if (t.attributes.has(this.getUID(
|
|
3418
|
-
g[
|
|
3526
|
+
const E = r.morphAttributes[m][L], T = m.toUpperCase(), I = r.attributes[m];
|
|
3527
|
+
if (t.attributes.has(this.getUID(E, !0))) {
|
|
3528
|
+
g[T] = t.attributes.get(this.getUID(E, !0));
|
|
3419
3529
|
continue;
|
|
3420
3530
|
}
|
|
3421
|
-
const
|
|
3531
|
+
const N = E.clone();
|
|
3422
3532
|
if (!r.morphTargetsRelative)
|
|
3423
|
-
for (let
|
|
3424
|
-
for (let O = 0; O <
|
|
3425
|
-
O === 0 &&
|
|
3426
|
-
g[
|
|
3533
|
+
for (let D = 0, v = E.count; D < v; D++)
|
|
3534
|
+
for (let O = 0; O < E.itemSize; O++)
|
|
3535
|
+
O === 0 && N.setX(D, E.getX(D) - I.getX(D)), O === 1 && N.setY(D, E.getY(D) - I.getY(D)), O === 2 && N.setZ(D, E.getZ(D) - I.getZ(D)), O === 3 && N.setW(D, E.getW(D) - I.getW(D));
|
|
3536
|
+
g[T] = this.processAccessor(N, r), t.attributes.set(this.getUID(I, !0), g[T]);
|
|
3427
3537
|
}
|
|
3428
|
-
h.push(g),
|
|
3538
|
+
h.push(g), A.push(e.morphTargetInfluences[L]), e.morphTargetDictionary !== void 0 && P.push(M[L]);
|
|
3429
3539
|
}
|
|
3430
|
-
a.weights =
|
|
3540
|
+
a.weights = A, P.length > 0 && (a.extras = {}, a.extras.targetNames = P);
|
|
3431
3541
|
}
|
|
3432
3542
|
const y = Array.isArray(e.material);
|
|
3433
3543
|
if (y && r.groups.length === 0) return null;
|
|
3434
3544
|
let x = !1;
|
|
3435
3545
|
if (y && r.index === null) {
|
|
3436
|
-
const
|
|
3437
|
-
for (let
|
|
3438
|
-
|
|
3439
|
-
r.setIndex(
|
|
3546
|
+
const A = [];
|
|
3547
|
+
for (let P = 0, M = r.attributes.position.count; P < M; P++)
|
|
3548
|
+
A[P] = P;
|
|
3549
|
+
r.setIndex(A), x = !0;
|
|
3440
3550
|
}
|
|
3441
|
-
const S = y ? e.material : [e.material],
|
|
3442
|
-
for (let
|
|
3443
|
-
const
|
|
3551
|
+
const S = y ? e.material : [e.material], R = y ? r.groups : [{ materialIndex: 0, start: void 0, count: void 0 }];
|
|
3552
|
+
for (let A = 0, P = R.length; A < P; A++) {
|
|
3553
|
+
const M = {
|
|
3444
3554
|
mode: o,
|
|
3445
3555
|
attributes: l
|
|
3446
3556
|
};
|
|
3447
|
-
if (this.serializeUserData(r,
|
|
3557
|
+
if (this.serializeUserData(r, M), h.length > 0 && (M.targets = h), r.index !== null) {
|
|
3448
3558
|
let g = this.getUID(r.index);
|
|
3449
|
-
(
|
|
3559
|
+
(R[A].start !== void 0 || R[A].count !== void 0) && (g += ":" + R[A].start + ":" + R[A].count), t.attributes.has(g) ? M.indices = t.attributes.get(g) : (M.indices = this.processAccessor(r.index, r, R[A].start, R[A].count), t.attributes.set(g, M.indices)), M.indices === null && delete M.indices;
|
|
3450
3560
|
}
|
|
3451
|
-
const
|
|
3452
|
-
|
|
3561
|
+
const L = await this.processMaterialAsync(S[R[A].materialIndex]);
|
|
3562
|
+
L !== null && (M.material = L), c.push(M);
|
|
3453
3563
|
}
|
|
3454
|
-
x === !0 && r.setIndex(null), a.primitives = c, n.meshes || (n.meshes = []), await this._invokeAllAsync(function(
|
|
3455
|
-
|
|
3564
|
+
x === !0 && r.setIndex(null), a.primitives = c, n.meshes || (n.meshes = []), await this._invokeAllAsync(function(A) {
|
|
3565
|
+
A.writeMesh && A.writeMesh(e, a);
|
|
3456
3566
|
});
|
|
3457
|
-
const
|
|
3458
|
-
return t.meshes.set(i,
|
|
3567
|
+
const F = n.meshes.push(a) - 1;
|
|
3568
|
+
return t.meshes.set(i, F), F;
|
|
3459
3569
|
}
|
|
3460
3570
|
/**
|
|
3461
3571
|
* If a vertex attribute with a
|
|
@@ -3469,7 +3579,7 @@ class dt {
|
|
|
3469
3579
|
* @param {THREE.BufferAttribute} attribute
|
|
3470
3580
|
*/
|
|
3471
3581
|
detectMeshQuantization(e, t) {
|
|
3472
|
-
if (this.extensionsUsed[
|
|
3582
|
+
if (this.extensionsUsed[re]) return;
|
|
3473
3583
|
let n;
|
|
3474
3584
|
switch (t.array.constructor) {
|
|
3475
3585
|
case Int8Array:
|
|
@@ -3489,7 +3599,7 @@ class dt {
|
|
|
3489
3599
|
}
|
|
3490
3600
|
t.normalized && (n += " normalized");
|
|
3491
3601
|
const s = e.split("_", 1)[0];
|
|
3492
|
-
|
|
3602
|
+
me[s] && me[s].includes(n) && (this.extensionsUsed[re] = !0, this.extensionsRequired[re] = !0);
|
|
3493
3603
|
}
|
|
3494
3604
|
/**
|
|
3495
3605
|
* Process camera
|
|
@@ -3509,7 +3619,7 @@ class dt {
|
|
|
3509
3619
|
znear: e.near < 0 ? 0 : e.near
|
|
3510
3620
|
} : s.perspective = {
|
|
3511
3621
|
aspectRatio: e.aspect,
|
|
3512
|
-
yfov:
|
|
3622
|
+
yfov: ce.degToRad(e.fov),
|
|
3513
3623
|
zfar: e.far <= 0 ? 1e-3 : e.far,
|
|
3514
3624
|
znear: e.near < 0 ? 0 : e.near
|
|
3515
3625
|
}, e.name !== "" && (s.name = e.type), t.cameras.push(s) - 1;
|
|
@@ -3526,23 +3636,23 @@ class dt {
|
|
|
3526
3636
|
*/
|
|
3527
3637
|
processAnimation(e, t) {
|
|
3528
3638
|
const n = this.json, s = this.nodeMap;
|
|
3529
|
-
n.animations || (n.animations = []), e =
|
|
3639
|
+
n.animations || (n.animations = []), e = ne.Utils.mergeMorphTargetTracks(e.clone(), t);
|
|
3530
3640
|
const i = e.tracks, r = [], o = [];
|
|
3531
3641
|
for (let l = 0; l < i.length; ++l) {
|
|
3532
|
-
const c = i[l], h =
|
|
3533
|
-
let f =
|
|
3534
|
-
const u =
|
|
3642
|
+
const c = i[l], h = te.parseTrackName(c.name);
|
|
3643
|
+
let f = te.findNode(t, h.nodeName);
|
|
3644
|
+
const u = ge[h.propertyName];
|
|
3535
3645
|
if (h.objectName === "bones" && (f.isSkinnedMesh === !0 ? f = f.skeleton.getBoneByName(h.objectIndex) : f = void 0), !f || !u) {
|
|
3536
3646
|
console.warn('THREE.GLTFExporter: Could not export animation track "%s".', c.name);
|
|
3537
3647
|
continue;
|
|
3538
3648
|
}
|
|
3539
3649
|
const p = 1;
|
|
3540
3650
|
let y = c.values.length / c.times.length;
|
|
3541
|
-
u ===
|
|
3651
|
+
u === ge.morphTargetInfluences && (y /= f.morphTargetInfluences.length);
|
|
3542
3652
|
let x;
|
|
3543
|
-
c.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === !0 ? (x = "CUBICSPLINE", y /= 3) : c.getInterpolation() ===
|
|
3544
|
-
input: this.processAccessor(new
|
|
3545
|
-
output: this.processAccessor(new
|
|
3653
|
+
c.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === !0 ? (x = "CUBICSPLINE", y /= 3) : c.getInterpolation() === _e ? x = "STEP" : x = "LINEAR", o.push({
|
|
3654
|
+
input: this.processAccessor(new H(c.times, p)),
|
|
3655
|
+
output: this.processAccessor(new H(c.values, y)),
|
|
3546
3656
|
interpolation: x
|
|
3547
3657
|
}), r.push({
|
|
3548
3658
|
sampler: o.length - 1,
|
|
@@ -3568,11 +3678,11 @@ class dt {
|
|
|
3568
3678
|
if (i === void 0) return null;
|
|
3569
3679
|
const r = e.skeleton.bones[0];
|
|
3570
3680
|
if (r === void 0) return null;
|
|
3571
|
-
const o = [], a = new Float32Array(i.bones.length * 16), l = new
|
|
3681
|
+
const o = [], a = new Float32Array(i.bones.length * 16), l = new Ae();
|
|
3572
3682
|
for (let h = 0; h < i.bones.length; ++h)
|
|
3573
3683
|
o.push(n.get(i.bones[h])), l.copy(i.boneInverses[h]), l.multiply(e.bindMatrix).toArray(a, h * 16);
|
|
3574
3684
|
return t.skins === void 0 && (t.skins = []), t.skins.push({
|
|
3575
|
-
inverseBindMatrices: this.processAccessor(new
|
|
3685
|
+
inverseBindMatrices: this.processAccessor(new H(a, 16)),
|
|
3576
3686
|
joints: o,
|
|
3577
3687
|
skeleton: n.get(r)
|
|
3578
3688
|
}), s.skin = t.skins.length - 1;
|
|
@@ -3588,9 +3698,9 @@ class dt {
|
|
|
3588
3698
|
const i = {};
|
|
3589
3699
|
if (n.trs) {
|
|
3590
3700
|
const o = e.quaternion.toArray(), a = e.position.toArray(), l = e.scale.toArray();
|
|
3591
|
-
|
|
3701
|
+
Z(o, [0, 0, 0, 1]) || (i.rotation = o), Z(a, [0, 0, 0]) || (i.translation = a), Z(l, [1, 1, 1]) || (i.scale = l);
|
|
3592
3702
|
} else
|
|
3593
|
-
e.matrixAutoUpdate && e.updateMatrix(),
|
|
3703
|
+
e.matrixAutoUpdate && e.updateMatrix(), ut(e.matrix) === !1 && (i.matrix = e.matrix.elements);
|
|
3594
3704
|
if (e.name !== "" && (i.name = String(e.name)), this.serializeUserData(e, i), e.isMesh || e.isLine || e.isPoints) {
|
|
3595
3705
|
const o = await this.processMeshAsync(e);
|
|
3596
3706
|
o !== null && (i.mesh = o);
|
|
@@ -3636,7 +3746,7 @@ class dt {
|
|
|
3636
3746
|
* @param {Array<THREE.Object3D>} objects List of objects to process
|
|
3637
3747
|
*/
|
|
3638
3748
|
async processObjectsAsync(e) {
|
|
3639
|
-
const t = new
|
|
3749
|
+
const t = new fe();
|
|
3640
3750
|
t.name = "AuxScene";
|
|
3641
3751
|
for (let n = 0; n < e.length; n++)
|
|
3642
3752
|
t.children.push(e[n]);
|
|
@@ -3652,7 +3762,7 @@ class dt {
|
|
|
3652
3762
|
});
|
|
3653
3763
|
const n = [];
|
|
3654
3764
|
for (let s = 0; s < e.length; s++)
|
|
3655
|
-
e[s] instanceof
|
|
3765
|
+
e[s] instanceof fe ? await this.processSceneAsync(e[s]) : n.push(e[s]);
|
|
3656
3766
|
n.length > 0 && await this.processObjectsAsync(n);
|
|
3657
3767
|
for (let s = 0; s < this.skins.length; ++s)
|
|
3658
3768
|
this.processSkin(this.skins[s]);
|
|
@@ -3667,7 +3777,7 @@ class dt {
|
|
|
3667
3777
|
await e(this.plugins[t]);
|
|
3668
3778
|
}
|
|
3669
3779
|
}
|
|
3670
|
-
class
|
|
3780
|
+
class xt {
|
|
3671
3781
|
constructor(e) {
|
|
3672
3782
|
this.writer = e, this.name = "KHR_lights_punctual";
|
|
3673
3783
|
}
|
|
@@ -3683,7 +3793,7 @@ class ft {
|
|
|
3683
3793
|
o.push(r), t.extensions = t.extensions || {}, t.extensions[this.name] = { light: o.length - 1 };
|
|
3684
3794
|
}
|
|
3685
3795
|
}
|
|
3686
|
-
class
|
|
3796
|
+
class yt {
|
|
3687
3797
|
constructor(e) {
|
|
3688
3798
|
this.writer = e, this.name = "KHR_materials_unlit";
|
|
3689
3799
|
}
|
|
@@ -3693,7 +3803,7 @@ class pt {
|
|
|
3693
3803
|
t.extensions = t.extensions || {}, t.extensions[this.name] = {}, s[this.name] = !0, t.pbrMetallicRoughness.metallicFactor = 0, t.pbrMetallicRoughness.roughnessFactor = 0.9;
|
|
3694
3804
|
}
|
|
3695
3805
|
}
|
|
3696
|
-
class
|
|
3806
|
+
class mt {
|
|
3697
3807
|
constructor(e) {
|
|
3698
3808
|
this.writer = e, this.name = "KHR_materials_clearcoat";
|
|
3699
3809
|
}
|
|
@@ -3724,7 +3834,7 @@ class xt {
|
|
|
3724
3834
|
t.extensions = t.extensions || {}, t.extensions[this.name] = i, s[this.name] = !0;
|
|
3725
3835
|
}
|
|
3726
3836
|
}
|
|
3727
|
-
class
|
|
3837
|
+
class gt {
|
|
3728
3838
|
constructor(e) {
|
|
3729
3839
|
this.writer = e, this.name = "KHR_materials_dispersion";
|
|
3730
3840
|
}
|
|
@@ -3734,7 +3844,7 @@ class yt {
|
|
|
3734
3844
|
i.dispersion = e.dispersion, t.extensions = t.extensions || {}, t.extensions[this.name] = i, s[this.name] = !0;
|
|
3735
3845
|
}
|
|
3736
3846
|
}
|
|
3737
|
-
class
|
|
3847
|
+
class wt {
|
|
3738
3848
|
constructor(e) {
|
|
3739
3849
|
this.writer = e, this.name = "KHR_materials_iridescence";
|
|
3740
3850
|
}
|
|
@@ -3758,7 +3868,7 @@ class mt {
|
|
|
3758
3868
|
t.extensions = t.extensions || {}, t.extensions[this.name] = i, s[this.name] = !0;
|
|
3759
3869
|
}
|
|
3760
3870
|
}
|
|
3761
|
-
class
|
|
3871
|
+
class Mt {
|
|
3762
3872
|
constructor(e) {
|
|
3763
3873
|
this.writer = e, this.name = "KHR_materials_transmission";
|
|
3764
3874
|
}
|
|
@@ -3775,7 +3885,7 @@ class gt {
|
|
|
3775
3885
|
t.extensions = t.extensions || {}, t.extensions[this.name] = i, s[this.name] = !0;
|
|
3776
3886
|
}
|
|
3777
3887
|
}
|
|
3778
|
-
class
|
|
3888
|
+
class Lt {
|
|
3779
3889
|
constructor(e) {
|
|
3780
3890
|
this.writer = e, this.name = "KHR_materials_volume";
|
|
3781
3891
|
}
|
|
@@ -3792,7 +3902,7 @@ class wt {
|
|
|
3792
3902
|
e.attenuationDistance !== 1 / 0 && (i.attenuationDistance = e.attenuationDistance), i.attenuationColor = e.attenuationColor.toArray(), t.extensions = t.extensions || {}, t.extensions[this.name] = i, s[this.name] = !0;
|
|
3793
3903
|
}
|
|
3794
3904
|
}
|
|
3795
|
-
class
|
|
3905
|
+
class St {
|
|
3796
3906
|
constructor(e) {
|
|
3797
3907
|
this.writer = e, this.name = "KHR_materials_ior";
|
|
3798
3908
|
}
|
|
@@ -3802,12 +3912,12 @@ class Mt {
|
|
|
3802
3912
|
i.ior = e.ior, t.extensions = t.extensions || {}, t.extensions[this.name] = i, s[this.name] = !0;
|
|
3803
3913
|
}
|
|
3804
3914
|
}
|
|
3805
|
-
class
|
|
3915
|
+
class At {
|
|
3806
3916
|
constructor(e) {
|
|
3807
3917
|
this.writer = e, this.name = "KHR_materials_specular";
|
|
3808
3918
|
}
|
|
3809
3919
|
async writeMaterialAsync(e, t) {
|
|
3810
|
-
if (!e.isMeshPhysicalMaterial || e.specularIntensity === 1 && e.specularColor.equals(
|
|
3920
|
+
if (!e.isMeshPhysicalMaterial || e.specularIntensity === 1 && e.specularColor.equals(rt) && !e.specularIntensityMap && !e.specularColorMap) return;
|
|
3811
3921
|
const n = this.writer, s = n.extensionsUsed, i = {};
|
|
3812
3922
|
if (e.specularIntensityMap) {
|
|
3813
3923
|
const r = {
|
|
@@ -3826,7 +3936,7 @@ class St {
|
|
|
3826
3936
|
i.specularFactor = e.specularIntensity, i.specularColorFactor = e.specularColor.toArray(), t.extensions = t.extensions || {}, t.extensions[this.name] = i, s[this.name] = !0;
|
|
3827
3937
|
}
|
|
3828
3938
|
}
|
|
3829
|
-
class
|
|
3939
|
+
class Et {
|
|
3830
3940
|
constructor(e) {
|
|
3831
3941
|
this.writer = e, this.name = "KHR_materials_sheen";
|
|
3832
3942
|
}
|
|
@@ -3850,7 +3960,7 @@ class Lt {
|
|
|
3850
3960
|
i.sheenRoughnessFactor = e.sheenRoughness, i.sheenColorFactor = e.sheenColor.toArray(), t.extensions = t.extensions || {}, t.extensions[this.name] = i, s[this.name] = !0;
|
|
3851
3961
|
}
|
|
3852
3962
|
}
|
|
3853
|
-
class
|
|
3963
|
+
class Tt {
|
|
3854
3964
|
constructor(e) {
|
|
3855
3965
|
this.writer = e, this.name = "KHR_materials_anisotropy";
|
|
3856
3966
|
}
|
|
@@ -3864,7 +3974,7 @@ class Et {
|
|
|
3864
3974
|
i.anisotropyStrength = e.anisotropy, i.anisotropyRotation = e.anisotropyRotation, t.extensions = t.extensions || {}, t.extensions[this.name] = i, s[this.name] = !0;
|
|
3865
3975
|
}
|
|
3866
3976
|
}
|
|
3867
|
-
class
|
|
3977
|
+
class Dt {
|
|
3868
3978
|
constructor(e) {
|
|
3869
3979
|
this.writer = e, this.name = "KHR_materials_emissive_strength";
|
|
3870
3980
|
}
|
|
@@ -3874,7 +3984,7 @@ class Tt {
|
|
|
3874
3984
|
i.emissiveStrength = e.emissiveIntensity, t.extensions = t.extensions || {}, t.extensions[this.name] = i, s[this.name] = !0;
|
|
3875
3985
|
}
|
|
3876
3986
|
}
|
|
3877
|
-
class
|
|
3987
|
+
class bt {
|
|
3878
3988
|
constructor(e) {
|
|
3879
3989
|
this.writer = e, this.name = "EXT_materials_bump";
|
|
3880
3990
|
}
|
|
@@ -3891,24 +4001,24 @@ class At {
|
|
|
3891
4001
|
i.bumpFactor = e.bumpScale, t.extensions = t.extensions || {}, t.extensions[this.name] = i, s[this.name] = !0;
|
|
3892
4002
|
}
|
|
3893
4003
|
}
|
|
3894
|
-
class
|
|
4004
|
+
class It {
|
|
3895
4005
|
constructor(e) {
|
|
3896
4006
|
this.writer = e, this.name = "EXT_mesh_gpu_instancing";
|
|
3897
4007
|
}
|
|
3898
4008
|
writeNode(e, t) {
|
|
3899
4009
|
if (!e.isInstancedMesh) return;
|
|
3900
|
-
const n = this.writer, s = e, i = new Float32Array(s.count * 3), r = new Float32Array(s.count * 4), o = new Float32Array(s.count * 3), a = new
|
|
4010
|
+
const n = this.writer, s = e, i = new Float32Array(s.count * 3), r = new Float32Array(s.count * 4), o = new Float32Array(s.count * 3), a = new Ae(), l = new ee(), c = new Ne(), h = new ee();
|
|
3901
4011
|
for (let u = 0; u < s.count; u++)
|
|
3902
4012
|
s.getMatrixAt(u, a), a.decompose(l, c, h), l.toArray(i, u * 3), c.toArray(r, u * 4), h.toArray(o, u * 3);
|
|
3903
4013
|
const f = {
|
|
3904
|
-
TRANSLATION: n.processAccessor(new
|
|
3905
|
-
ROTATION: n.processAccessor(new
|
|
3906
|
-
SCALE: n.processAccessor(new
|
|
4014
|
+
TRANSLATION: n.processAccessor(new H(i, 3)),
|
|
4015
|
+
ROTATION: n.processAccessor(new H(r, 4)),
|
|
4016
|
+
SCALE: n.processAccessor(new H(o, 3))
|
|
3907
4017
|
};
|
|
3908
4018
|
s.instanceColor && (f._COLOR_0 = n.processAccessor(s.instanceColor)), t.extensions = t.extensions || {}, t.extensions[this.name] = { attributes: f }, n.extensionsUsed[this.name] = !0, n.extensionsRequired[this.name] = !0;
|
|
3909
4019
|
}
|
|
3910
4020
|
}
|
|
3911
|
-
|
|
4021
|
+
ne.Utils = {
|
|
3912
4022
|
insertKeyframe: function(d, e) {
|
|
3913
4023
|
const n = d.getValueSize(), s = new d.TimeBufferType(d.times.length + 1), i = new d.ValueBufferType(d.values.length + n), r = d.createInterpolant(new d.ValueBufferType(n));
|
|
3914
4024
|
let o;
|
|
@@ -3938,7 +4048,7 @@ ee.Utils = {
|
|
|
3938
4048
|
const t = [], n = {}, s = d.tracks;
|
|
3939
4049
|
for (let i = 0; i < s.length; ++i) {
|
|
3940
4050
|
let r = s[i];
|
|
3941
|
-
const o =
|
|
4051
|
+
const o = te.parseTrackName(r.name), a = te.findNode(e, o.nodeName);
|
|
3942
4052
|
if (o.propertyName !== "morphTargetInfluences" || o.propertyIndex === void 0) {
|
|
3943
4053
|
t.push(r);
|
|
3944
4054
|
continue;
|
|
@@ -3946,7 +4056,7 @@ ee.Utils = {
|
|
|
3946
4056
|
if (r.createInterpolant !== r.InterpolantFactoryMethodDiscrete && r.createInterpolant !== r.InterpolantFactoryMethodLinear) {
|
|
3947
4057
|
if (r.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline)
|
|
3948
4058
|
throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");
|
|
3949
|
-
console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead."), r = r.clone(), r.setInterpolation(
|
|
4059
|
+
console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead."), r = r.clone(), r.setInterpolation(Ke);
|
|
3950
4060
|
}
|
|
3951
4061
|
const l = a.morphTargetInfluences.length, c = a.morphTargetDictionary[o.propertyIndex];
|
|
3952
4062
|
if (c === void 0)
|
|
@@ -3972,7 +4082,7 @@ ee.Utils = {
|
|
|
3972
4082
|
return d.tracks = t, d;
|
|
3973
4083
|
},
|
|
3974
4084
|
toFloat32BufferAttribute: function(d) {
|
|
3975
|
-
const e = new
|
|
4085
|
+
const e = new H(new Float32Array(d.count * d.itemSize), d.itemSize, !1);
|
|
3976
4086
|
if (!d.normalized && !d.isInterleavedBufferAttribute)
|
|
3977
4087
|
return e.array.set(d.array), e;
|
|
3978
4088
|
for (let t = 0, n = d.count; t < n; t++)
|
|
@@ -3981,7 +4091,7 @@ ee.Utils = {
|
|
|
3981
4091
|
return e;
|
|
3982
4092
|
}
|
|
3983
4093
|
};
|
|
3984
|
-
async function
|
|
4094
|
+
async function Rt(d) {
|
|
3985
4095
|
if (typeof FileReader > "u") {
|
|
3986
4096
|
const e = await d.arrayBuffer(), n = Buffer.from(e).toString("base64");
|
|
3987
4097
|
return `data:${d.type};base64,${n}`;
|
|
@@ -3991,7 +4101,7 @@ async function bt(d) {
|
|
|
3991
4101
|
n.onload = () => e(n.result), n.onerror = () => t(new Error("Failed to read Blob as Data URL")), n.readAsDataURL(d);
|
|
3992
4102
|
});
|
|
3993
4103
|
}
|
|
3994
|
-
async function
|
|
4104
|
+
async function ae(d) {
|
|
3995
4105
|
if (typeof d.arrayBuffer == "function")
|
|
3996
4106
|
return await d.arrayBuffer();
|
|
3997
4107
|
if (typeof FileReader < "u")
|
|
@@ -4004,8 +4114,8 @@ async function re(d) {
|
|
|
4004
4114
|
return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
|
|
4005
4115
|
}
|
|
4006
4116
|
}
|
|
4007
|
-
const
|
|
4008
|
-
function
|
|
4117
|
+
const Pt = new $e(), vt = new ne();
|
|
4118
|
+
function Nt(d, e, t = 0.1) {
|
|
4009
4119
|
const n = e.normal(d), s = e.direction(d).mutiplyScalar(t * 0.5), i = d.direction(e).mutiplyScalar(t * 0.5), r = n.x * t * 0.5, o = n.y * t * 0.5;
|
|
4010
4120
|
return {
|
|
4011
4121
|
points: [
|
|
@@ -4020,17 +4130,17 @@ function Pt(d, e, t = 0.1) {
|
|
|
4020
4130
|
rectIndices: [0, 1, 3, 2, 0]
|
|
4021
4131
|
};
|
|
4022
4132
|
}
|
|
4023
|
-
class
|
|
4133
|
+
class be extends J {
|
|
4024
4134
|
static name = "WhiteModel";
|
|
4025
4135
|
Dxf = null;
|
|
4026
4136
|
Variable = null;
|
|
4027
4137
|
// dxf数据白模
|
|
4028
|
-
whiteModelGroup = new
|
|
4138
|
+
whiteModelGroup = new U.Group();
|
|
4029
4139
|
// dxf数据白模边缘线
|
|
4030
|
-
whiteModelLineGroup = new
|
|
4140
|
+
whiteModelLineGroup = new U.Group();
|
|
4031
4141
|
// 原始数据白模
|
|
4032
|
-
originalWhiteMode = new
|
|
4033
|
-
material = new
|
|
4142
|
+
originalWhiteMode = new U.Group();
|
|
4143
|
+
material = new U.MeshStandardMaterial({ color: 16777215, transparent: !0, opacity: 0.8, side: U.DoubleSide });
|
|
4034
4144
|
onAddFromParent(e) {
|
|
4035
4145
|
this.Dxf = e.findComponentByName("Dxf"), this.Variable = e.findComponentByName("Variable"), this.originalWhiteMode.visible = !1, this.Dxf?.addEventListener("lineOffset", () => {
|
|
4036
4146
|
this.updateModel();
|
|
@@ -4040,17 +4150,17 @@ class Ae extends W {
|
|
|
4040
4150
|
this.Variable?.set("whiteModelVisible", !1);
|
|
4041
4151
|
const e = this.Dxf;
|
|
4042
4152
|
this.originalWhiteMode.clear(), this.whiteModelGroup.clear(), this.whiteModelLineGroup.clear(), this.whiteModelGroup.add(this.whiteModelLineGroup), this.whiteModelGroup.position.z = e.originalZAverage, this.originalWhiteMode.position.z = e.originalZAverage, e.wallsGroup.forEach((n) => {
|
|
4043
|
-
const s = new
|
|
4153
|
+
const s = new U.Shape();
|
|
4044
4154
|
n.forEach((o, a) => a === 0 ? s.moveTo(o.x / e.scale, o.y / e.scale) : s.lineTo(o.x / e.scale, o.y / e.scale));
|
|
4045
|
-
const i = new
|
|
4155
|
+
const i = new U.ExtrudeGeometry(s, {
|
|
4046
4156
|
depth: 2.8,
|
|
4047
4157
|
bevelSize: 0
|
|
4048
|
-
}), r = new
|
|
4158
|
+
}), r = new U.Mesh(i, this.material);
|
|
4049
4159
|
this.whiteModelGroup.add(r), this.whiteModelLineGroup.add(
|
|
4050
|
-
new
|
|
4160
|
+
new U.LineSegments(new U.EdgesGeometry(i), new U.LineBasicMaterial({ color: 0 }))
|
|
4051
4161
|
);
|
|
4052
4162
|
}), e.originalData.map(({ start: n, end: s, insetionArr: i }) => {
|
|
4053
|
-
const r = new w(n.x, n.y).mutiplyScalar(e.scale), o = new w(s.x, s.y).mutiplyScalar(e.scale), { points: a, indices: l, rectIndices: c } =
|
|
4163
|
+
const r = new w(n.x, n.y).mutiplyScalar(e.scale), o = new w(s.x, s.y).mutiplyScalar(e.scale), { points: a, indices: l, rectIndices: c } = Nt(r, o, e.width);
|
|
4054
4164
|
return {
|
|
4055
4165
|
points: a,
|
|
4056
4166
|
indices: l,
|
|
@@ -4058,17 +4168,17 @@ class Ae extends W {
|
|
|
4058
4168
|
insetions: (i ?? []).map((h) => h.index)
|
|
4059
4169
|
};
|
|
4060
4170
|
}).forEach((n) => {
|
|
4061
|
-
const s = new
|
|
4171
|
+
const s = new U.Shape();
|
|
4062
4172
|
n.rectIndices.forEach((o, a) => {
|
|
4063
4173
|
const l = n.points[o];
|
|
4064
4174
|
a === 0 ? s.moveTo(l.x, l.y) : s.lineTo(l.x, l.y);
|
|
4065
4175
|
});
|
|
4066
|
-
const i = new
|
|
4176
|
+
const i = new U.ExtrudeGeometry(s, {
|
|
4067
4177
|
depth: 2.8,
|
|
4068
4178
|
bevelSize: 0
|
|
4069
4179
|
});
|
|
4070
4180
|
if (i.attributes.position.array.filter((o) => Number.isNaN(o)).length) return;
|
|
4071
|
-
const r = new
|
|
4181
|
+
const r = new U.Mesh(i);
|
|
4072
4182
|
this.originalWhiteMode?.add(r);
|
|
4073
4183
|
}), this.dispatchEvent({
|
|
4074
4184
|
type: "updateModel",
|
|
@@ -4083,7 +4193,7 @@ class Ae extends W {
|
|
|
4083
4193
|
toOBJ() {
|
|
4084
4194
|
return new Promise((e) => {
|
|
4085
4195
|
this.material.opacity = 1, this.material.needsUpdate = !0, setTimeout(() => {
|
|
4086
|
-
e(
|
|
4196
|
+
e(Pt.parse(this.whiteModelGroup)), this.material.opacity = 0.8, this.material.transparent = !0;
|
|
4087
4197
|
}, 20);
|
|
4088
4198
|
});
|
|
4089
4199
|
}
|
|
@@ -4095,7 +4205,7 @@ class Ae extends W {
|
|
|
4095
4205
|
toGltf(e = !0) {
|
|
4096
4206
|
return new Promise((t) => {
|
|
4097
4207
|
this.material.opacity = 1, this.material.needsUpdate = !0, setTimeout(async () => {
|
|
4098
|
-
|
|
4208
|
+
vt.parse(this.whiteModelGroup.children, (n) => {
|
|
4099
4209
|
t(n), this.material.opacity = 0.8, this.material.transparent = !0;
|
|
4100
4210
|
}, () => {
|
|
4101
4211
|
t(void 0);
|
|
@@ -4136,7 +4246,7 @@ class Ae extends W {
|
|
|
4136
4246
|
n.href = URL.createObjectURL(t), n.download = e, n.click();
|
|
4137
4247
|
} else if (typeof global < "u") {
|
|
4138
4248
|
const t = await this.toOBJ();
|
|
4139
|
-
t && (await
|
|
4249
|
+
t && (await K("fs", !1)).writeFileSync(e, t);
|
|
4140
4250
|
}
|
|
4141
4251
|
}
|
|
4142
4252
|
/**
|
|
@@ -4152,11 +4262,11 @@ class Ae extends W {
|
|
|
4152
4262
|
s.href = URL.createObjectURL(n), s.download = e, s.click();
|
|
4153
4263
|
} else if (typeof global < "u") {
|
|
4154
4264
|
const n = await this.toGltf(t);
|
|
4155
|
-
n && (await
|
|
4265
|
+
n && (await K("fs", !1)).writeFileSync(e, t ? Buffer.from(n) : JSON.stringify(n));
|
|
4156
4266
|
}
|
|
4157
4267
|
}
|
|
4158
4268
|
}
|
|
4159
|
-
class
|
|
4269
|
+
class Ie extends J {
|
|
4160
4270
|
static name = "DetailsPoint";
|
|
4161
4271
|
Dxf = null;
|
|
4162
4272
|
WhiteModel = null;
|
|
@@ -4207,17 +4317,17 @@ class De extends W {
|
|
|
4207
4317
|
this._timer = null;
|
|
4208
4318
|
const e = this.parent?.findComponentByName("WhiteModel");
|
|
4209
4319
|
this.raylines.length = 0, this.desPoints.length = 0, this.data.forEach((t) => {
|
|
4210
|
-
const n = new
|
|
4320
|
+
const n = new U.Vector3(
|
|
4211
4321
|
t.position.x,
|
|
4212
4322
|
t.position.y,
|
|
4213
4323
|
t.position.z
|
|
4214
|
-
), s = new
|
|
4324
|
+
), s = new U.Vector3(
|
|
4215
4325
|
t.direction.x,
|
|
4216
4326
|
t.direction.y,
|
|
4217
4327
|
t.direction.z
|
|
4218
4328
|
), i = 100;
|
|
4219
4329
|
this.racasterHelper(n, s, i), s.z = 0;
|
|
4220
|
-
const o = new
|
|
4330
|
+
const o = new U.Raycaster(n, s, 0, i).intersectObject(e.originalWhiteMode);
|
|
4221
4331
|
if (o.length) {
|
|
4222
4332
|
const { point: a } = o[0];
|
|
4223
4333
|
this.desPoints.push({
|
|
@@ -4233,61 +4343,61 @@ class De extends W {
|
|
|
4233
4343
|
}, 50);
|
|
4234
4344
|
}
|
|
4235
4345
|
}
|
|
4236
|
-
class
|
|
4346
|
+
class Re extends J {
|
|
4237
4347
|
static name = "DxfLineModel";
|
|
4238
|
-
dxfLineModel = new
|
|
4239
|
-
dxfDoorsLineModel = new
|
|
4240
|
-
dxfModelGroup = new
|
|
4348
|
+
dxfLineModel = new U.LineSegments();
|
|
4349
|
+
dxfDoorsLineModel = new U.LineSegments();
|
|
4350
|
+
dxfModelGroup = new U.Group();
|
|
4241
4351
|
onAddFromParent(e) {
|
|
4242
4352
|
const t = e.findComponentByName("Dxf");
|
|
4243
|
-
this.dxfModelGroup.add(this.dxfLineModel), this.dxfModelGroup.add(this.dxfDoorsLineModel), this.dxfDoorsLineModel.material = new
|
|
4353
|
+
this.dxfModelGroup.add(this.dxfLineModel), this.dxfModelGroup.add(this.dxfDoorsLineModel), this.dxfDoorsLineModel.material = new U.LineBasicMaterial({ color: 16776960, vertexColors: !0 }), t?.addEventListener("lineOffset", () => this.updateMode());
|
|
4244
4354
|
}
|
|
4245
4355
|
updateMode() {
|
|
4246
4356
|
const e = this.parent?.findComponentByName("Dxf");
|
|
4247
4357
|
this.dxfLineModel.clear();
|
|
4248
4358
|
const t = e.to3DArray(1 / e.scale, 0);
|
|
4249
|
-
this.dxfLineModel.geometry = new
|
|
4359
|
+
this.dxfLineModel.geometry = new U.BufferGeometry().setAttribute("position", new U.BufferAttribute(t, 3, !0));
|
|
4250
4360
|
const n = new Float32Array(
|
|
4251
4361
|
e.doorLineSegment.flatMap(({ start: i, end: r }) => [i.x, i.y, 0, r.x, r.y, 0])
|
|
4252
4362
|
).map((i) => i / e.scale), s = new Float32Array(e.doorLineSegment.flatMap(() => [1, 0, 0, 0, 1, 0]));
|
|
4253
|
-
this.dxfDoorsLineModel.geometry = new
|
|
4363
|
+
this.dxfDoorsLineModel.geometry = new U.BufferGeometry().setAttribute("position", new U.BufferAttribute(n, 3, !0)).setAttribute("color", new U.BufferAttribute(s, 3)), this.dxfModelGroup.position.z = e.originalZAverage, this.dispatchEvent({
|
|
4254
4364
|
type: "modelUpdate",
|
|
4255
4365
|
model: this.dxfModelGroup
|
|
4256
4366
|
});
|
|
4257
4367
|
}
|
|
4258
4368
|
}
|
|
4259
|
-
const
|
|
4369
|
+
const Ct = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
4260
4370
|
__proto__: null,
|
|
4261
|
-
DetailsPoint:
|
|
4262
|
-
DxfLineModel:
|
|
4263
|
-
WhiteModel:
|
|
4371
|
+
DetailsPoint: Ie,
|
|
4372
|
+
DxfLineModel: Re,
|
|
4373
|
+
WhiteModel: be
|
|
4264
4374
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
4265
|
-
function
|
|
4375
|
+
function Se(d, e = {}) {
|
|
4266
4376
|
const {
|
|
4267
4377
|
detailsPoint: t = !0,
|
|
4268
4378
|
whiteModel: n = !0,
|
|
4269
4379
|
dxfLineModel: s = !0
|
|
4270
4380
|
} = e;
|
|
4271
|
-
s && d.addComponent(new
|
|
4381
|
+
s && d.addComponent(new Re()), n && d.addComponent(new be()), t && d.addComponent(new Ie());
|
|
4272
4382
|
}
|
|
4273
|
-
const
|
|
4383
|
+
const Bt = Object.assign(Se, {
|
|
4274
4384
|
create(d = {}) {
|
|
4275
|
-
return (e) =>
|
|
4385
|
+
return (e) => Se(e, d);
|
|
4276
4386
|
}
|
|
4277
|
-
}),
|
|
4387
|
+
}), Ot = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
4278
4388
|
__proto__: null,
|
|
4279
|
-
ModelDataPlugin:
|
|
4280
|
-
components:
|
|
4389
|
+
ModelDataPlugin: Bt,
|
|
4390
|
+
components: Ct
|
|
4281
4391
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
4282
|
-
function
|
|
4392
|
+
function Ft() {
|
|
4283
4393
|
return import("./index2.js");
|
|
4284
4394
|
}
|
|
4285
|
-
function
|
|
4395
|
+
function Ut() {
|
|
4286
4396
|
return import("./index3.js");
|
|
4287
4397
|
}
|
|
4288
|
-
let
|
|
4289
|
-
async function
|
|
4290
|
-
const s = await Promise.resolve().then(() =>
|
|
4398
|
+
let de = null;
|
|
4399
|
+
async function Yt(d, e, t = !1, n) {
|
|
4400
|
+
const s = await Promise.resolve().then(() => Ot), i = await Ft(), r = await Ut(), o = new it().usePlugin(s.ModelDataPlugin.create({
|
|
4291
4401
|
detailsPoint: !1,
|
|
4292
4402
|
whiteModel: !0
|
|
4293
4403
|
})).usePlugin(i.RenderPlugin.create({
|
|
@@ -4297,12 +4407,12 @@ async function qt(d, e, t = !1, n) {
|
|
|
4297
4407
|
orbitControls: t,
|
|
4298
4408
|
camera: e
|
|
4299
4409
|
})).usePlugin(r.Editor.create({ viewPermission: n })), a = o.findComponentByType(i.components.DomContainer);
|
|
4300
|
-
return a && d.appendChild(a.domElement),
|
|
4410
|
+
return a && d.appendChild(a.domElement), de = o, {
|
|
4301
4411
|
dxfSystem: o,
|
|
4302
4412
|
getFileAll: () => Gt(o)
|
|
4303
4413
|
};
|
|
4304
4414
|
}
|
|
4305
|
-
async function Gt(d =
|
|
4415
|
+
async function Gt(d = de) {
|
|
4306
4416
|
const e = d.findComponentByName("WhiteModel"), t = new File([await d.AngleCorrectionDxf.toDxfImageBlob()], "img.jpg", { type: "image/jpeg" }), n = new File([d.Dxf.toDxfBlob()], "dxf.dxf", { type: "application/dxf" }), s = new File([d.AngleCorrectionDxf.toDxfBlob()], "dxf.dxf", { type: "application/dxf" }), i = new File([await e.toOBJBlob()], "model.obj", { type: "application/octet-stream" }), r = new File([await e.toGltfBlob(!0)], "model.glb", { type: "application/octet-stream" }), o = new File([await e.toGltfBlob(!1)], "model.gltf", { type: "application/json" }), a = new File([JSON.stringify(d.Dxf.originalData)], "json.json", { type: "application/json" });
|
|
4307
4417
|
return {
|
|
4308
4418
|
dxf: n,
|
|
@@ -4314,27 +4424,27 @@ async function Gt(d = he) {
|
|
|
4314
4424
|
correctionDxf: s
|
|
4315
4425
|
};
|
|
4316
4426
|
}
|
|
4317
|
-
function
|
|
4318
|
-
return
|
|
4427
|
+
function Xt() {
|
|
4428
|
+
return de;
|
|
4319
4429
|
}
|
|
4320
4430
|
export {
|
|
4321
4431
|
_ as B,
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4432
|
+
J as C,
|
|
4433
|
+
it as D,
|
|
4434
|
+
Ee as E,
|
|
4325
4435
|
B as L,
|
|
4326
|
-
|
|
4436
|
+
Bt as M,
|
|
4327
4437
|
w as P,
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4438
|
+
X as Q,
|
|
4439
|
+
st as T,
|
|
4440
|
+
Te as V,
|
|
4441
|
+
be as W,
|
|
4442
|
+
Ie as a,
|
|
4443
|
+
he as b,
|
|
4444
|
+
V as c,
|
|
4445
|
+
Yt as d,
|
|
4446
|
+
Xt as e,
|
|
4337
4447
|
Gt as g,
|
|
4338
|
-
|
|
4339
|
-
|
|
4448
|
+
Ct as i,
|
|
4449
|
+
le as u
|
|
4340
4450
|
};
|