@xort/cga 0.0.76 → 0.0.79

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.
Files changed (215) hide show
  1. package/dist/app.js +4 -1
  2. package/dist/math/Color.d.ts +7 -9
  3. package/dist/math/Color.js +54 -56
  4. package/package.json +2 -1
  5. package/src/app.ts +4 -1
  6. package/src/index.ts +1 -0
  7. package/src/math/Color.ts +60 -36
  8. package/dist/src/IKanimation/Bone.d.ts +0 -9
  9. package/dist/src/IKanimation/Bone.js +0 -40
  10. package/dist/src/IKanimation/CCDSolver.d.ts +0 -37
  11. package/dist/src/IKanimation/CCDSolver.js +0 -93
  12. package/dist/src/IKanimation/Joint.d.ts +0 -3
  13. package/dist/src/IKanimation/Joint.js +0 -17
  14. package/dist/src/IKanimation/constaint/constraint.d.ts +0 -10
  15. package/dist/src/IKanimation/constaint/constraint.js +0 -25
  16. package/dist/src/IKanimation/constaint/hinge.d.ts +0 -12
  17. package/dist/src/IKanimation/constaint/hinge.js +0 -46
  18. package/dist/src/IKanimation/constaint/slider.d.ts +0 -12
  19. package/dist/src/IKanimation/constaint/slider.js +0 -44
  20. package/dist/src/IKanimation/index.d.ts +0 -0
  21. package/dist/src/IKanimation/index.js +0 -9
  22. package/dist/src/IKanimation/isolver.d.ts +0 -4
  23. package/dist/src/IKanimation/isolver.js +0 -10
  24. package/dist/src/IKanimation/skeleton.d.ts +0 -13
  25. package/dist/src/IKanimation/skeleton.js +0 -31
  26. package/dist/src/alg/common.d.ts +0 -114
  27. package/dist/src/alg/common.js +0 -302
  28. package/dist/src/alg/curve.d.ts +0 -4
  29. package/dist/src/alg/curve.js +0 -11
  30. package/dist/src/alg/delaunator.d.ts +0 -29
  31. package/dist/src/alg/delaunator.js +0 -442
  32. package/dist/src/alg/delaunay.d.ts +0 -20
  33. package/dist/src/alg/delaunay.js +0 -199
  34. package/dist/src/alg/delaunayslow.d.ts +0 -18
  35. package/dist/src/alg/delaunayslow.js +0 -140
  36. package/dist/src/alg/extrude/extrude.d.ts +0 -3
  37. package/dist/src/alg/extrude/extrude.js +0 -17
  38. package/dist/src/alg/extrude.d.ts +0 -199
  39. package/dist/src/alg/extrude.js +0 -731
  40. package/dist/src/alg/offset/index.d.ts +0 -0
  41. package/dist/src/alg/offset/index.js +0 -9
  42. package/dist/src/alg/offset.d.ts +0 -0
  43. package/dist/src/alg/offset.js +0 -472
  44. package/dist/src/alg/pointset.d.ts +0 -94
  45. package/dist/src/alg/pointset.js +0 -223
  46. package/dist/src/alg/recognition.d.ts +0 -14
  47. package/dist/src/alg/recognition.js +0 -37
  48. package/dist/src/alg/result.d.ts +0 -22
  49. package/dist/src/alg/result.js +0 -2
  50. package/dist/src/alg/segmentset.d.ts +0 -11
  51. package/dist/src/alg/segmentset.js +0 -45
  52. package/dist/src/alg/sort.d.ts +0 -2
  53. package/dist/src/alg/sort.js +0 -14
  54. package/dist/src/alg/split.d.ts +0 -8
  55. package/dist/src/alg/split.js +0 -10
  56. package/dist/src/alg/trianglution.d.ts +0 -20
  57. package/dist/src/alg/trianglution.js +0 -77
  58. package/dist/src/alg/vol.d.ts +0 -6
  59. package/dist/src/alg/vol.js +0 -18
  60. package/dist/src/alg/voronoi.d.ts +0 -31
  61. package/dist/src/alg/voronoi.js +0 -418
  62. package/dist/src/app.d.ts +0 -1
  63. package/dist/src/app.js +0 -245
  64. package/dist/src/basic/distance.d.ts +0 -12
  65. package/dist/src/basic/distance.js +0 -42
  66. package/dist/src/csg/bsp.d.ts +0 -9
  67. package/dist/src/csg/bsp.js +0 -22
  68. package/dist/src/csg/node.d.ts +0 -12
  69. package/dist/src/csg/node.js +0 -75
  70. package/dist/src/csg/polygon.d.ts +0 -43
  71. package/dist/src/csg/polygon.js +0 -161
  72. package/dist/src/diamondMaterialShader.d.ts +0 -92
  73. package/dist/src/diamondMaterialShader.js +0 -118
  74. package/dist/src/effect/breath-light.d.ts +0 -4
  75. package/dist/src/effect/breath-light.js +0 -39
  76. package/dist/src/extends/geometryaid.d.ts +0 -28
  77. package/dist/src/extends/geometryaid.js +0 -80
  78. package/dist/src/extends/split.d.ts +0 -3
  79. package/dist/src/extends/split.js +0 -13
  80. package/dist/src/glview.d.ts +0 -112
  81. package/dist/src/glview.js +0 -564
  82. package/dist/src/index.d.ts +0 -36
  83. package/dist/src/index.js +0 -54
  84. package/dist/src/math/Euler.d.ts +0 -47
  85. package/dist/src/math/Euler.js +0 -245
  86. package/dist/src/math/HVec3.d.ts +0 -44
  87. package/dist/src/math/HVec3.js +0 -195
  88. package/dist/src/math/Mat3.d.ts +0 -29
  89. package/dist/src/math/Mat3.js +0 -244
  90. package/dist/src/math/Mat4.d.ts +0 -85
  91. package/dist/src/math/Mat4.js +0 -791
  92. package/dist/src/math/Math.d.ts +0 -130
  93. package/dist/src/math/Math.js +0 -198
  94. package/dist/src/math/Quat.d.ts +0 -83
  95. package/dist/src/math/Quat.js +0 -440
  96. package/dist/src/math/Vec.d.ts +0 -7
  97. package/dist/src/math/Vec.js +0 -43
  98. package/dist/src/math/Vec2.d.ts +0 -68
  99. package/dist/src/math/Vec2.js +0 -347
  100. package/dist/src/math/Vec3.d.ts +0 -232
  101. package/dist/src/math/Vec3.js +0 -1089
  102. package/dist/src/math/Vec4.d.ts +0 -81
  103. package/dist/src/math/Vec4.js +0 -494
  104. package/dist/src/math/vector.d.ts +0 -114
  105. package/dist/src/math/vector.js +0 -373
  106. package/dist/src/render/buffer-attribute.d.ts +0 -100
  107. package/dist/src/render/buffer-attribute.js +0 -340
  108. package/dist/src/render/eventhandler.d.ts +0 -78
  109. package/dist/src/render/eventhandler.js +0 -189
  110. package/dist/src/render/geometry.d.ts +0 -89
  111. package/dist/src/render/geometry.js +0 -775
  112. package/dist/src/render/mesh.d.ts +0 -25
  113. package/dist/src/render/mesh.js +0 -82
  114. package/dist/src/render/thing.d.ts +0 -34
  115. package/dist/src/render/thing.js +0 -196
  116. package/dist/src/render/types.d.ts +0 -2
  117. package/dist/src/render/types.js +0 -8
  118. package/dist/src/robust/plane.d.ts +0 -7
  119. package/dist/src/robust/plane.js +0 -17
  120. package/dist/src/robust/vec.d.ts +0 -15
  121. package/dist/src/robust/vec.js +0 -71
  122. package/dist/src/shape/arc.d.ts +0 -2
  123. package/dist/src/shape/arc.js +0 -14
  124. package/dist/src/struct/3d/Box.d.ts +0 -23
  125. package/dist/src/struct/3d/Box.js +0 -109
  126. package/dist/src/struct/3d/Capsule.d.ts +0 -12
  127. package/dist/src/struct/3d/Capsule.js +0 -36
  128. package/dist/src/struct/3d/Circle.d.ts +0 -34
  129. package/dist/src/struct/3d/Circle.js +0 -80
  130. package/dist/src/struct/3d/Disk.d.ts +0 -10
  131. package/dist/src/struct/3d/Disk.js +0 -22
  132. package/dist/src/struct/3d/Frustum.d.ts +0 -35
  133. package/dist/src/struct/3d/Frustum.js +0 -159
  134. package/dist/src/struct/3d/Line.d.ts +0 -40
  135. package/dist/src/struct/3d/Line.js +0 -339
  136. package/dist/src/struct/3d/Path.d.ts +0 -75
  137. package/dist/src/struct/3d/Path.js +0 -308
  138. package/dist/src/struct/3d/Plane.d.ts +0 -74
  139. package/dist/src/struct/3d/Plane.js +0 -295
  140. package/dist/src/struct/3d/Point.d.ts +0 -4
  141. package/dist/src/struct/3d/Point.js +0 -30
  142. package/dist/src/struct/3d/Polygon.d.ts +0 -8
  143. package/dist/src/struct/3d/Polygon.js +0 -55
  144. package/dist/src/struct/3d/Polyline.d.ts +0 -25
  145. package/dist/src/struct/3d/Polyline.js +0 -109
  146. package/dist/src/struct/3d/Ray.d.ts +0 -21
  147. package/dist/src/struct/3d/Ray.js +0 -262
  148. package/dist/src/struct/3d/Rectangle.d.ts +0 -7
  149. package/dist/src/struct/3d/Rectangle.js +0 -35
  150. package/dist/src/struct/3d/Segment.d.ts +0 -32
  151. package/dist/src/struct/3d/Segment.js +0 -334
  152. package/dist/src/struct/3d/Shape.d.ts +0 -4
  153. package/dist/src/struct/3d/Shape.js +0 -27
  154. package/dist/src/struct/3d/Sphere.d.ts +0 -11
  155. package/dist/src/struct/3d/Sphere.js +0 -30
  156. package/dist/src/struct/3d/Triangle.d.ts +0 -8
  157. package/dist/src/struct/3d/Triangle.js +0 -53
  158. package/dist/src/struct/data/ArrayList.d.ts +0 -42
  159. package/dist/src/struct/data/ArrayList.js +0 -172
  160. package/dist/src/struct/data/ArrayObject.d.ts +0 -30
  161. package/dist/src/struct/data/ArrayObject.js +0 -131
  162. package/dist/src/struct/data/type.d.ts +0 -13
  163. package/dist/src/struct/data/type.js +0 -18
  164. package/dist/src/utils/array.d.ts +0 -24
  165. package/dist/src/utils/array.js +0 -89
  166. package/dist/src/utils/types.d.ts +0 -24
  167. package/dist/src/utils/types.js +0 -20
  168. package/dist/src-gis/app.d.ts +0 -1
  169. package/dist/src-gis/app.js +0 -4
  170. package/dist/src-gis/core/Cartographic.d.ts +0 -20
  171. package/dist/src-gis/core/Cartographic.js +0 -52
  172. package/dist/src-gis/core/EllipsoidGeodesic.d.ts +0 -14
  173. package/dist/src-gis/core/EllipsoidGeodesic.js +0 -51
  174. package/dist/src-gis/core/EllipsoidTerrainProvider.d.ts +0 -10
  175. package/dist/src-gis/core/EllipsoidTerrainProvider.js +0 -29
  176. package/dist/src-gis/core/HeightmapTerrainData.d.ts +0 -3
  177. package/dist/src-gis/core/HeightmapTerrainData.js +0 -9
  178. package/dist/src-gis/core/Rectangle.d.ts +0 -45
  179. package/dist/src-gis/core/Rectangle.js +0 -127
  180. package/dist/src-gis/core/TaskProcessor.d.ts +0 -35
  181. package/dist/src-gis/core/TaskProcessor.js +0 -183
  182. package/dist/src-gis/gis.d.ts +0 -5
  183. package/dist/src-gis/gis.js +0 -12
  184. package/dist/src-gis/globe.d.ts +0 -12
  185. package/dist/src-gis/globe.js +0 -61
  186. package/dist/src-gis/math/Cartographic.d.ts +0 -8
  187. package/dist/src-gis/math/Cartographic.js +0 -26
  188. package/dist/src-gis/math/GVec3.d.ts +0 -12
  189. package/dist/src-gis/math/GVec3.js +0 -69
  190. package/dist/src-gis/math/ellipsoid.d.ts +0 -8
  191. package/dist/src-gis/math/ellipsoid.js +0 -14
  192. package/dist/src-gis/provider/DcTerrainProvider.d.ts +0 -15
  193. package/dist/src-gis/provider/DcTerrainProvider.js +0 -19
  194. package/dist/src-gis/provider/TerrainProvider.d.ts +0 -3
  195. package/dist/src-gis/provider/TerrainProvider.js +0 -17
  196. package/dist/src-gis/scene/DcImageryProvider.d.ts +0 -6
  197. package/dist/src-gis/scene/DcImageryProvider.js +0 -35
  198. package/dist/src-gis/scene/GeographicTilingScheme.d.ts +0 -21
  199. package/dist/src-gis/scene/GeographicTilingScheme.js +0 -46
  200. package/dist/src-gis/scene/Globe.d.ts +0 -34
  201. package/dist/src-gis/scene/Globe.js +0 -62
  202. package/dist/src-gis/scene/GlobeSurfaceShaderSet.d.ts +0 -6
  203. package/dist/src-gis/scene/GlobeSurfaceShaderSet.js +0 -11
  204. package/dist/src-gis/scene/GlobeSurfaceTileProvider.d.ts +0 -21
  205. package/dist/src-gis/scene/GlobeSurfaceTileProvider.js +0 -15
  206. package/dist/src-gis/scene/ImageryLayerCollection.d.ts +0 -21
  207. package/dist/src-gis/scene/ImageryLayerCollection.js +0 -87
  208. package/dist/src-gis/scene/ImageryProvider.d.ts +0 -4
  209. package/dist/src-gis/scene/ImageryProvider.js +0 -28
  210. package/dist/src-gis/scene/QuadtreeTile.d.ts +0 -48
  211. package/dist/src-gis/scene/QuadtreeTile.js +0 -137
  212. package/dist/src-gis/scene/UrlTemplateImageryProvider.d.ts +0 -9
  213. package/dist/src-gis/scene/UrlTemplateImageryProvider.js +0 -29
  214. package/dist/src-gis/scene/quadtree_primitive.d.ts +0 -14
  215. package/dist/src-gis/scene/quadtree_primitive.js +0 -50
