poly-extrude 0.17.0 → 0.18.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 +1 -1
- package/dist/cylinder.js +2 -2
- package/dist/cylinder.js.map +1 -1
- package/dist/path.d.ts +1 -1
- package/dist/path.js +2 -2
- package/dist/path.js.map +1 -1
- package/dist/poly-extrude.js +45 -47
- package/dist/poly-extrude.js.map +1 -1
- package/dist/poly-extrude.min.js +2 -2
- package/dist/poly-extrude.mjs +45 -47
- package/dist/poly-extrude.mjs.map +1 -1
- package/dist/polygon.d.ts +2 -2
- package/dist/polygon.js +6 -5
- package/dist/polygon.js.map +1 -1
- package/dist/polygonpath.d.ts +2 -1
- package/dist/polygonpath.js +25 -29
- package/dist/polygonpath.js.map +1 -1
- package/dist/polyline.d.ts +2 -2
- package/dist/polyline.js +4 -4
- package/dist/polyline.js.map +1 -1
- package/dist/tube.d.ts +1 -1
- package/dist/tube.js +2 -2
- package/dist/tube.js.map +1 -1
- package/dist/util.d.ts +5 -11
- package/dist/util.js +5 -3
- package/dist/util.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +106 -7
- package/src/cylinder.ts +2 -2
- package/src/path.ts +3 -3
- package/src/polygon.ts +8 -7
- package/src/polygonpath.ts +33 -32
- package/src/polyline.ts +6 -6
- package/src/tube.ts +3 -3
- package/src/util.ts +11 -9
package/readme.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Extrude polygons/polylines. Born in [maptalks.three](https://github.com/maptalks/maptalks.three) project<br>
|
4
4
|
|
5
|
-
## Examples
|
5
|
+
<!-- ## Examples
|
6
6
|
|
7
7
|
[](https://deyihu.github.io/poly-extrude/test/building.html)
|
8
8
|
|
@@ -21,7 +21,7 @@ Extrude polygons/polylines. Born in [maptalks.three](https://github.com/maptalks
|
|
21
21
|
[](https://deyihu.github.io/poly-extrude/test/tube.html)<br>
|
22
22
|
[](https://deyihu.github.io/poly-extrude/test/terrain.html)<br>
|
23
23
|
|
24
|
-
[shape demo ](https://deyihu.github.io/poly-extrude/test/shape.html)<br>
|
24
|
+
[shape demo ](https://deyihu.github.io/poly-extrude/test/shape.html)<br> -->
|
25
25
|
|
26
26
|
## Install
|
27
27
|
|
@@ -41,7 +41,9 @@ npm i poly-extrude
|
|
41
41
|
|
42
42
|
```js
|
43
43
|
import {
|
44
|
+
polygons,
|
44
45
|
extrudePolygons,
|
46
|
+
extrudePolygonsOnPath,
|
45
47
|
extrudePolylines,
|
46
48
|
cylinder,
|
47
49
|
expandPaths,
|
@@ -107,6 +109,7 @@ npm i poly-extrude
|
|
107
109
|
|
108
110
|
## API
|
109
111
|
|
112
|
+
|
110
113
|

|
111
114
|
|
112
115
|
### `extrudePolygons(polygons, options)`
|
@@ -127,6 +130,49 @@ npm i poly-extrude
|
|
127
130
|
} = result;
|
128
131
|
//do something
|
129
132
|
```
|
133
|
+
[building](https://deyihu.github.io/poly-extrude/test/building.html)
|
134
|
+
[buildings](https://deyihu.github.io/poly-extrude/test/buildings.html)
|
135
|
+
[china](https://deyihu.github.io/poly-extrude/test/china.html)
|
136
|
+
[muti polygon](https://deyihu.github.io/poly-extrude/test/multi-polygon.html)
|
137
|
+
[ny buildings](https://deyihu.github.io/poly-extrude/test/ny-building.html)
|
138
|
+
[custom shape](https://deyihu.github.io/poly-extrude/test/shape.html)
|
139
|
+
|
140
|
+
___
|
141
|
+
|
142
|
+

|
143
|
+
|
144
|
+
### `extrudePolygonsOnPath(polygons, options)`
|
145
|
+
|
146
|
+
* `polygons`
|
147
|
+
* `options.extrudePath` is line
|
148
|
+
* `options.openEnd`
|
149
|
+
* `options.openEndUV`
|
150
|
+
|
151
|
+
```js
|
152
|
+
const result = extrudePolygonsOnPath(polygons, {
|
153
|
+
extrudePath: [
|
154
|
+
[0, 0],
|
155
|
+
[100, 0]
|
156
|
+
]
|
157
|
+
});
|
158
|
+
const {
|
159
|
+
positon,
|
160
|
+
normal,
|
161
|
+
uv,
|
162
|
+
indices
|
163
|
+
} = result;
|
164
|
+
//do something
|
165
|
+
```
|
166
|
+
|
167
|
+
[base demo](https://deyihu.github.io/poly-extrude/test/polygon-on-path.html)
|
168
|
+
[with holes demo](https://deyihu.github.io/poly-extrude/test/polygon-on-path-hole.html)
|
169
|
+
[with holes by custom shape](https://deyihu.github.io/poly-extrude/test/polygon-on-path-hole1.html)
|
170
|
+
[extrude along spring](https://deyihu.github.io/poly-extrude/test/polygon-on-path-spring.html)
|
171
|
+
[extrude taihu lake](https://deyihu.github.io/poly-extrude/test/polygon-on-path-taihu.html)
|
172
|
+
|
173
|
+
|
174
|
+
___
|
175
|
+
|
130
176
|
|
131
177
|

|
132
178
|
|
@@ -138,8 +184,6 @@ npm i poly-extrude
|
|
138
184
|
* `options.bottomStickGround` Is the bottom attached to the ground
|
139
185
|
* `options.pathUV` generate Path UV
|
140
186
|
|
141
|
-
[extrudePolylines pathUV demo](https://deyihu.github.io/poly-extrude/test/line-pathuv.html)
|
142
|
-
|
143
187
|
```js
|
144
188
|
const result = extrudePolylines(polylines, {
|
145
189
|
depth: 2,
|
@@ -153,6 +197,21 @@ npm i poly-extrude
|
|
153
197
|
} = result;
|
154
198
|
//do something
|
155
199
|
```
|
200
|
+
[line](https://deyihu.github.io/poly-extrude/test/line.html)
|
201
|
+
[line uv](https://deyihu.github.io/poly-extrude/test/line-uv.html)
|
202
|
+
[line pathUV](https://deyihu.github.io/poly-extrude/test/line-pathuv.html)
|
203
|
+
[brige](https://deyihu.github.io/poly-extrude/test/brige.html)
|
204
|
+
[brige bottomStickGround](https://deyihu.github.io/poly-extrude/test/brige-bottomStickGround.html)
|
205
|
+
[extrude brige](https://deyihu.github.io/poly-extrude/test/extrudepolyline-brige.html)
|
206
|
+
[spring](https://deyihu.github.io/poly-extrude/test/spring.html)
|
207
|
+
[wall](https://deyihu.github.io/poly-extrude/test/wall.html)
|
208
|
+
[street](https://deyihu.github.io/poly-extrude/test/street.html)
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
___
|
214
|
+
|
156
215
|
|
157
216
|

|
158
217
|
|
@@ -181,6 +240,10 @@ const {
|
|
181
240
|
} = result;
|
182
241
|
//do something
|
183
242
|
```
|
243
|
+
[cylinder](https://deyihu.github.io/poly-extrude/test/cylinder.html)
|
244
|
+
___
|
245
|
+
|
246
|
+
|
184
247
|
|
185
248
|

|
186
249
|
|
@@ -207,6 +270,12 @@ const {
|
|
207
270
|
//do something
|
208
271
|
```
|
209
272
|
|
273
|
+
[paths](https://deyihu.github.io/poly-extrude/test/expand-path.html)
|
274
|
+
[street paths](https://deyihu.github.io/poly-extrude/test/expand-path-street.html)
|
275
|
+
[brige paths](https://deyihu.github.io/poly-extrude/test/expand-paths-brige.html)
|
276
|
+
___
|
277
|
+
|
278
|
+
|
210
279
|

|
211
280
|
|
212
281
|
### `extrudeSlopes(lines, options)`
|
@@ -219,7 +288,6 @@ const {
|
|
219
288
|
* `options.bottomStickGround` Is the bottom attached to the ground
|
220
289
|
* `options.pathUV` generate Path UV
|
221
290
|
|
222
|
-
[extrudeSlopes pathUV demo](https://deyihu.github.io/poly-extrude/test/slope-pathuv.html)
|
223
291
|
|
224
292
|
```js
|
225
293
|
const result = extrudeSlopes(polylines, {
|
@@ -241,6 +309,10 @@ const {
|
|
241
309
|
//do something
|
242
310
|
```
|
243
311
|
|
312
|
+
[slope](https://deyihu.github.io/poly-extrude/test/slope.html)
|
313
|
+
[extrudeSlopes pathUV demo](https://deyihu.github.io/poly-extrude/test/slope-pathuv.html)
|
314
|
+
___
|
315
|
+
|
244
316
|

|
245
317
|
|
246
318
|
### `expandTubes(lines, options)`
|
@@ -267,6 +339,9 @@ const {
|
|
267
339
|
//do something
|
268
340
|
```
|
269
341
|
|
342
|
+
[tube](https://deyihu.github.io/poly-extrude/test/tube.html)
|
343
|
+
___
|
344
|
+
|
270
345
|

|
271
346
|
|
272
347
|
### `plane(width, height,devideW,devideH)`
|
@@ -276,8 +351,6 @@ const {
|
|
276
351
|
* `devideW`
|
277
352
|
* `devideH`
|
278
353
|
|
279
|
-
[plane demo](https://deyihu.github.io/poly-extrude/test/plane.html)
|
280
|
-
[custom terrain demo](https://deyihu.github.io/poly-extrude/test/terrain.html)
|
281
354
|
|
282
355
|
```js
|
283
356
|
const result = plane(100, 100, 10, 10);
|
@@ -291,3 +364,29 @@ const {
|
|
291
364
|
} = result;
|
292
365
|
//do something
|
293
366
|
```
|
367
|
+
|
368
|
+
[plane demo](https://deyihu.github.io/poly-extrude/test/plane.html)
|
369
|
+
[custom terrain demo](https://deyihu.github.io/poly-extrude/test/terrain.html)
|
370
|
+
|
371
|
+
___
|
372
|
+
|
373
|
+

|
374
|
+
|
375
|
+
### `polygons(polygons, options)`
|
376
|
+
|
377
|
+
* `polygons`
|
378
|
+
|
379
|
+
```js
|
380
|
+
const result = polygons(polygons, {
|
381
|
+
|
382
|
+
});
|
383
|
+
const {
|
384
|
+
positon,
|
385
|
+
normal,
|
386
|
+
uv,
|
387
|
+
indices
|
388
|
+
} = result;
|
389
|
+
//do something
|
390
|
+
```
|
391
|
+
|
392
|
+
[polygons demo](https://deyihu.github.io/poly-extrude/test/simplepolygon.html)
|
package/src/cylinder.ts
CHANGED
@@ -11,8 +11,8 @@ type CylinderResult = ResultType & {
|
|
11
11
|
points: Float32Array
|
12
12
|
}
|
13
13
|
|
14
|
-
export function cylinder(point: [number, number],
|
15
|
-
options = Object.assign({}, { radius: 1, height: 2, radialSegments: 6 },
|
14
|
+
export function cylinder(point: [number, number], opts?: CylinderOptions): CylinderResult {
|
15
|
+
const options = Object.assign({}, { radius: 1, height: 2, radialSegments: 6 }, opts);
|
16
16
|
const radialSegments = Math.round(Math.max(4, options.radialSegments as number));
|
17
17
|
let { radius, height } = options;
|
18
18
|
radius = (radius as number);
|
package/src/path.ts
CHANGED
@@ -24,8 +24,8 @@ type PathsResult = ResultType & {
|
|
24
24
|
lines: Array<PolylineType>;
|
25
25
|
}
|
26
26
|
|
27
|
-
export function expandPaths(lines: Array<PolylineType>,
|
28
|
-
options = Object.assign({}, { lineWidth: 1, cornerRadius: 0, cornerSplit: 10 },
|
27
|
+
export function expandPaths(lines: Array<PolylineType>, opts?: PathsOptions): PathsResult {
|
28
|
+
const options = Object.assign({}, { lineWidth: 1, cornerRadius: 0, cornerSplit: 10 }, opts);
|
29
29
|
const results = lines.map(line => {
|
30
30
|
const points = line2Vectors(line);
|
31
31
|
const pathPointList = new PathPointList();
|
@@ -43,7 +43,7 @@ export function expandPaths(lines: Array<PolylineType>, options?: PathsOptions):
|
|
43
43
|
}
|
44
44
|
return result;
|
45
45
|
});
|
46
|
-
const result = merge(results)
|
46
|
+
const result = merge<PathsResult>(results)
|
47
47
|
result.lines = lines;
|
48
48
|
return result;
|
49
49
|
}
|
package/src/polygon.ts
CHANGED
@@ -13,10 +13,10 @@ type PolygonsResult = ResultType & {
|
|
13
13
|
}
|
14
14
|
|
15
15
|
|
16
|
-
export function extrudePolygons(polygons: Array<PolygonType>,
|
17
|
-
options = Object.assign({}, { depth: 2, top: true },
|
16
|
+
export function extrudePolygons(polygons: Array<PolygonType>, opts?: PolygonsOptions): PolygonsResult {
|
17
|
+
const options = Object.assign({}, { depth: 2, top: true }, opts);
|
18
18
|
const results = polygons.map(polygon => {
|
19
|
-
validatePolygon(polygon);
|
19
|
+
validatePolygon(polygon, true);
|
20
20
|
const result = flatVertices(polygon, options) as Record<string, any>;
|
21
21
|
result.polygon = polygon;
|
22
22
|
const triangles = earcut(result.flatVertices, result.holes, 2);
|
@@ -28,7 +28,7 @@ export function extrudePolygons(polygons: Array<PolygonType>, options?: Polygons
|
|
28
28
|
result.normal = generateNormal(result.indices, result.position);
|
29
29
|
return result;
|
30
30
|
});
|
31
|
-
const result = merge(results as Array<ResultType>)
|
31
|
+
const result = merge<PolygonsResult>(results as Array<ResultType>);
|
32
32
|
result.polygons = polygons;
|
33
33
|
return result;
|
34
34
|
|
@@ -193,9 +193,10 @@ function simplePolygon(polygon, options = {}) {
|
|
193
193
|
}
|
194
194
|
}
|
195
195
|
|
196
|
-
export function polygons(polygons,
|
196
|
+
export function polygons(polygons, opts = {}): PolygonsResult {
|
197
|
+
const options = Object.assign({}, opts);
|
197
198
|
const results = polygons.map(polygon => {
|
198
|
-
validatePolygon(polygon);
|
199
|
+
validatePolygon(polygon, true);
|
199
200
|
|
200
201
|
const result = simplePolygon(polygon, options) as Record<string, any>;
|
201
202
|
result.polygon = polygon;
|
@@ -205,7 +206,7 @@ export function polygons(polygons, options = {}): PolygonsResult {
|
|
205
206
|
result.normal = new Float32Array(result.normal);
|
206
207
|
return result;
|
207
208
|
});
|
208
|
-
const result = merge(results as Array<ResultType>)
|
209
|
+
const result = merge<PolygonsResult>(results as Array<ResultType>);
|
209
210
|
result.polygons = polygons;
|
210
211
|
return result;
|
211
212
|
|
package/src/polygonpath.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { Vector3 } from './math/Vector3';
|
2
|
-
import { PathPoint } from './path/PathPoint';
|
2
|
+
// import { PathPoint } from './path/PathPoint';
|
3
3
|
import { PathPointList } from './path/PathPointList';
|
4
4
|
import { PolygonType, PolylineType, ResultType } from './type';
|
5
|
-
import { generateNormal,
|
5
|
+
import { generateNormal, line2Vectors, merge, isClosedRing, calPolygonPointsCount, getPolygonsBBOX, mergeArray, validatePolygon } from './util';
|
6
6
|
import earcut from 'earcut';
|
7
7
|
const UP = new Vector3(0, 0, 1);
|
8
8
|
const normalDir = new Vector3();
|
@@ -11,18 +11,23 @@ type PolygonsOnPathOptions = {
|
|
11
11
|
extrudePath: PolylineType;
|
12
12
|
openEnd?: boolean;
|
13
13
|
openEndUV?: boolean;
|
14
|
+
polygonRotation?: number;
|
14
15
|
|
15
16
|
}
|
16
17
|
|
18
|
+
type PrivatePolygonsOnPathOptions = PolygonsOnPathOptions & {
|
19
|
+
center: Point;
|
20
|
+
bbox: [number, number, number, number]
|
21
|
+
}
|
22
|
+
|
17
23
|
type PolygonsOnPathResult = ResultType & {
|
18
24
|
polygons: Array<PolygonType>;
|
19
25
|
}
|
20
26
|
|
21
|
-
|
22
27
|
type Point = [number, number];
|
23
28
|
|
24
|
-
export function extrudePolygonsOnPath(polygons: Array<PolygonType>,
|
25
|
-
options = Object.assign({}, { openEnd: false, openEndUV: true },
|
29
|
+
export function extrudePolygonsOnPath(polygons: Array<PolygonType>, opts?: PolygonsOnPathOptions) {
|
30
|
+
const options = (Object.assign({}, { openEnd: false, openEndUV: true, polygonRotation: 0 }, opts)) as PrivatePolygonsOnPathOptions;
|
26
31
|
const { extrudePath, openEnd } = options;
|
27
32
|
if (!extrudePath || !Array.isArray(extrudePath) || extrudePath.length < 2) {
|
28
33
|
console.error('extrudePath is error:', extrudePath);
|
@@ -31,6 +36,8 @@ export function extrudePolygonsOnPath(polygons: Array<PolygonType>, options?: Po
|
|
31
36
|
const bbox = getPolygonsBBOX(polygons);
|
32
37
|
const [minx, miny, maxx, maxy] = bbox;
|
33
38
|
const center = [(minx + maxx) / 2, (miny + maxy) / 2] as Point;
|
39
|
+
options.center = center;
|
40
|
+
options.bbox = bbox;
|
34
41
|
|
35
42
|
const points = line2Vectors(extrudePath);
|
36
43
|
const pathPointList = new PathPointList();
|
@@ -38,19 +45,8 @@ export function extrudePolygonsOnPath(polygons: Array<PolygonType>, options?: Po
|
|
38
45
|
pathPointList.set(points, 0, options.cornerSplit, UP);
|
39
46
|
|
40
47
|
const results = polygons.map(polygon => {
|
41
|
-
|
42
|
-
|
43
|
-
validateRing(ring);
|
44
|
-
if (i === 0) {
|
45
|
-
if (isClockwise(ring)) {
|
46
|
-
polygon[i] = ring.reverse();
|
47
|
-
}
|
48
|
-
} else if (!isClockwise(ring)) {
|
49
|
-
polygon[i] = ring.reverse();
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
const result = generatePolygonOnPathVertexData(pathPointList, polygon, center) as Record<string, any>;
|
48
|
+
validatePolygon(polygon, false);
|
49
|
+
const result = generatePolygonOnPathVertexData(pathPointList, polygon, options as PrivatePolygonsOnPathOptions) as Record<string, any>;
|
54
50
|
if (!openEnd) {
|
55
51
|
generateStartAndEnd(result, polygon, options);
|
56
52
|
}
|
@@ -61,7 +57,7 @@ export function extrudePolygonsOnPath(polygons: Array<PolygonType>, options?: Po
|
|
61
57
|
result.normal = new Float32Array(result.normal);
|
62
58
|
return result;
|
63
59
|
});
|
64
|
-
const result = merge(results as Array<ResultType>)
|
60
|
+
const result = merge<PolygonsOnPathResult>(results as Array<ResultType>);
|
65
61
|
result.polygons = polygons;
|
66
62
|
return result;
|
67
63
|
}
|
@@ -76,7 +72,8 @@ function getAngle(c1: Point, c2: Point) {
|
|
76
72
|
}
|
77
73
|
|
78
74
|
|
79
|
-
function transformPolygon(polygon: PolygonType,
|
75
|
+
function transformPolygon(polygon: PolygonType, options: PrivatePolygonsOnPathOptions) {
|
76
|
+
const { center, polygonRotation } = options;
|
80
77
|
const [cx, cy] = center;
|
81
78
|
const list = [];
|
82
79
|
polygon.forEach((ring, rIndex) => {
|
@@ -100,7 +97,7 @@ function transformPolygon(polygon: PolygonType, center: Point) {
|
|
100
97
|
// dz: 0,
|
101
98
|
distance,
|
102
99
|
radius: Math.sqrt(offsetx * offsetx + offsety * offsety),
|
103
|
-
angle: getAngle(center, p as Point)
|
100
|
+
angle: -getAngle(center, p as Point) + polygonRotation
|
104
101
|
}
|
105
102
|
tempPoint = p;
|
106
103
|
}
|
@@ -115,8 +112,8 @@ function transformPolygon(polygon: PolygonType, center: Point) {
|
|
115
112
|
const TEMP_VECTOR3 = new Vector3(0, 0, 0);
|
116
113
|
// Vertex Data Generate Functions
|
117
114
|
// code copy from https://github.com/shawn0326/three.path/blob/master/src/PathGeometry.js
|
118
|
-
function generatePolygonOnPathVertexData(pathPointList, polygon: PolygonType,
|
119
|
-
const tpolygon = transformPolygon(polygon,
|
115
|
+
function generatePolygonOnPathVertexData(pathPointList, polygon: PolygonType, options: PrivatePolygonsOnPathOptions) {
|
116
|
+
const tpolygon = transformPolygon(polygon, options);
|
120
117
|
// let count = 0;
|
121
118
|
// modify data
|
122
119
|
const points: number[] = [];
|
@@ -154,9 +151,13 @@ function generatePolygonOnPathVertexData(pathPointList, polygon: PolygonType, ce
|
|
154
151
|
v.y *= radius;
|
155
152
|
v.z *= radius;
|
156
153
|
|
157
|
-
|
158
|
-
|
159
|
-
|
154
|
+
const x = pathPoint.pos.x + v.x;
|
155
|
+
const y = pathPoint.pos.y + v.y;
|
156
|
+
const z = pathPoint.pos.z + v.z;
|
157
|
+
|
158
|
+
points[++pIndex] = x;
|
159
|
+
points[++pIndex] = y;
|
160
|
+
points[++pIndex] = z;
|
160
161
|
|
161
162
|
// if (i === 0 || i === radialSegments - 1) {
|
162
163
|
// console.log(i, radialSegments, v.x, v.y, v.z);
|
@@ -174,15 +175,15 @@ function generatePolygonOnPathVertexData(pathPointList, polygon: PolygonType, ce
|
|
174
175
|
|
175
176
|
if (first && !isLast) {
|
176
177
|
let index = startPoints.length - 1;
|
177
|
-
startPoints[++index] =
|
178
|
-
startPoints[++index] =
|
179
|
-
startPoints[++index] =
|
178
|
+
startPoints[++index] = x;
|
179
|
+
startPoints[++index] = y;
|
180
|
+
startPoints[++index] = z;
|
180
181
|
}
|
181
182
|
if (end && !isLast) {
|
182
183
|
let index = endPoints.length - 1;
|
183
|
-
endPoints[++index] =
|
184
|
-
endPoints[++index] =
|
185
|
-
endPoints[++index] =
|
184
|
+
endPoints[++index] = x;
|
185
|
+
endPoints[++index] = y;
|
186
|
+
endPoints[++index] = z;
|
186
187
|
}
|
187
188
|
}
|
188
189
|
|
package/src/polyline.ts
CHANGED
@@ -18,8 +18,8 @@ type PolylinesResult = ResultType & {
|
|
18
18
|
lines: Array<PolylineType>;
|
19
19
|
}
|
20
20
|
|
21
|
-
export function extrudePolylines(lines: Array<PolylineType>,
|
22
|
-
options = Object.assign({}, { depth: 2, lineWidth: 1, bottomStickGround: false, pathUV: false },
|
21
|
+
export function extrudePolylines(lines: Array<PolylineType>, opts?: PolylinesOptions): PolylinesResult {
|
22
|
+
const options = Object.assign({}, { depth: 2, lineWidth: 1, bottomStickGround: false, pathUV: false }, opts);
|
23
23
|
checkOptions(options);
|
24
24
|
const results = lines.map(line => {
|
25
25
|
const result = expandLine(line, options) as Record<string, any>;
|
@@ -32,7 +32,7 @@ export function extrudePolylines(lines: Array<PolylineType>, options?: Polylines
|
|
32
32
|
result.normal = generateNormal(result.indices, result.position);
|
33
33
|
return result;
|
34
34
|
});
|
35
|
-
const result = merge(results as Array<ResultType>)
|
35
|
+
const result = merge<PolylinesResult>(results as Array<ResultType>);
|
36
36
|
result.lines = lines;
|
37
37
|
return result;
|
38
38
|
}
|
@@ -42,8 +42,8 @@ type SlopesOptions = PolylinesOptions & {
|
|
42
42
|
sideDepth?: number
|
43
43
|
}
|
44
44
|
|
45
|
-
export function extrudeSlopes(lines: Array<PolylineType>,
|
46
|
-
options = Object.assign({}, { depth: 2, lineWidth: 1, side: 'left', sideDepth: 0, bottomStickGround: false, pathUV: false, isSlope: true },
|
45
|
+
export function extrudeSlopes(lines: Array<PolylineType>, opts?: SlopesOptions): PolylinesResult {
|
46
|
+
const options = Object.assign({}, { depth: 2, lineWidth: 1, side: 'left', sideDepth: 0, bottomStickGround: false, pathUV: false, isSlope: true }, opts);
|
47
47
|
checkOptions(options);
|
48
48
|
const { depth, side, sideDepth } = options;
|
49
49
|
const results = lines.map(line => {
|
@@ -73,7 +73,7 @@ export function extrudeSlopes(lines: Array<PolylineType>, options?: SlopesOption
|
|
73
73
|
result.normal = generateNormal(result.indices, result.position);
|
74
74
|
return result;
|
75
75
|
});
|
76
|
-
const result = merge(results as Array<ResultType>)
|
76
|
+
const result = merge<PolylinesResult>(results as Array<ResultType>);
|
77
77
|
result.lines = lines;
|
78
78
|
return result;
|
79
79
|
}
|
package/src/tube.ts
CHANGED
@@ -17,8 +17,8 @@ type TubesResult = ResultType & {
|
|
17
17
|
lines: Array<PolylineType>;
|
18
18
|
}
|
19
19
|
|
20
|
-
export function expandTubes(lines: Array<PolylineType>,
|
21
|
-
options = Object.assign({}, { radius: 1, cornerSplit: 0, radialSegments: 8, startRad: -Math.PI / 4 },
|
20
|
+
export function expandTubes(lines: Array<PolylineType>, opts?: TubesOptions) {
|
21
|
+
const options = Object.assign({}, { radius: 1, cornerSplit: 0, radialSegments: 8, startRad: -Math.PI / 4 }, opts);
|
22
22
|
const results = lines.map(line => {
|
23
23
|
const points = line2Vectors(line);
|
24
24
|
const pathPointList = new PathPointList();
|
@@ -32,7 +32,7 @@ export function expandTubes(lines: Array<PolylineType>, options?: TubesOptions)
|
|
32
32
|
result.normal = new Float32Array(result.normal);
|
33
33
|
return result;
|
34
34
|
});
|
35
|
-
const result = merge(results as Array<ResultType>)
|
35
|
+
const result = merge<TubesResult>(results as Array<ResultType>);
|
36
36
|
result.lines = lines;
|
37
37
|
return result;
|
38
38
|
}
|
package/src/util.ts
CHANGED
@@ -72,7 +72,7 @@ export function getPolygonsBBOX(polygons, bbox?) {
|
|
72
72
|
return bbox;
|
73
73
|
}
|
74
74
|
|
75
|
-
export function validatePolygon(polygon: PolygonType) {
|
75
|
+
export function validatePolygon(polygon: PolygonType, ignoreEndPoint: boolean) {
|
76
76
|
for (let i = 0, len = polygon.length; i < len; i++) {
|
77
77
|
const ring = polygon[i];
|
78
78
|
validateRing(ring);
|
@@ -83,8 +83,10 @@ export function validatePolygon(polygon: PolygonType) {
|
|
83
83
|
} else if (isClockwise(ring)) {
|
84
84
|
polygon[i] = ring.reverse();
|
85
85
|
}
|
86
|
-
if (
|
87
|
-
|
86
|
+
if (ignoreEndPoint) {
|
87
|
+
if (isClosedRing(ring)) {
|
88
|
+
ring.splice(ring.length - 1, 1);
|
89
|
+
}
|
88
90
|
}
|
89
91
|
}
|
90
92
|
}
|
@@ -176,7 +178,7 @@ export function generateNormal(indices, position) {
|
|
176
178
|
return normals;
|
177
179
|
}
|
178
180
|
|
179
|
-
export function merge(results: Array<ResultType>) {
|
181
|
+
export function merge<T extends ResultType>(results: Array<ResultType>): T {
|
180
182
|
if (results.length === 1) {
|
181
183
|
const result = {
|
182
184
|
position: results[0].position,
|
@@ -185,7 +187,7 @@ export function merge(results: Array<ResultType>) {
|
|
185
187
|
indices: results[0].indices,
|
186
188
|
results
|
187
189
|
};
|
188
|
-
return result;
|
190
|
+
return result as T;
|
189
191
|
}
|
190
192
|
let plen = 0, ilen = 0;
|
191
193
|
for (let i = 0, len = results.length; i < len; i++) {
|
@@ -218,14 +220,14 @@ export function merge(results: Array<ResultType>) {
|
|
218
220
|
pOffset += position.length;
|
219
221
|
pCount += position.length / 3;
|
220
222
|
}
|
221
|
-
return result;
|
223
|
+
return result as T;
|
222
224
|
}
|
223
225
|
|
224
|
-
export function radToDeg(rad) {
|
226
|
+
export function radToDeg(rad: number) {
|
225
227
|
return rad * 180 / Math.PI;
|
226
228
|
}
|
227
229
|
|
228
|
-
export function degToRad(angle) {
|
230
|
+
export function degToRad(angle: number) {
|
229
231
|
return angle / 180 * Math.PI;
|
230
232
|
}
|
231
233
|
|
@@ -279,7 +281,7 @@ export function generateSideWallUV(uvs, vertices, indexA, indexB, indexC, indexD
|
|
279
281
|
|
280
282
|
}
|
281
283
|
|
282
|
-
export function line2Vectors(line) {
|
284
|
+
export function line2Vectors(line: PolylineType) {
|
283
285
|
const points: Vector3[] = [];
|
284
286
|
for (let i = 0, len = line.length; i < len; i++) {
|
285
287
|
const p = line[i];
|