@xort/cga 0.0.75 → 0.0.78

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 (261) hide show
  1. package/dist/IKanimation/Bone.js +3 -1
  2. package/dist/IKanimation/CCDSolver.js +2 -2
  3. package/dist/IKanimation/constaint/hinge.js +3 -1
  4. package/dist/IKanimation/constaint/slider.js +3 -1
  5. package/dist/alg/common.js +2 -2
  6. package/dist/alg/extrude.js +56 -54
  7. package/dist/alg/pointset.js +5 -5
  8. package/dist/alg/trianglution.js +12 -10
  9. package/dist/app.js +18 -11
  10. package/dist/diamondMaterialShader.js +6 -2
  11. package/dist/effect/breath-light.js +3 -1
  12. package/dist/extends/geometryaid.js +7 -7
  13. package/dist/index.js +6 -2
  14. package/dist/math/Color.d.ts +6 -9
  15. package/dist/math/Color.js +18 -55
  16. package/dist/math/Euler.js +12 -10
  17. package/dist/math/HVec3.js +3 -1
  18. package/dist/math/Mat3.js +1 -1
  19. package/dist/math/Mat4.js +6 -6
  20. package/dist/math/Quat.js +4 -2
  21. package/dist/math/Vec.js +3 -1
  22. package/dist/math/Vec2.js +3 -1
  23. package/dist/math/Vec3.js +7 -5
  24. package/dist/math/Vec4.js +3 -1
  25. package/dist/math/vector.js +9 -7
  26. package/dist/render/buffer-attribute.js +12 -28
  27. package/dist/render/eventhandler.d.ts +1 -1
  28. package/dist/render/eventhandler.js +9 -7
  29. package/dist/render/geometry.js +2 -2
  30. package/dist/render/mesh.js +11 -9
  31. package/dist/render/thing.js +10 -8
  32. package/dist/render/types.js +2 -1
  33. package/dist/struct/3d/Box.js +3 -3
  34. package/dist/struct/3d/Capsule.js +3 -1
  35. package/dist/struct/3d/Circle.js +2 -2
  36. package/dist/struct/3d/Disk.js +1 -1
  37. package/dist/struct/3d/Line.js +4 -4
  38. package/dist/struct/3d/Path.js +13 -11
  39. package/dist/struct/3d/Plane.js +12 -10
  40. package/dist/struct/3d/Point.js +3 -1
  41. package/dist/struct/3d/Polygon.js +3 -1
  42. package/dist/struct/3d/Polyline.js +3 -1
  43. package/dist/struct/3d/Rectangle.js +3 -1
  44. package/dist/struct/3d/Segment.js +9 -7
  45. package/dist/struct/3d/Shape.js +3 -1
  46. package/dist/struct/3d/Sphere.js +1 -1
  47. package/dist/struct/3d/Triangle.js +3 -1
  48. package/dist/struct/data/ArrayList.js +11 -9
  49. package/dist/struct/data/ArrayObject.js +3 -1
  50. package/package.json +4 -3
  51. package/src/app.ts +4 -1
  52. package/src/index.ts +1 -0
  53. package/src/math/Color.ts +14 -32
  54. package/dist/src/IKanimation/Bone.d.ts +0 -9
  55. package/dist/src/IKanimation/Bone.js +0 -40
  56. package/dist/src/IKanimation/CCDSolver.d.ts +0 -37
  57. package/dist/src/IKanimation/CCDSolver.js +0 -93
  58. package/dist/src/IKanimation/Joint.d.ts +0 -3
  59. package/dist/src/IKanimation/Joint.js +0 -17
  60. package/dist/src/IKanimation/constaint/constraint.d.ts +0 -10
  61. package/dist/src/IKanimation/constaint/constraint.js +0 -25
  62. package/dist/src/IKanimation/constaint/hinge.d.ts +0 -12
  63. package/dist/src/IKanimation/constaint/hinge.js +0 -46
  64. package/dist/src/IKanimation/constaint/slider.d.ts +0 -12
  65. package/dist/src/IKanimation/constaint/slider.js +0 -44
  66. package/dist/src/IKanimation/index.d.ts +0 -0
  67. package/dist/src/IKanimation/index.js +0 -9
  68. package/dist/src/IKanimation/isolver.d.ts +0 -4
  69. package/dist/src/IKanimation/isolver.js +0 -10
  70. package/dist/src/IKanimation/skeleton.d.ts +0 -13
  71. package/dist/src/IKanimation/skeleton.js +0 -31
  72. package/dist/src/alg/common.d.ts +0 -114
  73. package/dist/src/alg/common.js +0 -302
  74. package/dist/src/alg/curve.d.ts +0 -4
  75. package/dist/src/alg/curve.js +0 -11
  76. package/dist/src/alg/delaunator.d.ts +0 -29
  77. package/dist/src/alg/delaunator.js +0 -442
  78. package/dist/src/alg/delaunay.d.ts +0 -20
  79. package/dist/src/alg/delaunay.js +0 -199
  80. package/dist/src/alg/delaunayslow.d.ts +0 -18
  81. package/dist/src/alg/delaunayslow.js +0 -140
  82. package/dist/src/alg/extrude/extrude.d.ts +0 -3
  83. package/dist/src/alg/extrude/extrude.js +0 -17
  84. package/dist/src/alg/extrude.d.ts +0 -199
  85. package/dist/src/alg/extrude.js +0 -731
  86. package/dist/src/alg/offset/index.d.ts +0 -0
  87. package/dist/src/alg/offset/index.js +0 -9
  88. package/dist/src/alg/offset.d.ts +0 -0
  89. package/dist/src/alg/offset.js +0 -472
  90. package/dist/src/alg/pointset.d.ts +0 -94
  91. package/dist/src/alg/pointset.js +0 -223
  92. package/dist/src/alg/recognition.d.ts +0 -14
  93. package/dist/src/alg/recognition.js +0 -37
  94. package/dist/src/alg/result.d.ts +0 -22
  95. package/dist/src/alg/result.js +0 -2
  96. package/dist/src/alg/segmentset.d.ts +0 -11
  97. package/dist/src/alg/segmentset.js +0 -45
  98. package/dist/src/alg/sort.d.ts +0 -2
  99. package/dist/src/alg/sort.js +0 -14
  100. package/dist/src/alg/split.d.ts +0 -8
  101. package/dist/src/alg/split.js +0 -10
  102. package/dist/src/alg/trianglution.d.ts +0 -20
  103. package/dist/src/alg/trianglution.js +0 -77
  104. package/dist/src/alg/vol.d.ts +0 -6
  105. package/dist/src/alg/vol.js +0 -18
  106. package/dist/src/alg/voronoi.d.ts +0 -31
  107. package/dist/src/alg/voronoi.js +0 -418
  108. package/dist/src/app.d.ts +0 -1
  109. package/dist/src/app.js +0 -245
  110. package/dist/src/basic/distance.d.ts +0 -12
  111. package/dist/src/basic/distance.js +0 -42
  112. package/dist/src/csg/bsp.d.ts +0 -9
  113. package/dist/src/csg/bsp.js +0 -22
  114. package/dist/src/csg/node.d.ts +0 -12
  115. package/dist/src/csg/node.js +0 -75
  116. package/dist/src/csg/polygon.d.ts +0 -43
  117. package/dist/src/csg/polygon.js +0 -161
  118. package/dist/src/diamondMaterialShader.d.ts +0 -92
  119. package/dist/src/diamondMaterialShader.js +0 -118
  120. package/dist/src/effect/breath-light.d.ts +0 -4
  121. package/dist/src/effect/breath-light.js +0 -39
  122. package/dist/src/extends/geometryaid.d.ts +0 -28
  123. package/dist/src/extends/geometryaid.js +0 -80
  124. package/dist/src/extends/split.d.ts +0 -3
  125. package/dist/src/extends/split.js +0 -13
  126. package/dist/src/glview.d.ts +0 -112
  127. package/dist/src/glview.js +0 -564
  128. package/dist/src/index.d.ts +0 -36
  129. package/dist/src/index.js +0 -54
  130. package/dist/src/math/Euler.d.ts +0 -47
  131. package/dist/src/math/Euler.js +0 -245
  132. package/dist/src/math/HVec3.d.ts +0 -44
  133. package/dist/src/math/HVec3.js +0 -195
  134. package/dist/src/math/Mat3.d.ts +0 -29
  135. package/dist/src/math/Mat3.js +0 -244
  136. package/dist/src/math/Mat4.d.ts +0 -85
  137. package/dist/src/math/Mat4.js +0 -791
  138. package/dist/src/math/Math.d.ts +0 -130
  139. package/dist/src/math/Math.js +0 -198
  140. package/dist/src/math/Quat.d.ts +0 -83
  141. package/dist/src/math/Quat.js +0 -440
  142. package/dist/src/math/Vec.d.ts +0 -7
  143. package/dist/src/math/Vec.js +0 -43
  144. package/dist/src/math/Vec2.d.ts +0 -68
  145. package/dist/src/math/Vec2.js +0 -347
  146. package/dist/src/math/Vec3.d.ts +0 -232
  147. package/dist/src/math/Vec3.js +0 -1089
  148. package/dist/src/math/Vec4.d.ts +0 -81
  149. package/dist/src/math/Vec4.js +0 -494
  150. package/dist/src/math/vector.d.ts +0 -114
  151. package/dist/src/math/vector.js +0 -373
  152. package/dist/src/render/buffer-attribute.d.ts +0 -100
  153. package/dist/src/render/buffer-attribute.js +0 -340
  154. package/dist/src/render/eventhandler.d.ts +0 -78
  155. package/dist/src/render/eventhandler.js +0 -189
  156. package/dist/src/render/geometry.d.ts +0 -89
  157. package/dist/src/render/geometry.js +0 -775
  158. package/dist/src/render/mesh.d.ts +0 -25
  159. package/dist/src/render/mesh.js +0 -82
  160. package/dist/src/render/thing.d.ts +0 -34
  161. package/dist/src/render/thing.js +0 -196
  162. package/dist/src/render/types.d.ts +0 -2
  163. package/dist/src/render/types.js +0 -8
  164. package/dist/src/robust/plane.d.ts +0 -7
  165. package/dist/src/robust/plane.js +0 -17
  166. package/dist/src/robust/vec.d.ts +0 -15
  167. package/dist/src/robust/vec.js +0 -71
  168. package/dist/src/shape/arc.d.ts +0 -2
  169. package/dist/src/shape/arc.js +0 -14
  170. package/dist/src/struct/3d/Box.d.ts +0 -23
  171. package/dist/src/struct/3d/Box.js +0 -109
  172. package/dist/src/struct/3d/Capsule.d.ts +0 -12
  173. package/dist/src/struct/3d/Capsule.js +0 -36
  174. package/dist/src/struct/3d/Circle.d.ts +0 -34
  175. package/dist/src/struct/3d/Circle.js +0 -80
  176. package/dist/src/struct/3d/Disk.d.ts +0 -10
  177. package/dist/src/struct/3d/Disk.js +0 -22
  178. package/dist/src/struct/3d/Frustum.d.ts +0 -35
  179. package/dist/src/struct/3d/Frustum.js +0 -159
  180. package/dist/src/struct/3d/Line.d.ts +0 -40
  181. package/dist/src/struct/3d/Line.js +0 -339
  182. package/dist/src/struct/3d/Path.d.ts +0 -75
  183. package/dist/src/struct/3d/Path.js +0 -308
  184. package/dist/src/struct/3d/Plane.d.ts +0 -74
  185. package/dist/src/struct/3d/Plane.js +0 -295
  186. package/dist/src/struct/3d/Point.d.ts +0 -4
  187. package/dist/src/struct/3d/Point.js +0 -30
  188. package/dist/src/struct/3d/Polygon.d.ts +0 -8
  189. package/dist/src/struct/3d/Polygon.js +0 -55
  190. package/dist/src/struct/3d/Polyline.d.ts +0 -25
  191. package/dist/src/struct/3d/Polyline.js +0 -109
  192. package/dist/src/struct/3d/Ray.d.ts +0 -21
  193. package/dist/src/struct/3d/Ray.js +0 -262
  194. package/dist/src/struct/3d/Rectangle.d.ts +0 -7
  195. package/dist/src/struct/3d/Rectangle.js +0 -35
  196. package/dist/src/struct/3d/Segment.d.ts +0 -32
  197. package/dist/src/struct/3d/Segment.js +0 -334
  198. package/dist/src/struct/3d/Shape.d.ts +0 -4
  199. package/dist/src/struct/3d/Shape.js +0 -27
  200. package/dist/src/struct/3d/Sphere.d.ts +0 -11
  201. package/dist/src/struct/3d/Sphere.js +0 -30
  202. package/dist/src/struct/3d/Triangle.d.ts +0 -8
  203. package/dist/src/struct/3d/Triangle.js +0 -53
  204. package/dist/src/struct/data/ArrayList.d.ts +0 -42
  205. package/dist/src/struct/data/ArrayList.js +0 -172
  206. package/dist/src/struct/data/ArrayObject.d.ts +0 -30
  207. package/dist/src/struct/data/ArrayObject.js +0 -131
  208. package/dist/src/struct/data/type.d.ts +0 -13
  209. package/dist/src/struct/data/type.js +0 -18
  210. package/dist/src/utils/array.d.ts +0 -24
  211. package/dist/src/utils/array.js +0 -89
  212. package/dist/src/utils/types.d.ts +0 -24
  213. package/dist/src/utils/types.js +0 -20
  214. package/dist/src-gis/app.d.ts +0 -1
  215. package/dist/src-gis/app.js +0 -4
  216. package/dist/src-gis/core/Cartographic.d.ts +0 -20
  217. package/dist/src-gis/core/Cartographic.js +0 -52
  218. package/dist/src-gis/core/EllipsoidGeodesic.d.ts +0 -14
  219. package/dist/src-gis/core/EllipsoidGeodesic.js +0 -51
  220. package/dist/src-gis/core/EllipsoidTerrainProvider.d.ts +0 -10
  221. package/dist/src-gis/core/EllipsoidTerrainProvider.js +0 -29
  222. package/dist/src-gis/core/HeightmapTerrainData.d.ts +0 -3
  223. package/dist/src-gis/core/HeightmapTerrainData.js +0 -9
  224. package/dist/src-gis/core/Rectangle.d.ts +0 -45
  225. package/dist/src-gis/core/Rectangle.js +0 -127
  226. package/dist/src-gis/core/TaskProcessor.d.ts +0 -35
  227. package/dist/src-gis/core/TaskProcessor.js +0 -183
  228. package/dist/src-gis/gis.d.ts +0 -5
  229. package/dist/src-gis/gis.js +0 -12
  230. package/dist/src-gis/globe.d.ts +0 -12
  231. package/dist/src-gis/globe.js +0 -61
  232. package/dist/src-gis/math/Cartographic.d.ts +0 -8
  233. package/dist/src-gis/math/Cartographic.js +0 -26
  234. package/dist/src-gis/math/GVec3.d.ts +0 -12
  235. package/dist/src-gis/math/GVec3.js +0 -69
  236. package/dist/src-gis/math/ellipsoid.d.ts +0 -8
  237. package/dist/src-gis/math/ellipsoid.js +0 -14
  238. package/dist/src-gis/provider/DcTerrainProvider.d.ts +0 -15
  239. package/dist/src-gis/provider/DcTerrainProvider.js +0 -19
  240. package/dist/src-gis/provider/TerrainProvider.d.ts +0 -3
  241. package/dist/src-gis/provider/TerrainProvider.js +0 -17
  242. package/dist/src-gis/scene/DcImageryProvider.d.ts +0 -6
  243. package/dist/src-gis/scene/DcImageryProvider.js +0 -35
  244. package/dist/src-gis/scene/GeographicTilingScheme.d.ts +0 -21
  245. package/dist/src-gis/scene/GeographicTilingScheme.js +0 -46
  246. package/dist/src-gis/scene/Globe.d.ts +0 -34
  247. package/dist/src-gis/scene/Globe.js +0 -62
  248. package/dist/src-gis/scene/GlobeSurfaceShaderSet.d.ts +0 -6
  249. package/dist/src-gis/scene/GlobeSurfaceShaderSet.js +0 -11
  250. package/dist/src-gis/scene/GlobeSurfaceTileProvider.d.ts +0 -21
  251. package/dist/src-gis/scene/GlobeSurfaceTileProvider.js +0 -15
  252. package/dist/src-gis/scene/ImageryLayerCollection.d.ts +0 -21
  253. package/dist/src-gis/scene/ImageryLayerCollection.js +0 -87
  254. package/dist/src-gis/scene/ImageryProvider.d.ts +0 -4
  255. package/dist/src-gis/scene/ImageryProvider.js +0 -28
  256. package/dist/src-gis/scene/QuadtreeTile.d.ts +0 -48
  257. package/dist/src-gis/scene/QuadtreeTile.js +0 -137
  258. package/dist/src-gis/scene/UrlTemplateImageryProvider.d.ts +0 -9
  259. package/dist/src-gis/scene/UrlTemplateImageryProvider.js +0 -29
  260. package/dist/src-gis/scene/quadtree_primitive.d.ts +0 -14
  261. package/dist/src-gis/scene/quadtree_primitive.js +0 -50
