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.
Files changed (68) hide show
  1. package/dist/cylinder.d.ts +11 -0
  2. package/{src → dist}/cylinder.js +108 -111
  3. package/dist/cylinder.js.map +1 -0
  4. package/dist/index.d.ts +7 -0
  5. package/dist/index.js +8 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/math/Curve.d.ts +41 -0
  8. package/dist/math/Curve.js +142 -0
  9. package/dist/math/Curve.js.map +1 -0
  10. package/dist/math/Interpolations.d.ts +8 -0
  11. package/dist/math/Interpolations.js +48 -0
  12. package/dist/math/Interpolations.js.map +1 -0
  13. package/dist/math/Matrix4.d.ts +8 -0
  14. package/dist/math/Matrix4.js +582 -0
  15. package/dist/math/Matrix4.js.map +1 -0
  16. package/dist/math/QuadraticBezierCurve3.d.ts +10 -0
  17. package/dist/math/QuadraticBezierCurve3.js +22 -0
  18. package/dist/math/QuadraticBezierCurve3.js.map +1 -0
  19. package/dist/math/Quaternion.d.ts +46 -0
  20. package/dist/math/Quaternion.js +415 -0
  21. package/dist/math/Quaternion.js.map +1 -0
  22. package/dist/math/Vector3.d.ts +42 -0
  23. package/dist/math/Vector3.js +403 -0
  24. package/dist/math/Vector3.js.map +1 -0
  25. package/dist/path/PathPoint.d.ts +15 -0
  26. package/dist/path/PathPoint.js +35 -0
  27. package/dist/path/PathPoint.js.map +1 -0
  28. package/dist/path/PathPointList.d.ts +27 -0
  29. package/dist/path/PathPointList.js +212 -0
  30. package/dist/path/PathPointList.js.map +1 -0
  31. package/dist/path.d.ts +11 -0
  32. package/{src → dist}/path.js +334 -360
  33. package/dist/path.js.map +1 -0
  34. package/dist/plane.d.ts +2 -0
  35. package/{src → dist}/plane.js +57 -58
  36. package/dist/plane.js.map +1 -0
  37. package/dist/poly-extrude.js +1286 -1581
  38. package/dist/poly-extrude.js.map +1 -1
  39. package/dist/poly-extrude.min.js +2 -2
  40. package/dist/poly-extrude.mjs +1286 -1581
  41. package/dist/poly-extrude.mjs.map +1 -0
  42. package/dist/polygon.d.ts +9 -0
  43. package/{src → dist}/polygon.js +163 -179
  44. package/dist/polygon.js.map +1 -0
  45. package/dist/polyline.d.ts +24 -0
  46. package/{src → dist}/polyline.js +420 -456
  47. package/dist/polyline.js.map +1 -0
  48. package/dist/tube.d.ts +12 -0
  49. package/{src → dist}/tube.js +124 -142
  50. package/dist/tube.js.map +1 -0
  51. package/dist/type.d.ts +9 -0
  52. package/dist/type.js +2 -0
  53. package/dist/type.js.map +1 -0
  54. package/dist/util.d.ts +20 -0
  55. package/dist/util.js +217 -0
  56. package/dist/util.js.map +1 -0
  57. package/package.json +53 -48
  58. package/readme.md +12 -2
  59. package/src/cylinder.ts +124 -0
  60. package/src/index.ts +7 -0
  61. package/src/path.ts +385 -0
  62. package/src/plane.ts +60 -0
  63. package/src/polygon.ts +189 -0
  64. package/src/polyline.ts +473 -0
  65. package/src/tube.ts +155 -0
  66. package/src/type.ts +9 -0
  67. package/src/{util.js → util.ts} +1 -1
  68. package/index.js +0 -7
