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/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++) {
package/src/tube.js CHANGED
@@ -16,8 +16,8 @@ export function expandTubes(lines, options) {
16
16
  const result = generateTubeVertexData(pathPointList, options);
17
17
  result.line = line;
18
18
  result.position = new Float32Array(result.points);
19
- result.indices = new Uint32Array(result.index);
20
- result.uv = new Float32Array(result.uvs);
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
  });
@@ -46,9 +46,9 @@ function generateTubeVertexData(pathPointList, options) {
46
46
  // modify data
47
47
  const points = [];
48
48
  const normal = [];
49
- const uvs = [];
49
+ const uv = [];
50
50
  // const uv2 = [];
51
- const index = [];
51
+ const indices = [];
52
52
  let verticesCount = 0;
53
53
 
54
54
  const normalDir = new Vector3();
@@ -78,8 +78,8 @@ function generateTubeVertexData(pathPointList, options) {
78
78
  normal[++nIndex] = normalDir.y;
79
79
  normal[++nIndex] = normalDir.z;
80
80
 
81
- uvs[++uIndex] = uvDist;
82
- uvs[++uIndex] = i / radialSegments;
81
+ uv[++uIndex] = uvDist;
82
+ uv[++uIndex] = i / radialSegments;
83
83
 
84
84
  // uvs.push(uvDist, r / radialSegments);
85
85
 
@@ -95,12 +95,12 @@ function generateTubeVertexData(pathPointList, options) {
95
95
  const begin2 = verticesCount - (radialSegments + 1);
96
96
 
97
97
  for (let i = 0; i < radialSegments; i++) {
98
- index[++iIndex] = begin2 + i;
99
- index[++iIndex] = begin1 + i;
100
- index[++iIndex] = begin1 + i + 1;
101
- index[++iIndex] = begin2 + i;
102
- index[++iIndex] = begin1 + i + 1;
103
- index[++iIndex] = begin2 + i + 1;
98
+ indices[++iIndex] = begin2 + i;
99
+ indices[++iIndex] = begin1 + i;
100
+ indices[++iIndex] = begin1 + i + 1;
101
+ indices[++iIndex] = begin2 + i;
102
+ indices[++iIndex] = begin1 + i + 1;
103
+ indices[++iIndex] = begin2 + i + 1;
104
104
  // index.push(
105
105
  // begin2 + i,
106
106
  // begin1 + i,
@@ -138,9 +138,9 @@ function generateTubeVertexData(pathPointList, options) {
138
138
  return {
139
139
  points,
140
140
  normal,
141
- uvs,
141
+ uv,
142
142
  // uv2,
143
- index,
143
+ indices,
144
144
  count
145
145
  };
146
146
  }
package/src/util.js CHANGED
@@ -176,17 +176,35 @@ export function generateSideWallUV(uvs, vertices, indexA, indexB, indexC, indexD
176
176
  const d_y = vertices[idx4 + 1];
177
177
  const d_z = vertices[idx4 + 2];
178
178
 
179
+ let uIndex = uvs.length - 1;
179
180
  if (Math.abs(a_y - b_y) < Math.abs(a_x - b_x)) {
180
-
181
- uvs.push(a_x, 1 - a_z);
182
- uvs.push(b_x, 1 - b_z);
183
- uvs.push(c_x, 1 - c_z);
184
- uvs.push(d_x, 1 - d_z);
181
+ uvs[++uIndex] = a_x;
182
+ uvs[++uIndex] = 1 - a_z;
183
+ uvs[++uIndex] = b_x;
184
+ uvs[++uIndex] = 1 - b_z;
185
+ uvs[++uIndex] = c_x;
186
+ uvs[++uIndex] = 1 - c_z;
187
+ uvs[++uIndex] = d_x;
188
+ uvs[++uIndex] = 1 - d_z;
189
+
190
+ // uvs.push(a_x, 1 - a_z);
191
+ // uvs.push(b_x, 1 - b_z);
192
+ // uvs.push(c_x, 1 - c_z);
193
+ // uvs.push(d_x, 1 - d_z);
185
194
  } else {
186
- uvs.push(a_y, 1 - a_z);
187
- uvs.push(b_y, 1 - b_z);
188
- uvs.push(c_y, 1 - c_z);
189
- uvs.push(d_y, 1 - d_z);
195
+ uvs[++uIndex] = a_y;
196
+ uvs[++uIndex] = 1 - a_z;
197
+ uvs[++uIndex] = b_y;
198
+ uvs[++uIndex] = 1 - b_z;
199
+ uvs[++uIndex] = c_y;
200
+ uvs[++uIndex] = 1 - c_z;
201
+ uvs[++uIndex] = d_y;
202
+ uvs[++uIndex] = 1 - d_z;
203
+
204
+ // uvs.push(a_y, 1 - a_z);
205
+ // uvs.push(b_y, 1 - b_z);
206
+ // uvs.push(c_y, 1 - c_z);
207
+ // uvs.push(d_y, 1 - d_z);
190
208
  }
191
209
 
192
210
  }