poly-extrude 0.8.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.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "",
5
5
  "main": "dist/poly-extrude.js",
6
6
  "module": "dist/poly-extrude.mjs",
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,29 +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;
59
+ const { points, indices, polygon, uv } = result;
60
60
  const depth = options.depth;
61
61
  let pIndex = points.length - 1;
62
- let iIndex = index.length - 1;
62
+ let iIndex = indices.length - 1;
63
63
  for (let i = 0, len = polygon.length; i < len; i++) {
64
64
  const ring = polygon[i];
65
65
  let j = 0;
@@ -88,15 +88,15 @@ function generateSides(result, options) {
88
88
  const a = idx + 2, b = idx + 3, c = idx, d = idx + 1;
89
89
  // points.push(p3, p4, p1, p2);
90
90
  // index.push(a, c, b, c, d, b);
91
- index[++iIndex] = a;
92
- index[++iIndex] = c;
93
- index[++iIndex] = b;
94
- index[++iIndex] = c;
95
- index[++iIndex] = d;
96
- index[++iIndex] = 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;
97
97
  // index.push(c, d, b);
98
98
 
99
- generateSideWallUV(uvs, points, a, b, c, d);
99
+ generateSideWallUV(uv, points, a, b, c, d);
100
100
  j++;
101
101
  }
102
102
  }
@@ -116,7 +116,7 @@ function calPolygonPointsCount(polygon) {
116
116
  function flatVertices(polygon, options) {
117
117
  const count = calPolygonPointsCount(polygon);
118
118
  const len = polygon.length;
119
- const holes = [], flatVertices = new Float32Array(count * 2), points = [], uvs = [];
119
+ const holes = [], flatVertices = new Float32Array(count * 2), points = [], uv = [];
120
120
  const pOffset = count * 3, uOffset = count * 2;
121
121
  const depth = options.depth;
122
122
 
@@ -145,11 +145,11 @@ function flatVertices(polygon, options) {
145
145
  points[pOffset + idx1 + 1] = y;
146
146
  points[pOffset + idx1 + 2] = z;
147
147
 
148
- uvs[idx2] = x;
149
- uvs[idx2 + 1] = y;
148
+ uv[idx2] = x;
149
+ uv[idx2 + 1] = y;
150
150
 
151
- uvs[uOffset + idx2] = x;
152
- uvs[uOffset + idx2 + 1] = y;
151
+ uv[uOffset + idx2] = x;
152
+ uv[uOffset + idx2 + 1] = y;
153
153
 
154
154
  idx1 += 3;
155
155
  idx2 += 2;
@@ -161,7 +161,7 @@ function flatVertices(polygon, options) {
161
161
  holes,
162
162
  points,
163
163
  count,
164
- uvs
164
+ uv
165
165
  };
166
166
 
167
167
  }
package/src/polyline.js CHANGED
@@ -15,8 +15,8 @@ export function extrudePolylines(lines, options) {
15
15
  generateTopAndBottom(result, options);
16
16
  generateSides(result, options);
17
17
  result.position = new Float32Array(result.points);
18
- result.indices = new Uint32Array(result.index);
19
- result.uv = new Float32Array(result.uvs);
18
+ result.indices = new Uint32Array(result.indices);
19
+ result.uv = new Float32Array(result.uv);
20
20
  result.normal = generateNormal(result.indices, result.position);
21
21
  return result;
22
22
  });
@@ -51,8 +51,8 @@ export function extrudeSlopes(lines, options) {
51
51
  generateTopAndBottom(result, options);
52
52
  generateSides(result, options);
53
53
  result.position = new Float32Array(result.points);
54
- result.indices = new Uint32Array(result.index);
55
- result.uv = new Float32Array(result.uvs);
54
+ result.indices = new Uint32Array(result.indices);
55
+ result.uv = new Float32Array(result.uv);
56
56
  result.normal = generateNormal(result.indices, result.position);
57
57
  return result;
58
58
  });
@@ -70,7 +70,7 @@ function generateTopAndBottom(result, options) {
70
70
  lz = depths[0];
71
71
  rz = depths[1];
72
72
  }
