@vvfx/sdk 0.2.8 → 0.2.9

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 (107) hide show
  1. package/dist/config.js +231 -0
  2. package/dist/exporter/config.js +18 -0
  3. package/dist/exporter/const.js +71 -0
  4. package/dist/exporter/export-media.js +878 -0
  5. package/dist/exporter/exporter.js +121 -0
  6. package/dist/exporter/index.js +1 -0
  7. package/dist/exporter/types.js +1 -0
  8. package/dist/exporter/utils.js +190 -0
  9. package/dist/exporter/wav-audio.js +50 -0
  10. package/dist/gesture-handler/gizmo/adsorption-gizmo.js +227 -0
  11. package/dist/gesture-handler/gizmo/control-gizmo.js +149 -0
  12. package/dist/gesture-handler/gizmo/gizmo.js +17 -0
  13. package/dist/gesture-handler/gizmo/icon-gizmo.js +189 -0
  14. package/dist/gesture-handler/gizmo/index.js +6 -0
  15. package/dist/gesture-handler/gizmo/item-create-gizmo.js +256 -0
  16. package/dist/gesture-handler/gizmo/loading-gizmo.js +320 -0
  17. package/dist/gesture-handler/gizmo/mask-gizmo.js +648 -0
  18. package/dist/gesture-handler/gizmo/picture-cut-gizmo.js +550 -0
  19. package/dist/gesture-handler/gizmo/picture-expand-gizmo.js +491 -0
  20. package/dist/gesture-handler/gizmo/preference-gizmo.js +148 -0
  21. package/dist/gesture-handler/gizmo/selector-gizmo.d.ts +1 -1
  22. package/dist/gesture-handler/gizmo/selector-gizmo.js +468 -0
  23. package/dist/gesture-handler/gizmo/sprite-text-edit-gizmo.js +247 -0
  24. package/dist/gesture-handler/gizmo/text-gizmo.js +1033 -0
  25. package/dist/gesture-handler/gizmo/transform-gizmo.js +1199 -0
  26. package/dist/gesture-handler/gizmo/type.js +18 -0
  27. package/dist/gesture-handler/index.js +3 -0
  28. package/dist/gesture-handler/src/gesture-handler.js +770 -0
  29. package/dist/gesture-handler/src/icons.js +24 -0
  30. package/dist/gesture-handler/utils.js +40 -0
  31. package/dist/html-overlay/anchor-navigation-runtime.js +27 -0
  32. package/dist/html-overlay/auto-height-runtime.js +132 -0
  33. package/dist/html-overlay/document-runtime.js +71 -0
  34. package/dist/html-overlay/document-transform.js +96 -0
  35. package/dist/html-overlay/dom-order.js +8 -0
  36. package/dist/html-overlay/host-message-runtime.js +24 -0
  37. package/dist/html-overlay/html-capture-runtime.js +282 -0
  38. package/dist/html-overlay/html-viewport-style.js +10 -0
  39. package/dist/html-overlay/index.js +1 -0
  40. package/dist/html-overlay/manager.js +1663 -0
  41. package/dist/html-overlay/mime-utils.js +21 -0
  42. package/dist/html-overlay/overlay-transform.js +57 -0
  43. package/dist/html-overlay/path-utils.js +35 -0
  44. package/dist/html-overlay/shell-runtime.js +12 -0
  45. package/dist/index.cjs +1 -1
  46. package/dist/index.cjs.map +1 -1
  47. package/dist/index.js +13 -75311
  48. package/dist/index.mjs +75311 -0
  49. package/dist/{index.js.map → index.mjs.map} +1 -1
  50. package/dist/layer-order.js +8 -0
  51. package/dist/math/box2.js +396 -0
  52. package/dist/math/circle.js +131 -0
  53. package/dist/math/euler.js +35 -0
  54. package/dist/math/index.js +13 -0
  55. package/dist/math/line2.js +153 -0
  56. package/dist/math/line3.js +36 -0
  57. package/dist/math/matrix4.js +207 -0
  58. package/dist/math/plane.js +52 -0
  59. package/dist/math/quaternion.js +3 -0
  60. package/dist/math/ray-caster.js +25 -0
  61. package/dist/math/ray.js +47 -0
  62. package/dist/math/type.js +1 -0
  63. package/dist/math/utils.js +77 -0
  64. package/dist/math/vector2.js +70 -0
  65. package/dist/math/vector3.js +60 -0
  66. package/dist/screen-shot/index.js +1 -0
  67. package/dist/screen-shot/screen-shot.js +113 -0
  68. package/dist/sdk-item/base-item.js +160 -0
  69. package/dist/sdk-item/card-item.js +131 -0
  70. package/dist/sdk-item/effects-item.js +144 -0
  71. package/dist/sdk-item/frame-item.js +217 -0
  72. package/dist/sdk-item/generator-item.js +188 -0
  73. package/dist/sdk-item/group-item.js +116 -0
  74. package/dist/sdk-item/index.js +39 -0
  75. package/dist/sdk-item/sprite-item.js +147 -0
  76. package/dist/sdk-item/text-item.js +223 -0
  77. package/dist/sdk-item/types.d.ts +1 -1
  78. package/dist/sdk-item/types.js +15 -0
  79. package/dist/sdk-item/video-item.js +174 -0
  80. package/dist/sdk.js +1903 -0
  81. package/dist/service/UndoRedo.js +79 -0
  82. package/dist/shared/index.d.ts +1 -0
  83. package/dist/shared/index.js +2 -0
  84. package/dist/shared/player.d.ts +1 -1
  85. package/dist/shared/player.js +9 -0
  86. package/dist/shared/spec.d.ts +1 -0
  87. package/dist/shared/spec.js +1 -0
  88. package/dist/size-adapte/index.js +1 -0
  89. package/dist/size-adapte/size-adapt.js +395 -0
  90. package/dist/types.d.ts +5 -1
  91. package/dist/types.js +17 -0
  92. package/dist/utils/background-manager.js +189 -0
  93. package/dist/utils/common-utils.js +183 -0
  94. package/dist/utils/index.js +8 -0
  95. package/dist/utils/interaction-utils.js +205 -0
  96. package/dist/utils/json-data-utils.js +1529 -0
  97. package/dist/utils/layout-utils.js +1217 -0
  98. package/dist/utils/page-data-utils.js +5397 -0
  99. package/dist/utils/player-data-utils.js +48 -0
  100. package/dist/utils/types.js +8 -0
  101. package/dist/wireframe/common/box.js +18 -0
  102. package/dist/wireframe/common/dashed-line.js +21 -0
  103. package/dist/wireframe/common/line.js +17 -0
  104. package/dist/wireframe/common/pixi-ext.js +1 -0
  105. package/dist/wireframe/common/pixi.js +31 -0
  106. package/dist/wireframe/index.js +4 -0
  107. package/package.json +10 -3