package/package.json CHANGED
@@ -1,48 +1,53 @@
1
- {
2
- "name": "poly-extrude",
3
- "version": "0.13.0",
4
- "description": "",
5
- "main": "dist/poly-extrude.js",
6
- "module": "dist/poly-extrude.mjs",
7
- "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1",
9
- "lint": "eslint src/**/*.js",
10
- "build": "npm run lint && cross-env NODE_ENV=prd rollup -c",
11
- "dev": "npm run lint && cross-env NODE_ENV=dev rollup -c -w"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/deyihu/poly-extrude.git"
16
- },
17
- "author": "",
18
- "license": "ISC",
19
- "bugs": {
20
- "url": "https://github.com/deyihu/poly-extrude/issues"
21
- },
22
- "homepage": "https://github.com/deyihu/poly-extrude#readme",
23
- "devDependencies": {
24
- "@babel/core": "^7.17.5",
25
- "@babel/preset-env": "^7.16.11",
26
- "@rollup/plugin-babel": "^5.3.0",
27
- "@rollup/plugin-commonjs": "^21.0.1",
28
- "@rollup/plugin-json": "^4.1.0",
29
- "@rollup/plugin-node-resolve": "^13.1.3",
30
- "cross-env": "^5.1.4",
31
- "eslint": "^6.2.2",
32
- "eslint-config-standard": "^14.1.0",
33
- "eslint-plugin-import": "^2.18.2",
34
- "eslint-plugin-node": "^10.0.0",
35
- "eslint-plugin-promise": "^4.2.1",
36
- "eslint-plugin-standard": "^4.0.1",
37
- "rollup": "^2.64.0",
38
- "rollup-plugin-terser": "^7.0.2"
39
- },
40
- "dependencies": {
41
- "earcut": "^2.2.4"
42
- },
43
- "files": [
44
- "dist/",
45
- "src/",
46
- "index.js"
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
  [![](./gallery/slope.png)](https://deyihu.github.io/poly-extrude/test/slope.html)<br>
20
20
 
21
21
  [![](./gallery/tube.png)](https://deyihu.github.io/poly-extrude/test/tube.html)<br>
22
+ [![](./gallery/terrain.png)](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
@@ -133,6 +135,8 @@ npm i poly-extrude
133
135
  * `options.bottomStickGround` Is the bottom attached to the ground
134
136
  * `options.pathUV` generate Path UV
135
137
 
138
+ [extrudePolylines pathUV demo](https://deyihu.github.io/poly-extrude/test/line-pathuv.html)
139
+
136
140
  ```js
137
141
  const result = extrudePolylines(polylines, {
138
142
  depth: 2,
@@ -212,6 +216,9 @@ const {
212
216
  * `options.bottomStickGround` Is the bottom attached to the ground
213
217
  * `options.pathUV` generate Path UV
214
218
 
219
+
220
+ [extrudeSlopes pathUV demo](https://deyihu.github.io/poly-extrude/test/slope-pathuv.html)
221
+
215
222
  ```js
216
223
  const result = extrudeSlopes(polylines, {
217
224
 
@@ -267,8 +274,11 @@ const {
267
274
  * `devideW`
268
275
  * `devideH`
269
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
+
270
280
  ```js
271
- const result = plane(100,100,10,10);
281
+ const result = plane(100, 100, 10, 10);
272
282
  const {
273
283
 
274
284
  positon,
@@ -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 };
package/src/path.ts ADDED
@@ -0,0 +1,385 @@
1
+ import { Vector3 } from './math/Vector3';
2
+ import { PathPoint } from './path/PathPoint';
3
+ import { PathPointList } from './path/PathPointList';
4
+ import { PolylineType, ResultType } from './type';
5
+ import { line2Vectors, merge } from './util';
6
+ const UP = new Vector3(0, 0, 1);
7
+
8
+ const right = new Vector3();
9
+ const left = new Vector3();
10
+
11
+ // for sharp corners
12
+ const leftOffset = new Vector3();
13
+ const rightOffset = new Vector3();
14
+ const tempPoint1 = new Vector3();
15
+ const tempPoint2 = new Vector3();
16
+
17
+ type PathsOptions = {
18
+ lineWidth?: number;
19
+ cornerRadius?: number;
20
+ cornerSplit?: number;
21
+ }
22
+
23
+ type PathsResult = ResultType & {
24
+ lines: Array<PolylineType>;
25
+ }
26
+
27
+ export function expandPaths(lines: Array<PolylineType>, options?: PathsOptions): PathsResult {
28
+ options = Object.assign({}, { lineWidth: 1, cornerRadius: 0, cornerSplit: 10 }, options);
29
+ const results = lines.map(line => {
30
+ const points = line2Vectors(line);
31
+ const pathPointList = new PathPointList();
32
+ //@ts-ignore
33
+ pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP);
34
+ const params = generatePathVertexData(pathPointList, options);
35
+
36
+ const result = {
37
+ position: new Float32Array(params.position),
38
+ indices: new Uint32Array(params.indices),
39
+ uv: new Float32Array(params.uv),
40
+ normal: new Float32Array(params.normal),
41
+ line,
42
+ count: params.count
43
+ }
44
+ return result;
45
+ });
46
+ const result = merge(results) as PathsResult;
47
+ result.lines = lines;
48
+ return result;
49
+ }
50
+
51
+ // Vertex Data Generate Functions
52
+ // code copy from https://github.com/shawn0326/three.path/blob/master/src/PathGeometry.js
53
+ function generatePathVertexData(pathPointList, options: PathsOptions) {
54
+ const width = options.lineWidth || 0.1;
55
+ const progress = 1;
56
+ const side = 'both';
57
+
58
+ const halfWidth = width / 2;
59
+ const sideWidth = (side !== 'both' ? width / 2 : width);
60
+ const totalDistance = pathPointList.distance();
61
+ const progressDistance = progress * totalDistance;
62
+
63
+ let count = 0;
64
+
65
+ // modify data
66
+ const position: number[] = [];
67
+ const normal: number[] = [];
68
+ const uv: number[] = [];
69
+ const indices: number[] = [];
70
+ let verticesCount = 0;
71
+
72
+ if (totalDistance === 0) {
73
+ return {
74
+ position: position,
75
+ normal,
76
+ uv: uv,
77
+ indices: indices,
78
+ count
79
+ }
80
+ }
81
+
82
+ const sharpUvOffset = halfWidth / sideWidth;
83
+ // const sharpUvOffset2 = halfWidth / totalDistance;
84
+
85
+
86
+ let pIndex = position.length - 1;
87
+ let nIndex = normal.length - 1;
88
+ let uIndex = uv.length - 1;
89
+ let iIndex = indices.length - 1;
90
+ function addVertices(pathPoint) {
91
+ const first = position.length === 0;
92
+ const sharpCorner = pathPoint.sharp && !first;
93
+
94
+ const uvDist = pathPoint.dist / sideWidth;
95
+ // const uvDist2 = pathPoint.dist / totalDistance;
96
+
97
+ const dir = pathPoint.dir;
98
+ const up = pathPoint.up;
99
+ const _right = pathPoint.right;
100
+
101
+ //@ts-ignore
102
+ if (side !== 'left') {
103
+ right.copy(_right).multiplyScalar(halfWidth * pathPoint.widthScale);
104
+ } else {
105
+ right.set(0, 0, 0);
106
+ }
107
+ //@ts-ignore
108
+ if (side !== 'right') {
109
+ left.copy(_right).multiplyScalar(-halfWidth * pathPoint.widthScale);
110
+ } else {
111
+ left.set(0, 0, 0);
112
+ }
113
+
114
+ right.add(pathPoint.pos);
115
+ left.add(pathPoint.pos);
116
+
117
+ if (sharpCorner) {
118
+ leftOffset.fromArray(position, position.length - 6).sub(left);
119
+ rightOffset.fromArray(position, position.length - 3).sub(right);
120
+
121
+ const leftDist = leftOffset.length();
122
+ const rightDist = rightOffset.length();
123
+
124
+ const sideOffset = leftDist - rightDist;
125
+ let longerOffset, longEdge;
126
+
127
+ if (sideOffset > 0) {
128
+ longerOffset = leftOffset;
129
+ longEdge = left;
130
+ } else {
131
+ longerOffset = rightOffset;
132
+ longEdge = right;
133
+ }
134
+
135
+ tempPoint1.copy(longerOffset).setLength(Math.abs(sideOffset)).add(longEdge);
136
+
137
+ // eslint-disable-next-line prefer-const
138
+ let _cos = tempPoint2.copy(longEdge).sub(tempPoint1).normalize().dot(dir);
139
+ // eslint-disable-next-line prefer-const
140
+ let _len = tempPoint2.copy(longEdge).sub(tempPoint1).length();
141
+ // eslint-disable-next-line prefer-const
142
+ let _dist = _cos * _len * 2;
143
+
144
+ tempPoint2.copy(dir).setLength(_dist).add(tempPoint1);
145
+
146
+ if (sideOffset > 0) {
147
+ position[++pIndex] = tempPoint1.x;
148
+ position[++pIndex] = tempPoint1.y;
149
+ position[++pIndex] = tempPoint1.z;
150
+ position[++pIndex] = right.x;
151
+ position[++pIndex] = right.y;
152
+ position[++pIndex] = right.z;
153
+ position[++pIndex] = left.x;
154
+ position[++pIndex] = left.y;
155
+ position[++pIndex] = left.z;
156
+ position[++pIndex] = right.x;
157
+ position[++pIndex] = right.y;
158
+ position[++pIndex] = right.z;
159
+ position[++pIndex] = tempPoint2.x;
160
+ position[++pIndex] = tempPoint2.y;
161
+ position[++pIndex] = tempPoint2.z;
162
+ position[++pIndex] = right.x;
163
+ position[++pIndex] = right.y;
164
+ position[++pIndex] = right.z;
165
+ // position.push(
166
+ // tempPoint1.x, tempPoint1.y, tempPoint1.z, // 6
167
+ // right.x, right.y, right.z, // 5
168
+ // left.x, left.y, left.z, // 4
169
+ // right.x, right.y, right.z, // 3
170
+ // tempPoint2.x, tempPoint2.y, tempPoint2.z, // 2
171
+ // right.x, right.y, right.z // 1
172
+ // );
173
+
174
+ verticesCount += 6;
175
+
176
+ indices[++iIndex] = verticesCount - 6;
177
+ indices[++iIndex] = verticesCount - 8;
178
+ indices[++iIndex] = verticesCount - 7;
179
+ indices[++iIndex] = verticesCount - 6;
180
+ indices[++iIndex] = verticesCount - 7;
181
+ indices[++iIndex] = verticesCount - 5;
182
+ indices[++iIndex] = verticesCount - 4;
183
+ indices[++iIndex] = verticesCount - 6;
184
+ indices[++iIndex] = verticesCount - 5;
185
+ indices[++iIndex] = verticesCount - 2;
186
+ indices[++iIndex] = verticesCount - 4;
187
+ indices[++iIndex] = verticesCount - 1;
188
+
189
+ // indices.push(
190
+ // verticesCount - 6, verticesCount - 8, verticesCount - 7,
191
+ // verticesCount - 6, verticesCount - 7, verticesCount - 5,
192
+
193
+ // verticesCount - 4, verticesCount - 6, verticesCount - 5,
194
+ // verticesCount - 2, verticesCount - 4, verticesCount - 1
195
+ // );
196
+
197
+ count += 12;
198
+ } else {
199
+ position[++pIndex] = left.x;
200
+ position[++pIndex] = left.y;
201
+ position[++pIndex] = left.z;
202
+ position[++pIndex] = tempPoint1.x;
203
+ position[++pIndex] = tempPoint1.y;
204
+ position[++pIndex] = tempPoint1.z;
205
+ position[++pIndex] = left.x;
206
+ position[++pIndex] = left.y;
207
+ position[++pIndex] = left.z;
208
+ position[++pIndex] = right.x;
209
+ position[++pIndex] = right.y;
210
+ position[++pIndex] = right.z;
211
+ position[++pIndex] = left.x;
212
+ position[++pIndex] = left.y;
213
+ position[++pIndex] = left.z;
214
+ position[++pIndex] = tempPoint2.x;
215
+ position[++pIndex] = tempPoint2.y;
216
+ position[++pIndex] = tempPoint2.z;
217
+ // position.push(
218
+ // left.x, left.y, left.z, // 6
219
+ // tempPoint1.x, tempPoint1.y, tempPoint1.z, // 5
220
+ // left.x, left.y, left.z, // 4
221
+ // right.x, right.y, right.z, // 3
222
+ // left.x, left.y, left.z, // 2
223
+ // tempPoint2.x, tempPoint2.y, tempPoint2.z // 1
224
+ // );
225
+
226
+ verticesCount += 6;
227
+ indices[++iIndex] = verticesCount - 6;
228
+ indices[++iIndex] = verticesCount - 8;
229
+ indices[++iIndex] = verticesCount - 7;
230
+ indices[++iIndex] = verticesCount - 6;
231
+ indices[++iIndex] = verticesCount - 7;
232
+ indices[++iIndex] = verticesCount - 5;
233
+ indices[++iIndex] = verticesCount - 6;
234
+ indices[++iIndex] = verticesCount - 5;
235
+ indices[++iIndex] = verticesCount - 3;
236
+ indices[++iIndex] = verticesCount - 2;
237
+ indices[++iIndex] = verticesCount - 3;
238
+ indices[++iIndex] = verticesCount - 1;
239
+
240
+ // indices.push(
241
+ // verticesCount - 6, verticesCount - 8, verticesCount - 7,
242
+ // verticesCount - 6, verticesCount - 7, verticesCount - 5,
243
+
244
+ // verticesCount - 6, verticesCount - 5, verticesCount - 3,
245
+ // verticesCount - 2, verticesCount - 3, verticesCount - 1
246
+ // );
247
+
248
+ count += 12;
249
+ }
250
+ for (let i = 0; i < 6; i++) {
251
+ normal[++nIndex] = up.x;
252
+ normal[++nIndex] = up.y;
253
+ normal[++nIndex] = up.z;
254
+ }
255
+
256
+ // normal.push(
257
+ // up.x, up.y, up.z,
258
+ // up.x, up.y, up.z,
259
+ // up.x, up.y, up.z,
260
+ // up.x, up.y, up.z,
261
+ // up.x, up.y, up.z,
262
+ // up.x, up.y, up.z
263
+ // );
264
+
265
+ uv[++uIndex] = uvDist - sharpUvOffset;
266
+ uv[++uIndex] = 0;
267
+ uv[++uIndex] = uvDist - sharpUvOffset;
268
+ uv[++uIndex] = 1;
269
+ uv[++uIndex] = uvDist;
270
+ uv[++uIndex] = 0;
271
+ uv[++uIndex] = uvDist;
272
+ uv[++uIndex] = 1;
273
+ uv[++uIndex] = uvDist + sharpUvOffset;
274
+ uv[++uIndex] = 0;
275
+ uv[++uIndex] = uvDist + sharpUvOffset;
276
+ uv[++uIndex] = 1;
277
+ // uv.push(
278
+ // uvDist - sharpUvOffset, 0,
279
+ // uvDist - sharpUvOffset, 1,
280
+ // uvDist, 0,
281
+ // uvDist, 1,
282
+ // uvDist + sharpUvOffset, 0,
283
+ // uvDist + sharpUvOffset, 1
284
+ // );
285
+
286
+ // if (generateUv2) {
287
+ // uv2.push(
288
+ // uvDist2 - sharpUvOffset2, 0,
289
+ // uvDist2 - sharpUvOffset2, 1,
290
+ // uvDist2, 0,
291
+ // uvDist2, 1,
292
+ // uvDist2 + sharpUvOffset2, 0,
293
+ // uvDist2 + sharpUvOffset2, 1
294
+ // );
295
+ // }
296
+ } else {
297
+ position[++pIndex] = left.x;
298
+ position[++pIndex] = left.y;
299
+ position[++pIndex] = left.z;
300
+ position[++pIndex] = right.x;
301
+ position[++pIndex] = right.y;
302
+ position[++pIndex] = right.z;
303
+ // position.push(
304
+ // left.x, left.y, left.z,
305
+ // right.x, right.y, right.z
306
+ // );
307
+
308
+ normal[++nIndex] = up.x;
309
+ normal[++nIndex] = up.y;
310
+ normal[++nIndex] = up.z;
311
+ normal[++nIndex] = up.x;
312
+ normal[++nIndex] = up.y;
313
+ normal[++nIndex] = up.z;
314
+ // normal.push(
315
+ // up.x, up.y, up.z,
316
+ // up.x, up.y, up.z
317
+ // );
318
+
319
+ uv[++uIndex] = uvDist;
320
+ uv[++uIndex] = 0;
321
+ uv[++uIndex] = uvDist;
322
+ uv[++uIndex] = 1;
323
+ // uv.push(
324
+ // uvDist, 0,
325
+ // uvDist, 1
326
+ // );
327
+
328
+ // if (generateUv2) {
329
+ // uv2.push(
330
+ // uvDist2, 0,
331
+ // uvDist2, 1
332
+ // );
333
+ // }
334
+
335
+ verticesCount += 2;
336
+
337
+ if (!first) {
338
+ indices[++iIndex] = verticesCount - 2;
339
+ indices[++iIndex] = verticesCount - 4;
340
+ indices[++iIndex] = verticesCount - 3;
341
+ indices[++iIndex] = verticesCount - 2;
342
+ indices[++iIndex] = verticesCount - 3;
343
+ indices[++iIndex] = verticesCount - 1;
344
+ // indices.push(
345
+ // verticesCount - 2, verticesCount - 4, verticesCount - 3,
346
+ // verticesCount - 2, verticesCount - 3, verticesCount - 1
347
+ // );
348
+
349
+ count += 6;
350
+ }
351
+ }
352
+ }
353
+
354
+ let lastPoint;
355
+
356
+ if (progressDistance > 0) {
357
+ for (let i = 0; i < pathPointList.count; i++) {
358
+ const pathPoint = pathPointList.array[i];
359
+
360
+ if (pathPoint.dist > progressDistance) {
361
+ const prevPoint = pathPointList.array[i - 1];
362
+ lastPoint = new PathPoint();
363
+
364
+ // linear lerp for progress
365
+ const alpha = (progressDistance - prevPoint.dist) / (pathPoint.dist - prevPoint.dist);
366
+ lastPoint.lerpPathPoints(prevPoint, pathPoint, alpha);
367
+
368
+ addVertices(lastPoint);
369
+ break;
370
+ } else {
371
+ addVertices(pathPoint);
372
+ }
373
+ }
374
+ } else {
375
+ lastPoint = pathPointList.array[0];
376
+ }
377
+
378
+ return {
379
+ position: position,
380
+ normal,
381
+ uv: uv,
382
+ indices: indices,
383
+ count
384
+ };
385
+ }