poly-extrude 0.5.0 → 0.7.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/poly-extrude.js +1183 -42
- package/dist/poly-extrude.js.map +1 -1
- package/dist/poly-extrude.min.js +4 -2
- package/dist/poly-extrude.mjs +1183 -43
- package/index.js +2 -1
- package/package.json +1 -1
- package/readme.md +172 -170
- package/src/math/Quaternion.js +688 -0
- package/src/math/Vector3.js +21 -17
- package/src/polyline.js +43 -3
- package/src/tube.js +146 -0
package/index.js
CHANGED
@@ -2,4 +2,5 @@ import { extrudePolygons } from './src/polygon';
|
|
2
2
|
import { extrudePolylines, expandLine, leftOnLine, extrudeSlopes } from './src/polyline';
|
3
3
|
import { cylinder } from './src/cylinder';
|
4
4
|
import { expandPaths } from './src/path';
|
5
|
-
|
5
|
+
import { expandTubes } from './src/tube';
|
6
|
+
export { extrudePolygons, extrudePolylines, extrudeSlopes, expandLine, leftOnLine, cylinder, expandPaths, expandTubes };
|
package/package.json
CHANGED
package/readme.md
CHANGED
@@ -1,62 +1,75 @@
|
|
1
1
|
# poly-extrude
|
2
2
|
|
3
|
-
|
4
3
|
Extrude polygons/polylines. Born in [maptalks.three](https://github.com/maptalks/maptalks.three) project<br>
|
5
4
|
|
6
5
|
## Examples
|
7
|
-
|
8
|
-
|
9
|
-
[
|
10
|
-
|
6
|
+
|
7
|
+
[building](https://deyihu.github.io/poly-extrude/test/building.html)
|
8
|
+
<!-- <br> -->
|
9
|
+
[buildings](https://deyihu.github.io/poly-extrude/test/buildings.html)
|
10
|
+
<!-- <br> -->
|
11
11
|
[multi-polygon](https://deyihu.github.io/poly-extrude/test/multi-polygon.html)<br>
|
12
|
-
<br>
|
12
|
+
<!-- <br> -->
|
13
13
|
[street](https://deyihu.github.io/poly-extrude/test/street.html)<br>
|
14
|
-
<br>
|
14
|
+
<!-- <br> -->
|
15
15
|
[line-uv](https://deyihu.github.io/poly-extrude/test/line-uv.html)<br>
|
16
|
-

|
16
|
+
<!--  -->
|
17
17
|
[ny-building](https://deyihu.github.io/poly-extrude/test/ny-building.html)<br>
|
18
|
-

|
18
|
+
<!--  -->
|
19
19
|
[cylinder](https://deyihu.github.io/poly-extrude/test/cylinder.html)<br>
|
20
|
-

|
20
|
+
<!--  -->
|
21
21
|
[brige](https://deyihu.github.io/poly-extrude/test/brige.html)<br>
|
22
|
-

|
22
|
+
<!--  -->
|
23
23
|
[spring](https://deyihu.github.io/poly-extrude/test/spring.html)<br>
|
24
|
-

|
24
|
+
<!--  -->
|
25
25
|
[expand paths](https://deyihu.github.io/poly-extrude/test/expand-paths-brige.html)<br>
|
26
|
-

|
26
|
+
<!--  -->
|
27
|
+
[slope](https://deyihu.github.io/poly-extrude/test/slope.html)<br>
|
28
|
+
|
29
|
+
[tube](https://deyihu.github.io/poly-extrude/test/tube.html)<br>
|
27
30
|
|
28
31
|
## Install
|
29
32
|
|
33
|
+
### NPM
|
34
|
+
|
30
35
|
```sh
|
31
36
|
npm i poly-extrude
|
32
37
|
|
33
|
-
|
34
|
-
|
35
|
-
yarn add poly-extrude
|
38
|
+
```
|
36
39
|
|
37
|
-
|
40
|
+
### CDN
|
38
41
|
|
39
|
-
|
42
|
+
```html
|
43
|
+
<script type="text/javascript" src="https://unpkg.com/poly-extrude/dist/poly-extrude.js"></script>
|
40
44
|
```
|
41
45
|
|
42
|
-
##
|
43
|
-
|
44
|
-
### ESM
|
46
|
+
## Use
|
45
47
|
|
46
48
|
```js
|
47
49
|
import {
|
48
50
|
extrudePolygons,
|
49
51
|
extrudePolylines,
|
50
52
|
cylinder,
|
51
|
-
expandPaths
|
53
|
+
expandPaths,
|
54
|
+
extrudeSlopes,
|
55
|
+
expandTubes
|
52
56
|
} from 'poly-extrude';
|
57
|
+
|
58
|
+
//if you use cdn
|
59
|
+
|
60
|
+
// const {
|
61
|
+
// extrudePolygons,
|
62
|
+
// extrudePolylines
|
63
|
+
// } = window.polyextrude;
|
64
|
+
|
53
65
|
const polygons = [
|
54
66
|
//polygon
|
55
67
|
[
|
56
68
|
//outring
|
57
69
|
[
|
58
70
|
[x, y],
|
59
|
-
[x, y],
|
71
|
+
[x, y],
|
72
|
+
...........
|
60
73
|
],
|
61
74
|
//holes
|
62
75
|
[
|
@@ -68,35 +81,25 @@ pnpm i poly-extrude
|
|
68
81
|
],
|
69
82
|
//other polygons
|
70
83
|
......
|
71
|
-
]
|
72
|
-
|
73
|
-
const result = extrudePolygons(polygons, {
|
74
|
-
depth: 2
|
75
|
-
});
|
76
|
-
const {
|
77
|
-
positon,
|
78
|
-
normal,
|
79
|
-
uv,
|
80
|
-
indices
|
81
|
-
} = result;
|
82
|
-
//do something
|
84
|
+
];
|
83
85
|
|
84
86
|
const polylines = [
|
85
87
|
// polyline
|
86
88
|
[
|
87
89
|
[x, y],
|
88
|
-
[x, y],
|
90
|
+
[x, y],
|
91
|
+
...........
|
89
92
|
],
|
90
93
|
//polyline
|
91
94
|
[
|
92
95
|
[x, y],
|
93
|
-
[x, y],
|
96
|
+
[x, y],
|
97
|
+
...........
|
94
98
|
],
|
95
99
|
];
|
96
100
|
|
97
|
-
const result =
|
98
|
-
depth: 2
|
99
|
-
lineWidth: 2
|
101
|
+
const result = extrudePolygons(polygons, {
|
102
|
+
depth: 2
|
100
103
|
});
|
101
104
|
const {
|
102
105
|
positon,
|
@@ -105,39 +108,20 @@ pnpm i poly-extrude
|
|
105
108
|
indices
|
106
109
|
} = result;
|
107
110
|
//do something
|
111
|
+
```
|
108
112
|
|
109
|
-
|
110
|
-
const result = cylinder(center, {
|
111
|
-
radius: 1,
|
112
|
-
height: 2,
|
113
|
-
radialSegments: 6
|
114
|
-
});
|
115
|
-
const {
|
116
|
-
positon,
|
117
|
-
normal,
|
118
|
-
uv,
|
119
|
-
indices
|
120
|
-
} = result;
|
121
|
-
//do something
|
113
|
+
## API
|
122
114
|
|
115
|
+

|
123
116
|
|
124
|
-
|
125
|
-
const polylines = [
|
126
|
-
// polyline
|
127
|
-
[
|
128
|
-
[x, y],
|
129
|
-
[x, y], ...........
|
130
|
-
],
|
131
|
-
//polyline
|
132
|
-
[
|
133
|
-
[x, y],
|
134
|
-
[x, y], ...........
|
135
|
-
],
|
136
|
-
];
|
117
|
+
### `extrudePolygons(polygons, options)`
|
137
118
|
|
138
|
-
|
139
|
-
|
140
|
-
|
119
|
+
* `polygons`
|
120
|
+
* `options.depth`
|
121
|
+
|
122
|
+
```js
|
123
|
+
const result = extrudePolygons(polygons, {
|
124
|
+
depth: 2
|
141
125
|
});
|
142
126
|
const {
|
143
127
|
positon,
|
@@ -146,110 +130,128 @@ pnpm i poly-extrude
|
|
146
130
|
indices
|
147
131
|
} = result;
|
148
132
|
//do something
|
133
|
+
```
|
134
|
+
|
135
|
+
|
136
|
+
### `extrudePolylines(lines, options)`
|
149
137
|
|
138
|
+
* `lines`
|
139
|
+
* `options.depth`
|
140
|
+
* `options.lineWidth`
|
141
|
+
* `options.bottomStickGround` Is the bottom attached to the ground
|
142
|
+
|
143
|
+
```js
|
144
|
+
const result = extrudePolylines(polylines, {
|
145
|
+
depth: 2,
|
146
|
+
lineWidth: 2
|
147
|
+
});
|
148
|
+
const {
|
149
|
+
positon,
|
150
|
+
normal,
|
151
|
+
uv,
|
152
|
+
indices
|
153
|
+
} = result;
|
154
|
+
//do something
|
150
155
|
```
|
151
156
|
|
152
|
-
###
|
157
|
+
### `cylinder(center, options)`
|
153
158
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
const polygons = [
|
159
|
-
//polygon
|
160
|
-
[
|
161
|
-
//outring
|
162
|
-
[
|
163
|
-
[x, y],
|
164
|
-
[x, y], ...........
|
165
|
-
],
|
166
|
-
//holes
|
167
|
-
[
|
168
|
-
[x, y],
|
169
|
-
[x, y], ...........
|
170
|
-
],
|
171
|
-
........
|
172
|
-
|
173
|
-
],
|
174
|
-
//other polygons
|
175
|
-
......
|
176
|
-
]
|
177
|
-
|
178
|
-
const result = polyextrude.extrudePolygons(polygons, {
|
179
|
-
depth: 2
|
180
|
-
})
|
181
|
-
const {
|
182
|
-
positon,
|
183
|
-
normal,
|
184
|
-
uv,
|
185
|
-
indices
|
186
|
-
} = result;
|
187
|
-
//do something
|
188
|
-
|
189
|
-
const polylines = [
|
190
|
-
// polyline
|
191
|
-
[
|
192
|
-
[x, y],
|
193
|
-
[x, y], ...........
|
194
|
-
],
|
195
|
-
//polyline
|
196
|
-
[
|
197
|
-
[x, y],
|
198
|
-
[x, y], ...........
|
199
|
-
],
|
200
|
-
];
|
201
|
-
|
202
|
-
const result = polyextrude.extrudePolylines(polylines, {
|
203
|
-
depth: 2,
|
204
|
-
lineWidth: 2
|
205
|
-
});
|
206
|
-
const {
|
207
|
-
positon,
|
208
|
-
normal,
|
209
|
-
uv,
|
210
|
-
indices
|
211
|
-
} = result;
|
212
|
-
//do something
|
213
|
-
|
214
|
-
const center = [0, 0];
|
215
|
-
const result = polyextrude.cylinder(center, {
|
216
|
-
radius: 1,
|
217
|
-
height: 2,
|
218
|
-
radialSegments: 6
|
219
|
-
});
|
220
|
-
const {
|
221
|
-
positon,
|
222
|
-
normal,
|
223
|
-
uv,
|
224
|
-
indices
|
225
|
-
} = result;
|
226
|
-
//do something
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
const polylines = [
|
231
|
-
// polyline
|
232
|
-
[
|
233
|
-
[x, y],
|
234
|
-
[x, y], ...........
|
235
|
-
],
|
236
|
-
//polyline
|
237
|
-
[
|
238
|
-
[x, y],
|
239
|
-
[x, y], ...........
|
240
|
-
],
|
241
|
-
];
|
159
|
+
* `center`
|
160
|
+
* `options.radius`
|
161
|
+
* `options.height`
|
162
|
+
* `options.radialSegments`
|
242
163
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
164
|
+
```js
|
165
|
+
const center = [0, 0];
|
166
|
+
const result = cylinder(center, {
|
167
|
+
|
168
|
+
radius: 1,
|
169
|
+
height: 2,
|
170
|
+
radialSegments: 6
|
171
|
+
|
172
|
+
});
|
173
|
+
const {
|
174
|
+
positon,
|
175
|
+
normal,
|
176
|
+
uv,
|
177
|
+
indices
|
178
|
+
|
179
|
+
} = result;
|
180
|
+
//do something
|
181
|
+
```
|
182
|
+
|
183
|
+
### `expandPaths(lines, options)`
|
184
|
+
|
185
|
+
* `lines`
|
186
|
+
* `options.lineWidth`
|
187
|
+
|
188
|
+
```js
|
189
|
+
const result = expandPaths(polylines, {
|
190
|
+
|
191
|
+
cornerRadius: 0.5,
|
192
|
+
lineWidth: 2
|
193
|
+
|
194
|
+
});
|
195
|
+
const {
|
196
|
+
|
197
|
+
positon,
|
198
|
+
normal,
|
199
|
+
uv,
|
200
|
+
indices
|
201
|
+
|
202
|
+
} = result;
|
203
|
+
//do something
|
204
|
+
```
|
205
|
+
|
206
|
+
### `extrudeSlopes(lines, options)`
|
207
|
+
|
208
|
+
* `lines`
|
209
|
+
* `options.depth`
|
210
|
+
* `options.lineWidth`
|
211
|
+
* `options.side` Which side serves as the slope, 'left' or 'right'
|
212
|
+
* `options.sideDepth` slope depth
|
213
|
+
* `options.bottomStickGround` Is the bottom attached to the ground
|
214
|
+
|
215
|
+
```js
|
216
|
+
const result = extrudeSlopes(polylines, {
|
217
|
+
|
218
|
+
depth: 1,
|
219
|
+
side: 'left',
|
220
|
+
sideDepth: 0,
|
221
|
+
lineWidth: 2
|
222
|
+
|
223
|
+
});
|
224
|
+
const {
|
225
|
+
|
226
|
+
positon,
|
227
|
+
normal,
|
228
|
+
uv,
|
229
|
+
indices
|
230
|
+
|
231
|
+
} = result;
|
232
|
+
//do something
|
233
|
+
```
|
234
|
+
|
235
|
+
### `expandTubes(lines, options)`
|
236
|
+
|
237
|
+
* `lines`
|
238
|
+
* `options.radius`
|
239
|
+
* `options.radialSegments`
|
240
|
+
|
241
|
+
```js
|
242
|
+
const result = expandTubes(polylines, {
|
243
|
+
|
244
|
+
radius: 1,
|
245
|
+
radialSegments: 8
|
246
|
+
|
247
|
+
});
|
248
|
+
const {
|
249
|
+
|
250
|
+
positon,
|
251
|
+
normal,
|
252
|
+
uv,
|
253
|
+
indices
|
254
|
+
|
255
|
+
} = result;
|
256
|
+
//do something
|
255
257
|
```
|