@@ -0,0 +1,8 @@
1
+ export function orderSDKCanvasLayers({ container, playerContainer, htmlOverlayLayer, gestureCanvas, }) {
2
+ ;
3
+ [playerContainer, htmlOverlayLayer, gestureCanvas].forEach(layer => {
4
+ if (layer?.parentElement === container) {
5
+ container.appendChild(layer);
6
+ }
7
+ });
8
+ }
@@ -0,0 +1,396 @@
1
+ import { Line2 } from './line2';
2
+ import { Vector2 } from './vector2';
3
+ /**
4
+ * @class 二维包围盒
5
+ */
6
+ export class Box2 {
7
+ /**
8
+ * @member {Vector2[]} corners 二维包围盒角点
9
+ */
10
+ corners = [];
11
+ min = new Vector2(Infinity, Infinity);
12
+ max = new Vector2(-Infinity, -Infinity);
13
+ /**
14
+ * 构造函数,传入值为空时表示空包围盒
15
+ * @param {Vector2} [min=new Vector2(Infinity, Infinity)] 最小点
16
+ * @param {Vector2} [max=new Vector2(-Infinity, -Infinity)] 最大点
17
+ */
18
+ constructor(min = new Vector2(Infinity, Infinity), max = new Vector2(-Infinity, -Infinity)) {
19
+ this.min = min.clone();
20
+ this.max = max.clone();
21
+ if (!this.isEmpty()) {
22
+ this.corners = [
23
+ new Vector2(max.x, min.y),
24
+ max.clone(),
25
+ new Vector2(min.x, max.y),
26
+ min.clone(),
27
+ ];
28
+ }
29
+ else {
30
+ this.corners = [];
31
+ }
32
+ }
33
+ /**
34
+ * 通过最大最小点设置二维包围盒
35
+ * @param {Vector2} min 最小点
36
+ * @param {Vector2} max 最大点
37
+ * @returns {Box2} 二维包围盒
38
+ */
39
+ set(min, max) {
40
+ this.min.copyFrom(min);
41
+ this.max.copyFrom(max);
42
+ this.corners = [
43
+ new Vector2(max.x, min.y),
44
+ max.clone(),
45
+ new Vector2(min.x, max.y),
46
+ min.clone(),
47
+ ];
48
+ return this;
49
+ }
50
+ /**
51
+ * 通过角点设置二维包围盒
52
+ * @param {Vector2[]} vecArray 二维空间点数组
53
+ * @returns {Box2} 二维包围盒
54
+ */
55
+ setFromVec2Array(vecArray) {
56
+ this.min = new Vector2().copyFrom(vecArray[0]);
57
+ this.max = new Vector2().copyFrom(vecArray[0]);
58
+ vecArray.forEach(v => {
59
+ this.min.min(v);
60
+ this.max.max(v);
61
+ });
62
+ this.corners = [
63
+ new Vector2(this.max.x, this.min.y),
64
+ this.max.clone(),
65
+ new Vector2(this.min.x, this.max.y),
66
+ this.min.clone(),
67
+ ];
68
+ return this;
69
+ }
70
+ setFromCorners(corners) {
71
+ if (corners.length !== 4) {
72
+ throw new Error('corners length should be 4');
73
+ }
74
+ this.corners = [];
75
+ corners.forEach(corner => {
76
+ this.corners.push(corner.clone());
77
+ this.min.min(corner);
78
+ this.max.max(corner);
79
+ });
80
+ return this;
81
+ }
82
+ /**
83
+ * 通过屏幕坐标点设置二维包围盒 - 点为屏幕坐标点,x正方向为右,y正方向为向上
84
+ * @param vecArray 屏幕坐标点
85
+ */
86
+ setFromVec2ArrayWithOutCorners(vecArray) {
87
+ this.min = new Vector2().copyFrom(vecArray[0]);
88
+ this.max = new Vector2().copyFrom(vecArray[0]);
89
+ vecArray.forEach(v => {
90
+ this.min = this.min.min(v);
91
+ this.max = this.max.max(v);
92
+ });
93
+ this.corners.push(new Vector2(this.max.x, this.min.y));
94
+ this.corners.push(new Vector2(this.max.x, this.max.y));
95
+ this.corners.push(new Vector2(this.min.x, this.max.y));
96
+ this.corners.push(new Vector2(this.min.x, this.min.y));
97
+ return this;
98
+ }
99
+ /**
100
+ * 通过中心与大小设置二维包围盒
101
+ * @param {Vector2} center 二维中心点
102
+ * @param {Vector2} size 二维大小
103
+ * @returns {Box2} 二维包围盒
104
+ */
105
+ setFromCenterAndSize(center, size) {
106
+ const halfSize = new Vector2().copyFrom(size).multiply(0.5);
107
+ this.min.copyFrom(center).subtract(halfSize);
108
+ this.max.copyFrom(center).add(halfSize);
109
+ this.corners = [
110
+ new Vector2(this.max.x, this.min.y),
111
+ this.max.clone(),
112
+ new Vector2(this.min.x, this.max.y),
113
+ this.min.clone(),
114
+ ];
115
+ return this;
116
+ }
117
+ /**
118
+ * 克隆二维包围盒
119
+ * @returns {Box2} 克隆结果
120
+ */
121
+ clone() {
122
+ return new Box2().copyFrom(this);
123
+ }
124
+ /**
125
+ * 复制二维包围盒
126
+ * @param {Box2} box 二维包围盒
127
+ * @returns {Box2} 复制结果
128
+ */
129
+ copyFrom(box) {
130
+ this.corners = [];
131
+ this.min.copyFrom(box.min);
132
+ this.max.copyFrom(box.max);
133
+ box.corners.forEach(corner => {
134
+ this.corners.push(corner.clone());
135
+ });
136
+ return this;
137
+ }
138
+ /**
139
+ * 二维包围盒置空
140
+ * @returns {Box2} 置空结果
141
+ */
142
+ makeEmpty() {
143
+ this.min.x = this.min.y = Infinity;
144
+ this.max.x = this.max.y = -Infinity;
145
+ this.corners = [];
146
+ return this;
147
+ }
148
+ /**
149
+ * 二维包围盒判空
150
+ * @returns {boolean} 判空结果
151
+ */
152
+ isEmpty() {
153
+ // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
154
+ return (this.max.x < this.min.x) || (this.max.y < this.min.y);
155
+ }
156
+ /**
157
+ * 获取二维包围盒角点
158
+ * @returns {Vector2[]} 二维包围盒角点
159
+ */
160
+ getCorners() {
161
+ const res = [];
162
+ this.corners.forEach(corner => {
163
+ res.push(corner.clone());
164
+ });
165
+ return res;
166
+ }
167
+ /**
168
+ * 获取二维包围盒中心点
169
+ * @param {Vector2} [target=new Vector2()] 目标点(用以存放二维包围盒中心点)
170
+ * @returns {Vector2} 二维包围盒中心点
171
+ */
172
+ getCenter(target = new Vector2()) {
173
+ return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiply(0.5);
174
+ }
175
+ /**
176
+ * 获取二维包围盒大小
177
+ * @param {Vector2} [target=new Vector2()] 目标向量(用以存放二维包围盒大小)
178
+ * @returns {Vector2} 二维包围盒大小
179
+ */
180
+ getSize(target = new Vector2()) {
181
+ return this.isEmpty() ? target.set(0, 0) : target.subtractVectors(this.max, this.min);
182
+ }
183
+ /**
184
+ * 通过二维空间点扩展二维包围盒
185
+ * @param {Vector2} point 二维空间点
186
+ * @returns {Box2} 扩展包围盒
187
+ */
188
+ expandByPoint(point) {
189
+ this.min.min(point);
190
+ this.max.max(point);
191
+ return this;
192
+ }
193
+ /**
194
+ * 通过向量扩展二维包围盒
195
+ * @param {Vector2} vector 二维向量
196
+ * @returns {Box2} 扩展结果
197
+ */
198
+ expandByVector(vector) {
199
+ this.min.subtract(vector);
200
+ this.max.add(vector);
201
+ return this;
202
+ }
203
+ /**
204
+ * 通过大小扩展二维包围盒
205
+ * @param {number} scalar 扩展大小
206
+ * @returns {Box2} 扩展结果
207
+ */
208
+ expandByScalar(scalar) {
209
+ this.min.add(-scalar);
210
+ this.max.add(scalar);
211
+ return this;
212
+ }
213
+ /**
214
+ * 判断二维包围盒是否包含二维空间点
215
+ * @param {Vector2} point 二维空间点
216
+ * @param {boolean} [isOrthogonal=true] 包围盒正交判断(默认为true)
217
+ * @returns {boolean} 点包含判断结果
218
+ */
219
+ containsPoint(point, isOrthogonal = true) {
220
+ if (isOrthogonal) {
221
+ return point.x < this.min.x || point.x > this.max.x ||
222
+ point.y < this.min.y || point.y > this.max.y ? false : true;
223
+ }
224
+ else {
225
+ if (this.isEmpty()) {
226
+ return false;
227
+ }
228
+ for (let i = 0; i < this.corners.length; i++) {
229
+ const corner = this.corners[i];
230
+ const next = this.corners[(i + 1) % 4];
231
+ const edge = new Vector2(next.x - corner.x, next.y - corner.y);
232
+ const vec = new Vector2(point.x - corner.x, point.y - corner.y);
233
+ if (edge.cross(vec) < 0) {
234
+ return false;
235
+ }
236
+ }
237
+ return true;
238
+ }
239
+ }
240
+ /**
241
+ * 判断二维包围盒包含关系(if this contains other)
242
+ * @param {Box2} box 其它包围盒
243
+ * @returns {boolean} 二维包围盒包含判断结果
244
+ */
245
+ containsBox(box) {
246
+ return this.min.x <= box.min.x
247
+ && box.max.x <= this.max.x
248
+ && this.min.y <= box.min.y
249
+ && box.max.y <= this.max.y;
250
+ }
251
+ /**
252
+ * 获取点以包围盒左上角顶点为原点的相对位置
253
+ * @param {Vector2} point 指定二维空间点
254
+ * @param {Vector2} [target=new Vector2()] 目标空间点
255
+ * @returns {Vector2} 计算结果空间点
256
+ */
257
+ getParameter(point, target = new Vector2()) {
258
+ // This can potentially have a divide by zero if the box
259
+ // has a size dimension of 0.
260
+ return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y));
261
+ }
262
+ /**
263
+ * 求点与二维包围盒的最近点
264
+ * @param {Vector2} point 二维空间点
265
+ * @param {Vector2} [target=new Vector2()] 结果点
266
+ * @returns {Vector2} 二维空间点
267
+ */
268
+ clampPoint(point, target = new Vector2()) {
269
+ return target.copyFrom(point).clamp(this.min, this.max);
270
+ }
271
+ /**
272
+ * 求点到二维包围盒的距离
273
+ * @param {Vector2} point 二维空间点
274
+ * @returns {number} 距离
275
+ */
276
+ distanceToPoint(point) {
277
+ const clampedPoint = new Vector2().copyFrom(point).clamp(this.min, this.max);
278
+ return clampedPoint.subtract(point).length();
279
+ }
280
+ /**
281
+ * 二维包围盒求交集
282
+ * @param {Box2} box 二维包围盒
283
+ * @returns {Box2} 求交结果
284
+ */
285
+ intersect(box) {
286
+ this.min.max(box.min);
287
+ this.max.min(box.max);
288
+ if (this.min.x > this.max.x || this.min.y > this.max.y) {
289
+ return this.makeEmpty();
290
+ }
291
+ return this;
292
+ }
293
+ /**
294
+ * 二维包围盒求并集
295
+ * @param {Box2} box 二维包围盒
296
+ * @returns {Box2} 求并结果
297
+ */
298
+ union(target) {
299
+ if (target instanceof Box2) {
300
+ this.min.min(target.min);
301
+ this.max.max(target.max);
302
+ }
303
+ else {
304
+ this.min.min(target);
305
+ this.max.max(target);
306
+ }
307
+ this.corners = [
308
+ new Vector2(this.max.x, this.min.y),
309
+ this.max.clone(),
310
+ new Vector2(this.min.x, this.max.y),
311
+ this.min.clone(),
312
+ ];
313
+ return this;
314
+ }
315
+ /**
316
+ * 二维包围盒位移
317
+ * @param {Vector2} offset 位移向量
318
+ * @returns {Box2} 位移结果
319
+ */
320
+ translate(offset) {
321
+ this.min.add(offset);
322
+ this.max.add(offset);
323
+ this.corners.forEach(corner => {
324
+ corner.add(offset);
325
+ });
326
+ return this;
327
+ }
328
+ scale(scalar, anchor) {
329
+ anchor ??= this.getCenter();
330
+ const resultScalar = typeof scalar === 'number' ? new Vector2(scalar, scalar) : new Vector2(scalar.x, scalar.y);
331
+ this.min.scaleByCenter(resultScalar, anchor);
332
+ this.max.scaleByCenter(resultScalar, anchor);
333
+ this.corners.forEach(corner => {
334
+ corner.scaleByCenter(resultScalar, anchor);
335
+ });
336
+ return this;
337
+ }
338
+ /**
339
+ * 二维包围盒判等
340
+ * @param {Box2} box 二维包围盒
341
+ * @returns {boolean} 判等结果
342
+ */
343
+ equals(box) {
344
+ return box.min.equals(this.min) && box.max.equals(this.max);
345
+ }
346
+ /**
347
+ * 判断二维包围盒相交关系(if this intersect other)
348
+ * @param {Box2} box 二维包围盒
349
+ * @param {boolean} [isOrthogonal=true] 正交判断(当前包围盒)
350
+ * @returns {boolean} 相交判断结果
351
+ */
352
+ intersectsBox(box, isOrthogonal = true) {
353
+ // using 4 splitting planes to rule out intersections
354
+ // 基于点判断
355
+ if (isOrthogonal) {
356
+ return !(box.max.x < this.min.x
357
+ || box.min.x > this.max.x
358
+ || box.max.y < this.min.y
359
+ || box.min.y > this.max.y);
360
+ }
361
+ else {
362
+ if (!this.isEmpty()) {
363
+ for (let i = 0; i < this.corners.length; i++) {
364
+ const line = new Line2(this.corners[i], this.corners[(i + 1) % 4]);
365
+ if (box.containsPoint(this.corners[i], false)) {
366
+ return true;
367
+ }
368
+ for (let j = 0; j < box.corners.length; j++) {
369
+ const boxLine = new Line2(box.corners[j], box.corners[(j + 1) % 4]);
370
+ if (this.containsPoint(box.corners[j], false)) {
371
+ return true;
372
+ }
373
+ if (line.crossWithLine(boxLine)) {
374
+ return true;
375
+ }
376
+ }
377
+ }
378
+ }
379
+ for (let i = 0; i < box.corners.length; i++) {
380
+ const state = this.containsPoint(box.corners[i], false);
381
+ const stateOther = box.containsPoint(this.corners[i], false);
382
+ if (state || stateOther) {
383
+ return true;
384
+ }
385
+ }
386
+ return false;
387
+ }
388
+ }
389
+ rotate(angle, center) {
390
+ center ??= this.getCenter();
391
+ const corners = this.corners.map(corner => corner.rotateAround(center, angle));
392
+ this.makeEmpty();
393
+ this.setFromVec2Array(corners);
394
+ return this;
395
+ }
396
+ }
@@ -0,0 +1,131 @@
1
+ import { Vector2 } from './vector2';
2
+ export class Circle {
3
+ center;
4
+ radius;
5
+ constructor(center = new Vector2(), radius = 0) {
6
+ this.center = center.clone();
7
+ this.radius = radius;
8
+ }
9
+ /**
10
+ * 通过中心点与大小设置圆
11
+ * @param {Vector2} center 圆心
12
+ * @param {number} radius 半径
13
+ * @returns {Circle}
14
+ */
15
+ set(center, radius) {
16
+ this.center = new Vector2().copyFrom(center);
17
+ this.radius = radius;
18
+ return this;
19
+ }
20
+ /**
21
+ * 克隆圆
22
+ * @returns {Circle} 克隆结果
23
+ */
24
+ clone() {
25
+ return new Circle().copy(this);
26
+ }
27
+ /**
28
+ * 复制圆
29
+ * @param {Circle} circle 复制对象
30
+ * @returns {Circle} 复制结果
31
+ */
32
+ copy(circle) {
33
+ this.center.copyFrom(circle.center);
34
+ this.radius = circle.radius;
35
+ return this;
36
+ }
37
+ /**
38
+ * 圆置空
39
+ * @returns {Circle} 置空结果
40
+ */
41
+ makeEmpty() {
42
+ this.center = new Vector2();
43
+ this.radius = 0;
44
+ return this;
45
+ }
46
+ /**
47
+ * 圆判空
48
+ * @returns {boolean} 判空结果
49
+ */
50
+ isEmpty() {
51
+ // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
52
+ return this.radius <= 0;
53
+ }
54
+ /**
55
+ * 获取圆心
56
+ * @param {Vector2} [target=new Vector2()] 目标结果对象
57
+ * @returns {Vector2} 圆心
58
+ */
59
+ getCenter(target = new Vector2()) {
60
+ target.copyFrom(this.center);
61
+ return target;
62
+ }
63
+ /**
64
+ * 获取半径
65
+ * @returns {number} 半径
66
+ */
67
+ getRadius() {
68
+ return this.radius;
69
+ }
70
+ /**
71
+ * 通过二维空间点扩展圆
72
+ * @param {Vector2} point 二维空间点
73
+ * @returns {Circle} 扩展结果
74
+ */
75
+ expandByPoint(point) {
76
+ this.radius = this.center.distanceTo(point);
77
+ return this;
78
+ }
79
+ /**
80
+ * 通过大小扩展圆
81
+ * @param {number} scalar 扩展大小
82
+ * @returns {Circle} 扩展结果
83
+ */
84
+ expandByScalar(scalar) {
85
+ this.radius += scalar;
86
+ return this;
87
+ }
88
+ /**
89
+ * 判断圆是否包含二维空间点
90
+ * @param {Vector2} point 二维空间点
91
+ * @returns {boolean} 包含判断结果
92
+ */
93
+ containsPoint(point) {
94
+ return this.center.distanceTo(point) < this.radius;
95
+ }
96
+ /**
97
+ * 判断圆是否包含二维包围盒
98
+ * @param {Box2} box 二维包围盒
99
+ * @returns {boolean} 包含判断结果
100
+ */
101
+ containsBox(box) {
102
+ for (let i = 0; i < 4; i++) {
103
+ if (!this.containsPoint(box.corners[i])) {
104
+ return false;
105
+ }
106
+ }
107
+ return true;
108
+ }
109
+ /**
110
+ * 判断圆与二维包围盒的相交关系
111
+ * @param {Box2} box 二维包围盒
112
+ * @returns {boolean} 相交判断结果
113
+ */
114
+ intersectsBox(box) {
115
+ // using 4 splitting planes to rule out intersections
116
+ for (let i = 0; i < 4; i++) {
117
+ if (this.containsPoint(box.corners[i])) {
118
+ return true;
119
+ }
120
+ }
121
+ return false;
122
+ }
123
+ /**
124
+ * 求点与圆的最短距离
125
+ * @param {Vector2} point 二维空间点
126
+ * @returns {number} 距离
127
+ */
128
+ distanceToPoint(point) {
129
+ return this.center.distanceTo(point) - this.radius;
130
+ }
131
+ }
@@ -0,0 +1,35 @@
1
+ import { math } from '../shared';
2
+ import { Matrix4 } from './matrix4';
3
+ import { DEG2RAD, RAD2DEG } from './utils';
4
+ import { Vector3 } from './vector3';
5
+ export class Euler extends math.Euler {
6
+ constructor(x = 0, y = 0, z = 0, order = math.EulerOrder.XYZ) {
7
+ super(x, y, z, order);
8
+ }
9
+ getInvertMatrixByEuler() {
10
+ const matrix = new Matrix4().makeRotationFromEuler(this).invert();
11
+ return matrix;
12
+ }
13
+ /**
14
+ * 欧拉角保存于三维向量(应用于计算)
15
+ * @param {Vector3} [optionalResult] 目标保存对象
16
+ * @returns {Vector3} 保存结果
17
+ */
18
+ toDegreeVector3(optionalResult) {
19
+ if (optionalResult) {
20
+ return optionalResult.set(this.x * RAD2DEG, this.y * RAD2DEG, this.z * RAD2DEG);
21
+ }
22
+ else {
23
+ return new Vector3(this.x * RAD2DEG, this.y * RAD2DEG, this.z * RAD2DEG);
24
+ }
25
+ }
26
+ /**
27
+ * 由角度三维向量构建欧拉角
28
+ * @param {Vector3} v 角度三维向量
29
+ * @param {EulerOrder} [order] 欧拉角顺序,默认为ZYX
30
+ * @returns {Euler} 欧拉角
31
+ */
32
+ setFromDegreeVector3(degree, order) {
33
+ return this.set(degree.x * DEG2RAD, degree.y * DEG2RAD, degree.z * DEG2RAD, order ?? this.order);
34
+ }
35
+ }
@@ -0,0 +1,13 @@
1
+ export * from './box2';
2
+ export * from './circle';
3
+ export * from './euler';
4
+ export * from './line2';
5
+ export * from './line3';
6
+ export * from './matrix4';
7
+ export * from './plane';
8
+ export * from './quaternion';
9
+ export * from './ray-caster';
10
+ export * from './ray';
11
+ export * from './utils';
12
+ export * from './vector2';
13
+ export * from './vector3';