onejs-core 3.0.3 → 3.0.4
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/.gitattributes +2 -2
- package/.prettierrc +5 -5
- package/.vscode/settings.json +5 -5
- package/LICENSE +20 -20
- package/README.md +102 -102
- package/definitions/Assemblies/OneJS.Runtime.Ext.d.ts +6 -6
- package/definitions/Assemblies/OneJS.Runtime.d.ts +826 -826
- package/definitions/Assemblies/OneJS.Samples.d.ts +20 -20
- package/definitions/Assemblies/Unity.Mathematics.d.ts +9221 -9221
- package/definitions/Assemblies/UnityEditor.CoreModule.d.ts +32614 -32614
- package/definitions/Assemblies/UnityEngine.AIModule.d.ts +998 -998
- package/definitions/Assemblies/UnityEngine.AnimationModule.d.ts +3308 -3308
- package/definitions/Assemblies/UnityEngine.AssetBundleModule.d.ts +337 -337
- package/definitions/Assemblies/UnityEngine.AudioModule.d.ts +1154 -1154
- package/definitions/Assemblies/UnityEngine.CoreModule.d.ts +29587 -29587
- package/definitions/Assemblies/UnityEngine.PhysicsModule.d.ts +3137 -3137
- package/definitions/Assemblies/UnityEngine.TerrainModule.d.ts +1270 -1270
- package/definitions/Assemblies/UnityEngine.UIElementsModule.d.ts +32718 -32718
- package/definitions/Assemblies/UnityEngine.UnityAnalyticsCommonModule.d.ts +274 -274
- package/definitions/Assemblies/index.d.ts +16 -16
- package/definitions/Assemblies/mscorlib.d.ts +19416 -19416
- package/definitions/augments.d.ts +66 -66
- package/definitions/globals.d.ts +53 -53
- package/definitions/index.d.ts +11 -11
- package/definitions/jsx.d.ts +570 -570
- package/definitions/modules.d.ts +32 -32
- package/definitions/onejs.d.ts +171 -171
- package/definitions/preact.jsx.d.ts +6 -6
- package/definitions/proto-overrides.d.ts +41 -41
- package/definitions/puerts.d.ts +30 -30
- package/definitions/unity-engine.d.ts +22 -22
- package/dist/csharp/index.d.ts +3 -0
- package/dist/csharp/index.js +3 -0
- package/dist/dom/document.d.ts +30 -0
- package/dist/dom/document.js +89 -0
- package/dist/dom/dom-style.d.ts +9 -0
- package/dist/dom/dom-style.js +27 -0
- package/dist/dom/dom.d.ts +83 -0
- package/dist/dom/dom.js +313 -0
- package/dist/dom/index.d.ts +4 -0
- package/dist/dom/index.js +4 -0
- package/dist/dom/selector.d.ts +0 -0
- package/dist/dom/selector.js +0 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +45 -0
- package/dist/math/index.d.ts +86 -0
- package/dist/math/index.js +361 -0
- package/dist/preloads/inject.d.ts +3 -0
- package/dist/preloads/inject.js +36 -0
- package/dist/styling/index.d.ts +10 -0
- package/dist/styling/index.js +28 -0
- package/dist/styling/utils/generateAlphabeticName.d.ts +1 -0
- package/dist/styling/utils/generateAlphabeticName.js +16 -0
- package/dist/styling/utils/generateComponentId.d.ts +1 -0
- package/dist/styling/utils/generateComponentId.js +5 -0
- package/dist/styling/utils/hash.d.ts +5 -0
- package/dist/styling/utils/hash.js +34 -0
- package/dist/utils/arrays.d.ts +1 -0
- package/dist/utils/arrays.js +10 -0
- package/dist/utils/color-palettes.d.ts +2 -0
- package/dist/utils/color-palettes.js +2 -0
- package/dist/utils/color-parser.d.ts +161 -0
- package/dist/utils/color-parser.js +241 -0
- package/dist/utils/float-parser.d.ts +7 -0
- package/dist/utils/float-parser.js +23 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/responsive.d.ts +4 -0
- package/dist/utils/responsive.js +23 -0
- package/dist/utils/subscribe.d.ts +4 -0
- package/dist/utils/subscribe.js +10 -0
- package/dist/utils/system.d.ts +1 -0
- package/dist/utils/system.js +16 -0
- package/dist/utils/toJsArray.d.ts +1 -0
- package/dist/utils/toJsArray.js +10 -0
- package/dom/document.ts +115 -115
- package/dom/dom-style.ts +36 -36
- package/dom/dom.ts +376 -376
- package/dom/index.ts +3 -3
- package/index.ts +59 -59
- package/jsr.json +9 -9
- package/math/README.md +212 -212
- package/math/index.ts +487 -487
- package/package.json +33 -33
- package/preloads/inject.ts +43 -43
- package/scripts/esbuild/copy-assets.mjs +94 -94
- package/scripts/esbuild/decorator-fix.mjs +17 -17
- package/scripts/esbuild/import-transform.mjs +100 -100
- package/scripts/esbuild/index.mjs +3 -3
- package/scripts/esbuild/watch-output.mjs +38 -38
- package/scripts/postcss/cleanup-plugin.cjs +89 -89
- package/scripts/postcss/onejs-tw-config.cjs +252 -252
- package/scripts/postcss/optional-import-plugin.cjs +26 -26
- package/scripts/postcss/tailwind-logging-plugin.cjs +11 -11
- package/scripts/postcss/unwrap-is-plugin.cjs +16 -16
- package/scripts/postcss/uss-transform-plugin.cjs +92 -92
- package/scripts/switch.cjs +290 -290
- package/styling/index.tsx +32 -32
- package/styling/utils/generateAlphabeticName.ts +20 -20
- package/styling/utils/generateComponentId.ts +5 -5
- package/styling/utils/hash.ts +46 -46
- package/tsconfig.json +24 -24
- package/typings.d.ts +5 -5
- package/utils/arrays.ts +10 -10
- package/utils/color-palettes.ts +2 -2
- package/utils/color-parser.ts +248 -248
- package/utils/float-parser.ts +30 -30
- package/utils/index.ts +15 -15
- package/utils/subscribe.ts +16 -16
- package/utils/system.ts +16 -16
package/math/index.ts
CHANGED
|
@@ -1,488 +1,488 @@
|
|
|
1
|
-
import { Matrix4x4, Quaternion, Vector2, Vector2Int, Vector3, Vector3Int, Vector4, Color } from "UnityEngine"
|
|
2
|
-
|
|
3
|
-
type CSArray = CS.System.Array
|
|
4
|
-
const getType = CS.OneJS.Utils.TypeUtil.GetType
|
|
5
|
-
|
|
6
|
-
const { $typeof } = puer
|
|
7
|
-
|
|
8
|
-
// MARK: - Vectors
|
|
9
|
-
|
|
10
|
-
export function vec2(x: number, y: number): Vector2 {
|
|
11
|
-
return new Vector2(x, y);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function vec2i(x: number, y: number): Vector2Int {
|
|
15
|
-
return new Vector2Int(x, y);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function vec3(x: number, y: number, z: number): Vector3 {
|
|
19
|
-
return new Vector3(x, y, z);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function vec3i(x: number, y: number, z: number): Vector3Int {
|
|
23
|
-
return new Vector3Int(x, y, z);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function vec4(x: number, y: number, z: number, w: number): Vector4 {
|
|
27
|
-
return new Vector4(x, y, z, w);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// MARK: - Quaternions
|
|
31
|
-
|
|
32
|
-
export function quat(): Quaternion;
|
|
33
|
-
export function quat(x: number, y: number, z: number, w: number): Quaternion;
|
|
34
|
-
export function quat(x?: number, y?: number, z?: number, w?: number): Quaternion {
|
|
35
|
-
if (x === undefined && y === undefined && z === undefined && w === undefined) {
|
|
36
|
-
return Quaternion.identity;
|
|
37
|
-
}
|
|
38
|
-
if (x !== undefined && y !== undefined && z !== undefined && w !== undefined) {
|
|
39
|
-
return new Quaternion(x, y, z, w);
|
|
40
|
-
}
|
|
41
|
-
throw new Error("Invalid arguments: either no arguments or exactly four numbers.");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function euler(x: number, y: number, z: number): Quaternion {
|
|
45
|
-
return Quaternion.Euler(x, y, z);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// MARK: - Matrices
|
|
49
|
-
|
|
50
|
-
export function mat4x4(): Matrix4x4
|
|
51
|
-
export function mat4x4(a: Vector4, b: Vector4, c: Vector4, d: Vector4): Matrix4x4
|
|
52
|
-
export function mat4x4(a: number[][]): Matrix4x4
|
|
53
|
-
export function mat4x4(a?: any, b?: any, c?: any, d?: any): Matrix4x4 {
|
|
54
|
-
if (a === undefined && b === undefined && c === undefined && d === undefined) {
|
|
55
|
-
return Matrix4x4.identity;
|
|
56
|
-
}
|
|
57
|
-
if (a instanceof Vector4 && b instanceof Vector4 && c instanceof Vector4 && d instanceof Vector4) {
|
|
58
|
-
return new Matrix4x4(a, b, c, d);
|
|
59
|
-
}
|
|
60
|
-
if (Array.isArray(a) && a.length === 4 && a.every(v => Array.isArray(v) && v.length === 4)) {
|
|
61
|
-
return new Matrix4x4(
|
|
62
|
-
vec4(a[0][0], a[0][1], a[0][2], a[0][3]),
|
|
63
|
-
vec4(a[1][0], a[1][1], a[1][2], a[1][3]),
|
|
64
|
-
vec4(a[2][0], a[2][1], a[2][2], a[2][3]),
|
|
65
|
-
vec4(a[3][0], a[3][1], a[3][2], a[3][3])
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
throw new Error("Invalid arguments: either no arguments, four Vector4s or a 4x4 array of numbers.");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function trs(translation: Vector3, rotation: Quaternion, scale: Vector3): Matrix4x4 {
|
|
72
|
-
return Matrix4x4.TRS(translation, rotation, scale);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// MARK: - Arrays
|
|
76
|
-
|
|
77
|
-
export function floatArray(...items: number[]): CSArray {
|
|
78
|
-
const result = newCsArray(CS.System.Single, items.length);
|
|
79
|
-
for (let i = 0; i < items.length; i++) {
|
|
80
|
-
result.set(i, items[i]);
|
|
81
|
-
}
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function vec2Array(...items: number[][]): CSArray {
|
|
86
|
-
const result = newCsArray(Vector2, items.length);
|
|
87
|
-
for (let i = 0; i < items.length; i++) {
|
|
88
|
-
result.set(i, vec2(items[i][0], items[i][1]));
|
|
89
|
-
}
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function vec2iArray(...items: number[][]): CSArray {
|
|
94
|
-
const result = newCsArray(Vector2Int, items.length);
|
|
95
|
-
for (let i = 0; i < items.length; i++) {
|
|
96
|
-
result.set(i, vec2i(items[i][0], items[i][1]));
|
|
97
|
-
}
|
|
98
|
-
return result;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function vec3Array(...items: number[][]): CSArray {
|
|
102
|
-
const result = newCsArray(Vector3, items.length);
|
|
103
|
-
for (let i = 0; i < items.length; i++) {
|
|
104
|
-
result.set(i, vec3(items[i][0], items[i][1], items[i][2]));
|
|
105
|
-
}
|
|
106
|
-
return result;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function vec3iArray(...items: number[][]): CSArray {
|
|
110
|
-
const result = newCsArray(Vector3Int, items.length);
|
|
111
|
-
for (let i = 0; i < items.length; i++) {
|
|
112
|
-
result.set(i, vec3i(items[i][0], items[i][1], items[i][2]));
|
|
113
|
-
}
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function vec4Array(...items: number[][]): CSArray {
|
|
118
|
-
const result = newCsArray(Vector4, items.length);
|
|
119
|
-
for (let i = 0; i < items.length; i++) {
|
|
120
|
-
result.set(i, vec4(items[i][0], items[i][1], items[i][2], items[i][3]));
|
|
121
|
-
}
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// MARK: - Math Ops
|
|
126
|
-
|
|
127
|
-
export function add(a: Vector2, b: Vector2): Vector2
|
|
128
|
-
export function add(a: Vector3, b: Vector3): Vector3
|
|
129
|
-
export function add(a: Vector2Int, b: Vector2Int): Vector2Int
|
|
130
|
-
export function add(a: Vector3Int, b: Vector3Int): Vector3Int
|
|
131
|
-
export function add(a: Vector4, b: Vector4): Vector4
|
|
132
|
-
export function add(a: any, b: any): any {
|
|
133
|
-
function isBothOfType(type: any) {
|
|
134
|
-
return getType(a) == $typeof(type) && getType(b) == $typeof(type);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (isBothOfType(Vector2)) {
|
|
138
|
-
return Vector2.op_Addition(a, b);
|
|
139
|
-
} else if (isBothOfType(Vector2Int)) {
|
|
140
|
-
return Vector2Int.op_Addition(a, b);
|
|
141
|
-
} else if (isBothOfType(Vector3)) {
|
|
142
|
-
return Vector3.op_Addition(a, b);
|
|
143
|
-
} else if (isBothOfType(Vector3Int)) {
|
|
144
|
-
return Vector3Int.op_Addition(a, b);
|
|
145
|
-
} else if (isBothOfType(Vector4)) {
|
|
146
|
-
return Vector4.op_Addition(a, b);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
throw new Error("Unsupported types for add operation");
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function sub(a: Vector2, b: Vector2): Vector2
|
|
153
|
-
export function sub(a: Vector3, b: Vector3): Vector3
|
|
154
|
-
export function sub(a: Vector2Int, b: Vector2Int): Vector2Int
|
|
155
|
-
export function sub(a: Vector3Int, b: Vector3Int): Vector3Int
|
|
156
|
-
export function sub(a: Vector4, b: Vector4): Vector4
|
|
157
|
-
export function sub(a: any, b: any): any {
|
|
158
|
-
function isBothOfType(type: any) {
|
|
159
|
-
return getType(a) == $typeof(type) && getType(b) == $typeof(type);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (isBothOfType(Vector2)) {
|
|
163
|
-
return Vector2.op_Subtraction(a, b);
|
|
164
|
-
} else if (isBothOfType(Vector2Int)) {
|
|
165
|
-
return Vector2Int.op_Subtraction(a, b);
|
|
166
|
-
} else if (isBothOfType(Vector3)) {
|
|
167
|
-
return Vector3.op_Subtraction(a, b);
|
|
168
|
-
} else if (isBothOfType(Vector3Int)) {
|
|
169
|
-
return Vector3Int.op_Subtraction(a, b);
|
|
170
|
-
} else if (isBothOfType(Vector4)) {
|
|
171
|
-
return Vector4.op_Subtraction(a, b);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
throw new Error("Unsupported types for sub operation");
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export function neg(a: Vector2): Vector2
|
|
178
|
-
export function neg(a: Vector3): Vector3
|
|
179
|
-
export function neg(a: Vector2Int): Vector2Int
|
|
180
|
-
export function neg(a: Vector3Int): Vector3Int
|
|
181
|
-
export function neg(a: Vector4): Vector4
|
|
182
|
-
export function neg(a: any): any {
|
|
183
|
-
if (getType(a) == $typeof(Vector2)) {
|
|
184
|
-
return Vector2.op_UnaryNegation(a);
|
|
185
|
-
} else if (getType(a) == $typeof(Vector2Int)) {
|
|
186
|
-
return Vector2Int.op_UnaryNegation(a);
|
|
187
|
-
} else if (getType(a) == $typeof(Vector3)) {
|
|
188
|
-
return Vector3.op_UnaryNegation(a);
|
|
189
|
-
} else if (getType(a) == $typeof(Vector3Int)) {
|
|
190
|
-
return Vector3Int.op_UnaryNegation(a);
|
|
191
|
-
} else if (getType(a) == $typeof(Vector4)) {
|
|
192
|
-
return Vector4.op_UnaryNegation(a);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
throw new Error("Unsupported types for neg operation");
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export function mul(a: Vector2, b: number): Vector2
|
|
199
|
-
export function mul(a: number, b: Vector2): Vector3
|
|
200
|
-
export function mul(a: Vector3, b: number): Vector3
|
|
201
|
-
export function mul(a: number, b: Vector3): Vector3
|
|
202
|
-
export function mul(a: Vector2Int, b: number): Vector2Int
|
|
203
|
-
export function mul(a: number, b: Vector2Int): Vector2Int
|
|
204
|
-
export function mul(a: Vector3Int, b: number): Vector3Int
|
|
205
|
-
export function mul(a: number, b: Vector3Int): Vector3Int
|
|
206
|
-
export function mul(a: Vector4, b: number): Vector4
|
|
207
|
-
export function mul(a: number, b: Vector4): Vector4
|
|
208
|
-
export function mul(a: Quaternion, b: Quaternion): Quaternion
|
|
209
|
-
export function mul(a: Quaternion, b: Vector3): Vector3
|
|
210
|
-
export function mul(a: Matrix4x4, b: Matrix4x4): Matrix4x4
|
|
211
|
-
export function mul(a: Matrix4x4, b: Vector4): Vector4
|
|
212
|
-
export function mul(a: any, b: any): any {
|
|
213
|
-
|
|
214
|
-
if (isOfType(a, Quaternion) && isOfType(b, Quaternion)) {
|
|
215
|
-
return Quaternion.op_Multiply(a, b);
|
|
216
|
-
}
|
|
217
|
-
if (isOfType(a, Quaternion) && isOfType(b, Vector3)) {
|
|
218
|
-
return Quaternion.op_Multiply(a, b);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (isOfType(a, Matrix4x4) && isOfType(b, Matrix4x4)) {
|
|
222
|
-
return Matrix4x4.op_Multiply(a, b);
|
|
223
|
-
}
|
|
224
|
-
if (isOfType(a, Matrix4x4) && isOfType(b, Vector4)) {
|
|
225
|
-
return Matrix4x4.op_Multiply(a, b);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (typeof b === 'number') {
|
|
229
|
-
if (getType(a) == $typeof(Vector2)) {
|
|
230
|
-
return Vector2.op_Multiply(a, b);
|
|
231
|
-
} else if (getType(a) == $typeof(Vector2Int)) {
|
|
232
|
-
return Vector2Int.op_Multiply(a, b);
|
|
233
|
-
} else if (getType(a) == $typeof(Vector3)) {
|
|
234
|
-
return Vector3.op_Multiply(a, b);
|
|
235
|
-
} else if (getType(a) == $typeof(Vector3Int)) {
|
|
236
|
-
return Vector3Int.op_Multiply(a, b);
|
|
237
|
-
} else if (getType(a) == $typeof(Vector4)) {
|
|
238
|
-
return Vector4.op_Multiply(a, b);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
else if (typeof a === 'number') {
|
|
242
|
-
if (getType(b) == $typeof(Vector2)) {
|
|
243
|
-
return Vector2.op_Multiply(b, a);
|
|
244
|
-
} else if (getType(b) == $typeof(Vector2Int)) {
|
|
245
|
-
return Vector2Int.op_Multiply(b, a);
|
|
246
|
-
} else if (getType(b) == $typeof(Vector3)) {
|
|
247
|
-
return Vector3.op_Multiply(b, a);
|
|
248
|
-
} else if (getType(b) == $typeof(Vector3Int)) {
|
|
249
|
-
return Vector3Int.op_Multiply(b, a);
|
|
250
|
-
} else if (getType(b) == $typeof(Vector4)) {
|
|
251
|
-
return Vector4.op_Multiply(b, a);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
throw new Error("Unsupported types for mul operation");
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export function div(a: Vector2, b: number): Vector2
|
|
259
|
-
export function div(a: Vector3, b: number): Vector3
|
|
260
|
-
export function div(a: Vector2Int, b: number): Vector2Int
|
|
261
|
-
export function div(a: Vector3Int, b: number): Vector3Int
|
|
262
|
-
export function div(a: any, b: any): any {
|
|
263
|
-
if (typeof b === 'number') {
|
|
264
|
-
if (getType(a) == $typeof(Vector2)) {
|
|
265
|
-
return Vector2.op_Division(a, b);
|
|
266
|
-
} else if (getType(a) == $typeof(Vector2Int)) {
|
|
267
|
-
return Vector2Int.op_Division(a, b);
|
|
268
|
-
} else if (getType(a) == $typeof(Vector3)) {
|
|
269
|
-
return Vector3.op_Division(a, b);
|
|
270
|
-
} else if (getType(a) == $typeof(Vector3Int)) {
|
|
271
|
-
return Vector3Int.op_Division(a, b);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
throw new Error("Unsupported types for div operation");
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export function eq(a: Vector2, b: Vector2): boolean
|
|
279
|
-
export function eq(a: Vector3, b: Vector3): boolean
|
|
280
|
-
export function eq(a: Vector2Int, b: Vector2Int): boolean
|
|
281
|
-
export function eq(a: Vector3Int, b: Vector3Int): boolean
|
|
282
|
-
export function eq(a: Quaternion, b: Quaternion): boolean
|
|
283
|
-
export function eq(a: any, b: any): boolean {
|
|
284
|
-
function isBothOfType(type: any) {
|
|
285
|
-
return getType(a) == $typeof(type) && getType(b) == $typeof(type);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (isBothOfType(Vector2)) {
|
|
289
|
-
return Vector2.op_Equality(a, b);
|
|
290
|
-
} else if (isBothOfType(Vector2Int)) {
|
|
291
|
-
return Vector2Int.op_Equality(a, b);
|
|
292
|
-
} else if (isBothOfType(Vector3)) {
|
|
293
|
-
return Vector3.op_Equality(a, b);
|
|
294
|
-
} else if (isBothOfType(Vector3Int)) {
|
|
295
|
-
return Vector3Int.op_Equality(a, b);
|
|
296
|
-
} else if (isBothOfType(Quaternion)) {
|
|
297
|
-
return Quaternion.op_Equality(a, b);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
throw new Error("Unsupported types for eq operation");
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// MARK: - Vector Ops
|
|
304
|
-
|
|
305
|
-
export function dot(a: Vector2, b: Vector2): number
|
|
306
|
-
export function dot(a: Vector3, b: Vector3): number
|
|
307
|
-
export function dot(a: Vector4, b: Vector4): number
|
|
308
|
-
export function dot(a: Quaternion, b: Quaternion): number
|
|
309
|
-
export function dot(a: any, b: any): number {
|
|
310
|
-
function isBothOfType(type: any) {
|
|
311
|
-
return isOfType(a, type) && isOfType(b, type);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (isBothOfType(Vector2)) {
|
|
315
|
-
return Vector2.Dot(a, b);
|
|
316
|
-
} else if (isBothOfType(Vector3)) {
|
|
317
|
-
return Vector3.Dot(a, b);
|
|
318
|
-
} else if (isBothOfType(Vector4)) {
|
|
319
|
-
return Vector4.Dot(a, b);
|
|
320
|
-
} else if (isBothOfType(Quaternion)) {
|
|
321
|
-
return Quaternion.Dot(a, b);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
throw new Error("Unsupported types for dot operation");
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
export function clamp(a: Vector2, min: Vector2, max: Vector2): Vector2
|
|
328
|
-
export function clamp(a: Vector3, min: Vector3, max: Vector3): Vector3
|
|
329
|
-
export function clamp(a: Vector2Int, min: Vector2Int, max: Vector2Int): Vector2Int
|
|
330
|
-
export function clamp(a: Vector3Int, min: Vector3Int, max: Vector3Int): Vector3Int
|
|
331
|
-
export function clamp(a: Vector4, min: Vector4, max: Vector4): Vector4
|
|
332
|
-
export function clamp(a: any, min: any, max: any): any {
|
|
333
|
-
function isAllOfType(type: any) {
|
|
334
|
-
return isOfType(a, type) && isOfType(min, type) && isOfType(max, type);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
if (isAllOfType(Vector2)) {
|
|
338
|
-
return vec2(
|
|
339
|
-
Math.min(Math.max(a.x, min.x), max.x),
|
|
340
|
-
Math.min(Math.max(a.y, min.y), max.y)
|
|
341
|
-
);
|
|
342
|
-
} else if (isAllOfType(Vector3)) {
|
|
343
|
-
return vec3(
|
|
344
|
-
Math.min(Math.max(a.x, min.x), max.x),
|
|
345
|
-
Math.min(Math.max(a.y, min.y), max.y),
|
|
346
|
-
Math.min(Math.max(a.z, min.z), max.z)
|
|
347
|
-
);
|
|
348
|
-
} else if (isAllOfType(Vector2Int)) {
|
|
349
|
-
return vec2i(
|
|
350
|
-
Math.min(Math.max(a.x, min.x), max.x),
|
|
351
|
-
Math.min(Math.max(a.y, min.y), max.y)
|
|
352
|
-
);
|
|
353
|
-
} else if (isAllOfType(Vector3Int)) {
|
|
354
|
-
return vec3i(
|
|
355
|
-
Math.min(Math.max(a.x, min.x), max.x),
|
|
356
|
-
Math.min(Math.max(a.y, min.y), max.y),
|
|
357
|
-
Math.min(Math.max(a.z, min.z), max.z)
|
|
358
|
-
);
|
|
359
|
-
} else if (isAllOfType(Vector4)) {
|
|
360
|
-
return vec4(
|
|
361
|
-
Math.min(Math.max(a.x, min.x), max.x),
|
|
362
|
-
Math.min(Math.max(a.y, min.y), max.y),
|
|
363
|
-
Math.min(Math.max(a.z, min.z), max.z),
|
|
364
|
-
Math.min(Math.max(a.w, min.w), max.w)
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
throw new Error("Unsupported types for clamp operation");
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
export function clamp01(a: Vector2): Vector2
|
|
372
|
-
export function clamp01(a: Vector3): Vector3
|
|
373
|
-
export function clamp01(a: Vector4): Vector4
|
|
374
|
-
export function clamp01(a: any): any {
|
|
375
|
-
if (isOfType(a, Vector2)) {
|
|
376
|
-
return vec2(
|
|
377
|
-
Math.min(Math.max(a.x, 0), 1),
|
|
378
|
-
Math.min(Math.max(a.y, 0), 1)
|
|
379
|
-
);
|
|
380
|
-
} else if (isOfType(a, Vector3)) {
|
|
381
|
-
return vec3(
|
|
382
|
-
Math.min(Math.max(a.x, 0), 1),
|
|
383
|
-
Math.min(Math.max(a.y, 0), 1),
|
|
384
|
-
Math.min(Math.max(a.z, 0), 1)
|
|
385
|
-
);
|
|
386
|
-
} else if (isOfType(a, Vector4)) {
|
|
387
|
-
return vec4(
|
|
388
|
-
Math.min(Math.max(a.x, 0), 1),
|
|
389
|
-
Math.min(Math.max(a.y, 0), 1),
|
|
390
|
-
Math.min(Math.max(a.z, 0), 1),
|
|
391
|
-
Math.min(Math.max(a.w, 0), 1)
|
|
392
|
-
);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
throw new Error("Unsupported types for clamp01 operation");
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
export function distance(a: Vector2, b: Vector2): number
|
|
399
|
-
export function distance(a: Vector3, b: Vector3): number
|
|
400
|
-
export function distance(a: Vector2Int, b: Vector2Int): number
|
|
401
|
-
export function distance(a: Vector3Int, b: Vector3Int): number
|
|
402
|
-
export function distance(a: Vector4, b: Vector4): number
|
|
403
|
-
export function distance(a: any, b: any): number {
|
|
404
|
-
function isBothOfType(type: any) {
|
|
405
|
-
return isOfType(a, type) && isOfType(b, type);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
if (isBothOfType(Vector2)) {
|
|
409
|
-
return Vector2.Distance(a, b);
|
|
410
|
-
} else if (isBothOfType(Vector3)) {
|
|
411
|
-
return Vector3.Distance(a, b);
|
|
412
|
-
} else if (isBothOfType(Vector2Int)) {
|
|
413
|
-
const dx = a.x - b.x;
|
|
414
|
-
const dy = a.y - b.y;
|
|
415
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
416
|
-
} else if (isBothOfType(Vector3Int)) {
|
|
417
|
-
const dx = a.x - b.x;
|
|
418
|
-
const dy = a.y - b.y;
|
|
419
|
-
const dz = a.z - b.z;
|
|
420
|
-
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
421
|
-
} else if (isBothOfType(Vector4)) {
|
|
422
|
-
const dx = a.x - b.x;
|
|
423
|
-
const dy = a.y - b.y;
|
|
424
|
-
const dz = a.z - b.z;
|
|
425
|
-
const dw = a.w - b.w;
|
|
426
|
-
return Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
throw new Error("Unsupported types for distance operation");
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
export function normalize(a: Vector2): Vector2
|
|
433
|
-
export function normalize(a: Vector3): Vector3
|
|
434
|
-
export function normalize(a: Vector4): Vector4
|
|
435
|
-
export function normalize(a: any): any {
|
|
436
|
-
if (isOfType(a, Vector2)) {
|
|
437
|
-
const magnitude = Math.sqrt(a.x * a.x + a.y * a.y);
|
|
438
|
-
if (magnitude < 1e-6) {
|
|
439
|
-
return vec2(0, 0);
|
|
440
|
-
}
|
|
441
|
-
return vec2(a.x / magnitude, a.y / magnitude);
|
|
442
|
-
} else if (isOfType(a, Vector3)) {
|
|
443
|
-
return Vector3.Normalize(a);
|
|
444
|
-
} else if (isOfType(a, Vector4)) {
|
|
445
|
-
return Vector4.Normalize(a);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
throw new Error("Unsupported types for normalize operation");
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
export function lerp(a: number, b: number, t: number): number
|
|
452
|
-
export function lerp(a: Vector2, b: Vector2, t: number): Vector2
|
|
453
|
-
export function lerp(a: Vector3, b: Vector3, t: number): Vector3
|
|
454
|
-
export function lerp(a: Vector4, b: Vector4, t: number): Vector4
|
|
455
|
-
export function lerp(a: Quaternion, b: Quaternion, t: number): Quaternion
|
|
456
|
-
export function lerp(a: Color, b: Color, t: number): Color
|
|
457
|
-
export function lerp(a: any, b: any, t: number): any {
|
|
458
|
-
function isBothOfType(type: any) {
|
|
459
|
-
return isOfType(a, type) && isOfType(b, type);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
if (typeof a === 'number' && typeof b === 'number') {
|
|
463
|
-
return a + (b - a) * t;
|
|
464
|
-
} else if (isBothOfType(Vector2)) {
|
|
465
|
-
return Vector2.Lerp(a, b, t);
|
|
466
|
-
} else if (isBothOfType(Vector3)) {
|
|
467
|
-
return Vector3.Lerp(a, b, t);
|
|
468
|
-
} else if (isBothOfType(Vector4)) {
|
|
469
|
-
return vec4(
|
|
470
|
-
a.x + (b.x - a.x) * t,
|
|
471
|
-
a.y + (b.y - a.y) * t,
|
|
472
|
-
a.z + (b.z - a.z) * t,
|
|
473
|
-
a.w + (b.w - a.w) * t
|
|
474
|
-
);
|
|
475
|
-
} else if (isBothOfType(Quaternion)) {
|
|
476
|
-
return Quaternion.Lerp(a, b, t);
|
|
477
|
-
} else if (isBothOfType(Color)) {
|
|
478
|
-
return Color.Lerp(a, b, t);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
throw new Error("Unsupported types for lerp operation");
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
// MARK: - Utilities
|
|
485
|
-
|
|
486
|
-
function isOfType(obj: any, type: any) {
|
|
487
|
-
return getType(obj) == $typeof(type);
|
|
1
|
+
import { Matrix4x4, Quaternion, Vector2, Vector2Int, Vector3, Vector3Int, Vector4, Color } from "UnityEngine"
|
|
2
|
+
|
|
3
|
+
type CSArray = CS.System.Array
|
|
4
|
+
const getType = CS.OneJS.Utils.TypeUtil.GetType
|
|
5
|
+
|
|
6
|
+
const { $typeof } = puer
|
|
7
|
+
|
|
8
|
+
// MARK: - Vectors
|
|
9
|
+
|
|
10
|
+
export function vec2(x: number, y: number): Vector2 {
|
|
11
|
+
return new Vector2(x, y);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function vec2i(x: number, y: number): Vector2Int {
|
|
15
|
+
return new Vector2Int(x, y);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function vec3(x: number, y: number, z: number): Vector3 {
|
|
19
|
+
return new Vector3(x, y, z);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function vec3i(x: number, y: number, z: number): Vector3Int {
|
|
23
|
+
return new Vector3Int(x, y, z);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function vec4(x: number, y: number, z: number, w: number): Vector4 {
|
|
27
|
+
return new Vector4(x, y, z, w);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// MARK: - Quaternions
|
|
31
|
+
|
|
32
|
+
export function quat(): Quaternion;
|
|
33
|
+
export function quat(x: number, y: number, z: number, w: number): Quaternion;
|
|
34
|
+
export function quat(x?: number, y?: number, z?: number, w?: number): Quaternion {
|
|
35
|
+
if (x === undefined && y === undefined && z === undefined && w === undefined) {
|
|
36
|
+
return Quaternion.identity;
|
|
37
|
+
}
|
|
38
|
+
if (x !== undefined && y !== undefined && z !== undefined && w !== undefined) {
|
|
39
|
+
return new Quaternion(x, y, z, w);
|
|
40
|
+
}
|
|
41
|
+
throw new Error("Invalid arguments: either no arguments or exactly four numbers.");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function euler(x: number, y: number, z: number): Quaternion {
|
|
45
|
+
return Quaternion.Euler(x, y, z);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// MARK: - Matrices
|
|
49
|
+
|
|
50
|
+
export function mat4x4(): Matrix4x4
|
|
51
|
+
export function mat4x4(a: Vector4, b: Vector4, c: Vector4, d: Vector4): Matrix4x4
|
|
52
|
+
export function mat4x4(a: number[][]): Matrix4x4
|
|
53
|
+
export function mat4x4(a?: any, b?: any, c?: any, d?: any): Matrix4x4 {
|
|
54
|
+
if (a === undefined && b === undefined && c === undefined && d === undefined) {
|
|
55
|
+
return Matrix4x4.identity;
|
|
56
|
+
}
|
|
57
|
+
if (a instanceof Vector4 && b instanceof Vector4 && c instanceof Vector4 && d instanceof Vector4) {
|
|
58
|
+
return new Matrix4x4(a, b, c, d);
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(a) && a.length === 4 && a.every(v => Array.isArray(v) && v.length === 4)) {
|
|
61
|
+
return new Matrix4x4(
|
|
62
|
+
vec4(a[0][0], a[0][1], a[0][2], a[0][3]),
|
|
63
|
+
vec4(a[1][0], a[1][1], a[1][2], a[1][3]),
|
|
64
|
+
vec4(a[2][0], a[2][1], a[2][2], a[2][3]),
|
|
65
|
+
vec4(a[3][0], a[3][1], a[3][2], a[3][3])
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
throw new Error("Invalid arguments: either no arguments, four Vector4s or a 4x4 array of numbers.");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function trs(translation: Vector3, rotation: Quaternion, scale: Vector3): Matrix4x4 {
|
|
72
|
+
return Matrix4x4.TRS(translation, rotation, scale);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// MARK: - Arrays
|
|
76
|
+
|
|
77
|
+
export function floatArray(...items: number[]): CSArray {
|
|
78
|
+
const result = newCsArray(CS.System.Single, items.length);
|
|
79
|
+
for (let i = 0; i < items.length; i++) {
|
|
80
|
+
result.set(i, items[i]);
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function vec2Array(...items: number[][]): CSArray {
|
|
86
|
+
const result = newCsArray(Vector2, items.length);
|
|
87
|
+
for (let i = 0; i < items.length; i++) {
|
|
88
|
+
result.set(i, vec2(items[i][0], items[i][1]));
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function vec2iArray(...items: number[][]): CSArray {
|
|
94
|
+
const result = newCsArray(Vector2Int, items.length);
|
|
95
|
+
for (let i = 0; i < items.length; i++) {
|
|
96
|
+
result.set(i, vec2i(items[i][0], items[i][1]));
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function vec3Array(...items: number[][]): CSArray {
|
|
102
|
+
const result = newCsArray(Vector3, items.length);
|
|
103
|
+
for (let i = 0; i < items.length; i++) {
|
|
104
|
+
result.set(i, vec3(items[i][0], items[i][1], items[i][2]));
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function vec3iArray(...items: number[][]): CSArray {
|
|
110
|
+
const result = newCsArray(Vector3Int, items.length);
|
|
111
|
+
for (let i = 0; i < items.length; i++) {
|
|
112
|
+
result.set(i, vec3i(items[i][0], items[i][1], items[i][2]));
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function vec4Array(...items: number[][]): CSArray {
|
|
118
|
+
const result = newCsArray(Vector4, items.length);
|
|
119
|
+
for (let i = 0; i < items.length; i++) {
|
|
120
|
+
result.set(i, vec4(items[i][0], items[i][1], items[i][2], items[i][3]));
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// MARK: - Math Ops
|
|
126
|
+
|
|
127
|
+
export function add(a: Vector2, b: Vector2): Vector2
|
|
128
|
+
export function add(a: Vector3, b: Vector3): Vector3
|
|
129
|
+
export function add(a: Vector2Int, b: Vector2Int): Vector2Int
|
|
130
|
+
export function add(a: Vector3Int, b: Vector3Int): Vector3Int
|
|
131
|
+
export function add(a: Vector4, b: Vector4): Vector4
|
|
132
|
+
export function add(a: any, b: any): any {
|
|
133
|
+
function isBothOfType(type: any) {
|
|
134
|
+
return getType(a) == $typeof(type) && getType(b) == $typeof(type);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (isBothOfType(Vector2)) {
|
|
138
|
+
return Vector2.op_Addition(a, b);
|
|
139
|
+
} else if (isBothOfType(Vector2Int)) {
|
|
140
|
+
return Vector2Int.op_Addition(a, b);
|
|
141
|
+
} else if (isBothOfType(Vector3)) {
|
|
142
|
+
return Vector3.op_Addition(a, b);
|
|
143
|
+
} else if (isBothOfType(Vector3Int)) {
|
|
144
|
+
return Vector3Int.op_Addition(a, b);
|
|
145
|
+
} else if (isBothOfType(Vector4)) {
|
|
146
|
+
return Vector4.op_Addition(a, b);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
throw new Error("Unsupported types for add operation");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function sub(a: Vector2, b: Vector2): Vector2
|
|
153
|
+
export function sub(a: Vector3, b: Vector3): Vector3
|
|
154
|
+
export function sub(a: Vector2Int, b: Vector2Int): Vector2Int
|
|
155
|
+
export function sub(a: Vector3Int, b: Vector3Int): Vector3Int
|
|
156
|
+
export function sub(a: Vector4, b: Vector4): Vector4
|
|
157
|
+
export function sub(a: any, b: any): any {
|
|
158
|
+
function isBothOfType(type: any) {
|
|
159
|
+
return getType(a) == $typeof(type) && getType(b) == $typeof(type);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (isBothOfType(Vector2)) {
|
|
163
|
+
return Vector2.op_Subtraction(a, b);
|
|
164
|
+
} else if (isBothOfType(Vector2Int)) {
|
|
165
|
+
return Vector2Int.op_Subtraction(a, b);
|
|
166
|
+
} else if (isBothOfType(Vector3)) {
|
|
167
|
+
return Vector3.op_Subtraction(a, b);
|
|
168
|
+
} else if (isBothOfType(Vector3Int)) {
|
|
169
|
+
return Vector3Int.op_Subtraction(a, b);
|
|
170
|
+
} else if (isBothOfType(Vector4)) {
|
|
171
|
+
return Vector4.op_Subtraction(a, b);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
throw new Error("Unsupported types for sub operation");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function neg(a: Vector2): Vector2
|
|
178
|
+
export function neg(a: Vector3): Vector3
|
|
179
|
+
export function neg(a: Vector2Int): Vector2Int
|
|
180
|
+
export function neg(a: Vector3Int): Vector3Int
|
|
181
|
+
export function neg(a: Vector4): Vector4
|
|
182
|
+
export function neg(a: any): any {
|
|
183
|
+
if (getType(a) == $typeof(Vector2)) {
|
|
184
|
+
return Vector2.op_UnaryNegation(a);
|
|
185
|
+
} else if (getType(a) == $typeof(Vector2Int)) {
|
|
186
|
+
return Vector2Int.op_UnaryNegation(a);
|
|
187
|
+
} else if (getType(a) == $typeof(Vector3)) {
|
|
188
|
+
return Vector3.op_UnaryNegation(a);
|
|
189
|
+
} else if (getType(a) == $typeof(Vector3Int)) {
|
|
190
|
+
return Vector3Int.op_UnaryNegation(a);
|
|
191
|
+
} else if (getType(a) == $typeof(Vector4)) {
|
|
192
|
+
return Vector4.op_UnaryNegation(a);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
throw new Error("Unsupported types for neg operation");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function mul(a: Vector2, b: number): Vector2
|
|
199
|
+
export function mul(a: number, b: Vector2): Vector3
|
|
200
|
+
export function mul(a: Vector3, b: number): Vector3
|
|
201
|
+
export function mul(a: number, b: Vector3): Vector3
|
|
202
|
+
export function mul(a: Vector2Int, b: number): Vector2Int
|
|
203
|
+
export function mul(a: number, b: Vector2Int): Vector2Int
|
|
204
|
+
export function mul(a: Vector3Int, b: number): Vector3Int
|
|
205
|
+
export function mul(a: number, b: Vector3Int): Vector3Int
|
|
206
|
+
export function mul(a: Vector4, b: number): Vector4
|
|
207
|
+
export function mul(a: number, b: Vector4): Vector4
|
|
208
|
+
export function mul(a: Quaternion, b: Quaternion): Quaternion
|
|
209
|
+
export function mul(a: Quaternion, b: Vector3): Vector3
|
|
210
|
+
export function mul(a: Matrix4x4, b: Matrix4x4): Matrix4x4
|
|
211
|
+
export function mul(a: Matrix4x4, b: Vector4): Vector4
|
|
212
|
+
export function mul(a: any, b: any): any {
|
|
213
|
+
|
|
214
|
+
if (isOfType(a, Quaternion) && isOfType(b, Quaternion)) {
|
|
215
|
+
return Quaternion.op_Multiply(a, b);
|
|
216
|
+
}
|
|
217
|
+
if (isOfType(a, Quaternion) && isOfType(b, Vector3)) {
|
|
218
|
+
return Quaternion.op_Multiply(a, b);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (isOfType(a, Matrix4x4) && isOfType(b, Matrix4x4)) {
|
|
222
|
+
return Matrix4x4.op_Multiply(a, b);
|
|
223
|
+
}
|
|
224
|
+
if (isOfType(a, Matrix4x4) && isOfType(b, Vector4)) {
|
|
225
|
+
return Matrix4x4.op_Multiply(a, b);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (typeof b === 'number') {
|
|
229
|
+
if (getType(a) == $typeof(Vector2)) {
|
|
230
|
+
return Vector2.op_Multiply(a, b);
|
|
231
|
+
} else if (getType(a) == $typeof(Vector2Int)) {
|
|
232
|
+
return Vector2Int.op_Multiply(a, b);
|
|
233
|
+
} else if (getType(a) == $typeof(Vector3)) {
|
|
234
|
+
return Vector3.op_Multiply(a, b);
|
|
235
|
+
} else if (getType(a) == $typeof(Vector3Int)) {
|
|
236
|
+
return Vector3Int.op_Multiply(a, b);
|
|
237
|
+
} else if (getType(a) == $typeof(Vector4)) {
|
|
238
|
+
return Vector4.op_Multiply(a, b);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else if (typeof a === 'number') {
|
|
242
|
+
if (getType(b) == $typeof(Vector2)) {
|
|
243
|
+
return Vector2.op_Multiply(b, a);
|
|
244
|
+
} else if (getType(b) == $typeof(Vector2Int)) {
|
|
245
|
+
return Vector2Int.op_Multiply(b, a);
|
|
246
|
+
} else if (getType(b) == $typeof(Vector3)) {
|
|
247
|
+
return Vector3.op_Multiply(b, a);
|
|
248
|
+
} else if (getType(b) == $typeof(Vector3Int)) {
|
|
249
|
+
return Vector3Int.op_Multiply(b, a);
|
|
250
|
+
} else if (getType(b) == $typeof(Vector4)) {
|
|
251
|
+
return Vector4.op_Multiply(b, a);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
throw new Error("Unsupported types for mul operation");
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export function div(a: Vector2, b: number): Vector2
|
|
259
|
+
export function div(a: Vector3, b: number): Vector3
|
|
260
|
+
export function div(a: Vector2Int, b: number): Vector2Int
|
|
261
|
+
export function div(a: Vector3Int, b: number): Vector3Int
|
|
262
|
+
export function div(a: any, b: any): any {
|
|
263
|
+
if (typeof b === 'number') {
|
|
264
|
+
if (getType(a) == $typeof(Vector2)) {
|
|
265
|
+
return Vector2.op_Division(a, b);
|
|
266
|
+
} else if (getType(a) == $typeof(Vector2Int)) {
|
|
267
|
+
return Vector2Int.op_Division(a, b);
|
|
268
|
+
} else if (getType(a) == $typeof(Vector3)) {
|
|
269
|
+
return Vector3.op_Division(a, b);
|
|
270
|
+
} else if (getType(a) == $typeof(Vector3Int)) {
|
|
271
|
+
return Vector3Int.op_Division(a, b);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
throw new Error("Unsupported types for div operation");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function eq(a: Vector2, b: Vector2): boolean
|
|
279
|
+
export function eq(a: Vector3, b: Vector3): boolean
|
|
280
|
+
export function eq(a: Vector2Int, b: Vector2Int): boolean
|
|
281
|
+
export function eq(a: Vector3Int, b: Vector3Int): boolean
|
|
282
|
+
export function eq(a: Quaternion, b: Quaternion): boolean
|
|
283
|
+
export function eq(a: any, b: any): boolean {
|
|
284
|
+
function isBothOfType(type: any) {
|
|
285
|
+
return getType(a) == $typeof(type) && getType(b) == $typeof(type);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (isBothOfType(Vector2)) {
|
|
289
|
+
return Vector2.op_Equality(a, b);
|
|
290
|
+
} else if (isBothOfType(Vector2Int)) {
|
|
291
|
+
return Vector2Int.op_Equality(a, b);
|
|
292
|
+
} else if (isBothOfType(Vector3)) {
|
|
293
|
+
return Vector3.op_Equality(a, b);
|
|
294
|
+
} else if (isBothOfType(Vector3Int)) {
|
|
295
|
+
return Vector3Int.op_Equality(a, b);
|
|
296
|
+
} else if (isBothOfType(Quaternion)) {
|
|
297
|
+
return Quaternion.op_Equality(a, b);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
throw new Error("Unsupported types for eq operation");
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// MARK: - Vector Ops
|
|
304
|
+
|
|
305
|
+
export function dot(a: Vector2, b: Vector2): number
|
|
306
|
+
export function dot(a: Vector3, b: Vector3): number
|
|
307
|
+
export function dot(a: Vector4, b: Vector4): number
|
|
308
|
+
export function dot(a: Quaternion, b: Quaternion): number
|
|
309
|
+
export function dot(a: any, b: any): number {
|
|
310
|
+
function isBothOfType(type: any) {
|
|
311
|
+
return isOfType(a, type) && isOfType(b, type);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (isBothOfType(Vector2)) {
|
|
315
|
+
return Vector2.Dot(a, b);
|
|
316
|
+
} else if (isBothOfType(Vector3)) {
|
|
317
|
+
return Vector3.Dot(a, b);
|
|
318
|
+
} else if (isBothOfType(Vector4)) {
|
|
319
|
+
return Vector4.Dot(a, b);
|
|
320
|
+
} else if (isBothOfType(Quaternion)) {
|
|
321
|
+
return Quaternion.Dot(a, b);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
throw new Error("Unsupported types for dot operation");
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export function clamp(a: Vector2, min: Vector2, max: Vector2): Vector2
|
|
328
|
+
export function clamp(a: Vector3, min: Vector3, max: Vector3): Vector3
|
|
329
|
+
export function clamp(a: Vector2Int, min: Vector2Int, max: Vector2Int): Vector2Int
|
|
330
|
+
export function clamp(a: Vector3Int, min: Vector3Int, max: Vector3Int): Vector3Int
|
|
331
|
+
export function clamp(a: Vector4, min: Vector4, max: Vector4): Vector4
|
|
332
|
+
export function clamp(a: any, min: any, max: any): any {
|
|
333
|
+
function isAllOfType(type: any) {
|
|
334
|
+
return isOfType(a, type) && isOfType(min, type) && isOfType(max, type);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (isAllOfType(Vector2)) {
|
|
338
|
+
return vec2(
|
|
339
|
+
Math.min(Math.max(a.x, min.x), max.x),
|
|
340
|
+
Math.min(Math.max(a.y, min.y), max.y)
|
|
341
|
+
);
|
|
342
|
+
} else if (isAllOfType(Vector3)) {
|
|
343
|
+
return vec3(
|
|
344
|
+
Math.min(Math.max(a.x, min.x), max.x),
|
|
345
|
+
Math.min(Math.max(a.y, min.y), max.y),
|
|
346
|
+
Math.min(Math.max(a.z, min.z), max.z)
|
|
347
|
+
);
|
|
348
|
+
} else if (isAllOfType(Vector2Int)) {
|
|
349
|
+
return vec2i(
|
|
350
|
+
Math.min(Math.max(a.x, min.x), max.x),
|
|
351
|
+
Math.min(Math.max(a.y, min.y), max.y)
|
|
352
|
+
);
|
|
353
|
+
} else if (isAllOfType(Vector3Int)) {
|
|
354
|
+
return vec3i(
|
|
355
|
+
Math.min(Math.max(a.x, min.x), max.x),
|
|
356
|
+
Math.min(Math.max(a.y, min.y), max.y),
|
|
357
|
+
Math.min(Math.max(a.z, min.z), max.z)
|
|
358
|
+
);
|
|
359
|
+
} else if (isAllOfType(Vector4)) {
|
|
360
|
+
return vec4(
|
|
361
|
+
Math.min(Math.max(a.x, min.x), max.x),
|
|
362
|
+
Math.min(Math.max(a.y, min.y), max.y),
|
|
363
|
+
Math.min(Math.max(a.z, min.z), max.z),
|
|
364
|
+
Math.min(Math.max(a.w, min.w), max.w)
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
throw new Error("Unsupported types for clamp operation");
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export function clamp01(a: Vector2): Vector2
|
|
372
|
+
export function clamp01(a: Vector3): Vector3
|
|
373
|
+
export function clamp01(a: Vector4): Vector4
|
|
374
|
+
export function clamp01(a: any): any {
|
|
375
|
+
if (isOfType(a, Vector2)) {
|
|
376
|
+
return vec2(
|
|
377
|
+
Math.min(Math.max(a.x, 0), 1),
|
|
378
|
+
Math.min(Math.max(a.y, 0), 1)
|
|
379
|
+
);
|
|
380
|
+
} else if (isOfType(a, Vector3)) {
|
|
381
|
+
return vec3(
|
|
382
|
+
Math.min(Math.max(a.x, 0), 1),
|
|
383
|
+
Math.min(Math.max(a.y, 0), 1),
|
|
384
|
+
Math.min(Math.max(a.z, 0), 1)
|
|
385
|
+
);
|
|
386
|
+
} else if (isOfType(a, Vector4)) {
|
|
387
|
+
return vec4(
|
|
388
|
+
Math.min(Math.max(a.x, 0), 1),
|
|
389
|
+
Math.min(Math.max(a.y, 0), 1),
|
|
390
|
+
Math.min(Math.max(a.z, 0), 1),
|
|
391
|
+
Math.min(Math.max(a.w, 0), 1)
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
throw new Error("Unsupported types for clamp01 operation");
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export function distance(a: Vector2, b: Vector2): number
|
|
399
|
+
export function distance(a: Vector3, b: Vector3): number
|
|
400
|
+
export function distance(a: Vector2Int, b: Vector2Int): number
|
|
401
|
+
export function distance(a: Vector3Int, b: Vector3Int): number
|
|
402
|
+
export function distance(a: Vector4, b: Vector4): number
|
|
403
|
+
export function distance(a: any, b: any): number {
|
|
404
|
+
function isBothOfType(type: any) {
|
|
405
|
+
return isOfType(a, type) && isOfType(b, type);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (isBothOfType(Vector2)) {
|
|
409
|
+
return Vector2.Distance(a, b);
|
|
410
|
+
} else if (isBothOfType(Vector3)) {
|
|
411
|
+
return Vector3.Distance(a, b);
|
|
412
|
+
} else if (isBothOfType(Vector2Int)) {
|
|
413
|
+
const dx = a.x - b.x;
|
|
414
|
+
const dy = a.y - b.y;
|
|
415
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
416
|
+
} else if (isBothOfType(Vector3Int)) {
|
|
417
|
+
const dx = a.x - b.x;
|
|
418
|
+
const dy = a.y - b.y;
|
|
419
|
+
const dz = a.z - b.z;
|
|
420
|
+
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
421
|
+
} else if (isBothOfType(Vector4)) {
|
|
422
|
+
const dx = a.x - b.x;
|
|
423
|
+
const dy = a.y - b.y;
|
|
424
|
+
const dz = a.z - b.z;
|
|
425
|
+
const dw = a.w - b.w;
|
|
426
|
+
return Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
throw new Error("Unsupported types for distance operation");
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export function normalize(a: Vector2): Vector2
|
|
433
|
+
export function normalize(a: Vector3): Vector3
|
|
434
|
+
export function normalize(a: Vector4): Vector4
|
|
435
|
+
export function normalize(a: any): any {
|
|
436
|
+
if (isOfType(a, Vector2)) {
|
|
437
|
+
const magnitude = Math.sqrt(a.x * a.x + a.y * a.y);
|
|
438
|
+
if (magnitude < 1e-6) {
|
|
439
|
+
return vec2(0, 0);
|
|
440
|
+
}
|
|
441
|
+
return vec2(a.x / magnitude, a.y / magnitude);
|
|
442
|
+
} else if (isOfType(a, Vector3)) {
|
|
443
|
+
return Vector3.Normalize(a);
|
|
444
|
+
} else if (isOfType(a, Vector4)) {
|
|
445
|
+
return Vector4.Normalize(a);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
throw new Error("Unsupported types for normalize operation");
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export function lerp(a: number, b: number, t: number): number
|
|
452
|
+
export function lerp(a: Vector2, b: Vector2, t: number): Vector2
|
|
453
|
+
export function lerp(a: Vector3, b: Vector3, t: number): Vector3
|
|
454
|
+
export function lerp(a: Vector4, b: Vector4, t: number): Vector4
|
|
455
|
+
export function lerp(a: Quaternion, b: Quaternion, t: number): Quaternion
|
|
456
|
+
export function lerp(a: Color, b: Color, t: number): Color
|
|
457
|
+
export function lerp(a: any, b: any, t: number): any {
|
|
458
|
+
function isBothOfType(type: any) {
|
|
459
|
+
return isOfType(a, type) && isOfType(b, type);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
463
|
+
return a + (b - a) * t;
|
|
464
|
+
} else if (isBothOfType(Vector2)) {
|
|
465
|
+
return Vector2.Lerp(a, b, t);
|
|
466
|
+
} else if (isBothOfType(Vector3)) {
|
|
467
|
+
return Vector3.Lerp(a, b, t);
|
|
468
|
+
} else if (isBothOfType(Vector4)) {
|
|
469
|
+
return vec4(
|
|
470
|
+
a.x + (b.x - a.x) * t,
|
|
471
|
+
a.y + (b.y - a.y) * t,
|
|
472
|
+
a.z + (b.z - a.z) * t,
|
|
473
|
+
a.w + (b.w - a.w) * t
|
|
474
|
+
);
|
|
475
|
+
} else if (isBothOfType(Quaternion)) {
|
|
476
|
+
return Quaternion.Lerp(a, b, t);
|
|
477
|
+
} else if (isBothOfType(Color)) {
|
|
478
|
+
return Color.Lerp(a, b, t);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
throw new Error("Unsupported types for lerp operation");
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// MARK: - Utilities
|
|
485
|
+
|
|
486
|
+
function isOfType(obj: any, type: any) {
|
|
487
|
+
return getType(obj) == $typeof(type);
|
|
488
488
|
}
|