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/dist/poly-extrude.js +333 -107
- package/dist/poly-extrude.js.map +1 -1
- package/dist/poly-extrude.min.js +3 -3
- package/dist/poly-extrude.mjs +333 -107
- package/package.json +1 -1
- package/readme.md +22 -26
- package/src/cylinder.js +32 -10
- package/src/path.js +176 -72
- package/src/polygon.js +46 -26
- package/src/polyline.js +40 -16
- package/src/tube.js +14 -14
- package/src/util.js +27 -9
package/dist/poly-extrude.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* poly-extrude v0.
|
2
|
+
* poly-extrude v0.9.0
|
3
3
|
*/
|
4
4
|
var earcut$2 = {exports: {}};
|
5
5
|
|
@@ -862,17 +862,32 @@ function generateSideWallUV(uvs, vertices, indexA, indexB, indexC, indexD) {
|
|
862
862
|
var d_x = vertices[idx4];
|
863
863
|
var d_y = vertices[idx4 + 1];
|
864
864
|
var d_z = vertices[idx4 + 2];
|
865
|
+
var uIndex = uvs.length - 1;
|
865
866
|
|
866
867
|
if (Math.abs(a_y - b_y) < Math.abs(a_x - b_x)) {
|
867
|
-
uvs
|
868
|
-
uvs
|
869
|
-
uvs
|
870
|
-
uvs
|
868
|
+
uvs[++uIndex] = a_x;
|
869
|
+
uvs[++uIndex] = 1 - a_z;
|
870
|
+
uvs[++uIndex] = b_x;
|
871
|
+
uvs[++uIndex] = 1 - b_z;
|
872
|
+
uvs[++uIndex] = c_x;
|
873
|
+
uvs[++uIndex] = 1 - c_z;
|
874
|
+
uvs[++uIndex] = d_x;
|
875
|
+
uvs[++uIndex] = 1 - d_z; // uvs.push(a_x, 1 - a_z);
|
876
|
+
// uvs.push(b_x, 1 - b_z);
|
877
|
+
// uvs.push(c_x, 1 - c_z);
|
878
|
+
// uvs.push(d_x, 1 - d_z);
|
871
879
|
} else {
|
872
|
-
uvs
|
873
|
-
uvs
|
874
|
-
uvs
|
875
|
-
uvs
|
880
|
+
uvs[++uIndex] = a_y;
|
881
|
+
uvs[++uIndex] = 1 - a_z;
|
882
|
+
uvs[++uIndex] = b_y;
|
883
|
+
uvs[++uIndex] = 1 - b_z;
|
884
|
+
uvs[++uIndex] = c_y;
|
885
|
+
uvs[++uIndex] = 1 - c_z;
|
886
|
+
uvs[++uIndex] = d_y;
|
887
|
+
uvs[++uIndex] = 1 - d_z; // uvs.push(a_y, 1 - a_z);
|
888
|
+
// uvs.push(b_y, 1 - b_z);
|
889
|
+
// uvs.push(c_y, 1 - c_z);
|
890
|
+
// uvs.push(d_y, 1 - d_z);
|
876
891
|
}
|
877
892
|
}
|
878
893
|
|
@@ -904,8 +919,8 @@ function extrudePolygons(polygons, options) {
|
|
904
919
|
generateTopAndBottom$1(result, triangles);
|
905
920
|
generateSides$1(result, options);
|
906
921
|
result.position = new Float32Array(result.points);
|
907
|
-
result.indices = new Uint32Array(result.
|
908
|
-
result.uv = new Float32Array(result.
|
922
|
+
result.indices = new Uint32Array(result.indices);
|
923
|
+
result.uv = new Float32Array(result.uv);
|
909
924
|
result.normal = generateNormal(result.indices, result.position);
|
910
925
|
return result;
|
911
926
|
});
|
@@ -915,7 +930,7 @@ function extrudePolygons(polygons, options) {
|
|
915
930
|
}
|
916
931
|
|
917
932
|
function generateTopAndBottom$1(result, triangles) {
|
918
|
-
var
|
933
|
+
var indices = [];
|
919
934
|
var count = result.count;
|
920
935
|
|
921
936
|
for (var i = 0, len = triangles.length; i < len; i += 3) {
|
@@ -923,28 +938,30 @@ function generateTopAndBottom$1(result, triangles) {
|
|
923
938
|
var a = triangles[i],
|
924
939
|
b = triangles[i + 1],
|
925
940
|
c = triangles[i + 2];
|
926
|
-
|
927
|
-
|
928
|
-
|
941
|
+
indices[i] = a;
|
942
|
+
indices[i + 1] = b;
|
943
|
+
indices[i + 2] = c; // bottom
|
929
944
|
|
930
945
|
var idx = len + i;
|
931
946
|
var a1 = count + a,
|
932
947
|
b1 = count + b,
|
933
948
|
c1 = count + c;
|
934
|
-
|
935
|
-
|
936
|
-
|
949
|
+
indices[idx] = a1;
|
950
|
+
indices[idx + 1] = b1;
|
951
|
+
indices[idx + 2] = c1;
|
937
952
|
}
|
938
953
|
|
939
|
-
result.
|
954
|
+
result.indices = indices;
|
940
955
|
}
|
941
956
|
|
942
957
|
function generateSides$1(result, options) {
|
943
958
|
var points = result.points,
|
944
|
-
|
959
|
+
indices = result.indices,
|
945
960
|
polygon = result.polygon,
|
946
|
-
|
947
|
-
var
|
961
|
+
uv = result.uv;
|
962
|
+
var depth = options.depth;
|
963
|
+
var pIndex = points.length - 1;
|
964
|
+
var iIndex = indices.length - 1;
|
948
965
|
|
949
966
|
for (var i = 0, len = polygon.length; i < len; i++) {
|
950
967
|
var ring = polygon[i];
|
@@ -962,17 +979,37 @@ function generateSides$1(result, options) {
|
|
962
979
|
var idx = points.length / 3;
|
963
980
|
var x1 = v1[0],
|
964
981
|
y1 = v1[1],
|
982
|
+
z1 = v1[2] || 0,
|
965
983
|
x2 = v2[0],
|
966
|
-
y2 = v2[1]
|
967
|
-
|
984
|
+
y2 = v2[1],
|
985
|
+
z2 = v2[2] || 0;
|
986
|
+
points[++pIndex] = x1;
|
987
|
+
points[++pIndex] = y1;
|
988
|
+
points[++pIndex] = z1 + depth;
|
989
|
+
points[++pIndex] = x2;
|
990
|
+
points[++pIndex] = y2;
|
991
|
+
points[++pIndex] = z2 + depth;
|
992
|
+
points[++pIndex] = x1;
|
993
|
+
points[++pIndex] = y1;
|
994
|
+
points[++pIndex] = z1;
|
995
|
+
points[++pIndex] = x2;
|
996
|
+
points[++pIndex] = y2;
|
997
|
+
points[++pIndex] = z2; // points.push(x1, y1, z, x2, y2, z, x1, y1, 0, x2, y2, 0);
|
998
|
+
|
968
999
|
var a = idx + 2,
|
969
1000
|
b = idx + 3,
|
970
1001
|
c = idx,
|
971
1002
|
d = idx + 1; // points.push(p3, p4, p1, p2);
|
1003
|
+
// index.push(a, c, b, c, d, b);
|
972
1004
|
|
973
|
-
|
1005
|
+
indices[++iIndex] = a;
|
1006
|
+
indices[++iIndex] = c;
|
1007
|
+
indices[++iIndex] = b;
|
1008
|
+
indices[++iIndex] = c;
|
1009
|
+
indices[++iIndex] = d;
|
1010
|
+
indices[++iIndex] = b; // index.push(c, d, b);
|
974
1011
|
|
975
|
-
generateSideWallUV(
|
1012
|
+
generateSideWallUV(uv, points, a, b, c, d);
|
976
1013
|
j++;
|
977
1014
|
}
|
978
1015
|
}
|
@@ -997,10 +1034,10 @@ function flatVertices(polygon, options) {
|
|
997
1034
|
var holes = [],
|
998
1035
|
flatVertices = new Float32Array(count * 2),
|
999
1036
|
points = [],
|
1000
|
-
|
1037
|
+
uv = [];
|
1001
1038
|
var pOffset = count * 3,
|
1002
1039
|
uOffset = count * 2;
|
1003
|
-
var
|
1040
|
+
var depth = options.depth;
|
1004
1041
|
var idx0 = 0,
|
1005
1042
|
idx1 = 0,
|
1006
1043
|
idx2 = 0;
|
@@ -1018,21 +1055,22 @@ function flatVertices(polygon, options) {
|
|
1018
1055
|
while (j < len1) {
|
1019
1056
|
var c = ring[j];
|
1020
1057
|
var x = c[0],
|
1021
|
-
y = c[1]
|
1058
|
+
y = c[1],
|
1059
|
+
z = c[2] || 0;
|
1022
1060
|
flatVertices[idx0++] = x;
|
1023
1061
|
flatVertices[idx0++] = y; // top vertices
|
1024
1062
|
|
1025
1063
|
points[idx1] = x;
|
1026
1064
|
points[idx1 + 1] = y;
|
1027
|
-
points[idx1 + 2] = z; // bottom vertices
|
1065
|
+
points[idx1 + 2] = depth + z; // bottom vertices
|
1028
1066
|
|
1029
1067
|
points[pOffset + idx1] = x;
|
1030
1068
|
points[pOffset + idx1 + 1] = y;
|
1031
|
-
points[pOffset + idx1 + 2] =
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1069
|
+
points[pOffset + idx1 + 2] = z;
|
1070
|
+
uv[idx2] = x;
|
1071
|
+
uv[idx2 + 1] = y;
|
1072
|
+
uv[uOffset + idx2] = x;
|
1073
|
+
uv[uOffset + idx2 + 1] = y;
|
1036
1074
|
idx1 += 3;
|
1037
1075
|
idx2 += 2;
|
1038
1076
|
j++;
|
@@ -1044,7 +1082,7 @@ function flatVertices(polygon, options) {
|
|
1044
1082
|
holes: holes,
|
1045
1083
|
points: points,
|
1046
1084
|
count: count,
|
1047
|
-
|
1085
|
+
uv: uv
|
1048
1086
|
};
|
1049
1087
|
}
|
1050
1088
|
|
@@ -1084,8 +1122,8 @@ function extrudePolylines(lines, options) {
|
|
1084
1122
|
generateTopAndBottom(result, options);
|
1085
1123
|
generateSides(result, options);
|
1086
1124
|
result.position = new Float32Array(result.points);
|
1087
|
-
result.indices = new Uint32Array(result.
|
1088
|
-
result.uv = new Float32Array(result.
|
1125
|
+
result.indices = new Uint32Array(result.indices);
|
1126
|
+
result.uv = new Float32Array(result.uv);
|
1089
1127
|
result.normal = generateNormal(result.indices, result.position);
|
1090
1128
|
return result;
|
1091
1129
|
});
|
@@ -1134,8 +1172,8 @@ function extrudeSlopes(lines, options) {
|
|
1134
1172
|
generateTopAndBottom(result, options);
|
1135
1173
|
generateSides(result, options);
|
1136
1174
|
result.position = new Float32Array(result.points);
|
1137
|
-
result.indices = new Uint32Array(result.
|
1138
|
-
result.uv = new Float32Array(result.
|
1175
|
+
result.indices = new Uint32Array(result.indices);
|
1176
|
+
result.uv = new Float32Array(result.uv);
|
1139
1177
|
result.normal = generateNormal(result.indices, result.position);
|
1140
1178
|
return result;
|
1141
1179
|
});
|
@@ -1157,8 +1195,8 @@ function generateTopAndBottom(result, options) {
|
|
1157
1195
|
}
|
1158
1196
|
|
1159
1197
|
var points = [],
|
1160
|
-
|
1161
|
-
|
1198
|
+
indices = [],
|
1199
|
+
uv = [];
|
1162
1200
|
var leftPoints = result.leftPoints,
|
1163
1201
|
rightPoints = result.rightPoints;
|
1164
1202
|
var i = 0,
|
@@ -1208,16 +1246,20 @@ function generateTopAndBottom(result, options) {
|
|
1208
1246
|
|
1209
1247
|
i = 0;
|
1210
1248
|
len = points.length;
|
1249
|
+
var uIndex = uv.length - 1;
|
1211
1250
|
|
1212
1251
|
while (i < len) {
|
1213
1252
|
var x = points[i],
|
1214
1253
|
y = points[i + 1];
|
1215
|
-
|
1254
|
+
uv[++uIndex] = x;
|
1255
|
+
uv[++uIndex] = y; // uvs.push(x, y);
|
1256
|
+
|
1216
1257
|
i += 3;
|
1217
1258
|
}
|
1218
1259
|
|
1219
1260
|
i = 0;
|
1220
1261
|
len = leftPoints.length;
|
1262
|
+
var iIndex = indices.length - 1;
|
1221
1263
|
|
1222
1264
|
while (i < len - 1) {
|
1223
1265
|
// top
|
@@ -1226,8 +1268,14 @@ function generateTopAndBottom(result, options) {
|
|
1226
1268
|
b1 = i + 1,
|
1227
1269
|
c1 = a1 + len,
|
1228
1270
|
d1 = b1 + len;
|
1229
|
-
|
1230
|
-
|
1271
|
+
indices[++iIndex] = a1;
|
1272
|
+
indices[++iIndex] = c1;
|
1273
|
+
indices[++iIndex] = b1;
|
1274
|
+
indices[++iIndex] = c1;
|
1275
|
+
indices[++iIndex] = d1;
|
1276
|
+
indices[++iIndex] = b1; // index.push(a1, c1, b1);
|
1277
|
+
// index.push(c1, d1, b1);
|
1278
|
+
// bottom
|
1231
1279
|
// left1 left2 right1,right2
|
1232
1280
|
|
1233
1281
|
var len2 = len * 2;
|
@@ -1235,14 +1283,20 @@ function generateTopAndBottom(result, options) {
|
|
1235
1283
|
b2 = a2 + 1,
|
1236
1284
|
c2 = a2 + len,
|
1237
1285
|
d2 = b2 + len;
|
1238
|
-
|
1239
|
-
|
1286
|
+
indices[++iIndex] = a2;
|
1287
|
+
indices[++iIndex] = c2;
|
1288
|
+
indices[++iIndex] = b2;
|
1289
|
+
indices[++iIndex] = c2;
|
1290
|
+
indices[++iIndex] = d2;
|
1291
|
+
indices[++iIndex] = b2; // index.push(a2, c2, b2);
|
1292
|
+
// index.push(c2, d2, b2);
|
1293
|
+
|
1240
1294
|
i++;
|
1241
1295
|
}
|
1242
1296
|
|
1243
|
-
result.
|
1297
|
+
result.indices = indices;
|
1244
1298
|
result.points = points;
|
1245
|
-
result.
|
1299
|
+
result.uv = uv;
|
1246
1300
|
|
1247
1301
|
if (depths) {
|
1248
1302
|
len = leftPoints.length;
|
@@ -1258,18 +1312,20 @@ function generateTopAndBottom(result, options) {
|
|
1258
1312
|
|
1259
1313
|
function generateSides(result, options) {
|
1260
1314
|
var points = result.points,
|
1261
|
-
|
1315
|
+
indices = result.indices,
|
1262
1316
|
leftPoints = result.leftPoints,
|
1263
1317
|
rightPoints = result.rightPoints,
|
1264
|
-
|
1318
|
+
uv = result.uv;
|
1265
1319
|
var z = options.depth;
|
1266
1320
|
var bottomStickGround = options.bottomStickGround;
|
1267
1321
|
var rings = [leftPoints, rightPoints];
|
1268
1322
|
var depthsEnable = result.depths;
|
1323
|
+
var pIndex = points.length - 1;
|
1324
|
+
var iIndex = indices.length - 1;
|
1269
1325
|
|
1270
1326
|
function addOneSideIndex(v1, v2) {
|
1271
|
-
var idx = points.length / 3;
|
1272
|
-
|
1327
|
+
var idx = points.length / 3; // let pIndex = points.length - 1;
|
1328
|
+
// top
|
1273
1329
|
|
1274
1330
|
points[++pIndex] = v1[0];
|
1275
1331
|
points[++pIndex] = v1[1];
|
@@ -1290,8 +1346,14 @@ function generateSides(result, options) {
|
|
1290
1346
|
b = idx + 3,
|
1291
1347
|
c = idx,
|
1292
1348
|
d = idx + 1;
|
1293
|
-
|
1294
|
-
|
1349
|
+
indices[++iIndex] = a;
|
1350
|
+
indices[++iIndex] = c;
|
1351
|
+
indices[++iIndex] = b;
|
1352
|
+
indices[++iIndex] = c;
|
1353
|
+
indices[++iIndex] = d;
|
1354
|
+
indices[++iIndex] = b; // index.push(a, c, b, c, d, b);
|
1355
|
+
|
1356
|
+
generateSideWallUV(uv, points, a, b, c, d);
|
1295
1357
|
}
|
1296
1358
|
|
1297
1359
|
for (var i = 0, _len = rings.length; i < _len; i++) {
|
@@ -1539,7 +1601,8 @@ function cylinder(point, options) {
|
|
1539
1601
|
var offset = circlePointsLen * 3,
|
1540
1602
|
uOffset = circlePointsLen * 2;
|
1541
1603
|
var indices = [],
|
1542
|
-
|
1604
|
+
uv = [];
|
1605
|
+
var iIndex = indices.length - 1;
|
1543
1606
|
|
1544
1607
|
for (var i = -1; i < radialSegments; i++) {
|
1545
1608
|
var rad = aRad * i;
|
@@ -1557,16 +1620,19 @@ function cylinder(point, options) {
|
|
1557
1620
|
v = 0;
|
1558
1621
|
u = 0.5 + x / radius / 2;
|
1559
1622
|
v = 0.5 + y / radius / 2;
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1623
|
+
uv[uIdx] = u;
|
1624
|
+
uv[uIdx + 1] = v;
|
1625
|
+
uv[uIdx + uOffset] = u;
|
1626
|
+
uv[uIdx + 1 + uOffset] = v;
|
1564
1627
|
idx += 3;
|
1565
1628
|
uIdx += 2;
|
1566
1629
|
|
1567
1630
|
if (i > 1) {
|
1568
1631
|
// bottom indices
|
1569
|
-
indices.push(0, i - 1, i);
|
1632
|
+
// indices.push(0, i - 1, i);
|
1633
|
+
indices[++iIndex] = 0;
|
1634
|
+
indices[++iIndex] = i - 1;
|
1635
|
+
indices[++iIndex] = i;
|
1570
1636
|
}
|
1571
1637
|
}
|
1572
1638
|
|
@@ -1580,15 +1646,19 @@ function cylinder(point, options) {
|
|
1580
1646
|
points[pointsLen - 1] = height;
|
1581
1647
|
var indicesLen = indices.length; // top indices
|
1582
1648
|
|
1649
|
+
iIndex = indices.length - 1;
|
1650
|
+
|
1583
1651
|
for (var _i = 0; _i < indicesLen; _i++) {
|
1584
1652
|
var index = indices[_i];
|
1585
|
-
indices.push(index + circlePointsLen);
|
1653
|
+
indices[++iIndex] = index + circlePointsLen; // indices.push(index + circlePointsLen);
|
1586
1654
|
}
|
1587
1655
|
|
1588
1656
|
var sidePoints = new Float32Array((circlePointsLen * 3 * 2 - 6) * 2);
|
1589
1657
|
var pIndex = -1;
|
1590
1658
|
idx = circlePointsLen * 2;
|
1591
1659
|
uIdx = 0;
|
1660
|
+
iIndex = indices.length - 1;
|
1661
|
+
var uvIndex = uv.length - 1;
|
1592
1662
|
|
1593
1663
|
for (var _i2 = 0, len = points.length / 2; _i2 < len - 3; _i2 += 3) {
|
1594
1664
|
var x1 = points[_i2],
|
@@ -1612,11 +1682,25 @@ function cylinder(point, options) {
|
|
1612
1682
|
c = idx,
|
1613
1683
|
d = idx + 1; // indices.push(a, c, b, c, d, b);
|
1614
1684
|
|
1615
|
-
indices
|
1685
|
+
indices[++iIndex] = c;
|
1686
|
+
indices[++iIndex] = a;
|
1687
|
+
indices[++iIndex] = d;
|
1688
|
+
indices[++iIndex] = a;
|
1689
|
+
indices[++iIndex] = b;
|
1690
|
+
indices[++iIndex] = d; // indices.push(c, a, d, a, b, d);
|
1691
|
+
|
1616
1692
|
idx += 4;
|
1617
1693
|
var u1 = uIdx / circlePointsLen,
|
1618
1694
|
u2 = (uIdx + 1) / circlePointsLen;
|
1619
|
-
|
1695
|
+
uv[++uvIndex] = u1;
|
1696
|
+
uv[++uvIndex] = height / radius / 2;
|
1697
|
+
uv[++uvIndex] = u2;
|
1698
|
+
uv[++uvIndex] = height / radius / 2;
|
1699
|
+
uv[++uvIndex] = u1;
|
1700
|
+
uv[++uvIndex] = 0;
|
1701
|
+
uv[++uvIndex] = u2;
|
1702
|
+
uv[++uvIndex] = 0; // uvs.push(u1, height / radius / 2, u2, height / radius / 2, u1, 0, u2, 0);
|
1703
|
+
|
1620
1704
|
uIdx++;
|
1621
1705
|
}
|
1622
1706
|
|
@@ -1629,7 +1713,7 @@ function cylinder(point, options) {
|
|
1629
1713
|
indices: new Uint32Array(indices),
|
1630
1714
|
position: position,
|
1631
1715
|
normal: normal,
|
1632
|
-
uv: new Float32Array(
|
1716
|
+
uv: new Float32Array(uv)
|
1633
1717
|
};
|
1634
1718
|
}
|
1635
1719
|
|
@@ -4392,9 +4476,9 @@ function expandPaths(lines, options) {
|
|
4392
4476
|
pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP$1);
|
4393
4477
|
var result = generatePathVertexData(pathPointList, options);
|
4394
4478
|
result.line = line;
|
4395
|
-
result.position = new Float32Array(result.
|
4396
|
-
result.indices = new Uint32Array(result.
|
4397
|
-
result.uv = new Float32Array(result.
|
4479
|
+
result.position = new Float32Array(result.position);
|
4480
|
+
result.indices = new Uint32Array(result.indices);
|
4481
|
+
result.uv = new Float32Array(result.uv);
|
4398
4482
|
result.normal = new Float32Array(result.normal);
|
4399
4483
|
return result;
|
4400
4484
|
});
|
@@ -4432,6 +4516,10 @@ function generatePathVertexData(pathPointList, options) {
|
|
4432
4516
|
var rightOffset = new Vector3();
|
4433
4517
|
var tempPoint1 = new Vector3();
|
4434
4518
|
var tempPoint2 = new Vector3();
|
4519
|
+
var pIndex = position.length - 1;
|
4520
|
+
var nIndex = normal.length - 1;
|
4521
|
+
var uIndex = uv.length - 1;
|
4522
|
+
var iIndex = indices.length - 1;
|
4435
4523
|
|
4436
4524
|
function addVertices(pathPoint) {
|
4437
4525
|
var first = position.length === 0;
|
@@ -4482,31 +4570,135 @@ function generatePathVertexData(pathPointList, options) {
|
|
4482
4570
|
tempPoint2.copy(dir).setLength(_dist).add(tempPoint1);
|
4483
4571
|
|
4484
4572
|
if (sideOffset > 0) {
|
4485
|
-
position
|
4486
|
-
|
4487
|
-
|
4488
|
-
|
4489
|
-
|
4490
|
-
|
4491
|
-
|
4573
|
+
position[++pIndex] = tempPoint1.x;
|
4574
|
+
position[++pIndex] = tempPoint1.y;
|
4575
|
+
position[++pIndex] = tempPoint1.z;
|
4576
|
+
position[++pIndex] = right.x;
|
4577
|
+
position[++pIndex] = right.y;
|
4578
|
+
position[++pIndex] = right.z;
|
4579
|
+
position[++pIndex] = left.x;
|
4580
|
+
position[++pIndex] = left.y;
|
4581
|
+
position[++pIndex] = left.z;
|
4582
|
+
position[++pIndex] = right.x;
|
4583
|
+
position[++pIndex] = right.y;
|
4584
|
+
position[++pIndex] = right.z;
|
4585
|
+
position[++pIndex] = tempPoint2.x;
|
4586
|
+
position[++pIndex] = tempPoint2.y;
|
4587
|
+
position[++pIndex] = tempPoint2.z;
|
4588
|
+
position[++pIndex] = right.x;
|
4589
|
+
position[++pIndex] = right.y;
|
4590
|
+
position[++pIndex] = right.z; // position.push(
|
4591
|
+
// tempPoint1.x, tempPoint1.y, tempPoint1.z, // 6
|
4592
|
+
// right.x, right.y, right.z, // 5
|
4593
|
+
// left.x, left.y, left.z, // 4
|
4594
|
+
// right.x, right.y, right.z, // 3
|
4595
|
+
// tempPoint2.x, tempPoint2.y, tempPoint2.z, // 2
|
4596
|
+
// right.x, right.y, right.z // 1
|
4597
|
+
// );
|
4598
|
+
|
4492
4599
|
verticesCount += 6;
|
4493
|
-
indices
|
4600
|
+
indices[++iIndex] = verticesCount - 6;
|
4601
|
+
indices[++iIndex] = verticesCount - 8;
|
4602
|
+
indices[++iIndex] = verticesCount - 7;
|
4603
|
+
indices[++iIndex] = verticesCount - 6;
|
4604
|
+
indices[++iIndex] = verticesCount - 7;
|
4605
|
+
indices[++iIndex] = verticesCount - 5;
|
4606
|
+
indices[++iIndex] = verticesCount - 4;
|
4607
|
+
indices[++iIndex] = verticesCount - 6;
|
4608
|
+
indices[++iIndex] = verticesCount - 5;
|
4609
|
+
indices[++iIndex] = verticesCount - 2;
|
4610
|
+
indices[++iIndex] = verticesCount - 4;
|
4611
|
+
indices[++iIndex] = verticesCount - 1; // indices.push(
|
4612
|
+
// verticesCount - 6, verticesCount - 8, verticesCount - 7,
|
4613
|
+
// verticesCount - 6, verticesCount - 7, verticesCount - 5,
|
4614
|
+
// verticesCount - 4, verticesCount - 6, verticesCount - 5,
|
4615
|
+
// verticesCount - 2, verticesCount - 4, verticesCount - 1
|
4616
|
+
// );
|
4617
|
+
|
4494
4618
|
count += 12;
|
4495
4619
|
} else {
|
4496
|
-
position
|
4497
|
-
|
4498
|
-
|
4499
|
-
|
4500
|
-
|
4501
|
-
|
4502
|
-
|
4620
|
+
position[++pIndex] = left.x;
|
4621
|
+
position[++pIndex] = left.y;
|
4622
|
+
position[++pIndex] = left.z;
|
4623
|
+
position[++pIndex] = tempPoint1.x;
|
4624
|
+
position[++pIndex] = tempPoint1.y;
|
4625
|
+
position[++pIndex] = tempPoint1.z;
|
4626
|
+
position[++pIndex] = left.x;
|
4627
|
+
position[++pIndex] = left.y;
|
4628
|
+
position[++pIndex] = left.z;
|
4629
|
+
position[++pIndex] = right.x;
|
4630
|
+
position[++pIndex] = right.y;
|
4631
|
+
position[++pIndex] = right.z;
|
4632
|
+
position[++pIndex] = left.x;
|
4633
|
+
position[++pIndex] = left.y;
|
4634
|
+
position[++pIndex] = left.z;
|
4635
|
+
position[++pIndex] = tempPoint2.x;
|
4636
|
+
position[++pIndex] = tempPoint2.y;
|
4637
|
+
position[++pIndex] = tempPoint2.z; // position.push(
|
4638
|
+
// left.x, left.y, left.z, // 6
|
4639
|
+
// tempPoint1.x, tempPoint1.y, tempPoint1.z, // 5
|
4640
|
+
// left.x, left.y, left.z, // 4
|
4641
|
+
// right.x, right.y, right.z, // 3
|
4642
|
+
// left.x, left.y, left.z, // 2
|
4643
|
+
// tempPoint2.x, tempPoint2.y, tempPoint2.z // 1
|
4644
|
+
// );
|
4645
|
+
|
4503
4646
|
verticesCount += 6;
|
4504
|
-
indices
|
4647
|
+
indices[++iIndex] = verticesCount - 6;
|
4648
|
+
indices[++iIndex] = verticesCount - 8;
|
4649
|
+
indices[++iIndex] = verticesCount - 7;
|
4650
|
+
indices[++iIndex] = verticesCount - 6;
|
4651
|
+
indices[++iIndex] = verticesCount - 7;
|
4652
|
+
indices[++iIndex] = verticesCount - 5;
|
4653
|
+
indices[++iIndex] = verticesCount - 6;
|
4654
|
+
indices[++iIndex] = verticesCount - 5;
|
4655
|
+
indices[++iIndex] = verticesCount - 3;
|
4656
|
+
indices[++iIndex] = verticesCount - 2;
|
4657
|
+
indices[++iIndex] = verticesCount - 3;
|
4658
|
+
indices[++iIndex] = verticesCount - 1; // indices.push(
|
4659
|
+
// verticesCount - 6, verticesCount - 8, verticesCount - 7,
|
4660
|
+
// verticesCount - 6, verticesCount - 7, verticesCount - 5,
|
4661
|
+
// verticesCount - 6, verticesCount - 5, verticesCount - 3,
|
4662
|
+
// verticesCount - 2, verticesCount - 3, verticesCount - 1
|
4663
|
+
// );
|
4664
|
+
|
4505
4665
|
count += 12;
|
4506
4666
|
}
|
4507
4667
|
|
4508
|
-
|
4509
|
-
|
4668
|
+
for (var i = 0; i < 6; i++) {
|
4669
|
+
normal[++nIndex] = up.x;
|
4670
|
+
normal[++nIndex] = up.y;
|
4671
|
+
normal[++nIndex] = up.z;
|
4672
|
+
} // normal.push(
|
4673
|
+
// up.x, up.y, up.z,
|
4674
|
+
// up.x, up.y, up.z,
|
4675
|
+
// up.x, up.y, up.z,
|
4676
|
+
// up.x, up.y, up.z,
|
4677
|
+
// up.x, up.y, up.z,
|
4678
|
+
// up.x, up.y, up.z
|
4679
|
+
// );
|
4680
|
+
|
4681
|
+
|
4682
|
+
uv[++uIndex] = uvDist - sharpUvOffset;
|
4683
|
+
uv[++uIndex] = 0;
|
4684
|
+
uv[++uIndex] = uvDist - sharpUvOffset;
|
4685
|
+
uv[++uIndex] = 1;
|
4686
|
+
uv[++uIndex] = uvDist;
|
4687
|
+
uv[++uIndex] = 0;
|
4688
|
+
uv[++uIndex] = uvDist;
|
4689
|
+
uv[++uIndex] = 1;
|
4690
|
+
uv[++uIndex] = uvDist + sharpUvOffset;
|
4691
|
+
uv[++uIndex] = 0;
|
4692
|
+
uv[++uIndex] = uvDist + sharpUvOffset;
|
4693
|
+
uv[++uIndex] = 1; // uv.push(
|
4694
|
+
// uvDist - sharpUvOffset, 0,
|
4695
|
+
// uvDist - sharpUvOffset, 1,
|
4696
|
+
// uvDist, 0,
|
4697
|
+
// uvDist, 1,
|
4698
|
+
// uvDist + sharpUvOffset, 0,
|
4699
|
+
// uvDist + sharpUvOffset, 1
|
4700
|
+
// );
|
4701
|
+
// if (generateUv2) {
|
4510
4702
|
// uv2.push(
|
4511
4703
|
// uvDist2 - sharpUvOffset2, 0,
|
4512
4704
|
// uvDist2 - sharpUvOffset2, 1,
|
@@ -4517,9 +4709,34 @@ function generatePathVertexData(pathPointList, options) {
|
|
4517
4709
|
// );
|
4518
4710
|
// }
|
4519
4711
|
} else {
|
4520
|
-
position
|
4521
|
-
|
4522
|
-
|
4712
|
+
position[++pIndex] = left.x;
|
4713
|
+
position[++pIndex] = left.y;
|
4714
|
+
position[++pIndex] = left.z;
|
4715
|
+
position[++pIndex] = right.x;
|
4716
|
+
position[++pIndex] = right.y;
|
4717
|
+
position[++pIndex] = right.z; // position.push(
|
4718
|
+
// left.x, left.y, left.z,
|
4719
|
+
// right.x, right.y, right.z
|
4720
|
+
// );
|
4721
|
+
|
4722
|
+
normal[++nIndex] = up.x;
|
4723
|
+
normal[++nIndex] = up.y;
|
4724
|
+
normal[++nIndex] = up.z;
|
4725
|
+
normal[++nIndex] = up.x;
|
4726
|
+
normal[++nIndex] = up.y;
|
4727
|
+
normal[++nIndex] = up.z; // normal.push(
|
4728
|
+
// up.x, up.y, up.z,
|
4729
|
+
// up.x, up.y, up.z
|
4730
|
+
// );
|
4731
|
+
|
4732
|
+
uv[++uIndex] = uvDist;
|
4733
|
+
uv[++uIndex] = 0;
|
4734
|
+
uv[++uIndex] = uvDist;
|
4735
|
+
uv[++uIndex] = 1; // uv.push(
|
4736
|
+
// uvDist, 0,
|
4737
|
+
// uvDist, 1
|
4738
|
+
// );
|
4739
|
+
// if (generateUv2) {
|
4523
4740
|
// uv2.push(
|
4524
4741
|
// uvDist2, 0,
|
4525
4742
|
// uvDist2, 1
|
@@ -4529,7 +4746,16 @@ function generatePathVertexData(pathPointList, options) {
|
|
4529
4746
|
verticesCount += 2;
|
4530
4747
|
|
4531
4748
|
if (!first) {
|
4532
|
-
indices
|
4749
|
+
indices[++iIndex] = verticesCount - 2;
|
4750
|
+
indices[++iIndex] = verticesCount - 4;
|
4751
|
+
indices[++iIndex] = verticesCount - 3;
|
4752
|
+
indices[++iIndex] = verticesCount - 2;
|
4753
|
+
indices[++iIndex] = verticesCount - 3;
|
4754
|
+
indices[++iIndex] = verticesCount - 1; // indices.push(
|
4755
|
+
// verticesCount - 2, verticesCount - 4, verticesCount - 3,
|
4756
|
+
// verticesCount - 2, verticesCount - 3, verticesCount - 1
|
4757
|
+
// );
|
4758
|
+
|
4533
4759
|
count += 6;
|
4534
4760
|
}
|
4535
4761
|
}
|
@@ -4558,10 +4784,10 @@ function generatePathVertexData(pathPointList, options) {
|
|
4558
4784
|
}
|
4559
4785
|
|
4560
4786
|
return {
|
4561
|
-
|
4787
|
+
position: position,
|
4562
4788
|
normal: normal,
|
4563
|
-
|
4564
|
-
|
4789
|
+
uv: uv,
|
4790
|
+
indices: indices,
|
4565
4791
|
count: count
|
4566
4792
|
};
|
4567
4793
|
}
|
@@ -4586,8 +4812,8 @@ function expandTubes(lines, options) {
|
|
4586
4812
|
var result = generateTubeVertexData(pathPointList, options);
|
4587
4813
|
result.line = line;
|
4588
4814
|
result.position = new Float32Array(result.points);
|
4589
|
-
result.indices = new Uint32Array(result.
|
4590
|
-
result.uv = new Float32Array(result.
|
4815
|
+
result.indices = new Uint32Array(result.indices);
|
4816
|
+
result.uv = new Float32Array(result.uv);
|
4591
4817
|
result.normal = new Float32Array(result.normal);
|
4592
4818
|
return result;
|
4593
4819
|
});
|
@@ -4614,9 +4840,9 @@ function generateTubeVertexData(pathPointList, options) {
|
|
4614
4840
|
|
4615
4841
|
var points = [];
|
4616
4842
|
var normal = [];
|
4617
|
-
var
|
4843
|
+
var uv = []; // const uv2 = [];
|
4618
4844
|
|
4619
|
-
var
|
4845
|
+
var indices = [];
|
4620
4846
|
var verticesCount = 0;
|
4621
4847
|
var normalDir = new Vector3();
|
4622
4848
|
var pIndex = -1;
|
@@ -4643,8 +4869,8 @@ function generateTubeVertexData(pathPointList, options) {
|
|
4643
4869
|
normal[++nIndex] = normalDir.x;
|
4644
4870
|
normal[++nIndex] = normalDir.y;
|
4645
4871
|
normal[++nIndex] = normalDir.z;
|
4646
|
-
|
4647
|
-
|
4872
|
+
uv[++uIndex] = uvDist;
|
4873
|
+
uv[++uIndex] = i / radialSegments; // uvs.push(uvDist, r / radialSegments);
|
4648
4874
|
// if (generateUv2) {
|
4649
4875
|
// uv2.push(uvDist2, r / radialSegments);
|
4650
4876
|
// }
|
@@ -4657,12 +4883,12 @@ function generateTubeVertexData(pathPointList, options) {
|
|
4657
4883
|
var begin2 = verticesCount - (radialSegments + 1);
|
4658
4884
|
|
4659
4885
|
for (var _i = 0; _i < radialSegments; _i++) {
|
4660
|
-
|
4661
|
-
|
4662
|
-
|
4663
|
-
|
4664
|
-
|
4665
|
-
|
4886
|
+
indices[++iIndex] = begin2 + _i;
|
4887
|
+
indices[++iIndex] = begin1 + _i;
|
4888
|
+
indices[++iIndex] = begin1 + _i + 1;
|
4889
|
+
indices[++iIndex] = begin2 + _i;
|
4890
|
+
indices[++iIndex] = begin1 + _i + 1;
|
4891
|
+
indices[++iIndex] = begin2 + _i + 1; // index.push(
|
4666
4892
|
// begin2 + i,
|
4667
4893
|
// begin1 + i,
|
4668
4894
|
// begin1 + i + 1,
|
@@ -4697,9 +4923,9 @@ function generateTubeVertexData(pathPointList, options) {
|
|
4697
4923
|
return {
|
4698
4924
|
points: points,
|
4699
4925
|
normal: normal,
|
4700
|
-
|
4926
|
+
uv: uv,
|
4701
4927
|
// uv2,
|
4702
|
-
|
4928
|
+
indices: indices,
|
4703
4929
|
count: count
|
4704
4930
|
};
|
4705
4931
|
}
|