poly-extrude 0.7.0 → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poly-extrude",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "",
5
5
  "main": "dist/poly-extrude.js",
6
6
  "module": "dist/poly-extrude.mjs",
package/readme.md CHANGED
@@ -4,29 +4,21 @@ Extrude polygons/polylines. Born in [maptalks.three](https://github.com/maptalks
4
4
 
5
5
  ## Examples
6
6
 
7
- [building](https://deyihu.github.io/poly-extrude/test/building.html)
8
- <!-- ![](./gallery/building.png)<br> -->
9
- [buildings](https://deyihu.github.io/poly-extrude/test/buildings.html)
10
- <!-- ![](./gallery/buildings.png)<br> -->
11
- [multi-polygon](https://deyihu.github.io/poly-extrude/test/multi-polygon.html)<br>
12
- <!-- ![](./gallery/multi-polygon.png)<br> -->
13
- [street](https://deyihu.github.io/poly-extrude/test/street.html)<br>
14
- <!-- ![](./gallery/street.png)<br> -->
15
- [line-uv](https://deyihu.github.io/poly-extrude/test/line-uv.html)<br>
16
- <!-- ![](./gallery/line-uv.png) -->
17
- [ny-building](https://deyihu.github.io/poly-extrude/test/ny-building.html)<br>
18
- <!-- ![](./gallery/ny-building.png) -->
19
- [cylinder](https://deyihu.github.io/poly-extrude/test/cylinder.html)<br>
20
- <!-- ![](./gallery/cylinder.png) -->
21
- [brige](https://deyihu.github.io/poly-extrude/test/brige.html)<br>
22
- <!-- ![](./gallery/brige.png) -->
23
- [spring](https://deyihu.github.io/poly-extrude/test/spring.html)<br>
24
- <!-- ![](./gallery/spring.png) -->
25
- [expand paths](https://deyihu.github.io/poly-extrude/test/expand-paths-brige.html)<br>
26
- <!-- ![](./gallery/expand-paths-brige.png) -->
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>
7
+ [![](./gallery/building.png)](https://deyihu.github.io/poly-extrude/test/building.html)
8
+
9
+ [![](./gallery/buildings.png)](https://deyihu.github.io/poly-extrude/test/buildings.html)
10
+
11
+ [![](./gallery/multi-polygon.png)](https://deyihu.github.io/poly-extrude/test/multi-polygon.html)<br>
12
+ [![](./gallery/street.png)](https://deyihu.github.io/poly-extrude/test/street.html)<br>
13
+ [![](./gallery/line-uv.png)](https://deyihu.github.io/poly-extrude/test/line-uv.html)<br>
14
+ [![](./gallery/ny-building.png)](https://deyihu.github.io/poly-extrude/test/ny-building.html)<br>
15
+ [![](./gallery/cylinder.png)](https://deyihu.github.io/poly-extrude/test/cylinder.html)<br>
16
+ [![](./gallery/brige.png)](https://deyihu.github.io/poly-extrude/test/brige.html)<br>
17
+ [![](./gallery/spring.png)](https://deyihu.github.io/poly-extrude/test/spring.html)<br>
18
+ [![](./gallery/expand-paths-brige.png)](https://deyihu.github.io/poly-extrude/test/expand-paths-brige.html)<br>
19
+ [![](./gallery/slope.png)](https://deyihu.github.io/poly-extrude/test/slope.html)<br>
20
+
21
+ [![](./gallery/tube.png)](https://deyihu.github.io/poly-extrude/test/tube.html)<br>
30
22
 
31
23
  ## Install
32
24
 
@@ -34,7 +26,6 @@ Extrude polygons/polylines. Born in [maptalks.three](https://github.com/maptalks
34
26
 
35
27
  ```sh
36
28
  npm i poly-extrude
37
-
38
29
  ```
39
30
 
40
31
  ### CDN
@@ -55,7 +46,7 @@ npm i poly-extrude
55
46
  expandTubes
56
47
  } from 'poly-extrude';
57
48
 
58
- //if you use cdn
49
+ //if you use cdn,the namespace is polyextrude
59
50
 
60
51
  // const {
61
52
  // extrudePolygons,
@@ -132,7 +123,7 @@ npm i poly-extrude
132
123
  //do something
133
124
  ```
134
125
 
135
-
126
+ ![](./img/extrudePolylines.png)
136
127
  ### `extrudePolylines(lines, options)`
137
128
 
138
129
  * `lines`
@@ -154,6 +145,7 @@ npm i poly-extrude
154
145
  //do something
155
146
  ```
156
147
 
148
+ ![](./img/cylinder.png)
157
149
  ### `cylinder(center, options)`
158
150
 
159
151
  * `center`
@@ -180,6 +172,7 @@ const {
180
172
  //do something
181
173
  ```
182
174
 
175
+ ![](./img/expandPaths.png)
183
176
  ### `expandPaths(lines, options)`
184
177
 
185
178
  * `lines`
@@ -203,6 +196,8 @@ const {
203
196
  //do something
204
197
  ```
205
198
 
199
+ ![](./img/extrudeSlopes.png)
200
+
206
201
  ### `extrudeSlopes(lines, options)`
207
202
 
208
203
  * `lines`
@@ -232,6 +227,7 @@ const {
232
227
  //do something
233
228
  ```
234
229
 
230
+ ![](./img/expandTubes.png)
235
231
  ### `expandTubes(lines, options)`
236
232
 
237
233
  * `lines`
package/src/cylinder.js CHANGED
@@ -10,7 +10,8 @@ export function cylinder(point, options = {}) {
10
10
  const [centerx, centery] = point;
11
11
  let idx = 0, uIdx = 0;
12
12
  const offset = circlePointsLen * 3, uOffset = circlePointsLen * 2;
13
- const indices = [], uvs = [];
13
+ const indices = [], uv = [];
14
+ let iIndex = indices.length - 1;
14
15
  for (let i = -1; i < radialSegments; i++) {
15
16
  const rad = aRad * i;
16
17
  const x = Math.cos(rad) * radius + centerx, y = Math.sin(rad) * radius + centery;
@@ -27,16 +28,19 @@ export function cylinder(point, options = {}) {
27
28
  let u = 0, v = 0;
28
29
  u = 0.5 + x / radius / 2;
29
30
  v = 0.5 + y / radius / 2;
30
- uvs[uIdx] = u;
31
- uvs[uIdx + 1] = v;
32
- uvs[uIdx + uOffset] = u;
33
- uvs[uIdx + 1 + uOffset] = v;
31
+ uv[uIdx] = u;
32
+ uv[uIdx + 1] = v;
33
+ uv[uIdx + uOffset] = u;
34
+ uv[uIdx + 1 + uOffset] = v;
34
35
 
35
36
  idx += 3;
36
37
  uIdx += 2;
37
38
  if (i > 1) {
38
39
  // bottom indices
39
- indices.push(0, i - 1, i);
40
+ // indices.push(0, i - 1, i);
41
+ indices[++iIndex] = 0;
42
+ indices[++iIndex] = i - 1;
43
+ indices[++iIndex] = i;
40
44
  }
41
45
  }
42
46
  idx -= 3;
@@ -50,15 +54,19 @@ export function cylinder(point, options = {}) {
50
54
 
51
55
  const indicesLen = indices.length;
52
56
  // top indices
57
+ iIndex = indices.length - 1;
53
58
  for (let i = 0; i < indicesLen; i++) {
54
59
  const index = indices[i];
55
- indices.push(index + circlePointsLen);
60
+ indices[++iIndex] = index + circlePointsLen;
61
+ // indices.push(index + circlePointsLen);
56
62
  }
57
63
 
58
64
  const sidePoints = new Float32Array((circlePointsLen * 3 * 2 - 6) * 2);
59
65
  let pIndex = -1;
60
66
  idx = circlePointsLen * 2;
61
67
  uIdx = 0;
68
+ iIndex = indices.length - 1;
69
+ let uvIndex = uv.length - 1;
62
70
  for (let i = 0, len = points.length / 2; i < len - 3; i += 3) {
63
71
  const x1 = points[i], y1 = points[i + 1], x2 = points[i + 3], y2 = points[i + 4];
64
72
  sidePoints[++pIndex] = x1;
@@ -75,15 +83,29 @@ export function cylinder(point, options = {}) {
75
83
  sidePoints[++pIndex] = 0;
76
84
  const a = idx + 2, b = idx + 3, c = idx, d = idx + 1;
77
85
  // indices.push(a, c, b, c, d, b);
78
- indices.push(c, a, d, a, b, d);
86
+ indices[++iIndex] = c;
87
+ indices[++iIndex] = a;
88
+ indices[++iIndex] = d;
89
+ indices[++iIndex] = a;
90
+ indices[++iIndex] = b;
91
+ indices[++iIndex] = d;
92
+ // indices.push(c, a, d, a, b, d);
79
93
  idx += 4;
80
94
  const u1 = uIdx / circlePointsLen, u2 = (uIdx + 1) / circlePointsLen;
81
- uvs.push(u1, height / radius / 2, u2, height / radius / 2, u1, 0, u2, 0);
95
+ uv[++uvIndex] = u1;
96
+ uv[++uvIndex] = height / radius / 2;
97
+ uv[++uvIndex] = u2;
98
+ uv[++uvIndex] = height / radius / 2;
99
+ uv[++uvIndex] = u1;
100
+ uv[++uvIndex] = 0;
101
+ uv[++uvIndex] = u2;
102
+ uv[++uvIndex] = 0;
103
+ // uvs.push(u1, height / radius / 2, u2, height / radius / 2, u1, 0, u2, 0);
82
104
  uIdx++;
83
105
  }
84
106
  const position = new Float32Array(points.length + sidePoints.length);
85
107
  position.set(points, 0);
86
108
  position.set(sidePoints, points.length);
87
109
  const normal = generateNormal(indices, position);
88
- return { points, indices: new Uint32Array(indices), position, normal, uv: new Float32Array(uvs) };
110
+ return { points, indices: new Uint32Array(indices), position, normal, uv: new Float32Array(uv) };
89
111
  }
package/src/path.js CHANGED
@@ -15,9 +15,9 @@ export function expandPaths(lines, options) {
15
15
  pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP);
16
16
  const result = generatePathVertexData(pathPointList, options);
17
17
  result.line = line;
18
- result.position = new Float32Array(result.points);
19
- result.indices = new Uint32Array(result.index);
20
- result.uv = new Float32Array(result.uvs);
18
+ result.position = new Float32Array(result.position);
19
+ result.indices = new Uint32Array(result.indices);
20
+ result.uv = new Float32Array(result.uv);
21
21
  result.normal = new Float32Array(result.normal);
22
22
  return result;
23
23
  });
@@ -62,6 +62,10 @@ function generatePathVertexData(pathPointList, options) {
62
62
  const tempPoint1 = new Vector3();
63
63
  const tempPoint2 = new Vector3();
64
64
 
65
+ let pIndex = position.length - 1;
66
+ let nIndex = normal.length - 1;
67
+ let uIndex = uv.length - 1;
68
+ let iIndex = indices.length - 1;
65
69
  function addVertices(pathPoint) {
66
70
  const first = position.length === 0;
67
71
  const sharpCorner = pathPoint.sharp && !first;
@@ -118,66 +122,144 @@ function generatePathVertexData(pathPointList, options) {
118
122
  tempPoint2.copy(dir).setLength(_dist).add(tempPoint1);
119
123
 
120
124
  if (sideOffset > 0) {
121
- position.push(
122
- tempPoint1.x, tempPoint1.y, tempPoint1.z, // 6
123
- right.x, right.y, right.z, // 5
124
- left.x, left.y, left.z, // 4
125
- right.x, right.y, right.z, // 3
126
- tempPoint2.x, tempPoint2.y, tempPoint2.z, // 2
127
- right.x, right.y, right.z // 1
128
- );
125
+ position[++pIndex] = tempPoint1.x;
126
+ position[++pIndex] = tempPoint1.y;
127
+ position[++pIndex] = tempPoint1.z;
128
+ position[++pIndex] = right.x;
129
+ position[++pIndex] = right.y;
130
+ position[++pIndex] = right.z;
131
+ position[++pIndex] = left.x;
132
+ position[++pIndex] = left.y;
133
+ position[++pIndex] = left.z;
134
+ position[++pIndex] = right.x;
135
+ position[++pIndex] = right.y;
136
+ position[++pIndex] = right.z;
137
+ position[++pIndex] = tempPoint2.x;
138
+ position[++pIndex] = tempPoint2.y;
139
+ position[++pIndex] = tempPoint2.z;
140
+ position[++pIndex] = right.x;
141
+ position[++pIndex] = right.y;
142
+ position[++pIndex] = right.z;
143
+ // position.push(
144
+ // tempPoint1.x, tempPoint1.y, tempPoint1.z, // 6
145
+ // right.x, right.y, right.z, // 5
146
+ // left.x, left.y, left.z, // 4
147
+ // right.x, right.y, right.z, // 3
148
+ // tempPoint2.x, tempPoint2.y, tempPoint2.z, // 2
149
+ // right.x, right.y, right.z // 1
150
+ // );
129
151
 
130
152
  verticesCount += 6;
131
153
 
132
- indices.push(
133
- verticesCount - 6, verticesCount - 8, verticesCount - 7,
134
- verticesCount - 6, verticesCount - 7, verticesCount - 5,
135
-
136
- verticesCount - 4, verticesCount - 6, verticesCount - 5,
137
- verticesCount - 2, verticesCount - 4, verticesCount - 1
138
- );
154
+ indices[++iIndex] = verticesCount - 6;
155
+ indices[++iIndex] = verticesCount - 8;
156
+ indices[++iIndex] = verticesCount - 7;
157
+ indices[++iIndex] = verticesCount - 6;
158
+ indices[++iIndex] = verticesCount - 7;
159
+ indices[++iIndex] = verticesCount - 5;
160
+ indices[++iIndex] = verticesCount - 4;
161
+ indices[++iIndex] = verticesCount - 6;
162
+ indices[++iIndex] = verticesCount - 5;
163
+ indices[++iIndex] = verticesCount - 2;
164
+ indices[++iIndex] = verticesCount - 4;
165
+ indices[++iIndex] = verticesCount - 1;
166
+
167
+ // indices.push(
168
+ // verticesCount - 6, verticesCount - 8, verticesCount - 7,
169
+ // verticesCount - 6, verticesCount - 7, verticesCount - 5,
170
+
171
+ // verticesCount - 4, verticesCount - 6, verticesCount - 5,
172
+ // verticesCount - 2, verticesCount - 4, verticesCount - 1
173
+ // );
139
174
 
140
175
  count += 12;
141
176
  } else {
142
- position.push(
143
- left.x, left.y, left.z, // 6
144
- tempPoint1.x, tempPoint1.y, tempPoint1.z, // 5
145
- left.x, left.y, left.z, // 4
146
- right.x, right.y, right.z, // 3
147
- left.x, left.y, left.z, // 2
148
- tempPoint2.x, tempPoint2.y, tempPoint2.z // 1
149
- );
177
+ position[++pIndex] = left.x;
178
+ position[++pIndex] = left.y;
179
+ position[++pIndex] = left.z;
180
+ position[++pIndex] = tempPoint1.x;
181
+ position[++pIndex] = tempPoint1.y;
182
+ position[++pIndex] = tempPoint1.z;
183
+ position[++pIndex] = left.x;
184
+ position[++pIndex] = left.y;
185
+ position[++pIndex] = left.z;
186
+ position[++pIndex] = right.x;
187
+ position[++pIndex] = right.y;
188
+ position[++pIndex] = right.z;
189
+ position[++pIndex] = left.x;
190
+ position[++pIndex] = left.y;
191
+ position[++pIndex] = left.z;
192
+ position[++pIndex] = tempPoint2.x;
193
+ position[++pIndex] = tempPoint2.y;
194
+ position[++pIndex] = tempPoint2.z;
195
+ // position.push(
196
+ // left.x, left.y, left.z, // 6
197
+ // tempPoint1.x, tempPoint1.y, tempPoint1.z, // 5
198
+ // left.x, left.y, left.z, // 4
199
+ // right.x, right.y, right.z, // 3
200
+ // left.x, left.y, left.z, // 2
201
+ // tempPoint2.x, tempPoint2.y, tempPoint2.z // 1
202
+ // );
150
203
 
151
204
  verticesCount += 6;
152
-
153
- indices.push(
154
- verticesCount - 6, verticesCount - 8, verticesCount - 7,
155
- verticesCount - 6, verticesCount - 7, verticesCount - 5,
156
-
157
- verticesCount - 6, verticesCount - 5, verticesCount - 3,
158
- verticesCount - 2, verticesCount - 3, verticesCount - 1
159
- );
205
+ indices[++iIndex] = verticesCount - 6;
206
+ indices[++iIndex] = verticesCount - 8;
207
+ indices[++iIndex] = verticesCount - 7;
208
+ indices[++iIndex] = verticesCount - 6;
209
+ indices[++iIndex] = verticesCount - 7;
210
+ indices[++iIndex] = verticesCount - 5;
211
+ indices[++iIndex] = verticesCount - 6;
212
+ indices[++iIndex] = verticesCount - 5;
213
+ indices[++iIndex] = verticesCount - 3;
214
+ indices[++iIndex] = verticesCount - 2;
215
+ indices[++iIndex] = verticesCount - 3;
216
+ indices[++iIndex] = verticesCount - 1;
217
+
218
+ // indices.push(
219
+ // verticesCount - 6, verticesCount - 8, verticesCount - 7,
220
+ // verticesCount - 6, verticesCount - 7, verticesCount - 5,
221
+
222
+ // verticesCount - 6, verticesCount - 5, verticesCount - 3,
223
+ // verticesCount - 2, verticesCount - 3, verticesCount - 1
224
+ // );
160
225
 
161
226
  count += 12;
162
227
  }
228
+ for (let i = 0; i < 6; i++) {
229
+ normal[++nIndex] = up.x;
230
+ normal[++nIndex] = up.y;
231
+ normal[++nIndex] = up.z;
232
+ }
163
233
 
164
- normal.push(
165
- up.x, up.y, up.z,
166
- up.x, up.y, up.z,
167
- up.x, up.y, up.z,
168
- up.x, up.y, up.z,
169
- up.x, up.y, up.z,
170
- up.x, up.y, up.z
171
- );
172
-
173
- uv.push(
174
- uvDist - sharpUvOffset, 0,
175
- uvDist - sharpUvOffset, 1,
176
- uvDist, 0,
177
- uvDist, 1,
178
- uvDist + sharpUvOffset, 0,
179
- uvDist + sharpUvOffset, 1
180
- );
234
+ // normal.push(
235
+ // up.x, up.y, up.z,
236
+ // up.x, up.y, up.z,
237
+ // up.x, up.y, up.z,
238
+ // up.x, up.y, up.z,
239
+ // up.x, up.y, up.z,
240
+ // up.x, up.y, up.z
241
+ // );
242
+
243
+ uv[++uIndex] = uvDist - sharpUvOffset;
244
+ uv[++uIndex] = 0;
245
+ uv[++uIndex] = uvDist - sharpUvOffset;
246
+ uv[++uIndex] = 1;
247
+ uv[++uIndex] = uvDist;
248
+ uv[++uIndex] = 0;
249
+ uv[++uIndex] = uvDist;
250
+ uv[++uIndex] = 1;
251
+ uv[++uIndex] = uvDist + sharpUvOffset;
252
+ uv[++uIndex] = 0;
253
+ uv[++uIndex] = uvDist + sharpUvOffset;
254
+ uv[++uIndex] = 1;
255
+ // uv.push(
256
+ // uvDist - sharpUvOffset, 0,
257
+ // uvDist - sharpUvOffset, 1,
258
+ // uvDist, 0,
259
+ // uvDist, 1,
260
+ // uvDist + sharpUvOffset, 0,
261
+ // uvDist + sharpUvOffset, 1
262
+ // );
181
263
 
182
264
  // if (generateUv2) {
183
265
  // uv2.push(
@@ -190,20 +272,36 @@ function generatePathVertexData(pathPointList, options) {
190
272
  // );
191
273
  // }
192
274
  } else {
193
- position.push(
194
- left.x, left.y, left.z,
195
- right.x, right.y, right.z
196
- );
197
-
198
- normal.push(
199
- up.x, up.y, up.z,
200
- up.x, up.y, up.z
201
- );
202
-
203
- uv.push(
204
- uvDist, 0,
205
- uvDist, 1
206
- );
275
+ position[++pIndex] = left.x;
276
+ position[++pIndex] = left.y;
277
+ position[++pIndex] = left.z;
278
+ position[++pIndex] = right.x;
279
+ position[++pIndex] = right.y;
280
+ position[++pIndex] = right.z;
281
+ // position.push(
282
+ // left.x, left.y, left.z,
283
+ // right.x, right.y, right.z
284
+ // );
285
+
286
+ normal[++nIndex] = up.x;
287
+ normal[++nIndex] = up.y;
288
+ normal[++nIndex] = up.z;
289
+ normal[++nIndex] = up.x;
290
+ normal[++nIndex] = up.y;
291
+ normal[++nIndex] = up.z;
292
+ // normal.push(
293
+ // up.x, up.y, up.z,
294
+ // up.x, up.y, up.z
295
+ // );
296
+
297
+ uv[++uIndex] = uvDist;
298
+ uv[++uIndex] = 0;
299
+ uv[++uIndex] = uvDist;
300
+ uv[++uIndex] = 1;
301
+ // uv.push(
302
+ // uvDist, 0,
303
+ // uvDist, 1
304
+ // );
207
305
 
208
306
  // if (generateUv2) {
209
307
  // uv2.push(
@@ -215,10 +313,16 @@ function generatePathVertexData(pathPointList, options) {
215
313
  verticesCount += 2;
216
314
 
217
315
  if (!first) {
218
- indices.push(
219
- verticesCount - 2, verticesCount - 4, verticesCount - 3,
220
- verticesCount - 2, verticesCount - 3, verticesCount - 1
221
- );
316
+ indices[++iIndex] = verticesCount - 2;
317
+ indices[++iIndex] = verticesCount - 4;
318
+ indices[++iIndex] = verticesCount - 3;
319
+ indices[++iIndex] = verticesCount - 2;
320
+ indices[++iIndex] = verticesCount - 3;
321
+ indices[++iIndex] = verticesCount - 1;
322
+ // indices.push(
323
+ // verticesCount - 2, verticesCount - 4, verticesCount - 3,
324
+ // verticesCount - 2, verticesCount - 3, verticesCount - 1
325
+ // );
222
326
 
223
327
  count += 6;
224
328
  }
@@ -250,10 +354,10 @@ function generatePathVertexData(pathPointList, options) {
250
354
  }
251
355
 
252
356
  return {
253
- points: position,
357
+ position: position,
254
358
  normal,
255
- uvs: uv,
256
- index: indices,
359
+ uv: uv,
360
+ indices: indices,
257
361
  count
258
362
  };
259
363
  }
package/src/polygon.js CHANGED
@@ -25,8 +25,8 @@ export function extrudePolygons(polygons, options) {
25
25
  generateTopAndBottom(result, triangles);
26
26
  generateSides(result, options);
27
27
  result.position = new Float32Array(result.points);
28
- result.indices = new Uint32Array(result.index);
29
- result.uv = new Float32Array(result.uvs);
28
+ result.indices = new Uint32Array(result.indices);
29
+ result.uv = new Float32Array(result.uv);
30
30
  result.normal = generateNormal(result.indices, result.position);
31
31
  return result;
32
32
  });
@@ -37,27 +37,29 @@ export function extrudePolygons(polygons, options) {
37
37
  }
38
38
 
39
39
  function generateTopAndBottom(result, triangles) {
40
- const index = [];
40
+ const indices = [];
41
41
  const { count } = result;
42
42
  for (let i = 0, len = triangles.length; i < len; i += 3) {
43
43
  // top
44
44
  const a = triangles[i], b = triangles[i + 1], c = triangles[i + 2];
45
- index[i] = a;
46
- index[i + 1] = b;
47
- index[i + 2] = c;
45
+ indices[i] = a;
46
+ indices[i + 1] = b;
47
+ indices[i + 2] = c;
48
48
  // bottom
49
49
  const idx = len + i;
50
50
  const a1 = count + a, b1 = count + b, c1 = count + c;
51
- index[idx] = a1;
52
- index[idx + 1] = b1;
53
- index[idx + 2] = c1;
51
+ indices[idx] = a1;
52
+ indices[idx + 1] = b1;
53
+ indices[idx + 2] = c1;
54
54
  }
55
- result.index = index;
55
+ result.indices = indices;
56
56
  }
57
57
 
58
58
  function generateSides(result, options) {
59
- const { points, index, polygon, uvs } = result;
60
- const z = options.depth;
59
+ const { points, indices, polygon, uv } = result;
60
+ const depth = options.depth;
61
+ let pIndex = points.length - 1;
62
+ let iIndex = indices.length - 1;
61
63
  for (let i = 0, len = polygon.length; i < len; i++) {
62
64
  const ring = polygon[i];
63
65
  let j = 0;
@@ -69,14 +71,32 @@ function generateSides(result, options) {
69
71
  v2 = ring[0];
70
72
  }
71
73
  const idx = points.length / 3;
72
- const x1 = v1[0], y1 = v1[1], x2 = v2[0], y2 = v2[1];
73
- points.push(x1, y1, z, x2, y2, z, x1, y1, 0, x2, y2, 0);
74
+ const x1 = v1[0], y1 = v1[1], z1 = v1[2] || 0, x2 = v2[0], y2 = v2[1], z2 = v2[2] || 0;
75
+ points[++pIndex] = x1;
76
+ points[++pIndex] = y1;
77
+ points[++pIndex] = z1 + depth;
78
+ points[++pIndex] = x2;
79
+ points[++pIndex] = y2;
80
+ points[++pIndex] = z2 + depth;
81
+ points[++pIndex] = x1;
82
+ points[++pIndex] = y1;
83
+ points[++pIndex] = z1;
84
+ points[++pIndex] = x2;
85
+ points[++pIndex] = y2;
86
+ points[++pIndex] = z2;
87
+ // points.push(x1, y1, z, x2, y2, z, x1, y1, 0, x2, y2, 0);
74
88
  const a = idx + 2, b = idx + 3, c = idx, d = idx + 1;
75
89
  // points.push(p3, p4, p1, p2);
76
- index.push(a, c, b, c, d, b);
90
+ // index.push(a, c, b, c, d, b);
91
+ indices[++iIndex] = a;
92
+ indices[++iIndex] = c;
93
+ indices[++iIndex] = b;
94
+ indices[++iIndex] = c;
95
+ indices[++iIndex] = d;
96
+ indices[++iIndex] = b;
77
97
  // index.push(c, d, b);
78
98
 
79
- generateSideWallUV(uvs, points, a, b, c, d);
99
+ generateSideWallUV(uv, points, a, b, c, d);
80
100
  j++;
81
101
  }
82
102
  }
@@ -96,9 +116,9 @@ function calPolygonPointsCount(polygon) {
96
116
  function flatVertices(polygon, options) {
97
117
  const count = calPolygonPointsCount(polygon);
98
118
  const len = polygon.length;
99
- const holes = [], flatVertices = new Float32Array(count * 2), points = [], uvs = [];
119
+ const holes = [], flatVertices = new Float32Array(count * 2), points = [], uv = [];
100
120
  const pOffset = count * 3, uOffset = count * 2;
101
- const z = options.depth;
121
+ const depth = options.depth;
102
122
 
103
123
  let idx0 = 0, idx1 = 0, idx2 = 0;
104
124
  for (let i = 0; i < len; i++) {
@@ -110,7 +130,7 @@ function flatVertices(polygon, options) {
110
130
  const len1 = ring.length;
111
131
  while (j < len1) {
112
132
  const c = ring[j];
113
- const x = c[0], y = c[1];
133
+ const x = c[0], y = c[1], z = c[2] || 0;
114
134
 
115
135
  flatVertices[idx0++] = x;
116
136
  flatVertices[idx0++] = y;
@@ -118,18 +138,18 @@ function flatVertices(polygon, options) {
118
138
  // top vertices
119
139
  points[idx1] = x;
120
140
  points[idx1 + 1] = y;
121
- points[idx1 + 2] = z;
141
+ points[idx1 + 2] = depth + z;
122
142
 
123
143
  // bottom vertices
124
144
  points[pOffset + idx1] = x;
125
145
  points[pOffset + idx1 + 1] = y;
126
- points[pOffset + idx1 + 2] = 0;
146
+ points[pOffset + idx1 + 2] = z;
127
147
 
128
- uvs[idx2] = x;
129
- uvs[idx2 + 1] = y;
148
+ uv[idx2] = x;
149
+ uv[idx2 + 1] = y;
130
150
 
131
- uvs[uOffset + idx2] = x;
132
- uvs[uOffset + idx2 + 1] = y;
151
+ uv[uOffset + idx2] = x;
152
+ uv[uOffset + idx2 + 1] = y;
133
153
 
134
154
  idx1 += 3;
135
155
  idx2 += 2;
@@ -141,7 +161,7 @@ function flatVertices(polygon, options) {
141
161
  holes,
142
162
  points,
143
163
  count,
144
- uvs
164
+ uv
145
165
  };
146
166
 
147
167
  }