@vvfx/sdk 0.2.8 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.js +231 -0
- package/dist/exporter/config.js +18 -0
- package/dist/exporter/const.js +71 -0
- package/dist/exporter/export-media.js +878 -0
- package/dist/exporter/exporter.js +121 -0
- package/dist/exporter/index.js +1 -0
- package/dist/exporter/types.js +1 -0
- package/dist/exporter/utils.js +190 -0
- package/dist/exporter/wav-audio.js +50 -0
- package/dist/gesture-handler/gizmo/adsorption-gizmo.js +227 -0
- package/dist/gesture-handler/gizmo/control-gizmo.js +149 -0
- package/dist/gesture-handler/gizmo/gizmo.js +17 -0
- package/dist/gesture-handler/gizmo/icon-gizmo.js +189 -0
- package/dist/gesture-handler/gizmo/index.js +6 -0
- package/dist/gesture-handler/gizmo/item-create-gizmo.js +256 -0
- package/dist/gesture-handler/gizmo/loading-gizmo.js +320 -0
- package/dist/gesture-handler/gizmo/mask-gizmo.js +648 -0
- package/dist/gesture-handler/gizmo/picture-cut-gizmo.js +550 -0
- package/dist/gesture-handler/gizmo/picture-expand-gizmo.js +491 -0
- package/dist/gesture-handler/gizmo/preference-gizmo.js +148 -0
- package/dist/gesture-handler/gizmo/selector-gizmo.d.ts +1 -1
- package/dist/gesture-handler/gizmo/selector-gizmo.js +468 -0
- package/dist/gesture-handler/gizmo/sprite-text-edit-gizmo.js +247 -0
- package/dist/gesture-handler/gizmo/text-gizmo.js +1033 -0
- package/dist/gesture-handler/gizmo/transform-gizmo.js +1199 -0
- package/dist/gesture-handler/gizmo/type.js +18 -0
- package/dist/gesture-handler/index.js +3 -0
- package/dist/gesture-handler/src/gesture-handler.js +770 -0
- package/dist/gesture-handler/src/icons.js +24 -0
- package/dist/gesture-handler/utils.js +40 -0
- package/dist/html-overlay/anchor-navigation-runtime.js +27 -0
- package/dist/html-overlay/auto-height-layout.d.ts +6 -0
- package/dist/html-overlay/auto-height-layout.js +7 -0
- package/dist/html-overlay/auto-height-runtime.js +132 -0
- package/dist/html-overlay/document-runtime.js +71 -0
- package/dist/html-overlay/document-transform.js +96 -0
- package/dist/html-overlay/dom-order.js +8 -0
- package/dist/html-overlay/host-message-runtime.js +24 -0
- package/dist/html-overlay/html-capture-runtime.js +282 -0
- package/dist/html-overlay/html-viewport-style.js +10 -0
- package/dist/html-overlay/index.js +1 -0
- package/dist/html-overlay/manager.d.ts +1 -0
- package/dist/html-overlay/manager.js +1677 -0
- package/dist/html-overlay/mime-utils.js +21 -0
- package/dist/html-overlay/overlay-transform.js +57 -0
- package/dist/html-overlay/path-utils.js +35 -0
- package/dist/html-overlay/shell-runtime.js +12 -0
- package/dist/index.cjs +34 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -75311
- package/dist/index.mjs +75337 -0
- package/dist/index.mjs.map +1 -0
- package/dist/layer-order.js +8 -0
- package/dist/math/box2.js +396 -0
- package/dist/math/circle.js +131 -0
- package/dist/math/euler.js +35 -0
- package/dist/math/index.js +13 -0
- package/dist/math/line2.js +153 -0
- package/dist/math/line3.js +36 -0
- package/dist/math/matrix4.js +207 -0
- package/dist/math/plane.js +52 -0
- package/dist/math/quaternion.js +3 -0
- package/dist/math/ray-caster.js +25 -0
- package/dist/math/ray.js +47 -0
- package/dist/math/type.js +1 -0
- package/dist/math/utils.js +77 -0
- package/dist/math/vector2.js +70 -0
- package/dist/math/vector3.js +60 -0
- package/dist/screen-shot/index.js +1 -0
- package/dist/screen-shot/screen-shot.js +113 -0
- package/dist/sdk-item/base-item.js +160 -0
- package/dist/sdk-item/card-item.js +131 -0
- package/dist/sdk-item/effects-item.js +144 -0
- package/dist/sdk-item/frame-item.js +217 -0
- package/dist/sdk-item/generator-item.js +188 -0
- package/dist/sdk-item/group-item.js +116 -0
- package/dist/sdk-item/index.js +39 -0
- package/dist/sdk-item/sprite-item.js +147 -0
- package/dist/sdk-item/text-item.js +223 -0
- package/dist/sdk-item/types.d.ts +1 -1
- package/dist/sdk-item/types.js +15 -0
- package/dist/sdk-item/video-item.js +174 -0
- package/dist/sdk.js +1908 -0
- package/dist/service/UndoRedo.js +79 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +2 -0
- package/dist/shared/player.d.ts +1 -1
- package/dist/shared/player.js +9 -0
- package/dist/shared/spec.d.ts +1 -0
- package/dist/shared/spec.js +1 -0
- package/dist/size-adapte/index.js +1 -0
- package/dist/size-adapte/size-adapt.js +395 -0
- package/dist/types.d.ts +5 -1
- package/dist/types.js +17 -0
- package/dist/utils/background-manager.js +189 -0
- package/dist/utils/common-utils.js +183 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/interaction-utils.js +205 -0
- package/dist/utils/json-data-utils.js +1529 -0
- package/dist/utils/layout-utils.js +1217 -0
- package/dist/utils/page-data-utils.js +5397 -0
- package/dist/utils/player-data-utils.js +48 -0
- package/dist/utils/types.js +8 -0
- package/dist/wireframe/common/box.js +18 -0
- package/dist/wireframe/common/dashed-line.js +21 -0
- package/dist/wireframe/common/line.js +17 -0
- package/dist/wireframe/common/pixi-ext.js +1 -0
- package/dist/wireframe/common/pixi.js +31 -0
- package/dist/wireframe/index.js +4 -0
- package/package.json +10 -3
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { clamp } from './utils';
|
|
2
|
+
import { Vector2 } from './vector2';
|
|
3
|
+
/**
|
|
4
|
+
* @class 二维线段
|
|
5
|
+
*/
|
|
6
|
+
export class Line2 {
|
|
7
|
+
start = new Vector2();
|
|
8
|
+
end = new Vector2();
|
|
9
|
+
constructor(start = new Vector2(), end = new Vector2()) {
|
|
10
|
+
this.start.copyFrom(start);
|
|
11
|
+
this.end.copyFrom(end);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 设置二维线段
|
|
15
|
+
* @param {Vector2} start 线段起点
|
|
16
|
+
* @param {Vector2} end 线段终点
|
|
17
|
+
* @returns {Line2} 二维线段
|
|
18
|
+
*/
|
|
19
|
+
set(start, end) {
|
|
20
|
+
this.start.copyFrom(start);
|
|
21
|
+
this.end.copyFrom(end);
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 复制二维线段
|
|
26
|
+
* @param {Line2} line 复制对象
|
|
27
|
+
* @returns {Line2} 复制结果
|
|
28
|
+
*/
|
|
29
|
+
copyFrom(line) {
|
|
30
|
+
this.start.copyFrom(line.start);
|
|
31
|
+
this.end.copyFrom(line.end);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 二维线段求方向
|
|
36
|
+
* @returns {Vector2} 二维线段方向
|
|
37
|
+
*/
|
|
38
|
+
direction() {
|
|
39
|
+
return new Vector2().subtractVectors(this.end, this.start).normalize();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 二维线段求中点
|
|
43
|
+
* @param {Vector2} [target=new Vector2()] 目标保存对象
|
|
44
|
+
* @returns {Vector2} 二维线段中点
|
|
45
|
+
*/
|
|
46
|
+
getCenter(target = new Vector2()) {
|
|
47
|
+
return target.addVectors(this.start, this.end).multiply(0.5);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 二维线段向量值
|
|
51
|
+
* @param {Vector2} [target=new Vector2()] 目标保存对象
|
|
52
|
+
* @returns {Vector2} 二维线段向量值
|
|
53
|
+
*/
|
|
54
|
+
delta(target = new Vector2()) {
|
|
55
|
+
return target.subtractVectors(this.end, this.start);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 二维线段欧式距离平方(应用于计算)
|
|
59
|
+
* @returns {number} 计算结果
|
|
60
|
+
*/
|
|
61
|
+
distanceSq() {
|
|
62
|
+
return this.start.distanceSquared(this.end);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 二维线段欧式距离
|
|
66
|
+
* @returns {number} 计算结果
|
|
67
|
+
*/
|
|
68
|
+
distance() {
|
|
69
|
+
return this.start.distance(this.end);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 求二维线段比例点
|
|
73
|
+
* @param {number} t 比例值
|
|
74
|
+
* @param {Vector2} target 目标保存对象
|
|
75
|
+
* @returns {Vector2} 比例点结果
|
|
76
|
+
*/
|
|
77
|
+
at(t, target = new Vector2()) {
|
|
78
|
+
return this.delta(target).multiply(t).add(this.start);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 求点与线段的最短距离
|
|
82
|
+
* @param {Vector2} point 二维空间点
|
|
83
|
+
* @param {boolean} clampToLine 是否限制于线段内
|
|
84
|
+
* @returns {number} 距离结果
|
|
85
|
+
*/
|
|
86
|
+
closestPointToPointParameter(point, clampToLine) {
|
|
87
|
+
const startP = new Vector2();
|
|
88
|
+
const startEnd = new Vector2();
|
|
89
|
+
startP.subtractVectors(point, this.start);
|
|
90
|
+
startEnd.subtractVectors(this.end, this.start);
|
|
91
|
+
const se2se = startEnd.dot(startEnd);
|
|
92
|
+
const se2sp = startEnd.dot(startP);
|
|
93
|
+
let t = se2sp / se2se;
|
|
94
|
+
if (clampToLine) {
|
|
95
|
+
t = clamp(t, 0, 1);
|
|
96
|
+
}
|
|
97
|
+
return t;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 求点与线段的最近交点
|
|
101
|
+
* @param {Vector2} point 二维空间点
|
|
102
|
+
* @param {boolean} clampToLine 是否限制于线段内
|
|
103
|
+
* @param {Vector2} target 目标保存对象
|
|
104
|
+
* @returns {Vector2} 最近交点
|
|
105
|
+
*/
|
|
106
|
+
closestPointToPoint(point, clampToLine, target = new Vector2()) {
|
|
107
|
+
const t = this.closestPointToPointParameter(point, clampToLine);
|
|
108
|
+
return this.delta(target).multiply(t).add(this.start);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 二维线段判等
|
|
112
|
+
* @param {Line2} line 二维线段
|
|
113
|
+
* @returns {boolean} 判等结果
|
|
114
|
+
*/
|
|
115
|
+
equals(line) {
|
|
116
|
+
return line.start.equals(this.start) && line.end.equals(this.end);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 克隆二维线段
|
|
120
|
+
* @returns {Line2} 克隆结果
|
|
121
|
+
*/
|
|
122
|
+
clone() {
|
|
123
|
+
return new Line2().copyFrom(this);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* 二维线段求长度
|
|
127
|
+
* @returns {number} 长度
|
|
128
|
+
*/
|
|
129
|
+
length() {
|
|
130
|
+
return new Vector2().subtractVectors(this.end, this.start).length();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 二维线段判断相交
|
|
134
|
+
* @param {Line2} other 二维线段
|
|
135
|
+
* @returns {boolean} 相交判断结果
|
|
136
|
+
*/
|
|
137
|
+
crossWithLine(other) {
|
|
138
|
+
const vecA = this.delta();
|
|
139
|
+
const vecB = other.delta();
|
|
140
|
+
const vecAStart = new Vector2().subtractVectors(other.start, this.start);
|
|
141
|
+
const vecAEnd = new Vector2().subtractVectors(other.end, this.start);
|
|
142
|
+
const vecBStart = new Vector2().subtractVectors(this.start, other.start);
|
|
143
|
+
const vecBEnd = new Vector2().subtractVectors(this.end, other.start);
|
|
144
|
+
const crossA2BStart = vecAStart.cross(vecA);
|
|
145
|
+
const crossA2BEnd = vecAEnd.cross(vecA);
|
|
146
|
+
const crossB2AStart = vecBStart.cross(vecB);
|
|
147
|
+
const crossB2AEnd = vecBEnd.cross(vecB);
|
|
148
|
+
if (crossA2BStart * crossA2BEnd < 0 && crossB2AStart * crossB2AEnd < 0) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { clamp } from './utils';
|
|
2
|
+
import { Vector3 } from './vector3';
|
|
3
|
+
/**
|
|
4
|
+
* @class 三维线段
|
|
5
|
+
*/
|
|
6
|
+
export class Line3 {
|
|
7
|
+
start;
|
|
8
|
+
end;
|
|
9
|
+
/**
|
|
10
|
+
* 构造函数
|
|
11
|
+
* @param {Vector3} [start=new Vector3()] 线段起点,默认值为(0, 0, 0)
|
|
12
|
+
* @param {Vector3} [end=new Vector3()] 线段终点,默认值为(0, 0, 0)
|
|
13
|
+
*/
|
|
14
|
+
constructor(start = new Vector3(), end = new Vector3()) {
|
|
15
|
+
this.start = start.clone();
|
|
16
|
+
this.end = end.clone();
|
|
17
|
+
}
|
|
18
|
+
closestPointToPointParameter(point, clampToLine = false) {
|
|
19
|
+
const startP = new Vector3().subtractVectors(point, this.start);
|
|
20
|
+
const startEnd = new Vector3().subtractVectors(this.end, this.start);
|
|
21
|
+
const startEnd2 = startEnd.dot(startEnd);
|
|
22
|
+
const startEnd_startP = startEnd.dot(startP);
|
|
23
|
+
let t = startEnd_startP / startEnd2;
|
|
24
|
+
if (clampToLine) {
|
|
25
|
+
t = clamp(t, 0, 1);
|
|
26
|
+
}
|
|
27
|
+
return t;
|
|
28
|
+
}
|
|
29
|
+
closestPointToPoint(point, clampToLine = false) {
|
|
30
|
+
const t = this.closestPointToPointParameter(point, clampToLine);
|
|
31
|
+
return this.delta().multiply(t).add(this.start);
|
|
32
|
+
}
|
|
33
|
+
delta() {
|
|
34
|
+
return new Vector3().subtractVectors(this.end, this.start);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { math } from '../shared';
|
|
2
|
+
import { Vector3 } from './vector3';
|
|
3
|
+
export class Matrix4 extends math.Matrix4 {
|
|
4
|
+
/**
|
|
5
|
+
* 通过数组创建矩阵
|
|
6
|
+
* @param array - 数组
|
|
7
|
+
* @param [offset=0] - 起始偏移值
|
|
8
|
+
* @returns 矩阵
|
|
9
|
+
*/
|
|
10
|
+
static fromArray(array, offset = 0) {
|
|
11
|
+
return new Matrix4().setFromArray(array, offset);
|
|
12
|
+
}
|
|
13
|
+
clone() {
|
|
14
|
+
const e = this.elements;
|
|
15
|
+
return new Matrix4(e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7], e[8], e[9], e[10], e[11], e[12], e[13], e[14], e[15]);
|
|
16
|
+
}
|
|
17
|
+
compose(translation, rotation, scale, anchor = Vector3.ZERO) {
|
|
18
|
+
const te = this.elements;
|
|
19
|
+
const { x, y, z, w } = rotation;
|
|
20
|
+
const l = -anchor.x;
|
|
21
|
+
const m = -anchor.y;
|
|
22
|
+
const n = -anchor.z;
|
|
23
|
+
const x2 = x + x;
|
|
24
|
+
const y2 = y + y;
|
|
25
|
+
const z2 = z + z;
|
|
26
|
+
const xx = x * x2;
|
|
27
|
+
const xy = x * y2;
|
|
28
|
+
const xz = x * z2;
|
|
29
|
+
const yy = y * y2;
|
|
30
|
+
const yz = y * z2;
|
|
31
|
+
const zz = z * z2;
|
|
32
|
+
const wx = w * x2;
|
|
33
|
+
const wy = w * y2;
|
|
34
|
+
const wz = w * z2;
|
|
35
|
+
const { x: sx, y: sy, z: sz } = scale;
|
|
36
|
+
te[0] = (1 - (yy + zz)) * sx;
|
|
37
|
+
te[1] = (xy + wz) * sx;
|
|
38
|
+
te[2] = (xz - wy) * sx;
|
|
39
|
+
te[3] = 0;
|
|
40
|
+
te[4] = (xy - wz) * sy;
|
|
41
|
+
te[5] = (1 - (xx + zz)) * sy;
|
|
42
|
+
te[6] = (yz + wx) * sy;
|
|
43
|
+
te[7] = 0;
|
|
44
|
+
te[8] = (xz + wy) * sz;
|
|
45
|
+
te[9] = (yz - wx) * sz;
|
|
46
|
+
te[10] = (1 - (xx + yy)) * sz;
|
|
47
|
+
te[11] = 0;
|
|
48
|
+
te[12] = l * te[0] + m * te[4] + n * te[8] - l + translation.x;
|
|
49
|
+
te[13] = l * te[1] + m * te[5] + n * te[9] - m + translation.y;
|
|
50
|
+
te[14] = l * te[2] + m * te[6] + n * te[10] - n + translation.z;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 导出四维矩阵[三维空间变换矩阵]旋转部分
|
|
55
|
+
* @param {Matrix4} m 四维矩阵
|
|
56
|
+
* @returns {Matrix4} 导出结果
|
|
57
|
+
*/
|
|
58
|
+
extractRotation(m) {
|
|
59
|
+
// this method does not support reflection matrices
|
|
60
|
+
const _v = new Vector3();
|
|
61
|
+
const me = m.elements;
|
|
62
|
+
const te = this.elements;
|
|
63
|
+
const scaleX = 1 / _v.setFromMatrixColumn(m, 0).length();
|
|
64
|
+
const scaleY = 1 / _v.setFromMatrixColumn(m, 1).length();
|
|
65
|
+
const scaleZ = 1 / _v.setFromMatrixColumn(m, 2).length();
|
|
66
|
+
te[0] = me[0] * scaleX;
|
|
67
|
+
te[1] = me[1] * scaleX;
|
|
68
|
+
te[2] = me[2] * scaleX;
|
|
69
|
+
te[3] = 0;
|
|
70
|
+
te[4] = me[4] * scaleY;
|
|
71
|
+
te[5] = me[5] * scaleY;
|
|
72
|
+
te[6] = me[6] * scaleY;
|
|
73
|
+
te[7] = 0;
|
|
74
|
+
te[8] = me[8] * scaleZ;
|
|
75
|
+
te[9] = me[9] * scaleZ;
|
|
76
|
+
te[10] = me[10] * scaleZ;
|
|
77
|
+
te[11] = 0;
|
|
78
|
+
te[12] = 0;
|
|
79
|
+
te[13] = 0;
|
|
80
|
+
te[14] = 0;
|
|
81
|
+
te[15] = 1;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 由欧拉角设置四维矩阵
|
|
86
|
+
* @param {Euler} euler 欧拉角
|
|
87
|
+
* @returns {Matrix4} 四维矩阵
|
|
88
|
+
*/
|
|
89
|
+
makeRotationFromEuler(euler) {
|
|
90
|
+
const te = this.elements;
|
|
91
|
+
const x = euler.x;
|
|
92
|
+
const y = euler.y;
|
|
93
|
+
const z = euler.z;
|
|
94
|
+
const a = Math.cos(x);
|
|
95
|
+
const b = Math.sin(x);
|
|
96
|
+
const c = Math.cos(y);
|
|
97
|
+
const d = Math.sin(y);
|
|
98
|
+
const e = Math.cos(z);
|
|
99
|
+
const f = Math.sin(z);
|
|
100
|
+
if (euler.order === math.EulerOrder.XYZ) {
|
|
101
|
+
const ae = a * e;
|
|
102
|
+
const af = a * f;
|
|
103
|
+
const be = b * e;
|
|
104
|
+
const bf = b * f;
|
|
105
|
+
te[0] = c * e;
|
|
106
|
+
te[4] = -c * f;
|
|
107
|
+
te[8] = d;
|
|
108
|
+
te[1] = af + be * d;
|
|
109
|
+
te[5] = ae - bf * d;
|
|
110
|
+
te[9] = -b * c;
|
|
111
|
+
te[2] = bf - ae * d;
|
|
112
|
+
te[6] = be + af * d;
|
|
113
|
+
te[10] = a * c;
|
|
114
|
+
}
|
|
115
|
+
else if (euler.order === math.EulerOrder.YXZ) {
|
|
116
|
+
const ce = c * e;
|
|
117
|
+
const cf = c * f;
|
|
118
|
+
const de = d * e;
|
|
119
|
+
const df = d * f;
|
|
120
|
+
te[0] = ce + df * b;
|
|
121
|
+
te[4] = de * b - cf;
|
|
122
|
+
te[8] = a * d;
|
|
123
|
+
te[1] = a * f;
|
|
124
|
+
te[5] = a * e;
|
|
125
|
+
te[9] = -b;
|
|
126
|
+
te[2] = cf * b - de;
|
|
127
|
+
te[6] = df + ce * b;
|
|
128
|
+
te[10] = a * c;
|
|
129
|
+
}
|
|
130
|
+
else if (euler.order === math.EulerOrder.ZXY) {
|
|
131
|
+
const ce = c * e;
|
|
132
|
+
const cf = c * f;
|
|
133
|
+
const de = d * e;
|
|
134
|
+
const df = d * f;
|
|
135
|
+
te[0] = ce - df * b;
|
|
136
|
+
te[4] = -a * f;
|
|
137
|
+
te[8] = de + cf * b;
|
|
138
|
+
te[1] = cf + de * b;
|
|
139
|
+
te[5] = a * e;
|
|
140
|
+
te[9] = df - ce * b;
|
|
141
|
+
te[2] = -a * d;
|
|
142
|
+
te[6] = b;
|
|
143
|
+
te[10] = a * c;
|
|
144
|
+
}
|
|
145
|
+
else if (euler.order === math.EulerOrder.ZYX) {
|
|
146
|
+
const ae = a * e;
|
|
147
|
+
const af = a * f;
|
|
148
|
+
const be = b * e;
|
|
149
|
+
const bf = b * f;
|
|
150
|
+
te[0] = c * e;
|
|
151
|
+
te[4] = be * d - af;
|
|
152
|
+
te[8] = ae * d + bf;
|
|
153
|
+
te[1] = c * f;
|
|
154
|
+
te[5] = bf * d + ae;
|
|
155
|
+
te[9] = af * d - be;
|
|
156
|
+
te[2] = -d;
|
|
157
|
+
te[6] = b * c;
|
|
158
|
+
te[10] = a * c;
|
|
159
|
+
}
|
|
160
|
+
else if (euler.order === math.EulerOrder.YZX) {
|
|
161
|
+
const ac = a * c;
|
|
162
|
+
const ad = a * d;
|
|
163
|
+
const bc = b * c;
|
|
164
|
+
const bd = b * d;
|
|
165
|
+
te[0] = c * e;
|
|
166
|
+
te[4] = bd - ac * f;
|
|
167
|
+
te[8] = bc * f + ad;
|
|
168
|
+
te[1] = f;
|
|
169
|
+
te[5] = a * e;
|
|
170
|
+
te[9] = -b * e;
|
|
171
|
+
te[2] = -d * e;
|
|
172
|
+
te[6] = ad * f + bc;
|
|
173
|
+
te[10] = ac - bd * f;
|
|
174
|
+
}
|
|
175
|
+
else if (euler.order === math.EulerOrder.XZY) {
|
|
176
|
+
const ac = a * c;
|
|
177
|
+
const ad = a * d;
|
|
178
|
+
const bc = b * c;
|
|
179
|
+
const bd = b * d;
|
|
180
|
+
te[0] = c * e;
|
|
181
|
+
te[4] = -f;
|
|
182
|
+
te[8] = d * e;
|
|
183
|
+
te[1] = ac * f + bd;
|
|
184
|
+
te[5] = a * e;
|
|
185
|
+
te[9] = ad * f - bc;
|
|
186
|
+
te[2] = bc * f - ad;
|
|
187
|
+
te[6] = b * e;
|
|
188
|
+
te[10] = bd * f + ac;
|
|
189
|
+
}
|
|
190
|
+
// bottom row
|
|
191
|
+
te[3] = 0;
|
|
192
|
+
te[7] = 0;
|
|
193
|
+
te[11] = 0;
|
|
194
|
+
// last column
|
|
195
|
+
te[12] = 0;
|
|
196
|
+
te[13] = 0;
|
|
197
|
+
te[14] = 0;
|
|
198
|
+
te[15] = 1;
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
setPosition(position) {
|
|
202
|
+
this.elements[12] = position.x;
|
|
203
|
+
this.elements[13] = position.y;
|
|
204
|
+
this.elements[14] = position.z;
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Vector3 } from './vector3';
|
|
2
|
+
export class Plane {
|
|
3
|
+
distance;
|
|
4
|
+
normal;
|
|
5
|
+
constructor(distance = 0, normal = new Vector3(0, 0, 1)) {
|
|
6
|
+
const length = normal.length();
|
|
7
|
+
if (length === 0) {
|
|
8
|
+
this.normal = new Vector3(0, 0, 1);
|
|
9
|
+
}
|
|
10
|
+
this.distance = distance / (length ?? 1);
|
|
11
|
+
this.normal = normal.normalize();
|
|
12
|
+
}
|
|
13
|
+
static set(distance, normal) {
|
|
14
|
+
const plane = new Plane(distance, normal);
|
|
15
|
+
return plane;
|
|
16
|
+
}
|
|
17
|
+
set(distance, normal) {
|
|
18
|
+
const length = normal.length();
|
|
19
|
+
if (length === 0) {
|
|
20
|
+
this.normal = new Vector3(0, 0, 1);
|
|
21
|
+
}
|
|
22
|
+
this.distance = distance / length;
|
|
23
|
+
this.normal = normal.normalize();
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
static copy(target) {
|
|
27
|
+
const plane = new Plane(target.distance, target.normal.clone());
|
|
28
|
+
return plane;
|
|
29
|
+
}
|
|
30
|
+
copy(target) {
|
|
31
|
+
this.distance = target.distance;
|
|
32
|
+
this.normal.copyFrom(target.normal);
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
static setFromNormalAndCoplanarPoint(point, normal) {
|
|
36
|
+
const distance = -point.dot(normal);
|
|
37
|
+
const plane = new Plane(distance, normal);
|
|
38
|
+
return plane;
|
|
39
|
+
}
|
|
40
|
+
setFromNormalAndCoplanarPoint(point, normal) {
|
|
41
|
+
this.normal.copyFrom(normal);
|
|
42
|
+
this.distance = -point.dot(this.normal);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
clone() {
|
|
46
|
+
const plane = new Plane(this.distance, this.normal.clone());
|
|
47
|
+
return plane;
|
|
48
|
+
}
|
|
49
|
+
distanceToPoint(point) {
|
|
50
|
+
return this.normal.dot(point) + this.distance;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Ray } from './ray';
|
|
2
|
+
import { Vector3 } from './vector3';
|
|
3
|
+
export class RayCaster {
|
|
4
|
+
ray;
|
|
5
|
+
constructor(ray = new Ray()) {
|
|
6
|
+
this.ray = ray.clone();
|
|
7
|
+
}
|
|
8
|
+
setFromCamera(coords, camera) {
|
|
9
|
+
const origin = camera.position;
|
|
10
|
+
const direction = new Vector3(coords.x, coords.y, 0.5).applyMatrix(camera.inverseViewProjectMatrix).subtract(origin).normalize();
|
|
11
|
+
this.ray.set(origin, direction);
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
rayCastPlane(plane) {
|
|
15
|
+
const point = new Vector3();
|
|
16
|
+
const distance = this.ray.rayCastPlane(plane, point);
|
|
17
|
+
if (isNaN(distance)) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
distance,
|
|
22
|
+
point: this.ray.at(distance),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
package/dist/math/ray.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { math } from '../shared';
|
|
2
|
+
import { isZero } from './utils';
|
|
3
|
+
import { Vector3 } from './vector3';
|
|
4
|
+
export class Ray extends math.Ray {
|
|
5
|
+
origin;
|
|
6
|
+
direction;
|
|
7
|
+
constructor(origin = new Vector3(), direction = new Vector3(1, 0, 0)) {
|
|
8
|
+
super(origin, direction);
|
|
9
|
+
this.origin = origin.clone();
|
|
10
|
+
this.direction = direction.clone();
|
|
11
|
+
}
|
|
12
|
+
clone() {
|
|
13
|
+
return new Ray(this.origin, this.direction);
|
|
14
|
+
}
|
|
15
|
+
rayCastPlane(plane, _target) {
|
|
16
|
+
const t = this.distanceToPlane(plane);
|
|
17
|
+
if (isNaN(t)) {
|
|
18
|
+
return t;
|
|
19
|
+
}
|
|
20
|
+
// TODO:: @赤芍 无意义
|
|
21
|
+
_target = this.at(t);
|
|
22
|
+
return t;
|
|
23
|
+
}
|
|
24
|
+
at(t) {
|
|
25
|
+
return this.direction.clone().normalize().multiply(t).add(this.origin);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 射线到平面的距离
|
|
29
|
+
* 当两个向量都是单位向量的时候,从a投影到b的距离等于从b投影到a的距离
|
|
30
|
+
* @param plane 平面
|
|
31
|
+
* @returns 射线到平面的距离
|
|
32
|
+
*/
|
|
33
|
+
distanceToPlane(plane) {
|
|
34
|
+
/**
|
|
35
|
+
* 单位向量的投影距离
|
|
36
|
+
*/
|
|
37
|
+
const dotProduct = plane.normal.dot(this.direction);
|
|
38
|
+
if (isZero(dotProduct)) {
|
|
39
|
+
if (isZero(plane.distanceToPoint(this.origin))) {
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
return NaN;
|
|
43
|
+
}
|
|
44
|
+
const t = (-this.origin.dot(plane.normal) - plane.distance) / dotProduct;
|
|
45
|
+
return t > 0 ? t : NaN;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Box2 } from './box2';
|
|
2
|
+
import { Vector2 } from './vector2';
|
|
3
|
+
const Number_Tolerance = 0.000001;
|
|
4
|
+
export function clamp(value, min, max) {
|
|
5
|
+
const fixedMin = isNaN(min) ? -Infinity : min;
|
|
6
|
+
const fixedMax = isNaN(max) ? Infinity : max;
|
|
7
|
+
const lower = Math.min(fixedMin, fixedMax);
|
|
8
|
+
const upper = Math.max(fixedMin, fixedMax);
|
|
9
|
+
return Math.min(Math.max(value, lower), upper);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @description 角度转弧度系数
|
|
13
|
+
*/
|
|
14
|
+
export const DEG2RAD = Math.PI / 180;
|
|
15
|
+
/**
|
|
16
|
+
* @description 弧度转角度系数
|
|
17
|
+
*/
|
|
18
|
+
export const RAD2DEG = 180 / Math.PI;
|
|
19
|
+
export function getVector2Angle(vector) {
|
|
20
|
+
const angle = Math.atan2(-vector.y, -vector.x) + Math.PI;
|
|
21
|
+
return angle;
|
|
22
|
+
}
|
|
23
|
+
export function getAngleByVectors(vector1, vector2) {
|
|
24
|
+
const cosValue = Math.min(Math.max(vector1.dot(vector2) / vector1.length() / vector2.length(), -1), 1);
|
|
25
|
+
let angle = Math.acos(cosValue);
|
|
26
|
+
angle = vector1.x * vector2.y - vector1.y * vector2.x > 0 ? angle : -angle;
|
|
27
|
+
return angle;
|
|
28
|
+
}
|
|
29
|
+
export function roundNumber(number, precision, method = Math.round) {
|
|
30
|
+
// 已经是整数,则无需处理
|
|
31
|
+
if (Number.isInteger(number)) {
|
|
32
|
+
return number;
|
|
33
|
+
}
|
|
34
|
+
const decimal = Math.pow(10, precision);
|
|
35
|
+
return method(number * decimal) / decimal;
|
|
36
|
+
}
|
|
37
|
+
export function getAbsMaxIndex(numbers) {
|
|
38
|
+
let resultIndex = 0;
|
|
39
|
+
let max;
|
|
40
|
+
numbers.forEach((number, index) => {
|
|
41
|
+
if (index === 0) {
|
|
42
|
+
max = Math.abs(number);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const absNumber = Math.abs(number);
|
|
46
|
+
if (max < absNumber) {
|
|
47
|
+
max = absNumber;
|
|
48
|
+
resultIndex = index;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return resultIndex;
|
|
53
|
+
}
|
|
54
|
+
export function isEqual(a, b) {
|
|
55
|
+
return Math.abs(a - b) < Number_Tolerance || (a === Infinity && b === Infinity) || (a === -Infinity && b === -Infinity);
|
|
56
|
+
}
|
|
57
|
+
export function isZero(v) {
|
|
58
|
+
return isNaN(v) || Math.abs(v) < Number_Tolerance;
|
|
59
|
+
}
|
|
60
|
+
export function getBoxByNormalizeBox(origin, normalize) {
|
|
61
|
+
const result = new Box2();
|
|
62
|
+
const { min: originMin, max: originMax } = origin;
|
|
63
|
+
const { min: normalizeMin, max: normalizeMax } = normalize;
|
|
64
|
+
const min = originMin.clone().add(new Vector2().subtractVectors(originMax, originMin).multiply(normalizeMin));
|
|
65
|
+
const max = originMin.clone().add(new Vector2().subtractVectors(originMax, originMin).multiply(normalizeMax));
|
|
66
|
+
result.setFromVec2ArrayWithOutCorners([min, max]);
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
export function getNormalizeBoxByBoxes(origin, current) {
|
|
70
|
+
const result = new Box2();
|
|
71
|
+
const { min: originMin, max: originMax } = origin;
|
|
72
|
+
const { min: currentMin, max: currentMax } = current;
|
|
73
|
+
const min = new Vector2().subtractVectors(currentMin, originMin).divide(new Vector2().subtractVectors(originMax, originMin));
|
|
74
|
+
const max = new Vector2().subtractVectors(currentMax, originMin).divide(new Vector2().subtractVectors(originMax, originMin));
|
|
75
|
+
result.setFromVec2ArrayWithOutCorners([min, max]);
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { math } from '../shared';
|
|
2
|
+
import { clamp } from './utils';
|
|
3
|
+
export class Vector2 extends math.Vector2 {
|
|
4
|
+
subtract(other) {
|
|
5
|
+
this.x -= other.x;
|
|
6
|
+
this.y -= other.y;
|
|
7
|
+
return this;
|
|
8
|
+
}
|
|
9
|
+
toViewCoordinate(width, height) {
|
|
10
|
+
this.x = ((this.x + 1) / 2) * width;
|
|
11
|
+
this.y = (1 - (this.y + 1) / 2) * height;
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
clone() {
|
|
15
|
+
return new Vector2(this.x, this.y);
|
|
16
|
+
}
|
|
17
|
+
distanceTo(other) {
|
|
18
|
+
const dx = this.x - other.x;
|
|
19
|
+
const dy = this.y - other.y;
|
|
20
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
21
|
+
}
|
|
22
|
+
scaleByCenter(scalar, anchor = new Vector2()) {
|
|
23
|
+
const delta = new Vector2().subtractVectors(anchor, this).multiply(scalar);
|
|
24
|
+
return this.subtractVectors(anchor, delta);
|
|
25
|
+
}
|
|
26
|
+
round(precision = 0) {
|
|
27
|
+
// 已经是整数,则无需处理
|
|
28
|
+
const decimal = Math.pow(10, precision);
|
|
29
|
+
this.x = Math.round((this.x * decimal)) / decimal;
|
|
30
|
+
this.y = Math.round((this.y * decimal)) / decimal;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 点到直线的最短距离
|
|
35
|
+
* @returns {{d: number, t: number}} d表示距离,t表示最近点在直线的比例
|
|
36
|
+
*/
|
|
37
|
+
distanceToLine(line) {
|
|
38
|
+
const l2 = Math.pow(line.length(), 2);
|
|
39
|
+
const { start, end } = line;
|
|
40
|
+
if (l2 === 0) {
|
|
41
|
+
return { d: new Vector2().subtractVectors(this, start).length(), t: 0 };
|
|
42
|
+
}
|
|
43
|
+
const t = ((this.x - start.x) * (end.x - start.x) + (this.y - start.y) * (end.y - start.y)) / l2;
|
|
44
|
+
const clampedT = clamp(t, 0, 1);
|
|
45
|
+
return { d: new Vector2().subtractVectors(this, line.at(clampedT)).length(), t: clampedT };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 二维向量与x轴夹角
|
|
49
|
+
* @returns {number} 弧度值
|
|
50
|
+
*/
|
|
51
|
+
angle() {
|
|
52
|
+
// computes the angle in radians with respect to the positive x-axis
|
|
53
|
+
const angle = Math.atan2(-this.y, -this.x) + Math.PI;
|
|
54
|
+
return angle;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 二维点绕点旋转
|
|
58
|
+
* @param {Vec2} center 旋转中心
|
|
59
|
+
* @param {number} angle 旋转角度
|
|
60
|
+
* @returns {Vec2} 旋转结果
|
|
61
|
+
*/
|
|
62
|
+
rotateAround(center, angle) {
|
|
63
|
+
const c = Math.cos(angle), s = Math.sin(angle);
|
|
64
|
+
const x = this.x - center.x;
|
|
65
|
+
const y = this.y - center.y;
|
|
66
|
+
this.x = x * c - y * s + center.x;
|
|
67
|
+
this.y = x * s + y * c + center.y;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
}
|