poly-extrude 0.13.0 → 0.14.0
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/dist/cylinder.d.ts +11 -0
- package/{src → dist}/cylinder.js +108 -111
- package/dist/cylinder.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/math/Curve.d.ts +41 -0
- package/dist/math/Curve.js +142 -0
- package/dist/math/Curve.js.map +1 -0
- package/dist/math/Interpolations.d.ts +8 -0
- package/dist/math/Interpolations.js +48 -0
- package/dist/math/Interpolations.js.map +1 -0
- package/dist/math/Matrix4.d.ts +8 -0
- package/dist/math/Matrix4.js +582 -0
- package/dist/math/Matrix4.js.map +1 -0
- package/dist/math/QuadraticBezierCurve3.d.ts +10 -0
- package/dist/math/QuadraticBezierCurve3.js +22 -0
- package/dist/math/QuadraticBezierCurve3.js.map +1 -0
- package/dist/math/Quaternion.d.ts +46 -0
- package/dist/math/Quaternion.js +415 -0
- package/dist/math/Quaternion.js.map +1 -0
- package/dist/math/Vector3.d.ts +42 -0
- package/dist/math/Vector3.js +403 -0
- package/dist/math/Vector3.js.map +1 -0
- package/dist/path/PathPoint.d.ts +15 -0
- package/dist/path/PathPoint.js +35 -0
- package/dist/path/PathPoint.js.map +1 -0
- package/dist/path/PathPointList.d.ts +27 -0
- package/dist/path/PathPointList.js +212 -0
- package/dist/path/PathPointList.js.map +1 -0
- package/dist/path.d.ts +11 -0
- package/{src → dist}/path.js +334 -360
- package/dist/path.js.map +1 -0
- package/dist/plane.d.ts +2 -0
- package/{src → dist}/plane.js +57 -58
- package/dist/plane.js.map +1 -0
- package/dist/poly-extrude.js +1286 -1581
- package/dist/poly-extrude.js.map +1 -1
- package/dist/poly-extrude.min.js +2 -2
- package/dist/poly-extrude.mjs +1286 -1581
- package/dist/poly-extrude.mjs.map +1 -0
- package/dist/polygon.d.ts +9 -0
- package/{src → dist}/polygon.js +163 -179
- package/dist/polygon.js.map +1 -0
- package/dist/polyline.d.ts +24 -0
- package/{src → dist}/polyline.js +420 -456
- package/dist/polyline.js.map +1 -0
- package/dist/tube.d.ts +12 -0
- package/{src → dist}/tube.js +124 -142
- package/dist/tube.js.map +1 -0
- package/dist/type.d.ts +9 -0
- package/dist/type.js +2 -0
- package/dist/type.js.map +1 -0
- package/dist/util.d.ts +20 -0
- package/dist/util.js +217 -0
- package/dist/util.js.map +1 -0
- package/package.json +53 -48
- package/readme.md +12 -2
- package/src/cylinder.ts +124 -0
- package/src/index.ts +7 -0
- package/src/path.ts +385 -0
- package/src/plane.ts +60 -0
- package/src/polygon.ts +189 -0
- package/src/polyline.ts +473 -0
- package/src/tube.ts +155 -0
- package/src/type.ts +9 -0
- package/src/{util.js → util.ts} +1 -1
- package/index.js +0 -7
package/{src → dist}/polyline.js
RENAMED
@@ -1,456 +1,420 @@
|
|
1
|
-
import { calLineDistance, degToRad, generateNormal, generateSideWallUV, merge, radToDeg } from './util';
|
2
|
-
|
3
|
-
|
4
|
-
options.
|
5
|
-
options.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
result
|
15
|
-
|
16
|
-
|
17
|
-
result.
|
18
|
-
result.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
const
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
result
|
51
|
-
|
52
|
-
|
53
|
-
result.
|
54
|
-
result.
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
points[
|
97
|
-
points[
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
const
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
uv[
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
const
|
135
|
-
uv[
|
136
|
-
uv[
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
}
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
indices[++iIndex] =
|
162
|
-
indices[++iIndex] =
|
163
|
-
indices[++iIndex] =
|
164
|
-
indices[++iIndex] =
|
165
|
-
indices[++iIndex] =
|
166
|
-
|
167
|
-
// index.push(
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
const
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
let
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
const [
|
368
|
-
const
|
369
|
-
const
|
370
|
-
|
371
|
-
|
372
|
-
const
|
373
|
-
const
|
374
|
-
return [
|
375
|
-
}
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
const [
|
386
|
-
const [
|
387
|
-
|
388
|
-
|
389
|
-
}
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
*
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
function lineIntersection(p1, p2, p3, p4) {
|
422
|
-
const dx1 = p2[0] - p1[0], dy1 = p2[1] - p1[1];
|
423
|
-
const dx2 = p4[0] - p3[0], dy2 = p4[1] - p3[1];
|
424
|
-
if (dx1 === 0 && dx2 === 0) {
|
425
|
-
return null;
|
426
|
-
}
|
427
|
-
if (dy1 === 0 && dy2 === 0) {
|
428
|
-
return null;
|
429
|
-
}
|
430
|
-
|
431
|
-
const k1 = dy1 / dx1;
|
432
|
-
const k2 = dy2 / dx2;
|
433
|
-
|
434
|
-
const b1 = p1[1] - k1 * p1[0];
|
435
|
-
const b2 = p3[1] - k2 * p3[0];
|
436
|
-
|
437
|
-
let x, y;
|
438
|
-
|
439
|
-
if (dx1 === 0) {
|
440
|
-
x = p1[0];
|
441
|
-
y = k2 * x + b2;
|
442
|
-
} else if (dx2 === 0) {
|
443
|
-
x = p3[0];
|
444
|
-
y = k1 * x + b1;
|
445
|
-
} else if (dy1 === 0) {
|
446
|
-
y = p1[1];
|
447
|
-
x = (y - b2) / k2;
|
448
|
-
} else if (dy2 === 0) {
|
449
|
-
y = p3[1];
|
450
|
-
x = (y - b1) / k1;
|
451
|
-
} else {
|
452
|
-
x = (b2 - b1) / (k1 - k2);
|
453
|
-
y = k1 * x + b1;
|
454
|
-
}
|
455
|
-
return [x, y];
|
456
|
-
}
|
1
|
+
import { calLineDistance, degToRad, generateNormal, generateSideWallUV, merge, radToDeg } from './util';
|
2
|
+
function checkOptions(options) {
|
3
|
+
options.lineWidth = Math.max(0, options.lineWidth);
|
4
|
+
options.depth = Math.max(0, options.depth);
|
5
|
+
options.sideDepth = Math.max(0, options.sideDepth);
|
6
|
+
}
|
7
|
+
export function extrudePolylines(lines, options) {
|
8
|
+
options = Object.assign({}, { depth: 2, lineWidth: 1, bottomStickGround: false, pathUV: false }, options);
|
9
|
+
checkOptions(options);
|
10
|
+
const results = lines.map(line => {
|
11
|
+
const result = expandLine(line, options);
|
12
|
+
result.line = line;
|
13
|
+
generateTopAndBottom(result, options);
|
14
|
+
generateSides(result, options);
|
15
|
+
result.position = new Float32Array(result.points);
|
16
|
+
result.indices = new Uint32Array(result.indices);
|
17
|
+
result.uv = new Float32Array(result.uv);
|
18
|
+
result.normal = generateNormal(result.indices, result.position);
|
19
|
+
return result;
|
20
|
+
});
|
21
|
+
const result = merge(results);
|
22
|
+
result.lines = lines;
|
23
|
+
return result;
|
24
|
+
}
|
25
|
+
export function extrudeSlopes(lines, options) {
|
26
|
+
options = Object.assign({}, { depth: 2, lineWidth: 1, side: 'left', sideDepth: 0, bottomStickGround: false, pathUV: false, isSlope: true }, options);
|
27
|
+
checkOptions(options);
|
28
|
+
const { depth, side, sideDepth } = options;
|
29
|
+
const results = lines.map(line => {
|
30
|
+
const tempResult = expandLine(line, options);
|
31
|
+
tempResult.line = line;
|
32
|
+
const { leftPoints, rightPoints } = tempResult;
|
33
|
+
const result = { line };
|
34
|
+
let depths;
|
35
|
+
for (let i = 0, len = line.length; i < len; i++) {
|
36
|
+
line[i][2] = line[i][2] || 0;
|
37
|
+
}
|
38
|
+
if (side === 'left') {
|
39
|
+
result.leftPoints = leftPoints;
|
40
|
+
result.rightPoints = line;
|
41
|
+
depths = [sideDepth, depth];
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
result.leftPoints = line;
|
45
|
+
result.rightPoints = rightPoints;
|
46
|
+
depths = [depth, sideDepth];
|
47
|
+
}
|
48
|
+
result.depths = depths;
|
49
|
+
generateTopAndBottom(result, options);
|
50
|
+
generateSides(result, options);
|
51
|
+
result.position = new Float32Array(result.points);
|
52
|
+
result.indices = new Uint32Array(result.indices);
|
53
|
+
result.uv = new Float32Array(result.uv);
|
54
|
+
result.normal = generateNormal(result.indices, result.position);
|
55
|
+
return result;
|
56
|
+
});
|
57
|
+
const result = merge(results);
|
58
|
+
result.lines = lines;
|
59
|
+
return result;
|
60
|
+
}
|
61
|
+
function generateTopAndBottom(result, options) {
|
62
|
+
const bottomStickGround = options.bottomStickGround;
|
63
|
+
const z = options.depth;
|
64
|
+
const depths = result.depths;
|
65
|
+
let lz = z, rz = z;
|
66
|
+
if (depths) {
|
67
|
+
lz = depths[0];
|
68
|
+
rz = depths[1];
|
69
|
+
}
|
70
|
+
const { leftPoints, rightPoints } = result;
|
71
|
+
const line = result.line;
|
72
|
+
const pathUV = options.pathUV;
|
73
|
+
if (pathUV) {
|
74
|
+
calLineDistance(line);
|
75
|
+
for (let i = 0, len = line.length; i < len; i++) {
|
76
|
+
leftPoints[i].distance = rightPoints[i].distance = line[i].distance;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
let i = 0, len = leftPoints.length;
|
80
|
+
const points = [], indices = [], uv = [];
|
81
|
+
while (i < len) {
|
82
|
+
// top left
|
83
|
+
const idx0 = i * 3;
|
84
|
+
const [x1, y1, z1] = leftPoints[i];
|
85
|
+
points[idx0] = x1;
|
86
|
+
points[idx0 + 1] = y1;
|
87
|
+
points[idx0 + 2] = lz + z1;
|
88
|
+
// top right
|
89
|
+
const [x2, y2, z2] = rightPoints[i];
|
90
|
+
const idx1 = len * 3 + idx0;
|
91
|
+
points[idx1] = x2;
|
92
|
+
points[idx1 + 1] = y2;
|
93
|
+
points[idx1 + 2] = rz + z2;
|
94
|
+
// bottom left
|
95
|
+
const idx2 = (len * 2) * 3 + idx0;
|
96
|
+
points[idx2] = x1;
|
97
|
+
points[idx2 + 1] = y1;
|
98
|
+
points[idx2 + 2] = z1;
|
99
|
+
if (bottomStickGround) {
|
100
|
+
points[idx2 + 2] = 0;
|
101
|
+
}
|
102
|
+
// bottom right
|
103
|
+
const idx3 = (len * 2) * 3 + len * 3 + idx0;
|
104
|
+
points[idx3] = x2;
|
105
|
+
points[idx3 + 1] = y2;
|
106
|
+
points[idx3 + 2] = z2;
|
107
|
+
if (bottomStickGround) {
|
108
|
+
points[idx3 + 2] = 0;
|
109
|
+
}
|
110
|
+
// generate path uv
|
111
|
+
if (pathUV) {
|
112
|
+
const p = line[i];
|
113
|
+
const uvx = p.distance;
|
114
|
+
const uIndex0 = i * 2;
|
115
|
+
uv[uIndex0] = uvx;
|
116
|
+
uv[uIndex0 + 1] = 1;
|
117
|
+
const uIndex1 = len * 2 + uIndex0;
|
118
|
+
uv[uIndex1] = uvx;
|
119
|
+
uv[uIndex1 + 1] = 0;
|
120
|
+
const uIndex2 = (len * 2) * 2 + uIndex0;
|
121
|
+
uv[uIndex2] = uvx;
|
122
|
+
uv[uIndex2 + 1] = 1;
|
123
|
+
const uIndex3 = (len * 2) * 2 + len * 2 + uIndex0;
|
124
|
+
uv[uIndex3] = uvx;
|
125
|
+
uv[uIndex3 + 1] = 0;
|
126
|
+
}
|
127
|
+
i++;
|
128
|
+
}
|
129
|
+
if (!pathUV) {
|
130
|
+
i = 0;
|
131
|
+
len = points.length;
|
132
|
+
let uIndex = uv.length - 1;
|
133
|
+
while (i < len) {
|
134
|
+
const x = points[i], y = points[i + 1];
|
135
|
+
uv[++uIndex] = x;
|
136
|
+
uv[++uIndex] = y;
|
137
|
+
// uvs.push(x, y);
|
138
|
+
i += 3;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
i = 0;
|
142
|
+
len = leftPoints.length;
|
143
|
+
let iIndex = indices.length - 1;
|
144
|
+
while (i < len - 1) {
|
145
|
+
// top
|
146
|
+
// left1 left2 right1,right2
|
147
|
+
const a1 = i, b1 = i + 1, c1 = a1 + len, d1 = b1 + len;
|
148
|
+
indices[++iIndex] = a1;
|
149
|
+
indices[++iIndex] = c1;
|
150
|
+
indices[++iIndex] = b1;
|
151
|
+
indices[++iIndex] = c1;
|
152
|
+
indices[++iIndex] = d1;
|
153
|
+
indices[++iIndex] = b1;
|
154
|
+
// index.push(a1, c1, b1);
|
155
|
+
// index.push(c1, d1, b1);
|
156
|
+
// bottom
|
157
|
+
// left1 left2 right1,right2
|
158
|
+
const len2 = len * 2;
|
159
|
+
const a2 = i + len2, b2 = a2 + 1, c2 = a2 + len, d2 = b2 + len;
|
160
|
+
indices[++iIndex] = a2;
|
161
|
+
indices[++iIndex] = c2;
|
162
|
+
indices[++iIndex] = b2;
|
163
|
+
indices[++iIndex] = c2;
|
164
|
+
indices[++iIndex] = d2;
|
165
|
+
indices[++iIndex] = b2;
|
166
|
+
// index.push(a2, c2, b2);
|
167
|
+
// index.push(c2, d2, b2);
|
168
|
+
i++;
|
169
|
+
}
|
170
|
+
result.indices = indices;
|
171
|
+
result.points = points;
|
172
|
+
result.uv = uv;
|
173
|
+
if (depths) {
|
174
|
+
len = leftPoints.length;
|
175
|
+
i = 0;
|
176
|
+
while (i < len) {
|
177
|
+
leftPoints[i].depth = lz;
|
178
|
+
rightPoints[i].depth = rz;
|
179
|
+
i++;
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|
183
|
+
function generateSides(result, options) {
|
184
|
+
const { points, indices, leftPoints, rightPoints, uv } = result;
|
185
|
+
const z = options.depth;
|
186
|
+
const bottomStickGround = options.bottomStickGround;
|
187
|
+
const rings = [leftPoints, rightPoints];
|
188
|
+
const depthsEnable = result.depths;
|
189
|
+
const pathUV = options.pathUV;
|
190
|
+
const lineWidth = options.lineWidth;
|
191
|
+
let pIndex = points.length - 1;
|
192
|
+
let iIndex = indices.length - 1;
|
193
|
+
let uIndex = uv.length - 1;
|
194
|
+
function addOneSideIndex(v1, v2) {
|
195
|
+
const idx = points.length / 3;
|
196
|
+
// let pIndex = points.length - 1;
|
197
|
+
const v1Depth = (depthsEnable ? v1.depth : z);
|
198
|
+
const v2Depth = (depthsEnable ? v2.depth : z);
|
199
|
+
// top
|
200
|
+
points[++pIndex] = v1[0];
|
201
|
+
points[++pIndex] = v1[1];
|
202
|
+
points[++pIndex] = v1Depth + v1[2];
|
203
|
+
points[++pIndex] = v2[0];
|
204
|
+
points[++pIndex] = v2[1];
|
205
|
+
points[++pIndex] = v2Depth + v2[2];
|
206
|
+
// points.push(v1[0], v1[1], (depthsEnable ? v1.depth : z) + v1[2], v2[0], v2[1], (depthsEnable ? v2.depth : z) + v2[2]);
|
207
|
+
// bottom
|
208
|
+
points[++pIndex] = v1[0];
|
209
|
+
points[++pIndex] = v1[1];
|
210
|
+
points[++pIndex] = bottomStickGround ? 0 : v1[2];
|
211
|
+
points[++pIndex] = v2[0];
|
212
|
+
points[++pIndex] = v2[1];
|
213
|
+
points[++pIndex] = bottomStickGround ? 0 : v2[2];
|
214
|
+
// points.push(v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
|
215
|
+
const a = idx + 2, b = idx + 3, c = idx, d = idx + 1;
|
216
|
+
indices[++iIndex] = a;
|
217
|
+
indices[++iIndex] = c;
|
218
|
+
indices[++iIndex] = b;
|
219
|
+
indices[++iIndex] = c;
|
220
|
+
indices[++iIndex] = d;
|
221
|
+
indices[++iIndex] = b;
|
222
|
+
// index.push(a, c, b, c, d, b);
|
223
|
+
if (!pathUV) {
|
224
|
+
generateSideWallUV(uv, points, a, b, c, d);
|
225
|
+
}
|
226
|
+
else {
|
227
|
+
uv[++uIndex] = v1.distance;
|
228
|
+
uv[++uIndex] = v1Depth / lineWidth;
|
229
|
+
uv[++uIndex] = v2.distance;
|
230
|
+
uv[++uIndex] = v2Depth / lineWidth;
|
231
|
+
uv[++uIndex] = v1.distance;
|
232
|
+
uv[++uIndex] = 0;
|
233
|
+
uv[++uIndex] = v2.distance;
|
234
|
+
uv[++uIndex] = 0;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
for (let i = 0, len = rings.length; i < len; i++) {
|
238
|
+
let ring = rings[i];
|
239
|
+
if (i > 0) {
|
240
|
+
ring = ring.map(p => {
|
241
|
+
return p;
|
242
|
+
});
|
243
|
+
ring = ring.reverse();
|
244
|
+
}
|
245
|
+
let j = 0;
|
246
|
+
const len1 = ring.length - 1;
|
247
|
+
while (j < len1) {
|
248
|
+
const v1 = ring[j];
|
249
|
+
const v2 = ring[j + 1];
|
250
|
+
addOneSideIndex(v1, v2);
|
251
|
+
j++;
|
252
|
+
}
|
253
|
+
}
|
254
|
+
const len = leftPoints.length;
|
255
|
+
const vs = [rightPoints[0], leftPoints[0], leftPoints[len - 1], rightPoints[len - 1]];
|
256
|
+
for (let i = 0; i < vs.length; i += 2) {
|
257
|
+
const v1 = vs[i], v2 = vs[i + 1];
|
258
|
+
addOneSideIndex(v1, v2);
|
259
|
+
}
|
260
|
+
}
|
261
|
+
const TEMPV1 = { x: 0, y: 0 }, TEMPV2 = { x: 0, y: 0 };
|
262
|
+
export function expandLine(line, options) {
|
263
|
+
// let preAngle = 0;
|
264
|
+
let radius = options.lineWidth / 2;
|
265
|
+
if (options.isSlope) {
|
266
|
+
radius *= 2;
|
267
|
+
}
|
268
|
+
const points = [], leftPoints = [], rightPoints = [];
|
269
|
+
const len = line.length;
|
270
|
+
let i = 0;
|
271
|
+
while (i < len) {
|
272
|
+
let p1 = line[i], p2 = line[i + 1];
|
273
|
+
const currentp = line[i];
|
274
|
+
// last vertex
|
275
|
+
if (i === len - 1) {
|
276
|
+
p1 = line[len - 2];
|
277
|
+
p2 = line[len - 1];
|
278
|
+
}
|
279
|
+
const dy = p2[1] - p1[1], dx = p2[0] - p1[0];
|
280
|
+
let rAngle = 0;
|
281
|
+
const rad = Math.atan(dy / dx);
|
282
|
+
const angle = radToDeg(rad);
|
283
|
+
// preAngle = angle;
|
284
|
+
if (i === 0 || i === len - 1) {
|
285
|
+
rAngle = angle;
|
286
|
+
rAngle -= 90;
|
287
|
+
}
|
288
|
+
else {
|
289
|
+
// 至少3个顶点才会触发
|
290
|
+
const p0 = line[i - 1];
|
291
|
+
TEMPV1.x = p0[0] - p1[0];
|
292
|
+
TEMPV1.y = p0[1] - p1[1];
|
293
|
+
TEMPV2.x = p2[0] - p1[0];
|
294
|
+
TEMPV2.y = p2[1] - p1[1];
|
295
|
+
const vAngle = getAngle(TEMPV1, TEMPV2);
|
296
|
+
rAngle = angle - vAngle / 2;
|
297
|
+
}
|
298
|
+
const rRad = degToRad(rAngle);
|
299
|
+
const p3 = currentp;
|
300
|
+
const x = Math.cos(rRad) + p3[0], y = Math.sin(rRad) + p3[1];
|
301
|
+
const p4 = [x, y];
|
302
|
+
const [line1, line2] = translateLine(p1, p2, radius);
|
303
|
+
let op1 = lineIntersection(line1[0], line1[1], p3, p4);
|
304
|
+
let op2 = lineIntersection(line2[0], line2[1], p3, p4);
|
305
|
+
// 平行,回头路
|
306
|
+
if (!op1 || !op2) {
|
307
|
+
const len1 = points.length;
|
308
|
+
const point1 = points[len1 - 2];
|
309
|
+
const point2 = points[len1 - 1];
|
310
|
+
if (!point1 || !point2) {
|
311
|
+
continue;
|
312
|
+
}
|
313
|
+
op1 = [point1[0], point1[1]];
|
314
|
+
op2 = [point2[0], point2[1]];
|
315
|
+
}
|
316
|
+
op1[2] = currentp[2] || 0;
|
317
|
+
op2[2] = currentp[2] || 0;
|
318
|
+
// const [op1, op2] = calOffsetPoint(rRad, radius, p1);
|
319
|
+
points.push(op1, op2);
|
320
|
+
if (leftOnLine(op1, p1, p2)) {
|
321
|
+
leftPoints.push(op1);
|
322
|
+
rightPoints.push(op2);
|
323
|
+
}
|
324
|
+
else {
|
325
|
+
leftPoints.push(op2);
|
326
|
+
rightPoints.push(op1);
|
327
|
+
}
|
328
|
+
i++;
|
329
|
+
}
|
330
|
+
return { offsetPoints: points, leftPoints, rightPoints, line };
|
331
|
+
}
|
332
|
+
// eslint-disable-next-line no-unused-vars
|
333
|
+
function calOffsetPoint(rad, radius, p) {
|
334
|
+
const [x, y] = p;
|
335
|
+
const z = p[2] || 0;
|
336
|
+
const x1 = Math.cos(rad) * radius, y1 = Math.sin(rad) * radius;
|
337
|
+
const p1 = [x + x1, y + y1, z];
|
338
|
+
const rad1 = rad += Math.PI;
|
339
|
+
const x2 = Math.cos(rad1) * radius, y2 = Math.sin(rad1) * radius;
|
340
|
+
const p2 = [x + x2, y + y2, z];
|
341
|
+
return [p1, p2];
|
342
|
+
}
|
343
|
+
const getAngle = ({ x: x1, y: y1 }, { x: x2, y: y2 }) => {
|
344
|
+
const dot = x1 * x2 + y1 * y2;
|
345
|
+
const det = x1 * y2 - y1 * x2;
|
346
|
+
const angle = Math.atan2(det, dot) / Math.PI * 180;
|
347
|
+
return (angle + 360) % 360;
|
348
|
+
};
|
349
|
+
export function leftOnLine(p, p1, p2) {
|
350
|
+
const [x1, y1] = p1;
|
351
|
+
const [x2, y2] = p2;
|
352
|
+
const [x, y] = p;
|
353
|
+
return (y1 - y2) * x + (x2 - x1) * y + x1 * y2 - x2 * y1 > 0;
|
354
|
+
}
|
355
|
+
/**
|
356
|
+
* 平移线
|
357
|
+
* @param {*} p1
|
358
|
+
* @param {*} p2
|
359
|
+
* @param {*} distance
|
360
|
+
* @returns
|
361
|
+
*/
|
362
|
+
function translateLine(p1, p2, distance) {
|
363
|
+
const dy = p2[1] - p1[1], dx = p2[0] - p1[0];
|
364
|
+
const rad = Math.atan2(dy, dx);
|
365
|
+
const rad1 = rad + Math.PI / 2;
|
366
|
+
let offsetX = Math.cos(rad1) * distance, offsetY = Math.sin(rad1) * distance;
|
367
|
+
const tp1 = [p1[0] + offsetX, p1[1] + offsetY];
|
368
|
+
const tp2 = [p2[0] + offsetX, p2[1] + offsetY];
|
369
|
+
const rad2 = rad - Math.PI / 2;
|
370
|
+
offsetX = Math.cos(rad2) * distance;
|
371
|
+
offsetY = Math.sin(rad2) * distance;
|
372
|
+
const tp3 = [p1[0] + offsetX, p1[1] + offsetY];
|
373
|
+
const tp4 = [p2[0] + offsetX, p2[1] + offsetY];
|
374
|
+
return [[tp1, tp2], [tp3, tp4]];
|
375
|
+
}
|
376
|
+
/**
|
377
|
+
* 直线交点
|
378
|
+
* @param {*} p1
|
379
|
+
* @param {*} p2
|
380
|
+
* @param {*} p3
|
381
|
+
* @param {*} p4
|
382
|
+
* @returns
|
383
|
+
*/
|
384
|
+
function lineIntersection(p1, p2, p3, p4) {
|
385
|
+
const dx1 = p2[0] - p1[0], dy1 = p2[1] - p1[1];
|
386
|
+
const dx2 = p4[0] - p3[0], dy2 = p4[1] - p3[1];
|
387
|
+
if (dx1 === 0 && dx2 === 0) {
|
388
|
+
return null;
|
389
|
+
}
|
390
|
+
if (dy1 === 0 && dy2 === 0) {
|
391
|
+
return null;
|
392
|
+
}
|
393
|
+
const k1 = dy1 / dx1;
|
394
|
+
const k2 = dy2 / dx2;
|
395
|
+
const b1 = p1[1] - k1 * p1[0];
|
396
|
+
const b2 = p3[1] - k2 * p3[0];
|
397
|
+
let x, y;
|
398
|
+
if (dx1 === 0) {
|
399
|
+
x = p1[0];
|
400
|
+
y = k2 * x + b2;
|
401
|
+
}
|
402
|
+
else if (dx2 === 0) {
|
403
|
+
x = p3[0];
|
404
|
+
y = k1 * x + b1;
|
405
|
+
}
|
406
|
+
else if (dy1 === 0) {
|
407
|
+
y = p1[1];
|
408
|
+
x = (y - b2) / k2;
|
409
|
+
}
|
410
|
+
else if (dy2 === 0) {
|
411
|
+
y = p3[1];
|
412
|
+
x = (y - b1) / k1;
|
413
|
+
}
|
414
|
+
else {
|
415
|
+
x = (b2 - b1) / (k1 - k2);
|
416
|
+
y = k1 * x + b1;
|
417
|
+
}
|
418
|
+
return [x, y];
|
419
|
+
}
|
420
|
+
//# sourceMappingURL=polyline.js.map
|