@@ -1,731 +0,0 @@
1
- "use strict";
2
- /*
3
- * @Description : 挤压相关方法
4
- * @Author : 赵耀圣
5
- * @QQ : 549184003
6
- * @Date : 2020-12-10 15:01:42
7
- * @LastEditTime : 2021-09-14 10:07:25
8
- * @FilePath : \cesium-taji-dabaod:\github\cga.js\src\alg\extrude.ts
9
- */
10
- var __assign = (this && this.__assign) || function () {
11
- __assign = Object.assign || function(t) {
12
- for (var s, i = 1, n = arguments.length; i < n; i++) {
13
- s = arguments[i];
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
15
- t[p] = s[p];
16
- }
17
- return t;
18
- };
19
- return __assign.apply(this, arguments);
20
- };
21
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
22
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
23
- if (ar || !(i in from)) {
24
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
25
- ar[i] = from[i];
26
- }
27
- }
28
- return to.concat(ar || Array.prototype.slice.call(from));
29
- };
30
- var __importDefault = (this && this.__importDefault) || function (mod) {
31
- return (mod && mod.__esModule) ? mod : { "default": mod };
32
- };
33
- Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.extrudeNext = exports.EndType = exports.JoinType = exports.extrude_obsolete = exports.extrude = exports.linkSides = exports.linkSide = void 0;
35
- var Vec3_1 = require("../math/Vec3");
36
- var Vec2_1 = require("../math/Vec2");
37
- var Quat_1 = require("../math/Quat");
38
- var Path_1 = require("../struct/3d/Path");
39
- var common_1 = require("./common");
40
- var pointset_1 = require("./pointset");
41
- var mesh_1 = require("../render/mesh");
42
- var trianglution_1 = require("./trianglution");
43
- var array_1 = require("../utils/array");
44
- var types_1 = require("../utils/types");
45
- var Mat4_1 = require("../math/Mat4");
46
- var Math_1 = require("../math/Math");
47
- var vector_1 = __importDefault(require("../math/vector"));
48
- var distance_1 = require("../basic/distance");
49
- /**
50
- * 常用shape几何操作
51
- */
52
- /**
53
- * @description : 缝合两个边 不提供uv生成 uv有@linkSides 生成
54
- * @param { ILinkSideOption } options
55
- * @returns { Array<Vec3>} 三角形数组,每三个为一个三角形
56
- * @example :
57
- */
58
- function linkSide(options) {
59
- options = __assign({ shapeClosed: true, autoUV: true }, options);
60
- var side0 = options.side0;
61
- var side1 = options.side1;
62
- var shapeClosed = options.shapeClosed;
63
- if (side0.length !== side1.length)
64
- throw ("拉伸两边的点数量不一致 linkSide");
65
- if (side0.length < 2 || side1.length < 2)
66
- return [];
67
- var orgLen = side0.length;
68
- var length = shapeClosed ? side0.length : side0.length - 1;
69
- var triangles = [];
70
- if (side0[0] instanceof Number) {
71
- //索引三角形
72
- for (var i = 0; i < length; i++) {
73
- var v00 = side0[i];
74
- var v01 = side0[(i + 1) % orgLen];
75
- var v10 = side1[i];
76
- var v11 = side1[(i + 1) % orgLen];
77
- triangles.push(v00);
78
- triangles.push(v01);
79
- triangles.push(v11);
80
- triangles.push(v00);
81
- triangles.push(v11);
82
- triangles.push(v10);
83
- }
84
- }
85
- else {
86
- if ((0, types_1.isDefined)(side0[0].index)) {
87
- //含索引的顶点
88
- for (var i = 0; i < length; i++) {
89
- var v00 = side0[i];
90
- var v01 = side0[(i + 1) % orgLen];
91
- var v10 = side1[i];
92
- var v11 = side1[(i + 1) % orgLen];
93
- triangles.push(v00.index);
94
- triangles.push(v01.index);
95
- triangles.push(v11.index);
96
- triangles.push(v00.index);
97
- triangles.push(v11.index);
98
- triangles.push(v10.index);
99
- }
100
- }
101
- else {
102
- //三角形顶点
103
- for (var i = 0; i < length; i++) {
104
- var v00 = side0[i];
105
- var v01 = side0[(i + 1) % orgLen];
106
- var v10 = side1[i];
107
- var v11 = side1[(i + 1) % orgLen];
108
- triangles.push(v00);
109
- triangles.push(v01);
110
- triangles.push(v11);
111
- triangles.push(v00);
112
- triangles.push(v11);
113
- triangles.push(v10);
114
- }
115
- }
116
- }
117
- if (options.holes0 && options.holes1) {
118
- var holes0 = options.holes0;
119
- var holes1 = options.holes1;
120
- for (var h = 0; h < holes0.length; h++) {
121
- var holeTriangles = linkSide({ side0: holes0[h], side1: holes1[h] });
122
- holeTriangles.reverse();
123
- triangles.push.apply(triangles, holeTriangles);
124
- }
125
- }
126
- return triangles;
127
- }
128
- exports.linkSide = linkSide;
129
- /**
130
- * @description : 链接多个shape 生成几何体
131
- * @param {ILinkSideOptions} optionsILinkSideOptions {
132
- * shapes: Array<Array<IVec3 | number | any>>;
133
- * sealStart?: boolean,//开始封面
134
- * sealEnd?: boolean;//结束封面
135
- * shapeClosed?: boolean,//shape是否闭合
136
- * pathClosed?: boolean,//路径是否闭合
137
- * index?: { index: number },
138
- * generateUV?: boolean
139
- * }
140
- *
141
- * @return {*}
142
- * @example :
143
- *
144
- */
145
- function linkSides(options) {
146
- options = __assign({ sealEnd: true, sealStart: true, shapeClosed: true, pathClosed: false, generateUV: true, autoIndex: true, axisPlane: trianglution_1.AxisPlane.XY }, options);
147
- if (options.autoIndex)
148
- options.index = options.index || { index: 0 };
149
- var shapes = options.shapes;
150
- var holess = options.holes;
151
- var hasHole = !!(holess && holess.length > 0);
152
- var length = options.pathClosed ? shapes.length : shapes.length - 1;
153
- var triangles = [];
154
- var index = options.index;
155
- var allVertics = [shapes];
156
- if (hasHole)
157
- allVertics.push(holess);
158
- var orgShape = options.orgShape || shapes[0];
159
- var orgHoles = options.orgHoles || (holess && holess[0]);
160
- if (index)
161
- (0, mesh_1.indexable)(allVertics, index);
162
- for (var i = 0; i < length; i++) {
163
- if (holess)
164
- triangles.push.apply(triangles, linkSide({ side0: shapes[i], side1: shapes[(i + 1) % shapes.length], holes0: holess[i], holes1: holess[(i + 1) % shapes.length], shapeClosed: options.shapeClosed }));
165
- else
166
- triangles.push.apply(triangles, linkSide({ side0: shapes[i], side1: shapes[(i + 1) % shapes.length], shapeClosed: options.shapeClosed }));
167
- }
168
- if (options.sealStart) {
169
- var startShape = (0, common_1.clone)(shapes[0]);
170
- allVertics.push(startShape);
171
- if (holess && holess[0]) {
172
- var startHoles = (0, common_1.clone)(holess[0]);
173
- allVertics.push(startHoles);
174
- }
175
- var startTris = (0, trianglution_1.triangulation)(orgShape, orgHoles, { feature: trianglution_1.AxisPlane.XYZ });
176
- if (index) {
177
- startTris.forEach(function (v, i) {
178
- startTris[i] = v + (index === null || index === void 0 ? void 0 : index.index);
179
- });
180
- index.index += startShape.length;
181
- if (holess && holess[0])
182
- startHoles.forEach(function (h) {
183
- index.index += h.length;
184
- });
185
- }
186
- triangles.push.apply(triangles, startTris.reverse());
187
- }
188
- if (options.sealEnd) {
189
- var endShape = (0, common_1.clone)(shapes[shapes.length - 1]);
190
- allVertics.push(endShape);
191
- if (holess && holess[0]) {
192
- var endHoles = (0, common_1.clone)((0, common_1.clone)(holess[holess.length - 1]));
193
- allVertics.push(endHoles);
194
- }
195
- var endTris = (0, trianglution_1.triangulation)(orgShape, orgHoles, { feature: trianglution_1.AxisPlane.XYZ });
196
- if (index) {
197
- endTris.forEach(function (v, i) {
198
- endTris[i] = v + (index === null || index === void 0 ? void 0 : index.index);
199
- });
200
- index.index += endShape.length;
201
- if (holess && holess[0])
202
- endHoles.forEach(function (h) {
203
- index.index += h.length;
204
- });
205
- }
206
- triangles.push.apply(triangles, endTris);
207
- }
208
- triangles.shapes = allVertics;
209
- var uvs = [];
210
- if (options.generateUV) {
211
- //生成UV
212
- // let uBasicScalar = new Array(shapes[0].length).fill(0);
213
- var uBasicScalar = 0;
214
- for (var i_1 = 0; i_1 < shapes.length; i_1++) {
215
- var shape = shapes[i_1];
216
- var lastshape = shapes[i_1 - 1];
217
- if (isNaN(shape[0])) {
218
- //不是索引才生产纹理,其他都是顶点
219
- var vScalar = Path_1.Path.getPerMileages(shape, false);
220
- var uScalar = 0;
221
- // if (i > 0)
222
- // uScalar = uBasicScalar.map((e, k) => {
223
- // return e + shape[k].distanceTo(lastshape[k]);
224
- // });
225
- // else
226
- // uScalar = new Array(shapes[0].length).fill(0);
227
- if (i_1 > 0)
228
- uScalar = uBasicScalar + shape[0].distanceTo(lastshape[0]);
229
- for (var l = 0; l < shape.length; l++) {
230
- uvs.push(uScalar, vScalar[l]);
231
- }
232
- uBasicScalar = uScalar;
233
- }
234
- else
235
- console.error("索引无法生成纹理");
236
- }
237
- if (holess) {
238
- uBasicScalar = 0;
239
- for (var i_2 = 0; i_2 < holess.length; i_2++) {
240
- var holes = holess[i_2];
241
- var lastHole = holess[i_2 - 1];
242
- var uScalar = 0;
243
- if (i_2 > 0)
244
- uScalar = uBasicScalar + holes[0][0].distanceTo(lastHole[0][0]);
245
- for (var j = 0; j < holes.length; j++) {
246
- var hole = holes[j];
247
- var vScalar = Path_1.Path.getPerMileages(hole, false);
248
- for (var l = 0; l < hole.length; l++) {
249
- uvs.push(uScalar, vScalar[l]);
250
- }
251
- }
252
- uBasicScalar = uScalar;
253
- }
254
- }
255
- //前后纹理
256
- var sealUvs = [];
257
- switch (options.axisPlane) {
258
- case trianglution_1.AxisPlane.XY:
259
- orgShape.map(function (e) {
260
- sealUvs.push(e.x, e.y);
261
- });
262
- if (orgHoles)
263
- orgHoles.forEach(function (h) {
264
- h.forEach(function (e) {
265
- sealUvs.push(e.x, e.y);
266
- });
267
- });
268
- break;
269
- case trianglution_1.AxisPlane.XZ:
270
- orgShape.map(function (e) {
271
- sealUvs.push(e.x, e.z);
272
- });
273
- if (orgHoles)
274
- orgHoles.forEach(function (h) {
275
- h.forEach(function (e) {
276
- sealUvs.push(e.x, e.z);
277
- });
278
- });
279
- break;
280
- case trianglution_1.AxisPlane.YZ:
281
- orgShape.map(function (e) {
282
- sealUvs.push(e.y, e.z);
283
- });
284
- if (orgHoles)
285
- orgHoles.forEach(function (h) {
286
- h.forEach(function (e) {
287
- sealUvs.push(e.y, e.z);
288
- });
289
- });
290
- break;
291
- default:
292
- break;
293
- }
294
- uvs.push.apply(uvs, __spreadArray(__spreadArray([], sealUvs, false), sealUvs, false));
295
- }
296
- var indices = triangles || [];
297
- // if (isDefined(shapes[0][0].index)) {
298
- // //收集索引
299
- // for (let i = 0; i < shapes.length; i++) {
300
- // const shape = shapes[i];
301
- // for (let j = 0; j < shape.length; j++) {
302
- // const v = shape[j];
303
- // indices.push(v.index);
304
- // }
305
- // }
306
- // }
307
- var positions = vector_1.default.verctorToNumbers(allVertics);
308
- shapes.pop();
309
- shapes.pop();
310
- return { position: positions, index: indices, uv: uvs };
311
- }
312
- exports.linkSides = linkSides;
313
- var defaultExtrudeOption = {
314
- textureEnable: true,
315
- textureScale: new Vec2_1.Vec2(1, 1),
316
- smoothAngle: Math.PI / 180 * 30,
317
- sealStart: false,
318
- sealEnd: false,
319
- normal: Vec3_1.Vec3.UnitZ,
320
- };
321
- var _matrix = (0, Mat4_1.m4)();
322
- var _matrix1 = (0, Mat4_1.m4)();
323
- var _quat = (0, Quat_1.quat)();
324
- var _quat1 = (0, Quat_1.quat)();
325
- var _vec1 = (0, Vec3_1.v3)();
326
- var _vec2 = (0, Vec3_1.v3)();
327
- /**
328
- * @description : 挤压形状生成几何体
329
- * @param {IExtrudeOptionsEx} options
330
- * IExtrudeOptionsEx {
331
- * shape: Array<Vec3 | IVec3 | Vec2 | IVec2>;//shape默认的矩阵为正交矩阵
332
- * path: Array<Vec3 | IVec3>;//挤压路径
333
- * ups?: Array<Vec3 | IVec3>;
334
- * up?: Vec3 | IVec3;
335
- * shapeClosed?: boolean;//闭合为多边形 界面
336
- * pathClosed?: boolean;//首尾闭合为圈
337
- * textureEnable?: boolean;
338
- * smoothAngle?: number;
339
- * sealStart?: boolean;
340
- * sealEnd?: boolean;
341
- * normal?: Vec3,//面的法线
342
- * autoIndex?: boolean,
343
- * index?: { index: number }
344
- * holes?: Array<Vec3 | IVec3 | Vec2 | IVec2>[]
345
- *}
346
- * @return {IGeometry}
347
- * @example :
348
- *
349
- */
350
- function extrude(options) {
351
- options = __assign({ sealEnd: true, sealStart: true, shapeClosed: true, pathClosed: false, generateUV: true, autoIndex: true, axisPlane: trianglution_1.AxisPlane.XY, up: Vec3_1.Vec3.Up, smoothAngle: 30 * Math_1.RADIANS_PER_DEGREE, enableSmooth: false }, options);
352
- if (!vector_1.default.isCCW(options.shape))
353
- options.shape.reverse();
354
- if (options.holes)
355
- options.holes.forEach(function (hole) {
356
- if (!vector_1.default.isCCW(hole))
357
- hole.reverse();
358
- });
359
- var path = new Path_1.Path(options.path);
360
- var shapes = [];
361
- var shape = options.shape;
362
- if (options.shapeClosed && !shape[0].equals(shape[shape.length - 1]))
363
- shape.push(shape[0].clone());
364
- var shapePath = new Path_1.Path(shape, options.shapeClosed);
365
- if (options.enableSmooth)
366
- for (var i = 1; i < shapePath.length; i++) { //大角度插入点 角度过大为了呈现flat shader的效果
367
- if (shapePath.get(i).direction.dot(shapePath.get((i + 1) % shapePath.length).direction) < Math.cos(options.smoothAngle)) {
368
- shapePath.splice(i + 1, 0, shapePath.get(i).clone());
369
- i++;
370
- }
371
- }
372
- var ups = options.ups || [];
373
- if ((0, types_1.isUndefined)(shapePath.first.z)) {
374
- shapePath.array = shapePath.array.map(function (e) { return (0, Vec3_1.v3)(e.x, e.y, 0); });
375
- options.normal = options.normal || Vec3_1.Vec3.UnitZ;
376
- }
377
- var up = options.up;
378
- var right = options.right;
379
- var newholes = [];
380
- for (var i = 0; i < options.path.length; i++) {
381
- var point = path.get(i);
382
- var direction = point.direction;
383
- var upi = void 0;
384
- upi = ups[i] || up || (0, Vec3_1.v3)().crossVecs(right, direction);
385
- var righti = right;
386
- if (!right)
387
- righti = (0, Vec3_1.v3)().crossVecs(upi, direction).normalize();
388
- _matrix.makeBasis(righti, upi, direction);
389
- _matrix.setPosition(point);
390
- var new_shape = shapePath.clone();
391
- new_shape.applyMat4(_matrix);
392
- shapes.push(new_shape);
393
- if (options.holes) {
394
- var mholes = (0, pointset_1.applyMat4)(options.holes, _matrix, false);
395
- newholes.push(mholes);
396
- }
397
- }
398
- var geo = linkSides({
399
- shapes: shapes.map(function (e) { return e._array; }),
400
- holes: newholes,
401
- orgShape: shapePath._array,
402
- orgHoles: options.holes,
403
- sealStart: options.sealStart,
404
- sealEnd: options.sealEnd,
405
- shapeClosed: options.shapeClosed,
406
- pathClosed: options.pathClosed,
407
- axisPlane: options.axisPlane,
408
- autoIndex: options.autoIndex,
409
- generateUV: options.generateUV,
410
- });
411
- return geo;
412
- }
413
- exports.extrude = extrude;
414
- /**
415
- * 挤压
416
- * @param {Polygon|Array<Point|Vec3> } shape 多边形或顶点数组
417
- * @param {Path|Array<Point|Vec3> } path 路径或者或顶点数组
418
- * @param {Object} options {
419
- * isClosed: false,闭合为多边形 界面
420
- * isClosed2: false, 闭合为圈
421
- * textureEnable: true, 计算纹理坐标
422
- * textureScale: new Vec2(1, 1),纹理坐标缩放
423
- * smoothAngle: Math.PI / 180 * 30,大于这个角度则不平滑
424
- * sealStart: true, 是否密封开始面
425
- * sealEnd: true,是否密封结束面}
426
- */
427
- function extrude_obsolete(shape, arg_path, options) {
428
- var _a, _b;
429
- if (options === void 0) { options = defaultExtrudeOption; }
430
- options = __assign(__assign({}, defaultExtrudeOption), options);
431
- if (arg_path.length < 2) {
432
- throw ("路径节点数必须大于2");
433
- }
434
- var isCCW = vector_1.default.isCCW(shape);
435
- if (!isCCW)
436
- shape.reverse();
437
- var normal = options.normal;
438
- var startSeal = (0, common_1.clone)(shape);
439
- var shapepath = new Path_1.Path(shape);
440
- var insertNum = 0;
441
- for (var i = 1; i < shapepath.length - 1; i++) { //大角度插入点 角度过大为了呈现flat shader的效果
442
- if (Math.acos(shapepath.get(i).tangent.dot(shapepath.get(i + 1).tangent)) > options.smoothAngle)
443
- shape.splice(i + insertNum++, 0, shapepath.get(i).clone());
444
- }
445
- if (options.shapeClosed) {
446
- var dir1 = shapepath.get(-1).clone().sub(shapepath.get(-2)).normalize();
447
- var dir2 = shapepath.get(0).clone().sub(shapepath.get(-1)).normalize();
448
- if (Math.acos(dir1.dot(dir2)) > options.smoothAngle)
449
- shape.push(shape.get(-1).clone());
450
- //新加起始点纹理拉伸
451
- shape.unshift(shape.first.clone());
452
- }
453
- var path = arg_path;
454
- if (!(path instanceof Path_1.Path) && path instanceof Array)
455
- path = new Path_1.Path(arg_path);
456
- var shapeArray = [];
457
- for (var i = 0; i < path.length; i++) {
458
- var node = path[i];
459
- var dir = node.tangent;
460
- var newShape = (0, common_1.clone)(shape);
461
- (0, common_1.rotateByUnitVectors)(newShape, normal, dir);
462
- if (options.fixedY) {
463
- var v = Vec3_1.Vec3.UnitX;
464
- (0, common_1.rotateByUnitVectors)([v], normal, dir);
465
- var v1 = v.clone();
466
- v1.y = 0;
467
- (0, common_1.rotateByUnitVectors)(newShape, v, v1);
468
- }
469
- (0, pointset_1.translate)(newShape, node);
470
- shapeArray.push(newShape);
471
- }
472
- var gindex = { index: 0 };
473
- var vertices = (0, array_1.flat)(shapeArray);
474
- (0, mesh_1.indexable)(vertices, gindex);
475
- var index = linkSides({ shapes: shapeArray, shapeClosed: options.shapeClosed, pathClosed: options.isClosed2, orgShape: shape }).index;
476
- shapepath = new Path_1.Path(shape);
477
- var uvs = [];
478
- for (var i = 0; i < path.length; i++) {
479
- for (var j = 0; j < shapepath.length; j++) {
480
- uvs.push(shapepath.get(j).tlen * options.textureScale.x, path.get(i).tlen * options.textureScale.y);
481
- }
482
- }
483
- var sealUv = (0, common_1.clone)(startSeal);
484
- if (normal.dot(Vec3_1.Vec3.UnitZ) < 1 - 1e-4)
485
- (0, common_1.rotateByUnitVectors)(sealUv, normal, Vec3_1.Vec3.UnitZ);
486
- var endSeal = (0, common_1.clone)(startSeal);
487
- (0, common_1.rotateByUnitVectors)(startSeal, normal, path[0].tangent);
488
- if (options.fixedY) {
489
- var v = Vec3_1.Vec3.UnitX;
490
- (0, common_1.rotateByUnitVectors)([v], normal, path[0].tangent);
491
- var v1 = v.clone();
492
- v1.y = 0;
493
- (0, common_1.rotateByUnitVectors)(startSeal, v, v1);
494
- }
495
- (0, pointset_1.translate)(startSeal, path[0]);
496
- (0, common_1.rotateByUnitVectors)(endSeal, normal, path.get(-1).tangent);
497
- if (options.fixedY) {
498
- var v = Vec3_1.Vec3.UnitX;
499
- (0, common_1.rotateByUnitVectors)([v], normal, path.get(-1).tangent);
500
- var v1 = v.clone();
501
- v1.y = 0;
502
- (0, common_1.rotateByUnitVectors)(endSeal, v, v1);
503
- }
504
- (0, pointset_1.translate)(endSeal, path.get(-1));
505
- var sealStartTris = (0, trianglution_1.triangulation)(sealUv, [], { normal: normal });
506
- sealStartTris.reverse();
507
- if (options.sealStart)
508
- (0, mesh_1.indexable)(startSeal, gindex);
509
- if (options.sealEnd)
510
- (0, mesh_1.indexable)(endSeal, gindex);
511
- var sealEndTris = [];
512
- var hasVLen = vertices.length;
513
- if (options.sealStart)
514
- for (var i = 0; i < sealStartTris.length; i++) {
515
- sealStartTris[i] += hasVLen;
516
- }
517
- if (options.sealEnd && !options.sealStart)
518
- for (var i = 0; i < sealStartTris.length; i++) {
519
- sealEndTris[i] = sealStartTris[i] + hasVLen;
520
- }
521
- if (options.sealEnd && options.sealStart) {
522
- for (var i = 0; i < sealStartTris.length; i++) {
523
- sealEndTris[i] = sealStartTris[i] + startSeal.length;
524
- }
525
- }
526
- if (options.sealStart) {
527
- vertices.push.apply(vertices, startSeal);
528
- (_a = index).push.apply(_a, sealStartTris);
529
- for (var i = 0; i < sealUv.length; i++)
530
- uvs.push(sealUv[i].x, sealUv[i].y);
531
- }
532
- if (options.sealEnd) {
533
- vertices.push.apply(vertices, endSeal);
534
- sealEndTris.reverse();
535
- (_b = index).push.apply(_b, sealEndTris);
536
- for (var i = 0; i < sealUv.length; i++)
537
- uvs.push(sealUv[i].x, sealUv[i].y);
538
- }
539
- return {
540
- vertices: vertices,
541
- index: index,
542
- uvs: uvs
543
- };
544
- }
545
- exports.extrude_obsolete = extrude_obsolete;
546
- var JoinType;
547
- (function (JoinType) {
548
- JoinType[JoinType["Square"] = 0] = "Square";
549
- JoinType[JoinType["Round"] = 1] = "Round";
550
- JoinType[JoinType["Miter"] = 2] = "Miter";
551
- JoinType[JoinType["Bevel"] = 0] = "Bevel";
552
- })(JoinType = exports.JoinType || (exports.JoinType = {}));
553
- var EndType;
554
- (function (EndType) {
555
- EndType[EndType["Square"] = 0] = "Square";
556
- EndType[EndType["Round"] = 1] = "Round";
557
- EndType[EndType["Butt"] = 2] = "Butt";
558
- EndType[EndType["etClosedLine"] = 3] = "etClosedLine";
559
- EndType[EndType["etClosedPolygon"] = 4] = "etClosedPolygon";
560
- EndType[EndType["etOpenButt"] = 5] = "etOpenButt";
561
- EndType[EndType["etOpenSquare"] = 6] = "etOpenSquare";
562
- })(EndType = exports.EndType || (exports.EndType = {}));
563
- /**
564
- * 将路径看做挤压操作中心
565
- *
566
- * @param shape
567
- * @param followPath
568
- * @param options
569
- */
570
- function extrudeNext(options) {
571
- options = __assign({ sealEnd: true, sealStart: true, shapeClosed: true, pathClosed: false, generateUV: true, autoIndex: true, axisPlane: trianglution_1.AxisPlane.XY, smoothAngle: 30 * Math_1.RADIANS_PER_DEGREE, enableSmooth: false }, options);
572
- var path = options.shapeCenter ? (0, pointset_1.translate)(options.path, options.shapeCenter, false) : options.path;
573
- var shape = options.shape;
574
- (0, array_1.unique)(path, function (a, b) { return a.equals(b); });
575
- (0, array_1.unique)(shape, function (a, b) { return a.equals(b); });
576
- var pathPath = new Path_1.Path(path, options.pathClosed, true);
577
- var starti = options.shapeClosed ? 0 : 1;
578
- var shapePath = new Path_1.Path(shape, options.shapeClosed);
579
- if (options.enableSmooth)
580
- for (var i = 1; i < shapePath.length; i++) { //大角度插入点 角度过大为了呈现flat shader的效果
581
- if (shapePath.get(i).direction.dot(shapePath.get((i + 1) % shapePath.length).direction) < options.smoothAngle) {
582
- shapePath.splice(i + 1, 0, shapePath.get(i).clone());
583
- i++;
584
- }
585
- }
586
- options.normal = options.normal || Vec3_1.Vec3.UnitZ;
587
- if ((0, types_1.isUndefined)(shapePath.first.z)) {
588
- shapePath.array = shapePath.array.map(function (e) { return (0, Vec3_1.v3)(e.x, e.y, 0); });
589
- }
590
- var up = options.up;
591
- var right = options.right;
592
- var shapes = [], newholes = [];
593
- var accMat = (0, Mat4_1.m4)();
594
- /**
595
- * 如果路径闭合 要考虑首尾shape矩阵变化后还能一致吻合
596
- */
597
- switch (options.jtType) {
598
- case JoinType.Square: //切角
599
- break;
600
- case JoinType.Round: //圆角
601
- /**
602
- * 原理,计算所有交点处的平分面,
603
- * 两条相接不共线的的线段可以确定一个平面,平面法线与
604
- */
605
- for (var i = 0; i < pathPath.length; i++) {
606
- var p = pathPath.get(i);
607
- var pLast = pathPath.get(i - 1);
608
- var pNext = pathPath.get(i + 1);
609
- var dir = p.direction;
610
- //两个外向
611
- var bdir = p.bdirection;
612
- var bnormal = p.bnormal;
613
- var normal = p.normal;
614
- //相邻两个向量发生的旋转
615
- if (i === 0) {
616
- _quat.setFromUnitVecs(Vec3_1.Vec3.UnitZ, dir);
617
- }
618
- else {
619
- _quat.setFromUnitVecs(pathPath.get(i - 1).direction, dir);
620
- }
621
- var new_shape = shapePath.clone();
622
- //旋转
623
- _quat.setFromUnitVecs(dir, bdir);
624
- _matrix.makeRotationFromQuat(_quat);
625
- _matrix.multiply(accMat);
626
- //位置
627
- _matrix.setPosition(p);
628
- new_shape.applyMat4(_matrix);
629
- // 找出最近一个点 绕此点旋转
630
- var min = Infinity;
631
- var anchor = 0;
632
- for (var i_3 = 0; i_3 < new_shape.array.length; i_3++) {
633
- var p_1 = new_shape.get(i_3);
634
- var tdot = bdir.dot(_vec1.copy(p_1).sub(new_shape.get(0)));
635
- if (tdot < min) {
636
- min = tdot;
637
- anchor = i_3;
638
- }
639
- }
640
- var minPoint = new_shape.get(anchor);
641
- //找出距离连个线段最近的点
642
- // 垂直的两个点 这两个点与
643
- if (i !== 0 && i !== pathPath.length - 1) {
644
- var P0 = distance_1.Distance.Point2Line_Vec3(minPoint, pLast, _vec1.copy(p).sub(pLast).normalize());
645
- var P1 = distance_1.Distance.Point2Line_Vec3(minPoint, p, _vec1.copy(pNext).sub(p).normalize());
646
- _vec1.copy(P0).sub(minPoint);
647
- _vec2.copy(P1).sub(minPoint);
648
- var angle_1 = _vec1.angleTo(_vec2, normal);
649
- var seg = Math.ceil(angle_1 / 0.1);
650
- var perAngle = angle_1 / seg;
651
- for (var i_4 = 0; i_4 <= seg; i_4++) {
652
- var cAngle = i_4 * perAngle;
653
- for (var j = 0; j < new_shape.length; j++) {
654
- var np = new_shape.get(j);
655
- var v = new Vec3_1.Vec3().slerpVecs(_vec1, _vec2, cAngle);
656
- var t = np.clone().sub(minPoint);
657
- }
658
- }
659
- // if (options.holes) {
660
- // const mholes = applyMat4(options.holes, _matrix1, false);
661
- // applyMat4(mholes, _matrix, true);
662
- // newholes.push(mholes);
663
- // }
664
- }
665
- shapes.push(new_shape);
666
- }
667
- break;
668
- case JoinType.Miter: //直角
669
- for (var i = 0; i < pathPath.length; i++) {
670
- var p = pathPath.get(i);
671
- var dir = p.direction;
672
- var bdir = p.bdirection;
673
- var bnormal = p.bnormal;
674
- var normal = p.normal;
675
- //相邻两个向量发生的旋转
676
- if (i === 0) {
677
- _quat.setFromUnitVecs(Vec3_1.Vec3.UnitZ, dir);
678
- }
679
- else {
680
- _quat.setFromUnitVecs(pathPath.get(i - 1).direction, dir);
681
- }
682
- var new_shape = shapePath.clone();
683
- //旋转
684
- _matrix.makeRotationFromQuat(_quat);
685
- accMat.premultiply(_matrix);
686
- _quat.setFromUnitVecs(dir, bdir);
687
- _matrix.makeRotationFromQuat(_quat);
688
- _matrix.multiply(accMat);
689
- // /旋转到原地缩放----开始-----------------------
690
- var cosA = dir.dot(bdir);
691
- var shear = 1 / cosA;
692
- _vec1.crossVecs(normal, bdir);
693
- _matrix1.copy(_matrix);
694
- _matrix1.invert();
695
- _vec1.applyMat4(_matrix1);
696
- _quat.setFromUnitVecs(_vec1, Vec3_1.Vec3.Up);
697
- _matrix1.makeRotationFromQuat(_quat);
698
- new_shape.applyMat4(_matrix1);
699
- new_shape.scale(1, shear, 1);
700
- new_shape.applyMat4(_matrix1.invert());
701
- // /旋转到原地缩放----结束-----------------------
702
- //位置
703
- _matrix.setPosition(p);
704
- new_shape.applyMat4(_matrix);
705
- // if (options.holes) {
706
- // const mholes = applyMat4(options.holes, _matrix1, false);
707
- // applyMat4(mholes, _matrix, true);
708
- // newholes.push(mholes);
709
- // }
710
- shapes.push(new_shape);
711
- }
712
- break;
713
- default:
714
- break;
715
- }
716
- var geo = linkSides({
717
- shapes: shapes.map(function (e) { return e.array; }),
718
- holes: newholes,
719
- orgShape: shapePath._array,
720
- orgHoles: options.holes,
721
- sealStart: options.sealStart,
722
- sealEnd: options.sealEnd,
723
- shapeClosed: options.shapeClosed,
724
- pathClosed: options.pathClosed,
725
- axisPlane: options.axisPlane,
726
- autoIndex: options.autoIndex,
727
- generateUV: options.generateUV,
728
- });
729
- return geo;
730
- }
731
- exports.extrudeNext = extrudeNext;