73
- const points = [], index = [], uvs = [];
73
+ const points = [], indices = [], uv = [];
74
74
  const { leftPoints, rightPoints } = result;
75
75
  let i = 0, len = leftPoints.length;
76
76
  while (i < len) {
@@ -110,31 +110,47 @@ function generateTopAndBottom(result, options) {
110
110
  }
111
111
  i = 0;
112
112
  len = points.length;
113
+ let uIndex = uv.length - 1;
113
114
  while (i < len) {
114
115
  const x = points[i], y = points[i + 1];
115
- uvs.push(x, y);
116
+ uv[++uIndex] = x;
117
+ uv[++uIndex] = y;
118
+ // uvs.push(x, y);
116
119
  i += 3;
117
120
  }
118
121
  i = 0;
119
122
  len = leftPoints.length;
123
+ let iIndex = indices.length - 1;
120
124
  while (i < len - 1) {
121
125
  // top
122
126
  // left1 left2 right1,right2
123
127
  const a1 = i, b1 = i + 1, c1 = a1 + len, d1 = b1 + len;
124
- index.push(a1, c1, b1);
125
- index.push(c1, d1, b1);
128
+ indices[++iIndex] = a1;
129
+ indices[++iIndex] = c1;
130
+ indices[++iIndex] = b1;
131
+ indices[++iIndex] = c1;
132
+ indices[++iIndex] = d1;
133
+ indices[++iIndex] = b1;
134
+ // index.push(a1, c1, b1);
135
+ // index.push(c1, d1, b1);
126
136
 
127
137
  // bottom
128
138
  // left1 left2 right1,right2
129
139
  const len2 = len * 2;
130
140
  const a2 = i + len2, b2 = a2 + 1, c2 = a2 + len, d2 = b2 + len;
131
- index.push(a2, c2, b2);
132
- index.push(c2, d2, b2);
141
+ indices[++iIndex] = a2;
142
+ indices[++iIndex] = c2;
143
+ indices[++iIndex] = b2;
144
+ indices[++iIndex] = c2;
145
+ indices[++iIndex] = d2;
146
+ indices[++iIndex] = b2;
147
+ // index.push(a2, c2, b2);
148
+ // index.push(c2, d2, b2);
133
149
  i++;
134
150
  }
135
- result.index = index;
151
+ result.indices = indices;
136
152
  result.points = points;
137
- result.uvs = uvs;
153
+ result.uv = uv;
138
154
  if (depths) {
139
155
  len = leftPoints.length;
140
156
  i = 0;
@@ -147,15 +163,17 @@ function generateTopAndBottom(result, options) {
147
163
  }
148
164
 
149
165
  function generateSides(result, options) {
150
- const { points, index, leftPoints, rightPoints, uvs } = result;
166
+ const { points, indices, leftPoints, rightPoints, uv } = result;
151
167
  const z = options.depth;
152
168
  const bottomStickGround = options.bottomStickGround;
153
169
  const rings = [leftPoints, rightPoints];
154
170
  const depthsEnable = result.depths;
155
171
 
172
+ let pIndex = points.length - 1;
173
+ let iIndex = indices.length - 1;
156
174
  function addOneSideIndex(v1, v2) {
157
175
  const idx = points.length / 3;
158
- let pIndex = points.length - 1;
176
+ // let pIndex = points.length - 1;
159
177
 
160
178
  // top
161
179
  points[++pIndex] = v1[0];
@@ -181,8 +199,14 @@ function generateSides(result, options) {
181
199
  // points.push(v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
182
200
 
183
201
  const a = idx + 2, b = idx + 3, c = idx, d = idx + 1;
184
- index.push(a, c, b, c, d, b);
185
- generateSideWallUV(uvs, points, a, b, c, d);
202
+ indices[++iIndex] = a;
203
+ indices[++iIndex] = c;
204
+ indices[++iIndex] = b;
205
+ indices[++iIndex] = c;
206
+ indices[++iIndex] = d;
207
+ indices[++iIndex] = b;
208
+ // index.push(a, c, b, c, d, b);
209
+ generateSideWallUV(uv, points, a, b, c, d);
186
210
  }
187
211
 
188
212
  for (let i = 0, len = rings.length; i < len; i++) {