@vib3code/sdk 2.0.3-canary.45332e3 → 2.0.3-canary.4e0dace
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/DOCS/AGENT_HARNESS_ARCHITECTURE.md +2 -0
- package/DOCS/ANDROID_DEPLOYMENT.md +59 -0
- package/DOCS/ARCHITECTURE.md +1 -0
- package/DOCS/CI_TESTING.md +2 -0
- package/DOCS/CLI_ONBOARDING.md +2 -0
- package/DOCS/CONTROL_REFERENCE.md +2 -0
- package/DOCS/CROSS_SITE_DESIGN_PATTERNS.md +2 -0
- package/DOCS/ENV_SETUP.md +2 -0
- package/DOCS/EPIC_SCROLL_EVENTS.md +2 -0
- package/DOCS/EXPANSION_DESIGN.md +979 -0
- package/DOCS/EXPANSION_DESIGN_ULTRA.md +389 -0
- package/DOCS/EXPORT_FORMATS.md +2 -0
- package/DOCS/GPU_DISPOSAL_GUIDE.md +2 -0
- package/DOCS/HANDOFF_LANDING_PAGE.md +2 -0
- package/DOCS/HANDOFF_SDK_DEVELOPMENT.md +2 -0
- package/DOCS/LICENSING_TIERS.md +2 -0
- package/DOCS/MASTER_PLAN_2026-01-31.md +2 -0
- package/DOCS/MULTIVIZ_CHOREOGRAPHY_PATTERNS.md +3 -1
- package/DOCS/OBS_SETUP_GUIDE.md +2 -0
- package/DOCS/OPTIMIZATION_PLAN_MATH.md +119 -0
- package/DOCS/PRODUCT_STRATEGY.md +2 -0
- package/DOCS/PROJECT_SETUP.md +2 -0
- package/DOCS/README.md +5 -3
- package/DOCS/REFERENCE_SCROLL_ANALYSIS.md +2 -0
- package/DOCS/RENDERER_LIFECYCLE.md +2 -0
- package/DOCS/REPO_MANIFEST.md +2 -0
- package/DOCS/ROADMAP.md +2 -0
- package/DOCS/SCROLL_TIMELINE_v3.md +2 -0
- package/DOCS/SITE_REFACTOR_PLAN.md +2 -0
- package/DOCS/STATUS.md +2 -0
- package/DOCS/SYSTEM_INVENTORY.md +2 -0
- package/DOCS/TELEMETRY_EXPORTS.md +2 -0
- package/DOCS/VISUAL_ANALYSIS_CLICKERSS.md +2 -0
- package/DOCS/VISUAL_ANALYSIS_FACETAD.md +2 -0
- package/DOCS/VISUAL_ANALYSIS_SIMONE.md +2 -0
- package/DOCS/VISUAL_ANALYSIS_TABLESIDE.md +2 -0
- package/DOCS/WEBGPU_STATUS.md +2 -0
- package/DOCS/XR_BENCHMARKS.md +2 -0
- package/DOCS/archive/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md +1 -34
- package/DOCS/archive/DEV_TRACK_ANALYSIS.md +1 -80
- package/DOCS/archive/DEV_TRACK_PLAN_2026-01-07.md +1 -42
- package/DOCS/archive/SESSION_014_PLAN.md +1 -195
- package/DOCS/archive/SESSION_LOG_2026-01-07.md +1 -56
- package/DOCS/archive/STRATEGIC_BLUEPRINT_2026-01-07.md +1 -72
- package/DOCS/archive/SYSTEM_AUDIT_2026-01-30.md +1 -741
- package/DOCS/archive/WEBGPU_STATUS_2026-02-15_STALE.md +1 -38
- package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-01-31.md +2 -0
- package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-06.md +2 -0
- package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-13.md +2 -0
- package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-15.md +2 -0
- package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-16.md +2 -0
- package/DOCS/dev-tracks/PERF_UPGRADE_2026-02-16.md +310 -0
- package/DOCS/dev-tracks/README.md +2 -0
- package/package.json +2 -4
- package/src/cli/index.js +59 -5
- package/src/experimental/GameLoop.js +72 -0
- package/src/experimental/LatticePhysics.js +100 -0
- package/src/experimental/LiveDirector.js +143 -0
- package/src/experimental/PlayerController4D.js +154 -0
- package/src/experimental/VIB3Actor.js +138 -0
- package/src/experimental/VIB3Compositor.js +117 -0
- package/src/experimental/VIB3Link.js +122 -0
- package/src/experimental/VIB3Orchestrator.js +146 -0
- package/src/experimental/VIB3Universe.js +109 -0
- package/src/experimental/demos/CrystalLabyrinth.js +202 -0
- package/src/geometry/generators/Crystal.js +2 -2
- package/src/geometry/warp/HypersphereCore.js +53 -24
- package/src/math/Mat4x4.js +238 -92
- package/src/math/Projection.js +39 -4
- package/src/math/Rotor4D.js +69 -46
- package/src/math/Vec4.js +200 -103
- package/src/scene/Node4D.js +74 -24
- package/src/testing/ProjectionClass.test.js +38 -0
- package/tools/update_projection.py +109 -0
|
@@ -16,13 +16,14 @@ import { Vec4 } from '../../math/Vec4.js';
|
|
|
16
16
|
* @param {number} radius - Hypersphere radius
|
|
17
17
|
* @returns {Vec4} Point on hypersphere
|
|
18
18
|
*/
|
|
19
|
-
export function projectToHypersphere(point, radius = 1) {
|
|
19
|
+
export function projectToHypersphere(point, radius = 1, target = null) {
|
|
20
20
|
const len = point.length();
|
|
21
21
|
if (len < 0.0001) {
|
|
22
22
|
// Handle origin - project to north pole
|
|
23
|
+
if (target) return target.set(0, 0, 0, radius);
|
|
23
24
|
return new Vec4(0, 0, 0, radius);
|
|
24
25
|
}
|
|
25
|
-
return point.scale(radius / len);
|
|
26
|
+
return point.scale(radius / len, target);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
/**
|
|
@@ -30,9 +31,10 @@ export function projectToHypersphere(point, radius = 1) {
|
|
|
30
31
|
* Maps all of 3D space onto the 4D hypersphere
|
|
31
32
|
* @param {Vec4} point - Input point (uses x, y, z)
|
|
32
33
|
* @param {number} radius - Hypersphere radius
|
|
34
|
+
* @param {Vec4} [target=null] - Optional target vector
|
|
33
35
|
* @returns {Vec4} Point on hypersphere
|
|
34
36
|
*/
|
|
35
|
-
export function stereographicToHypersphere(point, radius = 1) {
|
|
37
|
+
export function stereographicToHypersphere(point, radius = 1, target = null) {
|
|
36
38
|
const x = point.x;
|
|
37
39
|
const y = point.y;
|
|
38
40
|
const z = point.z;
|
|
@@ -40,6 +42,15 @@ export function stereographicToHypersphere(point, radius = 1) {
|
|
|
40
42
|
const sumSq = x * x + y * y + z * z;
|
|
41
43
|
const denom = sumSq + 1;
|
|
42
44
|
|
|
45
|
+
if (target) {
|
|
46
|
+
return target.set(
|
|
47
|
+
(2 * x) / denom * radius,
|
|
48
|
+
(2 * y) / denom * radius,
|
|
49
|
+
(2 * z) / denom * radius,
|
|
50
|
+
(sumSq - 1) / denom * radius
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
return new Vec4(
|
|
44
55
|
(2 * x) / denom * radius,
|
|
45
56
|
(2 * y) / denom * radius,
|
|
@@ -56,12 +67,22 @@ export function stereographicToHypersphere(point, radius = 1) {
|
|
|
56
67
|
* @param {number} phi - Azimuth on base S² (0 to 2π)
|
|
57
68
|
* @param {number} psi - Fiber angle (0 to 2π)
|
|
58
69
|
* @param {number} radius - Hypersphere radius
|
|
70
|
+
* @param {Vec4} [target=null] - Optional target vector
|
|
59
71
|
* @returns {Vec4} Point on hypersphere
|
|
60
72
|
*/
|
|
61
|
-
export function hopfFibration(theta, phi, psi, radius = 1) {
|
|
73
|
+
export function hopfFibration(theta, phi, psi, radius = 1, target = null) {
|
|
62
74
|
const cosTheta2 = Math.cos(theta / 2);
|
|
63
75
|
const sinTheta2 = Math.sin(theta / 2);
|
|
64
76
|
|
|
77
|
+
if (target) {
|
|
78
|
+
return target.set(
|
|
79
|
+
cosTheta2 * Math.cos((phi + psi) / 2) * radius,
|
|
80
|
+
cosTheta2 * Math.sin((phi + psi) / 2) * radius,
|
|
81
|
+
sinTheta2 * Math.cos((phi - psi) / 2) * radius,
|
|
82
|
+
sinTheta2 * Math.sin((phi - psi) / 2) * radius
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
65
86
|
return new Vec4(
|
|
66
87
|
cosTheta2 * Math.cos((phi + psi) / 2) * radius,
|
|
67
88
|
cosTheta2 * Math.sin((phi + psi) / 2) * radius,
|
|
@@ -78,8 +99,9 @@ export function hopfFibration(theta, phi, psi, radius = 1) {
|
|
|
78
99
|
* @returns {Vec4[]} Warped vertices
|
|
79
100
|
*/
|
|
80
101
|
export function warpRadial(vertices, radius = 1, blendFactor = 1) {
|
|
102
|
+
const onSphere = new Vec4();
|
|
81
103
|
return vertices.map(v => {
|
|
82
|
-
|
|
104
|
+
projectToHypersphere(v, radius, onSphere);
|
|
83
105
|
return v.lerp(onSphere, blendFactor);
|
|
84
106
|
});
|
|
85
107
|
}
|
|
@@ -93,8 +115,9 @@ export function warpRadial(vertices, radius = 1, blendFactor = 1) {
|
|
|
93
115
|
* @returns {Vec4[]} Warped vertices
|
|
94
116
|
*/
|
|
95
117
|
export function warpStereographic(vertices, radius = 1, scale = 1) {
|
|
118
|
+
const scaled = new Vec4();
|
|
96
119
|
return vertices.map(v => {
|
|
97
|
-
|
|
120
|
+
v.scale(scale, scaled);
|
|
98
121
|
return stereographicToHypersphere(scaled, radius);
|
|
99
122
|
});
|
|
100
123
|
}
|
|
@@ -146,25 +169,31 @@ export function warpHypersphereCore(geometry, options = {}) {
|
|
|
146
169
|
twist = 1
|
|
147
170
|
} = options;
|
|
148
171
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
172
|
+
const temp = new Vec4();
|
|
173
|
+
const warpedVertices = geometry.vertices.map(v => {
|
|
174
|
+
// Combined scaling and warping to minimize allocations
|
|
175
|
+
const result = v.scale(scale);
|
|
176
|
+
|
|
177
|
+
if (method === 'stereographic') {
|
|
178
|
+
stereographicToHypersphere(result, radius, result);
|
|
179
|
+
} else if (method === 'hopf') {
|
|
180
|
+
const r = result.length();
|
|
181
|
+
if (r < 0.0001) {
|
|
182
|
+
result.set(0, 0, 0, radius);
|
|
183
|
+
} else {
|
|
184
|
+
const theta = Math.acos(result.z / r);
|
|
185
|
+
const phi = Math.atan2(result.y, result.x);
|
|
186
|
+
const psi = result.w * twist + phi * 0.5;
|
|
187
|
+
hopfFibration(theta, phi, psi, radius, result);
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
// Radial (default)
|
|
191
|
+
projectToHypersphere(result, radius, temp);
|
|
192
|
+
result.lerp(temp, blend, result);
|
|
193
|
+
}
|
|
162
194
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
warpedVertices = warpRadial(scaledVertices, radius, blend);
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
195
|
+
return result;
|
|
196
|
+
});
|
|
168
197
|
|
|
169
198
|
return {
|
|
170
199
|
...geometry,
|
package/src/math/Mat4x4.js
CHANGED
|
@@ -18,6 +18,12 @@
|
|
|
18
18
|
import { Vec4 } from './Vec4.js';
|
|
19
19
|
|
|
20
20
|
export class Mat4x4 {
|
|
21
|
+
/**
|
|
22
|
+
* Internal token to skip initialization during construction
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
static UNINITIALIZED = {};
|
|
26
|
+
|
|
21
27
|
/**
|
|
22
28
|
* Create a new 4x4 matrix
|
|
23
29
|
* Default is identity matrix
|
|
@@ -26,6 +32,8 @@ export class Mat4x4 {
|
|
|
26
32
|
constructor(elements = null) {
|
|
27
33
|
this.data = new Float32Array(16);
|
|
28
34
|
|
|
35
|
+
if (elements === Mat4x4.UNINITIALIZED) return;
|
|
36
|
+
|
|
29
37
|
if (elements) {
|
|
30
38
|
if (elements.length !== 16) {
|
|
31
39
|
throw new Error('Mat4x4 requires exactly 16 elements');
|
|
@@ -45,12 +53,7 @@ export class Mat4x4 {
|
|
|
45
53
|
* @returns {Mat4x4}
|
|
46
54
|
*/
|
|
47
55
|
static identity() {
|
|
48
|
-
return new Mat4x4(
|
|
49
|
-
1, 0, 0, 0,
|
|
50
|
-
0, 1, 0, 0,
|
|
51
|
-
0, 0, 1, 0,
|
|
52
|
-
0, 0, 0, 1
|
|
53
|
-
]);
|
|
56
|
+
return new Mat4x4();
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
/**
|
|
@@ -58,7 +61,7 @@ export class Mat4x4 {
|
|
|
58
61
|
* @returns {Mat4x4}
|
|
59
62
|
*/
|
|
60
63
|
static zero() {
|
|
61
|
-
return new Mat4x4(
|
|
64
|
+
return new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
/**
|
|
@@ -157,10 +160,11 @@ export class Mat4x4 {
|
|
|
157
160
|
/**
|
|
158
161
|
* Multiply two matrices
|
|
159
162
|
* @param {Mat4x4} m - Right operand
|
|
163
|
+
* @param {Mat4x4} [target=null] - Optional target matrix to store result
|
|
160
164
|
* @returns {Mat4x4} New matrix = this * m
|
|
161
165
|
*/
|
|
162
|
-
multiply(m) {
|
|
163
|
-
const out = new Mat4x4();
|
|
166
|
+
multiply(m, target = null) {
|
|
167
|
+
const out = target || new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
164
168
|
const r = out.data;
|
|
165
169
|
const a = this.data;
|
|
166
170
|
const b = m.data;
|
|
@@ -259,16 +263,22 @@ export class Mat4x4 {
|
|
|
259
263
|
/**
|
|
260
264
|
* Transform a Vec4 by this matrix
|
|
261
265
|
* @param {Vec4} v
|
|
266
|
+
* @param {Vec4} [target=null] - Optional target vector to store result
|
|
262
267
|
* @returns {Vec4} Transformed vector
|
|
263
268
|
*/
|
|
264
|
-
multiplyVec4(v) {
|
|
269
|
+
multiplyVec4(v, target = null) {
|
|
265
270
|
const m = this.data;
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
271
|
+
const out = target || new Vec4();
|
|
272
|
+
|
|
273
|
+
// Cache components to support aliasing (target === v)
|
|
274
|
+
const x = v.x, y = v.y, z = v.z, w = v.w;
|
|
275
|
+
|
|
276
|
+
out.x = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
|
|
277
|
+
out.y = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
|
|
278
|
+
out.z = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
|
|
279
|
+
out.w = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
|
|
280
|
+
|
|
281
|
+
return out;
|
|
272
282
|
}
|
|
273
283
|
|
|
274
284
|
/**
|
|
@@ -310,27 +320,36 @@ export class Mat4x4 {
|
|
|
310
320
|
/**
|
|
311
321
|
* Add another matrix
|
|
312
322
|
* @param {Mat4x4} m
|
|
323
|
+
* @param {Mat4x4} [target=null] - Optional target matrix
|
|
313
324
|
* @returns {Mat4x4} New matrix
|
|
314
325
|
*/
|
|
315
|
-
add(m) {
|
|
316
|
-
const
|
|
326
|
+
add(m, target = null) {
|
|
327
|
+
const out = target || new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
328
|
+
const r = out.data;
|
|
329
|
+
const a = this.data;
|
|
330
|
+
const b = m.data;
|
|
331
|
+
|
|
317
332
|
for (let i = 0; i < 16; i++) {
|
|
318
|
-
|
|
333
|
+
r[i] = a[i] + b[i];
|
|
319
334
|
}
|
|
320
|
-
return
|
|
335
|
+
return out;
|
|
321
336
|
}
|
|
322
337
|
|
|
323
338
|
/**
|
|
324
339
|
* Multiply by scalar
|
|
325
340
|
* @param {number} s
|
|
341
|
+
* @param {Mat4x4} [target=null] - Optional target matrix
|
|
326
342
|
* @returns {Mat4x4} New matrix
|
|
327
343
|
*/
|
|
328
|
-
scale(s) {
|
|
329
|
-
const
|
|
344
|
+
scale(s, target = null) {
|
|
345
|
+
const out = target || new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
346
|
+
const r = out.data;
|
|
347
|
+
const a = this.data;
|
|
348
|
+
|
|
330
349
|
for (let i = 0; i < 16; i++) {
|
|
331
|
-
|
|
350
|
+
r[i] = a[i] * s;
|
|
332
351
|
}
|
|
333
|
-
return
|
|
352
|
+
return out;
|
|
334
353
|
}
|
|
335
354
|
|
|
336
355
|
/**
|
|
@@ -339,12 +358,13 @@ export class Mat4x4 {
|
|
|
339
358
|
*/
|
|
340
359
|
transpose() {
|
|
341
360
|
const m = this.data;
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
]
|
|
361
|
+
const out = new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
362
|
+
const r = out.data;
|
|
363
|
+
r[0] = m[0]; r[4] = m[1]; r[8] = m[2]; r[12] = m[3];
|
|
364
|
+
r[1] = m[4]; r[5] = m[5]; r[9] = m[6]; r[13] = m[7];
|
|
365
|
+
r[2] = m[8]; r[6] = m[9]; r[10] = m[10]; r[14] = m[11];
|
|
366
|
+
r[3] = m[12]; r[7] = m[13]; r[11] = m[14]; r[15] = m[15];
|
|
367
|
+
return out;
|
|
348
368
|
}
|
|
349
369
|
|
|
350
370
|
/**
|
|
@@ -399,7 +419,8 @@ export class Mat4x4 {
|
|
|
399
419
|
*/
|
|
400
420
|
inverse() {
|
|
401
421
|
const m = this.data;
|
|
402
|
-
const
|
|
422
|
+
const out = new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
423
|
+
const inv = out.data;
|
|
403
424
|
|
|
404
425
|
inv[0] = m[5] * m[10] * m[15] - m[5] * m[11] * m[14] - m[9] * m[6] * m[15] +
|
|
405
426
|
m[9] * m[7] * m[14] + m[13] * m[6] * m[11] - m[13] * m[7] * m[10];
|
|
@@ -460,7 +481,7 @@ export class Mat4x4 {
|
|
|
460
481
|
inv[i] *= invDet;
|
|
461
482
|
}
|
|
462
483
|
|
|
463
|
-
return
|
|
484
|
+
return out;
|
|
464
485
|
}
|
|
465
486
|
|
|
466
487
|
/**
|
|
@@ -547,6 +568,122 @@ export class Mat4x4 {
|
|
|
547
568
|
return new Mat4x4(json.data);
|
|
548
569
|
}
|
|
549
570
|
|
|
571
|
+
// ========== IN-PLACE ROTATIONS ==========
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Rotate in XY plane in place
|
|
575
|
+
* @param {number} angle
|
|
576
|
+
* @returns {Mat4x4} this
|
|
577
|
+
*/
|
|
578
|
+
rotateXY(angle) {
|
|
579
|
+
const c = Math.cos(angle);
|
|
580
|
+
const s = Math.sin(angle);
|
|
581
|
+
const m = this.data;
|
|
582
|
+
|
|
583
|
+
for (let i = 0; i < 4; i++) {
|
|
584
|
+
const a0 = m[i]; // Col 0
|
|
585
|
+
const a1 = m[i + 4]; // Col 1
|
|
586
|
+
m[i] = a0 * c + a1 * s;
|
|
587
|
+
m[i + 4] = -a0 * s + a1 * c;
|
|
588
|
+
}
|
|
589
|
+
return this;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Rotate in XZ plane in place
|
|
594
|
+
* @param {number} angle
|
|
595
|
+
* @returns {Mat4x4} this
|
|
596
|
+
*/
|
|
597
|
+
rotateXZ(angle) {
|
|
598
|
+
const c = Math.cos(angle);
|
|
599
|
+
const s = Math.sin(angle);
|
|
600
|
+
const m = this.data;
|
|
601
|
+
|
|
602
|
+
for (let i = 0; i < 4; i++) {
|
|
603
|
+
const a0 = m[i]; // Col 0
|
|
604
|
+
const a2 = m[i + 8]; // Col 2
|
|
605
|
+
m[i] = a0 * c - a2 * s;
|
|
606
|
+
m[i + 8] = a0 * s + a2 * c;
|
|
607
|
+
}
|
|
608
|
+
return this;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Rotate in YZ plane in place
|
|
613
|
+
* @param {number} angle
|
|
614
|
+
* @returns {Mat4x4} this
|
|
615
|
+
*/
|
|
616
|
+
rotateYZ(angle) {
|
|
617
|
+
const c = Math.cos(angle);
|
|
618
|
+
const s = Math.sin(angle);
|
|
619
|
+
const m = this.data;
|
|
620
|
+
|
|
621
|
+
for (let i = 0; i < 4; i++) {
|
|
622
|
+
const a1 = m[i + 4]; // Col 1
|
|
623
|
+
const a2 = m[i + 8]; // Col 2
|
|
624
|
+
m[i + 4] = a1 * c + a2 * s;
|
|
625
|
+
m[i + 8] = -a1 * s + a2 * c;
|
|
626
|
+
}
|
|
627
|
+
return this;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Rotate in XW plane in place
|
|
632
|
+
* @param {number} angle
|
|
633
|
+
* @returns {Mat4x4} this
|
|
634
|
+
*/
|
|
635
|
+
rotateXW(angle) {
|
|
636
|
+
const c = Math.cos(angle);
|
|
637
|
+
const s = Math.sin(angle);
|
|
638
|
+
const m = this.data;
|
|
639
|
+
|
|
640
|
+
for (let i = 0; i < 4; i++) {
|
|
641
|
+
const a0 = m[i]; // Col 0
|
|
642
|
+
const a3 = m[i + 12]; // Col 3
|
|
643
|
+
m[i] = a0 * c + a3 * s;
|
|
644
|
+
m[i + 12] = -a0 * s + a3 * c;
|
|
645
|
+
}
|
|
646
|
+
return this;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Rotate in YW plane in place
|
|
651
|
+
* @param {number} angle
|
|
652
|
+
* @returns {Mat4x4} this
|
|
653
|
+
*/
|
|
654
|
+
rotateYW(angle) {
|
|
655
|
+
const c = Math.cos(angle);
|
|
656
|
+
const s = Math.sin(angle);
|
|
657
|
+
const m = this.data;
|
|
658
|
+
|
|
659
|
+
for (let i = 0; i < 4; i++) {
|
|
660
|
+
const a1 = m[i + 4]; // Col 1
|
|
661
|
+
const a3 = m[i + 12]; // Col 3
|
|
662
|
+
m[i + 4] = a1 * c + a3 * s;
|
|
663
|
+
m[i + 12] = -a1 * s + a3 * c;
|
|
664
|
+
}
|
|
665
|
+
return this;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Rotate in ZW plane in place
|
|
670
|
+
* @param {number} angle
|
|
671
|
+
* @returns {Mat4x4} this
|
|
672
|
+
*/
|
|
673
|
+
rotateZW(angle) {
|
|
674
|
+
const c = Math.cos(angle);
|
|
675
|
+
const s = Math.sin(angle);
|
|
676
|
+
const m = this.data;
|
|
677
|
+
|
|
678
|
+
for (let i = 0; i < 4; i++) {
|
|
679
|
+
const a2 = m[i + 8]; // Col 2
|
|
680
|
+
const a3 = m[i + 12]; // Col 3
|
|
681
|
+
m[i + 8] = a2 * c + a3 * s;
|
|
682
|
+
m[i + 12] = -a2 * s + a3 * c;
|
|
683
|
+
}
|
|
684
|
+
return this;
|
|
685
|
+
}
|
|
686
|
+
|
|
550
687
|
// ========== ROTATION MATRICES FOR ALL 6 PLANES ==========
|
|
551
688
|
|
|
552
689
|
/**
|
|
@@ -557,12 +694,13 @@ export class Mat4x4 {
|
|
|
557
694
|
static rotationXY(angle) {
|
|
558
695
|
const c = Math.cos(angle);
|
|
559
696
|
const s = Math.sin(angle);
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
]
|
|
697
|
+
const out = new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
698
|
+
const r = out.data;
|
|
699
|
+
r[0] = c; r[1] = s;
|
|
700
|
+
r[4] = -s; r[5] = c;
|
|
701
|
+
r[10] = 1;
|
|
702
|
+
r[15] = 1;
|
|
703
|
+
return out;
|
|
566
704
|
}
|
|
567
705
|
|
|
568
706
|
/**
|
|
@@ -573,12 +711,13 @@ export class Mat4x4 {
|
|
|
573
711
|
static rotationXZ(angle) {
|
|
574
712
|
const c = Math.cos(angle);
|
|
575
713
|
const s = Math.sin(angle);
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
]
|
|
714
|
+
const out = new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
715
|
+
const r = out.data;
|
|
716
|
+
r[0] = c; r[2] = -s;
|
|
717
|
+
r[5] = 1;
|
|
718
|
+
r[8] = s; r[10] = c;
|
|
719
|
+
r[15] = 1;
|
|
720
|
+
return out;
|
|
582
721
|
}
|
|
583
722
|
|
|
584
723
|
/**
|
|
@@ -589,12 +728,13 @@ export class Mat4x4 {
|
|
|
589
728
|
static rotationYZ(angle) {
|
|
590
729
|
const c = Math.cos(angle);
|
|
591
730
|
const s = Math.sin(angle);
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
]
|
|
731
|
+
const out = new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
732
|
+
const r = out.data;
|
|
733
|
+
r[0] = 1;
|
|
734
|
+
r[5] = c; r[6] = s;
|
|
735
|
+
r[9] = -s; r[10] = c;
|
|
736
|
+
r[15] = 1;
|
|
737
|
+
return out;
|
|
598
738
|
}
|
|
599
739
|
|
|
600
740
|
/**
|
|
@@ -606,12 +746,13 @@ export class Mat4x4 {
|
|
|
606
746
|
static rotationXW(angle) {
|
|
607
747
|
const c = Math.cos(angle);
|
|
608
748
|
const s = Math.sin(angle);
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
]
|
|
749
|
+
const out = new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
750
|
+
const r = out.data;
|
|
751
|
+
r[0] = c; r[3] = s;
|
|
752
|
+
r[5] = 1;
|
|
753
|
+
r[10] = 1;
|
|
754
|
+
r[12] = -s; r[15] = c;
|
|
755
|
+
return out;
|
|
615
756
|
}
|
|
616
757
|
|
|
617
758
|
/**
|
|
@@ -622,12 +763,13 @@ export class Mat4x4 {
|
|
|
622
763
|
static rotationYW(angle) {
|
|
623
764
|
const c = Math.cos(angle);
|
|
624
765
|
const s = Math.sin(angle);
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
]
|
|
766
|
+
const out = new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
767
|
+
const r = out.data;
|
|
768
|
+
r[0] = 1;
|
|
769
|
+
r[5] = c; r[7] = s;
|
|
770
|
+
r[10] = 1;
|
|
771
|
+
r[13] = -s; r[15] = c;
|
|
772
|
+
return out;
|
|
631
773
|
}
|
|
632
774
|
|
|
633
775
|
/**
|
|
@@ -638,12 +780,13 @@ export class Mat4x4 {
|
|
|
638
780
|
static rotationZW(angle) {
|
|
639
781
|
const c = Math.cos(angle);
|
|
640
782
|
const s = Math.sin(angle);
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
]
|
|
783
|
+
const out = new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
784
|
+
const r = out.data;
|
|
785
|
+
r[0] = 1;
|
|
786
|
+
r[5] = 1;
|
|
787
|
+
r[10] = c; r[11] = s;
|
|
788
|
+
r[14] = -s; r[15] = c;
|
|
789
|
+
return out;
|
|
647
790
|
}
|
|
648
791
|
|
|
649
792
|
/**
|
|
@@ -681,12 +824,12 @@ export class Mat4x4 {
|
|
|
681
824
|
static rotationFromAngles(angles) {
|
|
682
825
|
let result = Mat4x4.identity();
|
|
683
826
|
|
|
684
|
-
if (angles.xy) result
|
|
685
|
-
if (angles.xz) result
|
|
686
|
-
if (angles.yz) result
|
|
687
|
-
if (angles.xw) result
|
|
688
|
-
if (angles.yw) result
|
|
689
|
-
if (angles.zw) result
|
|
827
|
+
if (angles.xy) result.rotateXY(angles.xy);
|
|
828
|
+
if (angles.xz) result.rotateXZ(angles.xz);
|
|
829
|
+
if (angles.yz) result.rotateYZ(angles.yz);
|
|
830
|
+
if (angles.xw) result.rotateXW(angles.xw);
|
|
831
|
+
if (angles.yw) result.rotateYW(angles.yw);
|
|
832
|
+
if (angles.zw) result.rotateZW(angles.zw);
|
|
690
833
|
|
|
691
834
|
return result;
|
|
692
835
|
}
|
|
@@ -715,12 +858,13 @@ export class Mat4x4 {
|
|
|
715
858
|
* @returns {Mat4x4}
|
|
716
859
|
*/
|
|
717
860
|
static uniformScale(s) {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
]
|
|
861
|
+
const out = new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
862
|
+
const r = out.data;
|
|
863
|
+
r[0] = s;
|
|
864
|
+
r[5] = s;
|
|
865
|
+
r[10] = s;
|
|
866
|
+
r[15] = s;
|
|
867
|
+
return out;
|
|
724
868
|
}
|
|
725
869
|
|
|
726
870
|
/**
|
|
@@ -732,12 +876,13 @@ export class Mat4x4 {
|
|
|
732
876
|
* @returns {Mat4x4}
|
|
733
877
|
*/
|
|
734
878
|
static scale(sx, sy, sz, sw = 1) {
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
]
|
|
879
|
+
const out = new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
880
|
+
const r = out.data;
|
|
881
|
+
r[0] = sx;
|
|
882
|
+
r[5] = sy;
|
|
883
|
+
r[10] = sz;
|
|
884
|
+
r[15] = sw;
|
|
885
|
+
return out;
|
|
741
886
|
}
|
|
742
887
|
|
|
743
888
|
/**
|
|
@@ -753,12 +898,13 @@ export class Mat4x4 {
|
|
|
753
898
|
static translation(tx, ty, tz, tw = 0) {
|
|
754
899
|
// For true 4D translation, you need 5D homogeneous coordinates
|
|
755
900
|
// This is a placeholder that adds the translation to the W column
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
]
|
|
901
|
+
const out = new Mat4x4(Mat4x4.UNINITIALIZED);
|
|
902
|
+
const r = out.data;
|
|
903
|
+
r[0] = 1;
|
|
904
|
+
r[5] = 1;
|
|
905
|
+
r[10] = 1;
|
|
906
|
+
r[12] = tx; r[13] = ty; r[14] = tz; r[15] = 1 + tw;
|
|
907
|
+
return out;
|
|
762
908
|
}
|
|
763
909
|
}
|
|
764
910
|
|