poly-extrude 0.0.2 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
package/src/util.js CHANGED
@@ -64,8 +64,9 @@ export function generateNormal(indices, position) {
64
64
 
65
65
  const len = indices.length;
66
66
  const normals = new Float32Array(position.length);
67
+ let f = 0;
68
+ while (f < len) {
67
69
 
68
- for (let f = 0; f < len; f += 3) {
69
70
  // const i1 = indices[f++] * 3;
70
71
  // const i2 = indices[f++] * 3;
71
72
  // const i3 = indices[f++] * 3;
@@ -79,13 +80,6 @@ export function generateNormal(indices, position) {
79
80
  v3Set(p2, position[i2], position[i2 + 1], position[i2 + 2]);
80
81
  v3Set(p3, position[i3], position[i3 + 1], position[i3 + 2]);
81
82
 
82
- // pA.fromBufferAttribute(positionAttribute, vA);
83
- // pB.fromBufferAttribute(positionAttribute, vB);
84
- // pC.fromBufferAttribute(positionAttribute, vC);
85
-
86
- // cb.subVectors(pC, pB);
87
- // ab.subVectors(pA, pB);
88
- // cb.cross(ab);
89
83
  v3Sub(v32, p3, p2);
90
84
  v3Sub(v21, p1, p2);
91
85
  v3Cross(n, v32, v21);
@@ -95,15 +89,18 @@ export function generateNormal(indices, position) {
95
89
  normals[i2 + i] += n[i];
96
90
  normals[i3 + i] += n[i];
97
91
  }
92
+ f += 3;
98
93
  }
99
94
 
100
- for (let i = 0; i < normals.length; i += 3) {
95
+ let i = 0;
96
+ const l = normals.length;
97
+ while (i < l) {
101
98
  v3Set(n, normals[i], normals[i + 1], normals[i + 2]);
102
99
  v3Normalize(n, n);
103
100
  normals[i] = n[0] || 0;
104
101
  normals[i + 1] = n[1] || 0;
105
102
  normals[i + 2] = n[2] || 0;
106
-
103
+ i += 3;
107
104
  }
108
105
 
109
106
  return normals;
@@ -139,10 +136,13 @@ export function merge(results) {
139
136
  result.position.set(position, pOffset);
140
137
  result.normal.set(normal, pOffset);
141
138
  result.uv.set(uv, uvOffset);
142
- for (let j = 0, len1 = indices.length; j < len1; j++) {
139
+ let j = 0;
140
+ const len1 = indices.length;
141
+ while (j < len1) {
143
142
  const pIndex = indices[j] + pCount;
144
143
  result.indices[iIdx] = pIndex;
145
144
  iIdx++;
145
+ j++;
146
146
  }
147
147
  uvOffset += uv.length;
148
148
  pOffset += position.length;
@@ -162,18 +162,19 @@ export function degToRad(angle) {
162
162
  // https://github.com/mrdoob/three.js/blob/16f13e3b07e31d0e9a00df7c3366bbe0e464588c/src/geometries/ExtrudeGeometry.js?_pjax=%23js-repo-pjax-container#L736
163
163
  export function generateSideWallUV(uvs, vertices, indexA, indexB, indexC, indexD) {
164
164
 
165
- const a_x = vertices[indexA * 3];
166
- const a_y = vertices[indexA * 3 + 1];
167
- const a_z = vertices[indexA * 3 + 2];
168
- const b_x = vertices[indexB * 3];
169
- const b_y = vertices[indexB * 3 + 1];
170
- const b_z = vertices[indexB * 3 + 2];
171
- const c_x = vertices[indexC * 3];
172
- const c_y = vertices[indexC * 3 + 1];
173
- const c_z = vertices[indexC * 3 + 2];
174
- const d_x = vertices[indexD * 3];
175
- const d_y = vertices[indexD * 3 + 1];
176
- const d_z = vertices[indexD * 3 + 2];
165
+ const idx1 = indexA * 3, idx2 = indexB * 3, idx3 = indexC * 3, idx4 = indexD * 3;
166
+ const a_x = vertices[idx1];
167
+ const a_y = vertices[idx1 + 1];
168
+ const a_z = vertices[idx1 + 2];
169
+ const b_x = vertices[idx2];
170
+ const b_y = vertices[idx2 + 1];
171
+ const b_z = vertices[idx2 + 2];
172
+ const c_x = vertices[idx3];
173
+ const c_y = vertices[idx3 + 1];
174
+ const c_z = vertices[idx3 + 2];
175
+ const d_x = vertices[idx4];
176
+ const d_y = vertices[idx4 + 1];
177
+ const d_z = vertices[idx4 + 2];
177
178
 
178
179
  if (Math.abs(a_y - b_y) < Math.abs(a_x - b_x)) {
179
180
 
@@ -181,25 +182,11 @@ export function generateSideWallUV(uvs, vertices, indexA, indexB, indexC, indexD
181
182
  uvs.push(b_x, 1 - b_z);
182
183
  uvs.push(c_x, 1 - c_z);
183
184
  uvs.push(d_x, 1 - d_z);
184
- // return [
185
- // new Vector2(a_x, 1 - a_z),
186
- // new Vector2(b_x, 1 - b_z),
187
- // new Vector2(c_x, 1 - c_z),
188
- // new Vector2(d_x, 1 - d_z)
189
- // ];
190
-
191
185
  } else {
192
186
  uvs.push(a_y, 1 - a_z);
193
187
  uvs.push(b_y, 1 - b_z);
194
188
  uvs.push(c_y, 1 - c_z);
195
189
  uvs.push(d_y, 1 - d_z);
196
- // return [
197
- // new Vector2(a_y, 1 - a_z),
198
- // new Vector2(b_y, 1 - b_z),
199
- // new Vector2(c_y, 1 - c_z),
200
- // new Vector2(d_y, 1 - d_z)
201
- // ];
202
-
203
190
  }
204
191
 
205
192
  }