poly-extrude 0.8.0 → 0.10.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/dist/poly-extrude.js +2035 -2195
- package/dist/poly-extrude.js.map +1 -1
- package/dist/poly-extrude.min.js +2 -4
- package/dist/poly-extrude.mjs +2035 -2195
- package/package.json +1 -1
- package/src/cylinder.js +32 -10
- package/src/math/Quaternion.js +7 -7
- package/src/path.js +187 -86
- package/src/polygon.js +25 -25
- package/src/polyline.js +40 -16
- package/src/tube.js +17 -21
- package/src/util.js +40 -9
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.
|
19
|
-
result.uv = new Float32Array(result.
|
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.
|
55
|
-
result.uv = new Float32Array(result.
|
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 = [],
|
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
|
-
|
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
|
-
|
125
|
-
|
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
|
-
|
132
|
-
|
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.
|
151
|
+
result.indices = indices;
|
136
152
|
result.points = points;
|
137
|
-
result.
|
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,
|
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
|
-
|
185
|
-
|
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
@@ -1,23 +1,21 @@
|
|
1
1
|
import { Vector3 } from './math/Vector3';
|
2
2
|
import { PathPoint } from './path/PathPoint';
|
3
3
|
import { PathPointList } from './path/PathPointList';
|
4
|
-
import { merge } from './util';
|
4
|
+
import { line2Vectors, merge } from './util';
|
5
5
|
const UP = new Vector3(0, 0, 1);
|
6
|
+
const normalDir = new Vector3();
|
6
7
|
|
7
8
|
export function expandTubes(lines, options) {
|
8
9
|
options = Object.assign({}, { radius: 1, cornerSplit: 0, radialSegments: 8, startRad: -Math.PI / 4 }, options);
|
9
10
|
const results = lines.map(line => {
|
10
|
-
const points = line
|
11
|
-
const [x, y, z] = p;
|
12
|
-
return new Vector3(x, y, z || 0);
|
13
|
-
});
|
11
|
+
const points = line2Vectors(line);
|
14
12
|
const pathPointList = new PathPointList();
|
15
13
|
pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP);
|
16
14
|
const result = generateTubeVertexData(pathPointList, options);
|
17
15
|
result.line = line;
|
18
16
|
result.position = new Float32Array(result.points);
|
19
|
-
result.indices = new Uint32Array(result.
|
20
|
-
result.uv = new Float32Array(result.
|
17
|
+
result.indices = new Uint32Array(result.indices);
|
18
|
+
result.uv = new Float32Array(result.uv);
|
21
19
|
result.normal = new Float32Array(result.normal);
|
22
20
|
return result;
|
23
21
|
});
|
@@ -46,13 +44,11 @@ function generateTubeVertexData(pathPointList, options) {
|
|
46
44
|
// modify data
|
47
45
|
const points = [];
|
48
46
|
const normal = [];
|
49
|
-
const
|
47
|
+
const uv = [];
|
50
48
|
// const uv2 = [];
|
51
|
-
const
|
49
|
+
const indices = [];
|
52
50
|
let verticesCount = 0;
|
53
51
|
|
54
|
-
const normalDir = new Vector3();
|
55
|
-
|
56
52
|
let pIndex = -1;
|
57
53
|
let nIndex = -1;
|
58
54
|
let uIndex = -1;
|
@@ -78,8 +74,8 @@ function generateTubeVertexData(pathPointList, options) {
|
|
78
74
|
normal[++nIndex] = normalDir.y;
|
79
75
|
normal[++nIndex] = normalDir.z;
|
80
76
|
|
81
|
-
|
82
|
-
|
77
|
+
uv[++uIndex] = uvDist;
|
78
|
+
uv[++uIndex] = i / radialSegments;
|
83
79
|
|
84
80
|
// uvs.push(uvDist, r / radialSegments);
|
85
81
|
|
@@ -95,12 +91,12 @@ function generateTubeVertexData(pathPointList, options) {
|
|
95
91
|
const begin2 = verticesCount - (radialSegments + 1);
|
96
92
|
|
97
93
|
for (let i = 0; i < radialSegments; i++) {
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
94
|
+
indices[++iIndex] = begin2 + i;
|
95
|
+
indices[++iIndex] = begin1 + i;
|
96
|
+
indices[++iIndex] = begin1 + i + 1;
|
97
|
+
indices[++iIndex] = begin2 + i;
|
98
|
+
indices[++iIndex] = begin1 + i + 1;
|
99
|
+
indices[++iIndex] = begin2 + i + 1;
|
104
100
|
// index.push(
|
105
101
|
// begin2 + i,
|
106
102
|
// begin1 + i,
|
@@ -138,9 +134,9 @@ function generateTubeVertexData(pathPointList, options) {
|
|
138
134
|
return {
|
139
135
|
points,
|
140
136
|
normal,
|
141
|
-
|
137
|
+
uv,
|
142
138
|
// uv2,
|
143
|
-
|
139
|
+
indices,
|
144
140
|
count
|
145
141
|
};
|
146
142
|
}
|
package/src/util.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import { Vector3 } from './math/Vector3';
|
2
|
+
|
1
3
|
/**
|
2
4
|
* https://github.com/Turfjs/turf/blob/master/packages/turf-boolean-clockwise/index.ts
|
3
5
|
* @param {*} ring
|
@@ -176,17 +178,46 @@ export function generateSideWallUV(uvs, vertices, indexA, indexB, indexC, indexD
|
|
176
178
|
const d_y = vertices[idx4 + 1];
|
177
179
|
const d_z = vertices[idx4 + 2];
|
178
180
|
|
181
|
+
let uIndex = uvs.length - 1;
|
179
182
|
if (Math.abs(a_y - b_y) < Math.abs(a_x - b_x)) {
|
180
|
-
|
181
|
-
uvs
|
182
|
-
uvs
|
183
|
-
uvs
|
184
|
-
uvs
|
183
|
+
uvs[++uIndex] = a_x;
|
184
|
+
uvs[++uIndex] = 1 - a_z;
|
185
|
+
uvs[++uIndex] = b_x;
|
186
|
+
uvs[++uIndex] = 1 - b_z;
|
187
|
+
uvs[++uIndex] = c_x;
|
188
|
+
uvs[++uIndex] = 1 - c_z;
|
189
|
+
uvs[++uIndex] = d_x;
|
190
|
+
uvs[++uIndex] = 1 - d_z;
|
191
|
+
|
192
|
+
// uvs.push(a_x, 1 - a_z);
|
193
|
+
// uvs.push(b_x, 1 - b_z);
|
194
|
+
// uvs.push(c_x, 1 - c_z);
|
195
|
+
// uvs.push(d_x, 1 - d_z);
|
185
196
|
} else {
|
186
|
-
uvs
|
187
|
-
uvs
|
188
|
-
uvs
|
189
|
-
uvs
|
197
|
+
uvs[++uIndex] = a_y;
|
198
|
+
uvs[++uIndex] = 1 - a_z;
|
199
|
+
uvs[++uIndex] = b_y;
|
200
|
+
uvs[++uIndex] = 1 - b_z;
|
201
|
+
uvs[++uIndex] = c_y;
|
202
|
+
uvs[++uIndex] = 1 - c_z;
|
203
|
+
uvs[++uIndex] = d_y;
|
204
|
+
uvs[++uIndex] = 1 - d_z;
|
205
|
+
|
206
|
+
// uvs.push(a_y, 1 - a_z);
|
207
|
+
// uvs.push(b_y, 1 - b_z);
|
208
|
+
// uvs.push(c_y, 1 - c_z);
|
209
|
+
// uvs.push(d_y, 1 - d_z);
|
190
210
|
}
|
191
211
|
|
192
212
|
}
|
213
|
+
|
214
|
+
export function line2Vectors(line) {
|
215
|
+
const points = [];
|
216
|
+
for (let i = 0, len = line.length; i < len; i++) {
|
217
|
+
const p = line[i];
|
218
|
+
const [x, y, z] = p;
|
219
|
+
const v = new Vector3(x, y, z || 0);
|
220
|
+
points[i] = v;
|
221
|
+
}
|
222
|
+
return points;
|
223
|
+
}
|