@@ -1,1089 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.v3 = exports.Vec3 = void 0;
19
- var Quat_1 = require("./Quat");
20
- var Math_1 = require("./Math");
21
- var Segment_1 = require("../struct/3d/Segment");
22
- var eventhandler_1 = require("../render/eventhandler");
23
- var Vec3 = /** @class */ (function (_super) {
24
- __extends(Vec3, _super);
25
- function Vec3(_x, _y, _z) {
26
- if (_x === void 0) { _x = 0; }
27
- if (_y === void 0) { _y = 0; }
28
- if (_z === void 0) { _z = 0; }
29
- var _this = _super.call(this) || this;
30
- _this._x = _x;
31
- _this._y = _y;
32
- _this._z = _z;
33
- return _this;
34
- }
35
- Object.defineProperty(Vec3.prototype, "x", {
36
- get: function () {
37
- return this._x;
38
- },
39
- set: function (value) {
40
- if (this._x !== value) {
41
- this._x = value;
42
- this.fire('change', 'x', this._x, value);
43
- }
44
- },
45
- enumerable: false,
46
- configurable: true
47
- });
48
- Object.defineProperty(Vec3.prototype, "y", {
49
- get: function () {
50
- return this._y;
51
- },
52
- set: function (value) {
53
- if (this._y !== value) {
54
- this._y = value;
55
- this.fire('change', 'y', this._y, value);
56
- }
57
- },
58
- enumerable: false,
59
- configurable: true
60
- });
61
- Object.defineProperty(Vec3.prototype, "z", {
62
- get: function () {
63
- return this._z;
64
- },
65
- set: function (value) {
66
- if (this._z !== value) {
67
- this._z = value;
68
- this.fire('change', 'z', this._z, value);
69
- }
70
- },
71
- enumerable: false,
72
- configurable: true
73
- });
74
- Vec3.isVec3 = function (v) {
75
- return !isNaN(v.x) && !isNaN(v.y) && !isNaN(v.z) && isNaN(v.w);
76
- };
77
- Object.defineProperty(Vec3.prototype, "isVec3", {
78
- get: function () { return true; },
79
- enumerable: false,
80
- configurable: true
81
- });
82
- Object.defineProperty(Vec3, "Up", {
83
- get: function () {
84
- return new Vec3(0, 1, 0);
85
- },
86
- enumerable: false,
87
- configurable: true
88
- });
89
- Object.defineProperty(Vec3, "Down", {
90
- get: function () {
91
- return new Vec3(0, 1, 0);
92
- },
93
- enumerable: false,
94
- configurable: true
95
- });
96
- Object.defineProperty(Vec3, "UnitX", {
97
- get: function () {
98
- return new Vec3(1, 0, 0);
99
- },
100
- enumerable: false,
101
- configurable: true
102
- });
103
- Object.defineProperty(Vec3, "UnitY", {
104
- get: function () {
105
- return new Vec3(0, 1, 0);
106
- },
107
- enumerable: false,
108
- configurable: true
109
- });
110
- Object.defineProperty(Vec3, "UnitZ", {
111
- get: function () {
112
- return new Vec3(0, 0, 1);
113
- },
114
- enumerable: false,
115
- configurable: true
116
- });
117
- Vec3.prototype.set = function (x, y, z) {
118
- this._x = x;
119
- this._y = y;
120
- this._z = z;
121
- this.fire('change');
122
- return this;
123
- };
124
- Vec3.prototype.setScalar = function (scalar) {
125
- this._x = scalar;
126
- this._y = scalar;
127
- this._z = scalar;
128
- this.fire('change');
129
- return this;
130
- };
131
- Vec3.prototype.setComponent = function (index, value) {
132
- switch (index) {
133
- case 0:
134
- this._x = value;
135
- break;
136
- case 1:
137
- this._y = value;
138
- break;
139
- case 2:
140
- this._z = value;
141
- break;
142
- default:
143
- throw new Error("index is out of range: " + index);
144
- }
145
- return this;
146
- };
147
- Vec3.prototype.getComponent = function (index) {
148
- switch (index) {
149
- case 0:
150
- return this._x;
151
- case 1:
152
- return this._y;
153
- case 2:
154
- return this._z;
155
- default:
156
- throw new Error("index is out of range: " + index);
157
- }
158
- };
159
- Vec3.prototype.clone = function () {
160
- return new Vec3(this._x, this._y, this._z);
161
- };
162
- Vec3.prototype.copy = function (v) {
163
- this._x = v.x;
164
- this._y = v.y;
165
- this._z = v.z;
166
- this.fire('change');
167
- return this;
168
- };
169
- Vec3.prototype.add = function (v, w) {
170
- if (w !== undefined) {
171
- console.warn("Vec3: .add() now only accepts one argument. Use .addVecs( a, b ) instead.");
172
- return this.addVecs(v, w);
173
- }
174
- this._x += v.x;
175
- this._y += v.y;
176
- this._z += v.z;
177
- this.fire('change');
178
- return this;
179
- };
180
- Vec3.prototype.addScalar = function (s) {
181
- this._x += s;
182
- this._y += s;
183
- this._z += s;
184
- this.fire('change');
185
- return this;
186
- };
187
- Vec3.prototype.addVecs = function (a, b) {
188
- this._x = a.x + b.x;
189
- this._y = a.y + b.y;
190
- this._z = a.z + b.z;
191
- this.fire('change');
192
- return this;
193
- };
194
- Vec3.prototype.addScaledVec = function (v, s) {
195
- this._x += v.x * s;
196
- this._y += v.y * s;
197
- this._z += v.z * s;
198
- this.fire('change');
199
- return this;
200
- };
201
- Vec3.prototype.sub = function (v, w) {
202
- if (w !== undefined) {
203
- console.warn("Vec3: .sub() now only accepts one argument. Use .subVecs( a, b ) instead.");
204
- return this.subVecs(v, w);
205
- }
206
- this._x -= v.x;
207
- this._y -= v.y;
208
- this._z -= v.z;
209
- this.fire('change');
210
- return this;
211
- };
212
- Vec3.prototype.subScalar = function (s) {
213
- this._x -= s;
214
- this._y -= s;
215
- this._z -= s;
216
- this.fire('change');
217
- return this;
218
- };
219
- Vec3.prototype.subVecs = function (a, b) {
220
- this._x = a.x - b.x;
221
- this._y = a.y - b.y;
222
- this._z = a.z - b.z;
223
- this.fire('change');
224
- return this;
225
- };
226
- Vec3.prototype.multiply = function (v, w) {
227
- if (w !== undefined) {
228
- return this.multiplyVecs(v, w);
229
- }
230
- this._x *= v.x;
231
- this._y *= v.y;
232
- this._z *= v.z;
233
- this.fire('change');
234
- return this;
235
- };
236
- Vec3.prototype.multiplyScalar = function (scalar) {
237
- this._x *= scalar;
238
- this._y *= scalar;
239
- this._z *= scalar;
240
- this.fire('change');
241
- return this;
242
- };
243
- Vec3.prototype.multiplyVecs = function (a, b) {
244
- this._x = a.x * b.x;
245
- this._y = a.y * b.y;
246
- this._z = a.z * b.z;
247
- this.fire('change');
248
- return this;
249
- };
250
- Vec3.prototype.applyEuler = function (euler) {
251
- if (!(euler && euler.isEuler)) {
252
- console.error("Vec3: .applyEuler() now expects an Euler rotation rather than a Vec3 and order.");
253
- }
254
- return this.applyQuat(_quat.setFromEuler(euler));
255
- };
256
- Vec3.prototype.applyAxisAngle = function (axis, angle) {
257
- return this.applyQuat(_quat.setFromAxisAngle(axis, angle));
258
- };
259
- Vec3.prototype.applyNormalMat = function (m) {
260
- return this.applyMat3(m).normalize();
261
- };
262
- Vec3.prototype.applyMat3 = function (m) {
263
- var x = this._x, y = this._y, z = this._z;
264
- var e = m.elements;
265
- this._x = e[0] * x + e[3] * y + e[6] * z;
266
- this._y = e[1] * x + e[4] * y + e[7] * z;
267
- this._z = e[2] * x + e[5] * y + e[8] * z;
268
- this.fire('change');
269
- return this;
270
- };
271
- Vec3.prototype.applyMat4 = function (m) {
272
- var x = this._x, y = this._y, z = this._z;
273
- var e = m.elements;
274
- var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
275
- this._x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
276
- this._y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
277
- this._z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
278
- this.fire('change');
279
- return this;
280
- };
281
- Vec3.prototype.applyQuat = function (q) {
282
- var x = this._x, y = this._y, z = this._z;
283
- var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
284
- // calculate Quat * Vec
285
- var ix = qw * x + qy * z - qz * y;
286
- var iy = qw * y + qz * x - qx * z;
287
- var iz = qw * z + qx * y - qy * x;
288
- var iw = -qx * x - qy * y - qz * z;
289
- // calculate result * inverse Quat
290
- this._x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
291
- this._y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
292
- this._z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
293
- this.fire('change');
294
- return this;
295
- };
296
- Vec3.prototype.project = function (camera) {
297
- return this.applyMat4(camera.matrixWorldInverse).applyMat4(camera.projectionMat);
298
- };
299
- Vec3.prototype.unproject = function (camera) {
300
- return this.applyMat4(camera.projectionMatInverse).applyMat4(camera.matrixWorld);
301
- };
302
- Vec3.prototype.transformDirection = function (m) {
303
- // input: Mat4 affine matrix
304
- // Vec interpreted as a direction
305
- var x = this._x, y = this._y, z = this._z;
306
- var e = m.elements;
307
- this._x = e[0] * x + e[4] * y + e[8] * z;
308
- this._y = e[1] * x + e[5] * y + e[9] * z;
309
- this._z = e[2] * x + e[6] * y + e[10] * z;
310
- this.fire('change');
311
- return this.normalize();
312
- };
313
- Vec3.prototype.divide = function (v) {
314
- this._x /= v.x;
315
- this._y /= v.y;
316
- this._z /= v.z;
317
- this.fire('change');
318
- return this;
319
- };
320
- Vec3.prototype.divideScalar = function (scalar) {
321
- return this.multiplyScalar(1 / scalar);
322
- };
323
- Vec3.prototype.min = function (v) {
324
- this._x = Math.min(this._x, v.x);
325
- this._y = Math.min(this._y, v.y);
326
- this._z = Math.min(this._z, v.z);
327
- this.fire('change');
328
- return this;
329
- };
330
- Vec3.prototype.max = function (v) {
331
- this._x = Math.max(this._x, v.x);
332
- this._y = Math.max(this._y, v.y);
333
- this._z = Math.max(this._z, v.z);
334
- this.fire('change');
335
- return this;
336
- };
337
- Vec3.prototype.clamp = function (min, max) {
338
- // assumes min < max, componentwise
339
- this._x = Math.max(min.x, Math.min(max.x, this._x));
340
- this._y = Math.max(min.y, Math.min(max.y, this._y));
341
- this._z = Math.max(min.z, Math.min(max.z, this._z));
342
- this.fire('change');
343
- return this;
344
- };
345
- Vec3.prototype.clampScalar = function (minVal, maxVal) {
346
- this._x = Math.max(minVal, Math.min(maxVal, this._x));
347
- this._y = Math.max(minVal, Math.min(maxVal, this._y));
348
- this._z = Math.max(minVal, Math.min(maxVal, this._z));
349
- this.fire('change');
350
- return this;
351
- };
352
- Vec3.prototype.clampLength = function (min, max) {
353
- var length = this.length();
354
- return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
355
- };
356
- Vec3.prototype.floor = function () {
357
- this._x = Math.floor(this._x);
358
- this._y = Math.floor(this._y);
359
- this._z = Math.floor(this._z);
360
- this.fire('change');
361
- return this;
362
- };
363
- Vec3.prototype.ceil = function () {
364
- this._x = Math.ceil(this._x);
365
- this._y = Math.ceil(this._y);
366
- this._z = Math.ceil(this._z);
367
- this.fire('change');
368
- return this;
369
- };
370
- Vec3.prototype.round = function () {
371
- this._x = Math.round(this._x);
372
- this._y = Math.round(this._y);
373
- this._z = Math.round(this._z);
374
- this.fire('change');
375
- return this;
376
- };
377
- Vec3.prototype.roundToZero = function () {
378
- this._x = this._x < 0 ? Math.ceil(this._x) : Math.floor(this._x);
379
- this._y = this._y < 0 ? Math.ceil(this._y) : Math.floor(this._y);
380
- this._z = this._z < 0 ? Math.ceil(this._z) : Math.floor(this._z);
381
- this.fire('change');
382
- return this;
383
- };
384
- Vec3.prototype.negate = function () {
385
- this._x = -this._x;
386
- this._y = -this._y;
387
- this._z = -this._z;
388
- this.fire('change');
389
- return this;
390
- };
391
- Vec3.prototype.dot = function (v) {
392
- return this._x * v.x + this._y * v.y + this._z * v.z;
393
- };
394
- // TODO lengthSquared?
395
- Vec3.prototype.lengthSq = function () {
396
- return this._x * this._x + this._y * this._y + this._z * this._z;
397
- };
398
- Vec3.prototype.length = function () {
399
- return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z);
400
- };
401
- Vec3.prototype.manhattanLength = function () {
402
- return Math.abs(this._x) + Math.abs(this._y) + Math.abs(this._z);
403
- };
404
- Vec3.prototype.normalize = function (robust) {
405
- if (robust === void 0) { robust = false; }
406
- return this.divideScalar(this.length() || 1);
407
- // if (robust)
408
- // {
409
- // var maxAbsComp = Math.abs(v[0]);
410
- // for (var i = 1; i < N; ++i)
411
- // {
412
- // var absComp = Math.abs(v[i]);
413
- // if (absComp > maxAbsComp)
414
- // {
415
- // maxAbsComp = absComp;
416
- // }
417
- // }
418
- // var length;
419
- // if (maxAbsComp > 0)
420
- // {
421
- // v /= maxAbsComp;
422
- // length = Math.sqrt(Dot(v, v));
423
- // v /= length;
424
- // length *= maxAbsComp;
425
- // }
426
- // else
427
- // {
428
- // length = 0;
429
- // for (var i = 0; i < N; ++i)
430
- // {
431
- // v[i] = 0;
432
- // }
433
- // }
434
- // return length;
435
- // }
436
- // else
437
- // {
438
- // var length = this.length();
439
- // if (length > 0)
440
- // {
441
- // v /= length;
442
- // }
443
- // else
444
- // {
445
- // for (var i = 0; i < N; ++i)
446
- // {
447
- // v[i] = 0;
448
- // }
449
- // }
450
- // }
451
- };
452
- Vec3.prototype.setLength = function (length) {
453
- return this.normalize().multiplyScalar(length);
454
- };
455
- Vec3.prototype.lerp = function (v, alpha) {
456
- this._x += (v.x - this._x) * alpha;
457
- this._y += (v.y - this._y) * alpha;
458
- this._z += (v.z - this._z) * alpha;
459
- return this;
460
- };
461
- Vec3.prototype.lerpVecs = function (v1, v2, alpha) {
462
- return this.subVecs(v2, v1)
463
- .multiplyScalar(alpha)
464
- .add(v1);
465
- };
466
- Vec3.prototype.slerp = function (v2, radian) {
467
- return this.slerpVecs(this, v2, radian);
468
- };
469
- /**
470
- * v1 到 v2 选择angle弧度 v1,v2构成一个平面
471
- * @param v1
472
- * @param v2
473
- * @param alpha
474
- * @returns
475
- */
476
- Vec3.prototype.slerpVecs = function (v1, v2, radian) {
477
- this.crossVecs(v1, v2).normalize();
478
- _quat.setFromAxisAngle(this, radian);
479
- this.applyQuat(_quat);
480
- };
481
- Vec3.prototype.cross = function (v, w) {
482
- if (w !== undefined) {
483
- console.warn("Vec3: .cross() now only accepts one argument. Use .crossVecs( a, b ) instead.");
484
- return this.crossVecs(v, w);
485
- }
486
- return this.crossVecs(this, v);
487
- };
488
- Vec3.prototype.crossVecs = function (a, b) {
489
- var ax = a.x, ay = a.y, az = a.z;
490
- var bx = b.x, by = b.y, bz = b.z;
491
- this._x = ay * bz - az * by;
492
- this._y = az * bx - ax * bz;
493
- this._z = ax * by - ay * bx;
494
- return this;
495
- };
496
- Vec3.prototype.projectOnVec = function (vec) {
497
- var scalar = vec.dot(this) / vec.lengthSq();
498
- return this.copy(vec).multiplyScalar(scalar);
499
- };
500
- /**
501
- * 投影到法线的所在平面 相当于平面上距离点最近的点
502
- * @param planeNormal
503
- * @returns
504
- */
505
- Vec3.prototype.projectOnPlaneNormal = function (planeNormal) {
506
- _vec.copy(this).projectOnVec(planeNormal);
507
- return this.sub(_vec);
508
- };
509
- /**
510
- * 投影到平面
511
- * @param normal 正交化的法线
512
- * @param w 距离
513
- * @returns
514
- */
515
- Vec3.prototype.projectOnPlaneNormalDis = function (normal, w) {
516
- var scalar = normal.dot(this) - w;
517
- _vec.copy(normal).multiplyScalar(scalar);
518
- return this.sub(_vec);
519
- };
520
- /**
521
- * 投影到平面
522
- * @param plane 平面
523
- * @returns
524
- */
525
- Vec3.prototype.projectOnPlane = function (plane) {
526
- var scalar = plane.normal.dot(this) - plane.w;
527
- _vec.copy(plane.normal).multiplyScalar(scalar);
528
- return this.sub(_vec);
529
- };
530
- /**
531
- * 从指定方向线(斜线,也可能是法线)上投影到平面
532
- * @param planeNormal
533
- * @param dir
534
- */
535
- Vec3.prototype.projectDirectionOnPlane = function (plane, dir) {
536
- var scalar = plane.normal.dot(this) - plane.w;
537
- _vec.copy(plane.normal).multiplyScalar(scalar);
538
- _vec.negate().add(this);
539
- var len = this.distanceTo(_vec);
540
- var nlen = len / plane.normal.dot(dir);
541
- this.add(_vec.copy(dir).negate().multiplyScalar(nlen));
542
- return this;
543
- };
544
- Vec3.prototype.reflect = function (normal) {
545
- // reflect incident Vec off plane orthogonal to normal
546
- // normal is assumed to have unit length
547
- return this.sub(_vec.copy(normal).multiplyScalar(2 * this.dot(normal)));
548
- };
549
- Vec3.prototype.angleTo = function (v, normal) {
550
- if (normal)
551
- return this.angleToEx(v, normal);
552
- var theta = this.dot(v) / Math.sqrt(this.lengthSq() * v.lengthSq());
553
- return Math.acos((0, Math_1.clamp)(theta, -1, 1));
554
- };
555
- Vec3.prototype.angleToEx = function (v, normal) {
556
- var theta = this.dot(v) / Math.sqrt(this.lengthSq() * v.lengthSq());
557
- if (this.clone().cross(v).dot(normal) > 0)
558
- return Math.acos((0, Math_1.clamp)(theta, -1, 1));
559
- else
560
- return Math.PI * 2 - Math.acos((0, Math_1.clamp)(theta, -1, 1));
561
- };
562
- Vec3.prototype.distanceTo = function (v) {
563
- return Math.sqrt(this.distanceToSquared(v));
564
- };
565
- Vec3.prototype.distanceToSquared = function (v) {
566
- var dx = this._x - v.x, dy = this._y - v.y, dz = this._z - v.z;
567
- return dx * dx + dy * dy + dz * dz;
568
- };
569
- Vec3.prototype.manhattanDistanceTo = function (v) {
570
- return (Math.abs(this._x - v.x) + Math.abs(this._y - v.y) + Math.abs(this._z - v.z));
571
- };
572
- Vec3.prototype.setFromSpherical = function (s) {
573
- return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
574
- };
575
- Vec3.prototype.setFromSphericalCoords = function (radius, phi, theta) {
576
- var sinPhiRadius = Math.sin(phi) * radius;
577
- this._x = sinPhiRadius * Math.sin(theta);
578
- this._y = Math.cos(phi) * radius;
579
- this._z = sinPhiRadius * Math.cos(theta);
580
- return this;
581
- };
582
- Vec3.prototype.setFromCylindrical = function (c) {
583
- return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
584
- };
585
- Vec3.prototype.setFromCylindricalCoords = function (radius, theta, y) {
586
- this._x = radius * Math.sin(theta);
587
- this._y = y;
588
- this._z = radius * Math.cos(theta);
589
- return this;
590
- };
591
- Vec3.prototype.setFromMatPosition = function (m) {
592
- var e = m.elements;
593
- this._x = e[12];
594
- this._y = e[13];
595
- this._z = e[14];
596
- return this;
597
- };
598
- Vec3.prototype.setFromMatScale = function (m) {
599
- var sx = this.setFromMatColumn(m, 0).length();
600
- var sy = this.setFromMatColumn(m, 1).length();
601
- var sz = this.setFromMatColumn(m, 2).length();
602
- this._x = sx;
603
- this._y = sy;
604
- this._z = sz;
605
- return this;
606
- };
607
- Vec3.prototype.setFromMatColumn = function (m, index) {
608
- return this.fromArray(m.elements, index * 4);
609
- };
610
- Vec3.prototype.equals = function (v) {
611
- return v.x === this._x && v.y === this._y && v.z === this._z;
612
- };
613
- Vec3.prototype.fromArray = function (array, offset) {
614
- if (offset === undefined)
615
- offset = 0;
616
- this._x = array[offset];
617
- this._y = array[offset + 1];
618
- this._z = array[offset + 2];
619
- return this;
620
- };
621
- Vec3.prototype.toArray = function (array, offset) {
622
- if (array === void 0) { array = []; }
623
- if (offset === void 0) { offset = 0; }
624
- array[offset] = this._x;
625
- array[offset + 1] = this._y;
626
- array[offset + 2] = this._z;
627
- return array;
628
- };
629
- Vec3.prototype.fromBufferAttribute = function (attribute, index, offset) {
630
- if (offset !== undefined) {
631
- console.warn("Vec3: offset has been removed from .fromBufferAttribute().");
632
- }
633
- this._x = attribute.getX(index);
634
- this._y = attribute.getY(index);
635
- this._z = attribute.getZ(index);
636
- return this;
637
- };
638
- Vec3.prototype.toFixed = function (fractionDigits) {
639
- if (fractionDigits !== undefined) {
640
- this._x = parseFloat(this._x.toFixed(fractionDigits));
641
- this._y = parseFloat(this._y.toFixed(fractionDigits));
642
- this._z = parseFloat(this._z.toFixed(fractionDigits));
643
- }
644
- return this;
645
- };
646
- //---Distance-------------------------------------------------------------------------------
647
- Vec3.prototype.distancePoint = function (point) {
648
- var result = {};
649
- result.distanceSqr = this.distanceToSquared(point);
650
- result.distance = Math.sqrt(result.distanceSqr);
651
- return result;
652
- };
653
- Vec3.prototype.distanceVec3 = function (point) {
654
- return this.distancePoint(point);
655
- };
656
- /**
657
- * 点到直线的距离 point distance to Line
658
- * @param line
659
- */
660
- Vec3.prototype.distanceLine = function (line) {
661
- var result = { parameters: [], closests: [] };
662
- var diff = this.clone().sub(line.origin);
663
- var lineParameter = line.direction.dot(diff);
664
- var lineClosest = line.direction
665
- .clone()
666
- .multiplyScalar(lineParameter)
667
- .add(line.origin);
668
- result.parameters.push(0, lineParameter);
669
- result.closests.push(this, lineClosest);
670
- diff = result.closests[0].clone().sub(result.closests[1]);
671
- result.distanceSqr = diff.dot(diff);
672
- result.distance = Math.sqrt(result.distanceSqr);
673
- return result;
674
- };
675
- /**
676
- * Test success
677
- * 到射线的距离
678
- * @param {Line} line
679
- * @returns {Object} lineParameter 最近点的参数 lineClosest 最近点 distanceSqr 到最近点距离的平方 distance 到最近点距离
680
- */
681
- Vec3.prototype.distanceRay = function (ray) {
682
- var result = {
683
- parameters: [0],
684
- closests: [this]
685
- };
686
- var diff = this.clone().sub(ray.origin);
687
- result.parameters[1] = ray.direction.dot(diff);
688
- if (result.parameters[1] > 0) {
689
- result.closests[1] = ray.direction
690
- .clone()
691
- .multiplyScalar(result.parameters[1])
692
- .add(ray.origin);
693
- }
694
- else {
695
- result.closests[1] = ray.origin.clone();
696
- }
697
- diff = this.clone().sub(result.closests[1]);
698
- result.distanceSqr = diff.dot(diff);
699
- result.distance = Math.sqrt(result.distanceSqr);
700
- return result;
701
- };
702
- /**
703
- * Test success
704
- * 到线段的距离
705
- * @param {Line} line
706
- * @returns {Object} lineParameter 最近点的参数 lineClosest 最近点 distanceSqr 到最近点距离的平方 distance 到最近点距离
707
- */
708
- Vec3.prototype.distanceSegment = function (segment) {
709
- var result = {
710
- parameters: [],
711
- closests: []
712
- };
713
- var diff = this.clone().sub(segment.p1);
714
- var t = segment.extentDirection.dot(diff);
715
- if (t >= 0) {
716
- result.parameters[1] = 1;
717
- result.closests[1] = segment.p1;
718
- }
719
- else {
720
- diff = this.clone().sub(segment.p0);
721
- t = segment.extentDirection.dot(diff);
722
- if (t <= 0) {
723
- result.parameters[1] = 0;
724
- result.closests[1] = segment.p0;
725
- }
726
- else {
727
- var sqrLength = segment.extentSqr;
728
- if (sqrLength <= 0)
729
- sqrLength = 0;
730
- t /= sqrLength;
731
- result.parameters[1] = t;
732
- result.closests[1] = segment.extentDirection
733
- .clone()
734
- .multiplyScalar(t)
735
- .add(segment.p0);
736
- }
737
- }
738
- result.closests[0] = this;
739
- diff = this.clone().sub(result.closests[1]);
740
- result.distanceSqr = diff.dot(diff);
741
- result.distance = Math.sqrt(result.distanceSqr);
742
- return result;
743
- };
744
- /**
745
- * 点与线段的距离
746
- * @param plane
747
- */
748
- Vec3.prototype.distancePlane = function (plane) {
749
- // this.clone().sub(plane.origin).dot(plane.normal);
750
- var result = {
751
- parameters: [],
752
- closests: [],
753
- signedDistance: 0,
754
- distance: 0
755
- };
756
- result.signedDistance = this.clone().dot(plane.normal) - plane.w;
757
- result.distance = Math.abs(result.signedDistance);
758
- result.closests[1] = this.clone().sub(plane.normal.clone().multiplyScalar(result.signedDistance));
759
- return result;
760
- };
761
- /**
762
- * 点与圆圈的距离
763
- * @param {*} circle
764
- * @param {*} disk
765
- * @returns {} result
766
- */
767
- Vec3.prototype.distanceCircle = function (circle) {
768
- var result = {
769
- parameters: [],
770
- closests: [],
771
- equidistant: false //是否等距
772
- };
773
- // Projection of P-C onto plane is Q-C = P-C - Dot(N,P-C)*N.
774
- var PmC = this.clone().sub(circle.center);
775
- var QmC = PmC.clone().sub(circle.normal.clone().multiplyScalar(circle.normal.dot(PmC)));
776
- var lengthQmC = QmC.length();
777
- if (lengthQmC > Math_1.delta4) {
778
- result.circleClosest = QmC.clone().multiplyScalar(circle.radius / lengthQmC).add(circle.center);
779
- result.equidistant = false;
780
- }
781
- else {
782
- var offsetPoint = circle.center.clone().add(v3(10, 10, 10));
783
- var CP = offsetPoint.sub(circle.center);
784
- var CQ = CP.clone().sub(circle.normal.clone().multiplyScalar(circle.normal.dot(CP))).normalize();
785
- //在圆圈圆心的法线上,到圆圈上的没一点都相同
786
- result.circleClosest = CQ.clone().multiplyScalar(circle.radius).add(circle.center);
787
- result.equidistant = true;
788
- }
789
- result.closests.push(this, result.circleClosest);
790
- var diff = this.clone().sub(result.circleClosest);
791
- result.distanceSqr = diff.dot(diff);
792
- result.distance = Math.sqrt(result.distanceSqr);
793
- return result;
794
- };
795
- /**
796
- * 点与圆盘的距离
797
- * @param {*} Disk
798
- * @returns {} result
799
- */
800
- Vec3.prototype.distanceDisk = function (disk) {
801
- var result = {
802
- parameters: [],
803
- closests: [],
804
- signedDistance: 1,
805
- distanceSqr: 0,
806
- distance: 0,
807
- };
808
- var PmC = this.clone().sub(disk.center);
809
- var QmC = PmC.clone().sub(disk.normal.clone().multiplyScalar(disk.normal.dot(PmC)));
810
- var lengthQmC = QmC.length();
811
- result.signedDistance = this.clone().dot(disk.normal) - disk.w;
812
- if (lengthQmC > disk.radius) {
813
- result.diskClosest = QmC.clone().multiplyScalar(disk.radius / lengthQmC).add(disk.center);
814
- }
815
- else {
816
- var signedDistance = this.clone().dot(disk.normal) - disk.w;
817
- result.diskClosest = this.clone().sub(disk.normal.clone().multiplyScalar(signedDistance));
818
- }
819
- result.closests.push(this, result.diskClosest);
820
- var diff = this.clone().sub(result.diskClosest);
821
- result.distanceSqr = diff.dot(diff);
822
- result.distance = Math.sqrt(result.distanceSqr);
823
- return result;
824
- };
825
- /**
826
- * 点与线段的距离
827
- * 点与折线的距离 测试排除法,平均比线性检索(暴力法)要快两倍以上
828
- * @param { Polyline | Vec3[]} polyline
829
- */
830
- Vec3.prototype.distancePolyline = function (polyline) {
831
- var u = +Infinity;
832
- var ipos = -1;
833
- var tempResult;
834
- var result = null;
835
- for (var i = 0; i < polyline.length - 1; i++) {
836
- var pti = void 0, ptj = void 0;
837
- if (Array.isArray(polyline)) {
838
- pti = polyline[i];
839
- ptj = polyline[i + 1];
840
- }
841
- else {
842
- pti = polyline.get(i);
843
- ptj = polyline.get(i + 1);
844
- }
845
- if (Math.abs(pti.x - this._x) > u && Math.abs(ptj.x - this._x) > u && (pti.x - this._x) * (ptj.x - this._x) > 0)
846
- continue;
847
- if (Math.abs(pti.y - this._y) > u && Math.abs(ptj.y - this._y) > u && (pti.y - this._y) * (ptj.y - this._y) > 0)
848
- continue;
849
- if (Math.abs(pti.z - this._z) > u && Math.abs(ptj.z - this._z) > u && (pti.z - this._z) * (ptj.z - this._z) > 0)
850
- continue;
851
- tempResult = this.distanceSegment(new Segment_1.Segment(pti, ptj));
852
- if (tempResult.distance < u) {
853
- u = tempResult.distance;
854
- result = tempResult;
855
- ipos = i;
856
- }
857
- }
858
- result.segmentIndex = ipos;
859
- return result;
860
- };
861
- /**
862
- * 点到三角形的距离
863
- * @param {Triangle} triangle
864
- */
865
- Vec3.prototype.distanceTriangle = function (triangle) {
866
- function GetMinEdge02(a11, b1, p) {
867
- p[0] = 0;
868
- if (b1 >= 0) {
869
- p[1] = 0;
870
- }
871
- else if (a11 + b1 <= 0) {
872
- p[1] = 1;
873
- }
874
- else {
875
- p[1] = -b1 / a11;
876
- }
877
- }
878
- function GetMinEdge12(a01, a11, b1, f10, f01, p) {
879
- var h0 = a01 + b1 - f10;
880
- if (h0 >= 0) {
881
- p[1] = 0;
882
- }
883
- else {
884
- var h1 = a11 + b1 - f01;
885
- if (h1 <= 0) {
886
- p[1] = 1;
887
- }
888
- else {
889
- p[1] = h0 / (h0 - h1);
890
- }
891
- }
892
- p[0] = 1 - p[1];
893
- }
894
- function GetMinInterior(p0, h0, p1, h1, p) {
895
- var z = h0 / (h0 - h1);
896
- p[0] = (1 - z) * p0[0] + z * p1[0];
897
- p[1] = (1 - z) * p0[1] + z * p1[1];
898
- }
899
- var diff = this.clone().sub(triangle.p0);
900
- var edge0 = triangle.p1.clone().sub(triangle.p0);
901
- var edge1 = triangle.p2.clone().sub(triangle.p0);
902
- var a00 = edge0.dot(edge0);
903
- var a01 = edge0.dot(edge1);
904
- var a11 = edge1.dot(edge1);
905
- var b0 = -diff.dot(edge0);
906
- var b1 = -diff.dot(edge1);
907
- var f00 = b0;
908
- var f10 = b0 + a00;
909
- var f01 = b0 + a01;
910
- var p0 = [0, 0], p1 = [0, 0], p = [0, 0];
911
- var dt1, h0, h1;
912
- if (f00 >= 0) {
913
- if (f01 >= 0) {
914
- // (1) p0 = (0,0), p1 = (0,1), H(z) = G(L(z))
915
- GetMinEdge02(a11, b1, p);
916
- }
917
- else {
918
- // (2) p0 = (0,t10), p1 = (t01,1-t01),
919
- // H(z) = (t11 - t10)*G(L(z))
920
- p0[0] = 0;
921
- p0[1] = f00 / (f00 - f01);
922
- p1[0] = f01 / (f01 - f10);
923
- p1[1] = 1 - p1[0];
924
- dt1 = p1[1] - p0[1];
925
- h0 = dt1 * (a11 * p0[1] + b1);
926
- if (h0 >= 0) {
927
- GetMinEdge02(a11, b1, p);
928
- }
929
- else {
930
- h1 = dt1 * (a01 * p1[0] + a11 * p1[1] + b1);
931
- if (h1 <= 0) {
932
- GetMinEdge12(a01, a11, b1, f10, f01, p);
933
- }
934
- else {
935
- GetMinInterior(p0, h0, p1, h1, p);
936
- }
937
- }
938
- }
939
- }
940
- else if (f01 <= 0) {
941
- if (f10 <= 0) {
942
- // (3) p0 = (1,0), p1 = (0,1),
943
- // H(z) = G(L(z)) - F(L(z))
944
- GetMinEdge12(a01, a11, b1, f10, f01, p);
945
- }
946
- else {
947
- // (4) p0 = (t00,0), p1 = (t01,1-t01), H(z) = t11*G(L(z))
948
- p0[0] = f00 / (f00 - f10);
949
- p0[1] = 0;
950
- p1[0] = f01 / (f01 - f10);
951
- p1[1] = 1 - p1[0];
952
- h0 = p1[1] * (a01 * p0[0] + b1);
953
- if (h0 >= 0) {
954
- p = p0; // GetMinEdge01
955
- }
956
- else {
957
- h1 = p1[1] * (a01 * p1[0] + a11 * p1[1] + b1);
958
- if (h1 <= 0) {
959
- GetMinEdge12(a01, a11, b1, f10, f01, p);
960
- }
961
- else {
962
- GetMinInterior(p0, h0, p1, h1, p);
963
- }
964
- }
965
- }
966
- }
967
- else if (f10 <= 0) {
968
- // (5) p0 = (0,t10), p1 = (t01,1-t01),
969
- // H(z) = (t11 - t10)*G(L(z))
970
- p0[0] = 0;
971
- p0[1] = f00 / (f00 - f01);
972
- p1[0] = f01 / (f01 - f10);
973
- p1[1] = 1 - p1[0];
974
- dt1 = p1[1] - p0[1];
975
- h0 = dt1 * (a11 * p0[1] + b1);
976
- if (h0 >= 0) {
977
- GetMinEdge02(a11, b1, p);
978
- }
979
- else {
980
- h1 = dt1 * (a01 * p1[0] + a11 * p1[1] + b1);
981
- if (h1 <= 0) {
982
- GetMinEdge12(a01, a11, b1, f10, f01, p);
983
- }
984
- else {
985
- GetMinInterior(p0, h0, p1, h1, p);
986
- }
987
- }
988
- }
989
- else {
990
- // (6) p0 = (t00,0), p1 = (0,t11), H(z) = t11*G(L(z))
991
- p0[0] = f00 / (f00 - f10);
992
- p0[1] = 0;
993
- p1[0] = 0;
994
- p1[1] = f00 / (f00 - f01);
995
- h0 = p1[1] * (a01 * p0[0] + b1);
996
- if (h0 >= 0) {
997
- p = p0; // GetMinEdge01
998
- }
999
- else {
1000
- h1 = p1[1] * (a11 * p1[1] + b1);
1001
- if (h1 <= 0) {
1002
- GetMinEdge02(a11, b1, p);
1003
- }
1004
- else {
1005
- GetMinInterior(p0, h0, p1, h1, p);
1006
- }
1007
- }
1008
- }
1009
- var result = {
1010
- closests: [],
1011
- parameters: [],
1012
- triangleParameters: []
1013
- };
1014
- result.triangleParameters[0] = 1 - p[0] - p[1];
1015
- result.triangleParameters[1] = p[0];
1016
- result.triangleParameters[2] = p[1];
1017
- var closest = triangle.p0.clone().add(edge0.multiplyScalar(p[0])).add(edge1.multiplyScalar(p[1]));
1018
- result.parameters.push(0, result.triangleParameters);
1019
- result.closests.push(this, closest);
1020
- diff = this.clone().sub(closest);
1021
- result.distanceSqr = diff.dot(diff);
1022
- result.distance = Math.sqrt(result.distanceSqr);
1023
- return result;
1024
- };
1025
- /**
1026
- * 点到矩形的距离
1027
- * @param {Rectangle} rectangle
1028
- */
1029
- Vec3.prototype.distanceRectangle = function (rectangle) {
1030
- var result = {
1031
- rectangleParameters: [],
1032
- parameters: [],
1033
- closests: [],
1034
- };
1035
- var diff = rectangle.center.clone().sub(this);
1036
- var b0 = diff.dot(rectangle.axis[0]);
1037
- var b1 = diff.dot(rectangle.axis[1]);
1038
- var s0 = -b0, s1 = -b1;
1039
- result.distanceSqr = diff.dot(diff);
1040
- if (s0 < -rectangle.extent[0]) {
1041
- s0 = -rectangle.extent[0];
1042
- }
1043
- else if (s0 > rectangle.extent[0]) {
1044
- s0 = rectangle.extent[0];
1045
- }
1046
- result.distanceSqr += s0 * (s0 + 2 * b0);
1047
- if (s1 < -rectangle.extent[1]) {
1048
- s1 = -rectangle.extent[1];
1049
- }
1050
- else if (s1 > rectangle.extent[1]) {
1051
- s1 = rectangle.extent[1];
1052
- }
1053
- result.distanceSqr += s1 * (s1 + 2 * b1);
1054
- // Account for numerical round-off error.
1055
- if (result.distanceSqr < 0) {
1056
- result.distanceSqr = 0;
1057
- }
1058
- result.distance = Math.sqrt(result.distanceSqr);
1059
- result.rectangleParameters[0] = s0;
1060
- result.rectangleParameters[1] = s1;
1061
- var rectangleClosestPoint = rectangle.center.clone();
1062
- for (var i = 0; i < 2; ++i) {
1063
- rectangleClosestPoint.add(rectangle.axis[i].multiplyScalar(result.rectangleParameters[i]));
1064
- }
1065
- result.closests[0] = this;
1066
- result.closests[1] = rectangleClosestPoint;
1067
- return result;
1068
- };
1069
- /**
1070
- * 点到胶囊的距离
1071
- * @param {Capsule} capsule
1072
- */
1073
- Vec3.prototype.distanceCapsule = function (capsule) {
1074
- var result = this.distanceSegment(capsule);
1075
- result.distance = result.distance - capsule.radius;
1076
- var closest = this.clone().sub(result.closests[1]).normalize().multiplyScalar(capsule.radius);
1077
- result.interior = result.distance < 0;
1078
- result.closests = [this, closest];
1079
- return result;
1080
- };
1081
- return Vec3;
1082
- }(eventhandler_1.EventHandler));
1083
- exports.Vec3 = Vec3;
1084
- var _vec = v3();
1085
- var _quat = (0, Quat_1.quat)();
1086
- function v3(x, y, z) {
1087
- return new Vec3(x, y, z);
1088
- }
1089
- exports.v3 = v3;