poly-extrude 0.12.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/dist/plane.js +57 -0
- package/dist/plane.js.map +1 -0
- package/dist/poly-extrude.js +1290 -1511
- package/dist/poly-extrude.js.map +1 -1
- package/dist/poly-extrude.min.js +2 -2
- package/dist/poly-extrude.mjs +1290 -1512
- 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 +39 -3
- 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 -6
package/package.json
CHANGED
@@ -1,48 +1,53 @@
|
|
1
|
-
{
|
2
|
-
"name": "poly-extrude",
|
3
|
-
"version": "0.
|
4
|
-
"description": "",
|
5
|
-
"main": "dist/poly-extrude.js",
|
6
|
-
"module": "dist/poly-extrude.mjs",
|
7
|
-
"
|
8
|
-
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
"
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
"@
|
27
|
-
"@
|
28
|
-
"@rollup/plugin-
|
29
|
-
"@rollup/plugin-
|
30
|
-
"
|
31
|
-
"
|
32
|
-
"
|
33
|
-
"
|
34
|
-
"eslint
|
35
|
-
"eslint-
|
36
|
-
"eslint-plugin-
|
37
|
-
"
|
38
|
-
"
|
39
|
-
|
40
|
-
|
41
|
-
"
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
"
|
47
|
-
|
48
|
-
|
1
|
+
{
|
2
|
+
"name": "poly-extrude",
|
3
|
+
"version": "0.14.0",
|
4
|
+
"description": "extrude polyline/polygon etc",
|
5
|
+
"main": "dist/poly-extrude.js",
|
6
|
+
"module": "dist/poly-extrude.mjs",
|
7
|
+
"types": "dist/index.d.ts",
|
8
|
+
"scripts": {
|
9
|
+
"tsc": "npx tsc",
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
11
|
+
"lint": "eslint src/**/*.js",
|
12
|
+
"build": "npm run lint && npm run tsc && cross-env NODE_ENV=prd rollup -c",
|
13
|
+
"dev": "npm run lint && cross-env NODE_ENV=dev rollup -c -w"
|
14
|
+
},
|
15
|
+
"repository": {
|
16
|
+
"type": "git",
|
17
|
+
"url": "git+https://github.com/deyihu/poly-extrude.git"
|
18
|
+
},
|
19
|
+
"author": "",
|
20
|
+
"license": "ISC",
|
21
|
+
"bugs": {
|
22
|
+
"url": "https://github.com/deyihu/poly-extrude/issues"
|
23
|
+
},
|
24
|
+
"homepage": "https://github.com/deyihu/poly-extrude#readme",
|
25
|
+
"devDependencies": {
|
26
|
+
"@babel/core": "^7.17.5",
|
27
|
+
"@babel/preset-env": "^7.16.11",
|
28
|
+
"@rollup/plugin-babel": "^5.3.0",
|
29
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
30
|
+
"@rollup/plugin-json": "^4.1.0",
|
31
|
+
"@rollup/plugin-node-resolve": "^13.1.3",
|
32
|
+
"@rollup/plugin-typescript": "^8.3.0",
|
33
|
+
"cross-env": "^5.1.4",
|
34
|
+
"eslint": "^6.2.2",
|
35
|
+
"eslint-config-standard": "^14.1.0",
|
36
|
+
"eslint-plugin-import": "^2.18.2",
|
37
|
+
"eslint-plugin-node": "^10.0.0",
|
38
|
+
"eslint-plugin-promise": "^4.2.1",
|
39
|
+
"eslint-plugin-standard": "^4.0.1",
|
40
|
+
"rollup": "^2.64.0",
|
41
|
+
"rollup-plugin-terser": "^7.0.2",
|
42
|
+
"typescript": "^5.7.2",
|
43
|
+
"tslib": "^2.8.1"
|
44
|
+
},
|
45
|
+
"dependencies": {
|
46
|
+
"earcut": "^2.2.4"
|
47
|
+
},
|
48
|
+
"files": [
|
49
|
+
"dist/",
|
50
|
+
"src/",
|
51
|
+
"index.js"
|
52
|
+
]
|
53
|
+
}
|
package/readme.md
CHANGED
@@ -19,6 +19,7 @@ Extrude polygons/polylines. Born in [maptalks.three](https://github.com/maptalks
|
|
19
19
|
[](https://deyihu.github.io/poly-extrude/test/slope.html)<br>
|
20
20
|
|
21
21
|
[](https://deyihu.github.io/poly-extrude/test/tube.html)<br>
|
22
|
+
[](https://deyihu.github.io/poly-extrude/test/terrain.html)<br>
|
22
23
|
|
23
24
|
## Install
|
24
25
|
|
@@ -43,7 +44,8 @@ npm i poly-extrude
|
|
43
44
|
cylinder,
|
44
45
|
expandPaths,
|
45
46
|
extrudeSlopes,
|
46
|
-
expandTubes
|
47
|
+
expandTubes,
|
48
|
+
plane
|
47
49
|
} from 'poly-extrude';
|
48
50
|
|
49
51
|
//if you use cdn,the namespace is polyextrude
|
@@ -124,13 +126,16 @@ npm i poly-extrude
|
|
124
126
|
```
|
125
127
|
|
126
128
|

|
129
|
+
|
127
130
|
### `extrudePolylines(lines, options)`
|
128
131
|
|
129
132
|
* `lines`
|
130
133
|
* `options.depth`
|
131
134
|
* `options.lineWidth`
|
132
135
|
* `options.bottomStickGround` Is the bottom attached to the ground
|
133
|
-
* `options.
|
136
|
+
* `options.pathUV` generate Path UV
|
137
|
+
|
138
|
+
[extrudePolylines pathUV demo](https://deyihu.github.io/poly-extrude/test/line-pathuv.html)
|
134
139
|
|
135
140
|
```js
|
136
141
|
const result = extrudePolylines(polylines, {
|
@@ -147,6 +152,7 @@ npm i poly-extrude
|
|
147
152
|
```
|
148
153
|
|
149
154
|

|
155
|
+
|
150
156
|
### `cylinder(center, options)`
|
151
157
|
|
152
158
|
* `center`
|
@@ -174,6 +180,7 @@ const {
|
|
174
180
|
```
|
175
181
|
|
176
182
|

|
183
|
+
|
177
184
|
### `expandPaths(lines, options)`
|
178
185
|
|
179
186
|
* `lines`
|
@@ -207,7 +214,10 @@ const {
|
|
207
214
|
* `options.side` Which side serves as the slope, 'left' or 'right'
|
208
215
|
* `options.sideDepth` slope depth
|
209
216
|
* `options.bottomStickGround` Is the bottom attached to the ground
|
210
|
-
* `options.
|
217
|
+
* `options.pathUV` generate Path UV
|
218
|
+
|
219
|
+
|
220
|
+
[extrudeSlopes pathUV demo](https://deyihu.github.io/poly-extrude/test/slope-pathuv.html)
|
211
221
|
|
212
222
|
```js
|
213
223
|
const result = extrudeSlopes(polylines, {
|
@@ -230,6 +240,7 @@ const {
|
|
230
240
|
```
|
231
241
|
|
232
242
|

|
243
|
+
|
233
244
|
### `expandTubes(lines, options)`
|
234
245
|
|
235
246
|
* `lines`
|
@@ -253,3 +264,28 @@ const {
|
|
253
264
|
} = result;
|
254
265
|
//do something
|
255
266
|
```
|
267
|
+
|
268
|
+

|
269
|
+
|
270
|
+
### `plane(width, height,devideW,devideH)`
|
271
|
+
|
272
|
+
* `width`
|
273
|
+
* `height`
|
274
|
+
* `devideW`
|
275
|
+
* `devideH`
|
276
|
+
|
277
|
+
[plane demo](https://deyihu.github.io/poly-extrude/test/plane.html)
|
278
|
+
[custom terrain demo](https://deyihu.github.io/poly-extrude/test/terrain.html)
|
279
|
+
|
280
|
+
```js
|
281
|
+
const result = plane(100, 100, 10, 10);
|
282
|
+
const {
|
283
|
+
|
284
|
+
positon,
|
285
|
+
normal,
|
286
|
+
uv,
|
287
|
+
indices
|
288
|
+
|
289
|
+
} = result;
|
290
|
+
//do something
|
291
|
+
```
|
package/src/cylinder.ts
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
import { ResultType } from './type';
|
2
|
+
import { generateNormal } from './util';
|
3
|
+
|
4
|
+
type CylinderOptions = {
|
5
|
+
radius?: number;
|
6
|
+
height?: number;
|
7
|
+
radialSegments?: number;
|
8
|
+
}
|
9
|
+
|
10
|
+
type CylinderResult = ResultType & {
|
11
|
+
points: Float32Array
|
12
|
+
}
|
13
|
+
|
14
|
+
export function cylinder(point: [number, number], options?: CylinderOptions): CylinderResult {
|
15
|
+
options = Object.assign({}, { radius: 1, height: 2, radialSegments: 6 }, options);
|
16
|
+
const radialSegments = Math.round(Math.max(4, options.radialSegments as number));
|
17
|
+
let { radius, height } = options;
|
18
|
+
radius = (radius as number);
|
19
|
+
height = (height as number);
|
20
|
+
const aRad = 360 / radialSegments / 360 * Math.PI * 2;
|
21
|
+
const circlePointsLen = (radialSegments + 1);
|
22
|
+
const points = new Float32Array(circlePointsLen * 3 * 2);
|
23
|
+
const [centerx, centery] = point;
|
24
|
+
let idx = 0, uIdx = 0;
|
25
|
+
const offset = circlePointsLen * 3, uOffset = circlePointsLen * 2;
|
26
|
+
const indices: number[] = [], uv: number[] = [];
|
27
|
+
let iIndex = indices.length - 1;
|
28
|
+
for (let i = -1; i < radialSegments; i++) {
|
29
|
+
const rad = aRad * i;
|
30
|
+
const x = Math.cos(rad) * radius + centerx, y = Math.sin(rad) * radius + centery;
|
31
|
+
// bottom vertices
|
32
|
+
points[idx] = x;
|
33
|
+
points[idx + 1] = y;
|
34
|
+
points[idx + 2] = 0;
|
35
|
+
|
36
|
+
// top vertices
|
37
|
+
points[idx + offset] = x;
|
38
|
+
points[idx + 1 + offset] = y;
|
39
|
+
points[idx + 2 + offset] = height;
|
40
|
+
|
41
|
+
let u = 0, v = 0;
|
42
|
+
u = 0.5 + x / radius / 2;
|
43
|
+
v = 0.5 + y / radius / 2;
|
44
|
+
uv[uIdx] = u;
|
45
|
+
uv[uIdx + 1] = v;
|
46
|
+
uv[uIdx + uOffset] = u;
|
47
|
+
uv[uIdx + 1 + uOffset] = v;
|
48
|
+
|
49
|
+
idx += 3;
|
50
|
+
uIdx += 2;
|
51
|
+
if (i > 1) {
|
52
|
+
// bottom indices
|
53
|
+
// indices.push(0, i - 1, i);
|
54
|
+
indices[++iIndex] = 0;
|
55
|
+
indices[++iIndex] = i - 1;
|
56
|
+
indices[++iIndex] = i;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
idx -= 3;
|
60
|
+
points[idx] = points[0];
|
61
|
+
points[idx + 1] = points[1];
|
62
|
+
points[idx + 2] = points[2];
|
63
|
+
const pointsLen = points.length;
|
64
|
+
points[pointsLen - 3] = points[0];
|
65
|
+
points[pointsLen - 2] = points[1];
|
66
|
+
points[pointsLen - 1] = height;
|
67
|
+
|
68
|
+
const indicesLen = indices.length;
|
69
|
+
// top indices
|
70
|
+
iIndex = indices.length - 1;
|
71
|
+
for (let i = 0; i < indicesLen; i++) {
|
72
|
+
const index = indices[i];
|
73
|
+
indices[++iIndex] = index + circlePointsLen;
|
74
|
+
// indices.push(index + circlePointsLen);
|
75
|
+
}
|
76
|
+
|
77
|
+
const sidePoints = new Float32Array((circlePointsLen * 3 * 2 - 6) * 2);
|
78
|
+
let pIndex = -1;
|
79
|
+
idx = circlePointsLen * 2;
|
80
|
+
uIdx = 0;
|
81
|
+
iIndex = indices.length - 1;
|
82
|
+
let uvIndex = uv.length - 1;
|
83
|
+
for (let i = 0, len = points.length / 2; i < len - 3; i += 3) {
|
84
|
+
const x1 = points[i], y1 = points[i + 1], x2 = points[i + 3], y2 = points[i + 4];
|
85
|
+
sidePoints[++pIndex] = x1;
|
86
|
+
sidePoints[++pIndex] = y1;
|
87
|
+
sidePoints[++pIndex] = height;
|
88
|
+
sidePoints[++pIndex] = x2;
|
89
|
+
sidePoints[++pIndex] = y2;
|
90
|
+
sidePoints[++pIndex] = height;
|
91
|
+
sidePoints[++pIndex] = x1;
|
92
|
+
sidePoints[++pIndex] = y1;
|
93
|
+
sidePoints[++pIndex] = 0;
|
94
|
+
sidePoints[++pIndex] = x2;
|
95
|
+
sidePoints[++pIndex] = y2;
|
96
|
+
sidePoints[++pIndex] = 0;
|
97
|
+
const a = idx + 2, b = idx + 3, c = idx, d = idx + 1;
|
98
|
+
// indices.push(a, c, b, c, d, b);
|
99
|
+
indices[++iIndex] = c;
|
100
|
+
indices[++iIndex] = a;
|
101
|
+
indices[++iIndex] = d;
|
102
|
+
indices[++iIndex] = a;
|
103
|
+
indices[++iIndex] = b;
|
104
|
+
indices[++iIndex] = d;
|
105
|
+
// indices.push(c, a, d, a, b, d);
|
106
|
+
idx += 4;
|
107
|
+
const u1 = uIdx / circlePointsLen, u2 = (uIdx + 1) / circlePointsLen;
|
108
|
+
uv[++uvIndex] = u1;
|
109
|
+
uv[++uvIndex] = height / radius / 2;
|
110
|
+
uv[++uvIndex] = u2;
|
111
|
+
uv[++uvIndex] = height / radius / 2;
|
112
|
+
uv[++uvIndex] = u1;
|
113
|
+
uv[++uvIndex] = 0;
|
114
|
+
uv[++uvIndex] = u2;
|
115
|
+
uv[++uvIndex] = 0;
|
116
|
+
// uvs.push(u1, height / radius / 2, u2, height / radius / 2, u1, 0, u2, 0);
|
117
|
+
uIdx++;
|
118
|
+
}
|
119
|
+
const position = new Float32Array(points.length + sidePoints.length);
|
120
|
+
position.set(points, 0);
|
121
|
+
position.set(sidePoints, points.length);
|
122
|
+
const normal = generateNormal(indices, position);
|
123
|
+
return { points, indices: new Uint32Array(indices), position, normal, uv: new Float32Array(uv) };
|
124
|
+
}
|
package/src/index.ts
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
import { extrudePolygons } from './polygon';
|
2
|
+
import { extrudePolylines, expandLine, leftOnLine, extrudeSlopes } from './polyline';
|
3
|
+
import { cylinder } from './cylinder';
|
4
|
+
import { expandPaths } from './path';
|
5
|
+
import { expandTubes } from './tube';
|
6
|
+
import { plane } from './plane';
|
7
|
+
export { extrudePolygons, extrudePolylines, extrudeSlopes, expandLine, leftOnLine, cylinder, expandPaths, expandTubes, plane };
|