@vib3code/sdk 2.0.3-canary.0e9a1ac → 2.0.3-canary.183c93e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/DOCS/AGENT_HARNESS_ARCHITECTURE.md +2 -0
  2. package/DOCS/ANDROID_DEPLOYMENT.md +59 -0
  3. package/DOCS/ARCHITECTURE.md +1 -0
  4. package/DOCS/CI_TESTING.md +2 -0
  5. package/DOCS/CLI_ONBOARDING.md +2 -0
  6. package/DOCS/CONTROL_REFERENCE.md +2 -0
  7. package/DOCS/CROSS_SITE_DESIGN_PATTERNS.md +2 -0
  8. package/DOCS/ENV_SETUP.md +2 -0
  9. package/DOCS/EPIC_SCROLL_EVENTS.md +2 -0
  10. package/DOCS/EXPANSION_DESIGN.md +979 -0
  11. package/DOCS/EXPANSION_DESIGN_ULTRA.md +389 -0
  12. package/DOCS/EXPORT_FORMATS.md +2 -0
  13. package/DOCS/GPU_DISPOSAL_GUIDE.md +2 -0
  14. package/DOCS/HANDOFF_LANDING_PAGE.md +2 -0
  15. package/DOCS/HANDOFF_SDK_DEVELOPMENT.md +2 -0
  16. package/DOCS/LICENSING_TIERS.md +2 -0
  17. package/DOCS/MASTER_PLAN_2026-01-31.md +4 -2
  18. package/DOCS/MULTIVIZ_CHOREOGRAPHY_PATTERNS.md +3 -1
  19. package/DOCS/OBS_SETUP_GUIDE.md +2 -0
  20. package/DOCS/OPTIMIZATION_PLAN_MATH.md +119 -0
  21. package/DOCS/PRODUCT_STRATEGY.md +2 -0
  22. package/DOCS/PROJECT_SETUP.md +2 -0
  23. package/DOCS/README.md +5 -3
  24. package/DOCS/REFERENCE_SCROLL_ANALYSIS.md +2 -0
  25. package/DOCS/RENDERER_LIFECYCLE.md +2 -0
  26. package/DOCS/REPO_MANIFEST.md +2 -0
  27. package/DOCS/ROADMAP.md +2 -0
  28. package/DOCS/SCROLL_TIMELINE_v3.md +2 -0
  29. package/DOCS/SITE_REFACTOR_PLAN.md +2 -0
  30. package/DOCS/STATUS.md +2 -0
  31. package/DOCS/SYSTEM_INVENTORY.md +4 -2
  32. package/DOCS/TELEMETRY_EXPORTS.md +2 -0
  33. package/DOCS/VISUAL_ANALYSIS_CLICKERSS.md +2 -0
  34. package/DOCS/VISUAL_ANALYSIS_FACETAD.md +2 -0
  35. package/DOCS/VISUAL_ANALYSIS_SIMONE.md +2 -0
  36. package/DOCS/VISUAL_ANALYSIS_TABLESIDE.md +2 -0
  37. package/DOCS/WEBGPU_STATUS.md +121 -38
  38. package/DOCS/XR_BENCHMARKS.md +2 -0
  39. package/DOCS/archive/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md +1 -34
  40. package/DOCS/archive/DEV_TRACK_ANALYSIS.md +1 -80
  41. package/DOCS/archive/DEV_TRACK_PLAN_2026-01-07.md +1 -42
  42. package/DOCS/archive/SESSION_014_PLAN.md +1 -195
  43. package/DOCS/archive/SESSION_LOG_2026-01-07.md +1 -56
  44. package/DOCS/archive/STRATEGIC_BLUEPRINT_2026-01-07.md +1 -72
  45. package/DOCS/archive/SYSTEM_AUDIT_2026-01-30.md +1 -741
  46. package/DOCS/archive/WEBGPU_STATUS_2026-02-15_STALE.md +1 -0
  47. package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-01-31.md +2 -0
  48. package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-06.md +2 -0
  49. package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-13.md +2 -0
  50. package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-15.md +2 -0
  51. package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-16.md +110 -0
  52. package/DOCS/dev-tracks/PERF_UPGRADE_2026-02-16.md +310 -0
  53. package/DOCS/dev-tracks/README.md +2 -0
  54. package/docs/webgpu-live.html +1 -1
  55. package/package.json +1 -1
  56. package/src/agent/mcp/MCPServer.js +346 -188
  57. package/src/agent/mcp/tools.js +45 -32
  58. package/src/experimental/GameLoop.js +72 -0
  59. package/src/experimental/LatticePhysics.js +100 -0
  60. package/src/experimental/LiveDirector.js +143 -0
  61. package/src/experimental/PlayerController4D.js +154 -0
  62. package/src/experimental/VIB3Actor.js +138 -0
  63. package/src/experimental/VIB3Compositor.js +117 -0
  64. package/src/experimental/VIB3Link.js +122 -0
  65. package/src/experimental/VIB3Orchestrator.js +146 -0
  66. package/src/experimental/VIB3Universe.js +109 -0
  67. package/src/experimental/demos/CrystalLabyrinth.js +202 -0
  68. package/src/faceted/FacetedSystem.js +19 -6
  69. package/src/games/glyph-war/GlyphWarVisualizer.js +641 -0
  70. package/src/geometry/generators/Crystal.js +2 -2
  71. package/src/holograms/HolographicVisualizer.js +58 -89
  72. package/src/math/Mat4x4.js +225 -36
  73. package/src/math/Rotor4D.js +124 -40
  74. package/src/math/Vec4.js +200 -103
  75. package/src/quantum/QuantumVisualizer.js +24 -20
  76. package/src/render/ShaderLoader.js +38 -0
  77. package/src/render/ShaderProgram.js +4 -4
  78. package/src/render/UnifiedRenderBridge.js +1 -1
  79. package/src/render/backends/WebGPUBackend.js +8 -4
  80. package/src/scene/Node4D.js +74 -24
  81. package/src/shaders/common/geometry24.glsl +65 -0
  82. package/src/shaders/common/geometry24.wgsl +54 -0
  83. package/src/shaders/common/rotation4d.glsl +4 -4
  84. package/src/shaders/common/rotation4d.wgsl +2 -2
  85. package/src/shaders/common/uniforms.wgsl +15 -8
  86. package/src/shaders/faceted/faceted.frag.wgsl +19 -6
  87. package/src/shaders/holographic/holographic.frag.wgsl +7 -5
  88. package/src/shaders/quantum/quantum.frag.wgsl +7 -5
  89. package/src/ui/adaptive/renderers/webgpu/WebGPURenderer.ts +2 -2
  90. package/tools/shader-sync-verify.js +6 -4
@@ -132,28 +132,28 @@ export class HolographicVisualizer {
132
132
  const finalName = geometryName + suffixes[variationLevel];
133
133
 
134
134
  const geometryConfigs = {
135
- 0: { density: 0.8 + variationLevel * 0.2, speed: 0.3 + variationLevel * 0.1, chaos: variationLevel * 0.1, morph: 0.0 + variationLevel * 0.2 },
136
- 1: { density: 1.0 + variationLevel * 0.3, speed: 0.5 + variationLevel * 0.1, chaos: variationLevel * 0.15, morph: variationLevel * 0.2 },
137
- 2: { density: 1.2 + variationLevel * 0.4, speed: 0.4 + variationLevel * 0.2, chaos: 0.1 + variationLevel * 0.1, morph: 0.3 + variationLevel * 0.2 },
138
- 3: { density: 0.9 + variationLevel * 0.3, speed: 0.6 + variationLevel * 0.2, chaos: 0.2 + variationLevel * 0.2, morph: 0.5 + variationLevel * 0.1 },
139
- 4: { density: 1.4 + variationLevel * 0.5, speed: 0.7 + variationLevel * 0.1, chaos: 0.3 + variationLevel * 0.2, morph: 0.7 + variationLevel * 0.1 },
140
- 5: { density: 1.8 + variationLevel * 0.3, speed: 0.5 + variationLevel * 0.3, chaos: 0.5 + variationLevel * 0.2, morph: 0.8 + variationLevel * 0.05 },
141
- 6: { density: 0.6 + variationLevel * 0.4, speed: 0.8 + variationLevel * 0.4, chaos: 0.4 + variationLevel * 0.3, morph: 0.6 + variationLevel * 0.2 },
142
- 7: { density: 1.6 + variationLevel * 0.2, speed: 0.2 + variationLevel * 0.1, chaos: 0.1 + variationLevel * 0.1, morph: 0.2 + variationLevel * 0.2 }
135
+ 0: { gridDensity: 0.8 + variationLevel * 0.2, speed: 0.3 + variationLevel * 0.1, chaos: variationLevel * 0.1, morphFactor: 0.0 + variationLevel * 0.2 },
136
+ 1: { gridDensity: 1.0 + variationLevel * 0.3, speed: 0.5 + variationLevel * 0.1, chaos: variationLevel * 0.15, morphFactor: variationLevel * 0.2 },
137
+ 2: { gridDensity: 1.2 + variationLevel * 0.4, speed: 0.4 + variationLevel * 0.2, chaos: 0.1 + variationLevel * 0.1, morphFactor: 0.3 + variationLevel * 0.2 },
138
+ 3: { gridDensity: 0.9 + variationLevel * 0.3, speed: 0.6 + variationLevel * 0.2, chaos: 0.2 + variationLevel * 0.2, morphFactor: 0.5 + variationLevel * 0.1 },
139
+ 4: { gridDensity: 1.4 + variationLevel * 0.5, speed: 0.7 + variationLevel * 0.1, chaos: 0.3 + variationLevel * 0.2, morphFactor: 0.7 + variationLevel * 0.1 },
140
+ 5: { gridDensity: 1.8 + variationLevel * 0.3, speed: 0.5 + variationLevel * 0.3, chaos: 0.5 + variationLevel * 0.2, morphFactor: 0.8 + variationLevel * 0.05 },
141
+ 6: { gridDensity: 0.6 + variationLevel * 0.4, speed: 0.8 + variationLevel * 0.4, chaos: 0.4 + variationLevel * 0.3, morphFactor: 0.6 + variationLevel * 0.2 },
142
+ 7: { gridDensity: 1.6 + variationLevel * 0.2, speed: 0.2 + variationLevel * 0.1, chaos: 0.1 + variationLevel * 0.1, morphFactor: 0.2 + variationLevel * 0.2 }
143
143
  };
144
-
144
+
145
145
  const config = geometryConfigs[baseGeometry];
146
-
146
+
147
147
  return {
148
- geometryType: baseGeometry,
148
+ geometry: baseGeometry,
149
149
  name: finalName,
150
- density: config.density,
150
+ gridDensity: config.gridDensity,
151
151
  speed: config.speed,
152
152
  hue: (variant * 12.27) % 360,
153
- saturation: 0.8 + (variationLevel * 0.05), // Add saturation parameter
153
+ saturation: 0.8 + (variationLevel * 0.05),
154
154
  intensity: 0.5 + (variationLevel * 0.1),
155
155
  chaos: config.chaos,
156
- morph: config.morph
156
+ morphFactor: config.morphFactor
157
157
  };
158
158
  }
159
159
 
@@ -169,20 +169,20 @@ export class HolographicVisualizer {
169
169
  densityMult: 0.8, speedMult: 0.3, colorShift: 180.0, intensity: 0.4,
170
170
  mouseReactivity: 0.5, clickReactivity: 0.3
171
171
  },
172
- 'content': {
173
- densityMult: vp.density, speedMult: vp.speed,
172
+ 'content': {
173
+ densityMult: vp.gridDensity, speedMult: vp.speed,
174
174
  colorShift: vp.hue, intensity: vp.intensity,
175
- mouseReactivity: 1.0, clickReactivity: 0.8
175
+ mouseReactivity: 1.0, clickReactivity: 0.8
176
176
  },
177
- 'highlight': {
178
- densityMult: 1.5 + (vp.density * 0.3), speedMult: 0.8 + (vp.speed * 0.2),
177
+ 'highlight': {
178
+ densityMult: 1.5 + (vp.gridDensity * 0.3), speedMult: 0.8 + (vp.speed * 0.2),
179
179
  colorShift: vp.hue + 60.0, intensity: 0.6 + (vp.intensity * 0.2),
180
- mouseReactivity: 1.2, clickReactivity: 1.0
180
+ mouseReactivity: 1.2, clickReactivity: 1.0
181
181
  },
182
- 'accent': {
183
- densityMult: 2.5 + (vp.density * 0.5), speedMult: 0.4 + (vp.speed * 0.1),
182
+ 'accent': {
183
+ densityMult: 2.5 + (vp.gridDensity * 0.5), speedMult: 0.4 + (vp.speed * 0.1),
184
184
  colorShift: vp.hue + 300.0, intensity: 0.3 + (vp.intensity * 0.1),
185
- mouseReactivity: 1.5, clickReactivity: 1.2
185
+ mouseReactivity: 1.5, clickReactivity: 1.2
186
186
  }
187
187
  };
188
188
 
@@ -207,7 +207,7 @@ export class HolographicVisualizer {
207
207
  uniform float u_time;
208
208
  uniform vec2 u_mouse;
209
209
  uniform float u_geometry;
210
- uniform float u_density;
210
+ uniform float u_gridDensity;
211
211
  uniform float u_speed;
212
212
  uniform vec3 u_color;
213
213
  uniform float u_intensity;
@@ -218,9 +218,8 @@ export class HolographicVisualizer {
218
218
  uniform float u_mouseIntensity;
219
219
  uniform float u_clickIntensity;
220
220
  uniform float u_densityVariation;
221
- uniform float u_geometryType;
222
221
  uniform float u_chaos;
223
- uniform float u_morph;
222
+ uniform float u_morphFactor;
224
223
  uniform float u_touchMorph;
225
224
  uniform float u_touchChaos;
226
225
  uniform float u_scrollParallax;
@@ -293,7 +292,7 @@ export class HolographicVisualizer {
293
292
  // ========================================
294
293
  vec3 warpHypersphereCore(vec3 p, int geometryIndex, vec2 mouseDelta) {
295
294
  float radius = length(p);
296
- float morphBlend = clamp(u_morph * 0.6 + 0.3, 0.0, 2.0);
295
+ float morphBlend = clamp(u_morphFactor * 0.6 + 0.3, 0.0, 2.0);
297
296
  float w = sin(radius * (1.3 + float(geometryIndex) * 0.12) + u_time * 0.0008 * u_speed);
298
297
  w *= (0.4 + morphBlend * 0.45);
299
298
 
@@ -315,7 +314,7 @@ export class HolographicVisualizer {
315
314
  vec3 c3 = normalize(vec3(-1.0, 1.0, -1.0));
316
315
  vec3 c4 = normalize(vec3(1.0, -1.0, -1.0));
317
316
 
318
- float morphBlend = clamp(u_morph * 0.8 + 0.2, 0.0, 2.0);
317
+ float morphBlend = clamp(u_morphFactor * 0.8 + 0.2, 0.0, 2.0);
319
318
  float basisMix = dot(p, c1) * 0.14 + dot(p, c2) * 0.1 + dot(p, c3) * 0.08;
320
319
  float w = sin(basisMix * 5.5 + u_time * 0.0009 * u_speed);
321
320
  w *= cos(dot(p, c4) * 4.2 - u_time * 0.0007 * u_speed);
@@ -551,12 +550,12 @@ export class HolographicVisualizer {
551
550
  float audioDensityMod = 1.0 + u_audioDensityBoost * 0.5;
552
551
  // Controlled density calculation - breathing modulation added
553
552
  float breathDensityMod = 1.0 + u_breath * 0.1;
554
- float baseDensity = u_density * u_roleDensity * breathDensityMod;
553
+ float baseDensity = u_gridDensity * u_roleDensity * breathDensityMod;
555
554
 
556
555
  float densityVariations = (u_densityVariation * 0.3 + (scrollDensityMod - 1.0) * 0.4 + (audioDensityMod - 1.0) * 0.2);
557
556
  float roleDensity = baseDensity + densityVariations;
558
557
 
559
- float morphedGeometry = u_geometryType + u_morph * 3.0 + u_touchMorph * 2.0 + u_audioMorphBoost * 1.5;
558
+ float morphedGeometry = u_geometry + u_morphFactor * 3.0 + u_touchMorph * 2.0 + u_audioMorphBoost * 1.5;
560
559
  float lattice = getDynamicGeometry(p, roleDensity, morphedGeometry);
561
560
 
562
561
  // Enhanced holographic color processing
@@ -590,9 +589,9 @@ export class HolographicVisualizer {
590
589
  color = rgbGlitch(color, uv, enhancedChaos);
591
590
 
592
591
  // Apply morph distortion to position
593
- vec2 morphDistortion = vec2(sin(uv.y * 10.0 + u_time * 0.001) * u_morph * 0.1,
594
- cos(uv.x * 10.0 + u_time * 0.001) * u_morph * 0.1);
595
- color = mix(color, color * (1.0 + length(morphDistortion)), u_morph * 0.5);
592
+ vec2 morphDistortion = vec2(sin(uv.y * 10.0 + u_time * 0.001) * u_morphFactor * 0.1,
593
+ cos(uv.x * 10.0 + u_time * 0.001) * u_morphFactor * 0.1);
594
+ color = mix(color, color * (1.0 + length(morphDistortion)), u_morphFactor * 0.5);
596
595
 
597
596
  // Enhanced holographic interaction effects
598
597
  float mouseDist = length(uv - (u_mouse - 0.5) * vec2(aspectRatio, 1.0));
@@ -621,7 +620,7 @@ export class HolographicVisualizer {
621
620
  time: this.gl.getUniformLocation(this.program, 'u_time'),
622
621
  mouse: this.gl.getUniformLocation(this.program, 'u_mouse'),
623
622
  geometry: this.gl.getUniformLocation(this.program, 'u_geometry'),
624
- density: this.gl.getUniformLocation(this.program, 'u_density'),
623
+ gridDensity: this.gl.getUniformLocation(this.program, 'u_gridDensity'),
625
624
  speed: this.gl.getUniformLocation(this.program, 'u_speed'),
626
625
  color: this.gl.getUniformLocation(this.program, 'u_color'),
627
626
  intensity: this.gl.getUniformLocation(this.program, 'u_intensity'),
@@ -632,9 +631,8 @@ export class HolographicVisualizer {
632
631
  mouseIntensity: this.gl.getUniformLocation(this.program, 'u_mouseIntensity'),
633
632
  clickIntensity: this.gl.getUniformLocation(this.program, 'u_clickIntensity'),
634
633
  densityVariation: this.gl.getUniformLocation(this.program, 'u_densityVariation'),
635
- geometryType: this.gl.getUniformLocation(this.program, 'u_geometryType'),
636
634
  chaos: this.gl.getUniformLocation(this.program, 'u_chaos'),
637
- morph: this.gl.getUniformLocation(this.program, 'u_morph'),
635
+ morphFactor: this.gl.getUniformLocation(this.program, 'u_morphFactor'),
638
636
  touchMorph: this.gl.getUniformLocation(this.program, 'u_touchMorph'),
639
637
  touchChaos: this.gl.getUniformLocation(this.program, 'u_touchChaos'),
640
638
  scrollParallax: this.gl.getUniformLocation(this.program, 'u_scrollParallax'),
@@ -894,11 +892,11 @@ export class HolographicVisualizer {
894
892
  this.gl.uniform2f(this.uniforms.resolution, this.canvas.width, this.canvas.height);
895
893
  this.gl.uniform1f(this.uniforms.time, time);
896
894
  this.gl.uniform2f(this.uniforms.mouse, this.mouseX, this.mouseY);
897
- this.gl.uniform1f(this.uniforms.geometryType, this.variantParams.geometryType || 0);
898
- this.gl.uniform1f(this.uniforms.density, this.variantParams.density || 1.0);
899
- // FIX: Controlled speed calculation - base speed controls main movement, audio provides subtle boost
900
- const baseSpeed = (this.variantParams.speed || 0.5) * 0.2; // Much slower base speed
901
- const audioBoost = (this.audioSpeedBoost || 0.0) * 0.1; // Subtle audio boost only
895
+ this.gl.uniform1f(this.uniforms.geometry, this.variantParams.geometry !== undefined ? this.variantParams.geometry : this.variant || 0);
896
+ this.gl.uniform1f(this.uniforms.gridDensity, this.variantParams.gridDensity || 1.0);
897
+ // Controlled speed calculation - base speed controls main movement, audio provides subtle boost
898
+ const baseSpeed = (this.variantParams.speed || 0.5) * 0.2;
899
+ const audioBoost = (this.audioSpeedBoost || 0.0) * 0.1;
902
900
  this.gl.uniform1f(this.uniforms.speed, baseSpeed + audioBoost);
903
901
  this.gl.uniform3fv(this.uniforms.color, new Float32Array(rgbColor));
904
902
  this.gl.uniform1f(this.uniforms.intensity, (this.variantParams.intensity || 0.5) * this.roleParams.intensity);
@@ -909,9 +907,8 @@ export class HolographicVisualizer {
909
907
  this.gl.uniform1f(this.uniforms.mouseIntensity, this.mouseIntensity);
910
908
  this.gl.uniform1f(this.uniforms.clickIntensity, this.clickIntensity);
911
909
  this.gl.uniform1f(this.uniforms.densityVariation, this.densityVariation);
912
- this.gl.uniform1f(this.uniforms.geometryType, this.variantParams.geometryType !== undefined ? this.variantParams.geometryType : this.variant || 0);
913
910
  this.gl.uniform1f(this.uniforms.chaos, this.variantParams.chaos || 0.0);
914
- this.gl.uniform1f(this.uniforms.morph, this.variantParams.morph || 0.0);
911
+ this.gl.uniform1f(this.uniforms.morphFactor, this.variantParams.morphFactor || 0.0);
915
912
 
916
913
  // Touch and scroll uniforms
917
914
  this.gl.uniform1f(this.uniforms.touchMorph, this.touchMorph);
@@ -1001,62 +998,34 @@ export class HolographicVisualizer {
1001
998
  }
1002
999
 
1003
1000
  /**
1004
- * CRITICAL FIX: Update visualization parameters with immediate re-render
1005
- * This method was missing and causing parameter sliders to not work in holographic system
1001
+ * Update visualization parameters from SDK global parameter names.
1002
+ * Parameters are written directly to variantParams no name mapping needed
1003
+ * since shader uniforms now use SDK-standard names.
1006
1004
  */
1007
1005
  updateParameters(params) {
1008
1006
  if (!params || typeof params !== 'object') return;
1009
- // Update variant parameters with proper mapping and scaling
1010
1007
  if (this.variantParams) {
1011
1008
  Object.keys(params).forEach(param => {
1012
- const mappedParam = this.mapParameterName(param);
1013
- if (mappedParam !== null) {
1014
- let scaledValue = params[param];
1015
- // Guard against NaN/Infinity reaching GPU uniforms
1016
- if (typeof scaledValue !== 'number' || !Number.isFinite(scaledValue)) return;
1017
-
1018
- // FIX: Scale gridDensity to reasonable holographic density range (back to normal levels)
1019
- if (param === 'gridDensity') {
1020
- // Convert gridDensity (5-100) to holographic density (0.3-2.5) - reasonable range
1021
- // Formula: density = 0.3 + (gridDensity - 5) / (100 - 5) * (2.5 - 0.3)
1022
- scaledValue = 0.3 + (parseFloat(params[param]) - 5) / 95 * 2.2;
1023
- console.log(`🔧 Density scaling: gridDensity=${params[param]} density=${scaledValue.toFixed(3)} (normal range)`);
1024
- }
1025
-
1026
- this.variantParams[mappedParam] = scaledValue;
1027
-
1028
- // Handle special parameter types
1029
- if (mappedParam === 'geometryType') {
1030
- // Regenerate role params with new geometry
1031
- this.roleParams = this.generateRoleParams(this.role);
1032
- }
1009
+ let scaledValue = params[param];
1010
+ // Guard against NaN/Infinity reaching GPU uniforms
1011
+ if (typeof scaledValue !== 'number' || !Number.isFinite(scaledValue)) return;
1012
+
1013
+ // Scale gridDensity (5-100) to holographic density range (0.3-2.5)
1014
+ if (param === 'gridDensity') {
1015
+ scaledValue = 0.3 + (parseFloat(params[param]) - 5) / 95 * 2.2;
1016
+ }
1017
+
1018
+ this.variantParams[param] = scaledValue;
1019
+
1020
+ // Regenerate role params when geometry changes
1021
+ if (param === 'geometry') {
1022
+ this.roleParams = this.generateRoleParams(this.role);
1033
1023
  }
1034
1024
  });
1035
1025
  }
1036
-
1026
+
1037
1027
  // Don't call render() here - engine will call it to prevent infinite loop
1038
1028
  }
1039
-
1040
- /**
1041
- * Map global parameter names to holographic system parameter names
1042
- */
1043
- mapParameterName(globalParam) {
1044
- const paramMap = {
1045
- 'gridDensity': 'density',
1046
- 'morphFactor': 'morph',
1047
- 'rot4dXW': 'rot4dXW',
1048
- 'rot4dYW': 'rot4dYW',
1049
- 'rot4dZW': 'rot4dZW',
1050
- 'hue': 'hue',
1051
- 'intensity': 'intensity',
1052
- 'saturation': 'saturation',
1053
- 'chaos': 'chaos',
1054
- 'speed': 'speed',
1055
- 'geometry': 'geometryType',
1056
- 'breath': 'breath'
1057
- };
1058
- return paramMap[globalParam] || globalParam;
1059
- }
1060
1029
 
1061
1030
  /**
1062
1031
  * Clean up all WebGL resources and event listeners
@@ -157,24 +157,46 @@ export class Mat4x4 {
157
157
  /**
158
158
  * Multiply two matrices
159
159
  * @param {Mat4x4} m - Right operand
160
+ * @param {Mat4x4} [target=null] - Optional target matrix to store result
160
161
  * @returns {Mat4x4} New matrix = this * m
161
162
  */
162
- multiply(m) {
163
+ multiply(m, target = null) {
164
+ const out = target || new Mat4x4();
165
+ const r = out.data;
163
166
  const a = this.data;
164
167
  const b = m.data;
165
- const result = new Float32Array(16);
166
-
167
- for (let col = 0; col < 4; col++) {
168
- for (let row = 0; row < 4; row++) {
169
- let sum = 0;
170
- for (let k = 0; k < 4; k++) {
171
- sum += a[k * 4 + row] * b[col * 4 + k];
172
- }
173
- result[col * 4 + row] = sum;
174
- }
175
- }
176
168
 
177
- return new Mat4x4(result);
169
+ const a00 = a[0], a01 = a[4], a02 = a[8], a03 = a[12];
170
+ const a10 = a[1], a11 = a[5], a12 = a[9], a13 = a[13];
171
+ const a20 = a[2], a21 = a[6], a22 = a[10], a23 = a[14];
172
+ const a30 = a[3], a31 = a[7], a32 = a[11], a33 = a[15];
173
+
174
+ const b00 = b[0], b01 = b[4], b02 = b[8], b03 = b[12];
175
+ const b10 = b[1], b11 = b[5], b12 = b[9], b13 = b[13];
176
+ const b20 = b[2], b21 = b[6], b22 = b[10], b23 = b[14];
177
+ const b30 = b[3], b31 = b[7], b32 = b[11], b33 = b[15];
178
+
179
+ r[0] = a00 * b00 + a01 * b10 + a02 * b20 + a03 * b30;
180
+ r[1] = a10 * b00 + a11 * b10 + a12 * b20 + a13 * b30;
181
+ r[2] = a20 * b00 + a21 * b10 + a22 * b20 + a23 * b30;
182
+ r[3] = a30 * b00 + a31 * b10 + a32 * b20 + a33 * b30;
183
+
184
+ r[4] = a00 * b01 + a01 * b11 + a02 * b21 + a03 * b31;
185
+ r[5] = a10 * b01 + a11 * b11 + a12 * b21 + a13 * b31;
186
+ r[6] = a20 * b01 + a21 * b11 + a22 * b21 + a23 * b31;
187
+ r[7] = a30 * b01 + a31 * b11 + a32 * b21 + a33 * b31;
188
+
189
+ r[8] = a00 * b02 + a01 * b12 + a02 * b22 + a03 * b32;
190
+ r[9] = a10 * b02 + a11 * b12 + a12 * b22 + a13 * b32;
191
+ r[10] = a20 * b02 + a21 * b12 + a22 * b22 + a23 * b32;
192
+ r[11] = a30 * b02 + a31 * b12 + a32 * b22 + a33 * b32;
193
+
194
+ r[12] = a00 * b03 + a01 * b13 + a02 * b23 + a03 * b33;
195
+ r[13] = a10 * b03 + a11 * b13 + a12 * b23 + a13 * b33;
196
+ r[14] = a20 * b03 + a21 * b13 + a22 * b23 + a23 * b33;
197
+ r[15] = a30 * b03 + a31 * b13 + a32 * b23 + a33 * b33;
198
+
199
+ return out;
178
200
  }
179
201
 
180
202
  /**
@@ -183,8 +205,44 @@ export class Mat4x4 {
183
205
  * @returns {Mat4x4} this
184
206
  */
185
207
  multiplyInPlace(m) {
186
- const result = this.multiply(m);
187
- this.data.set(result.data);
208
+ const a = this.data;
209
+ const b = m.data;
210
+
211
+ // Cache values to avoid aliasing issues and repeated array access
212
+ const a00 = a[0], a01 = a[4], a02 = a[8], a03 = a[12];
213
+ const a10 = a[1], a11 = a[5], a12 = a[9], a13 = a[13];
214
+ const a20 = a[2], a21 = a[6], a22 = a[10], a23 = a[14];
215
+ const a30 = a[3], a31 = a[7], a32 = a[11], a33 = a[15];
216
+
217
+ const b00 = b[0], b01 = b[4], b02 = b[8], b03 = b[12];
218
+ const b10 = b[1], b11 = b[5], b12 = b[9], b13 = b[13];
219
+ const b20 = b[2], b21 = b[6], b22 = b[10], b23 = b[14];
220
+ const b30 = b[3], b31 = b[7], b32 = b[11], b33 = b[15];
221
+
222
+ // Column 0
223
+ a[0] = a00 * b00 + a01 * b10 + a02 * b20 + a03 * b30;
224
+ a[1] = a10 * b00 + a11 * b10 + a12 * b20 + a13 * b30;
225
+ a[2] = a20 * b00 + a21 * b10 + a22 * b20 + a23 * b30;
226
+ a[3] = a30 * b00 + a31 * b10 + a32 * b20 + a33 * b30;
227
+
228
+ // Column 1
229
+ a[4] = a00 * b01 + a01 * b11 + a02 * b21 + a03 * b31;
230
+ a[5] = a10 * b01 + a11 * b11 + a12 * b21 + a13 * b31;
231
+ a[6] = a20 * b01 + a21 * b11 + a22 * b21 + a23 * b31;
232
+ a[7] = a30 * b01 + a31 * b11 + a32 * b21 + a33 * b31;
233
+
234
+ // Column 2
235
+ a[8] = a00 * b02 + a01 * b12 + a02 * b22 + a03 * b32;
236
+ a[9] = a10 * b02 + a11 * b12 + a12 * b22 + a13 * b32;
237
+ a[10] = a20 * b02 + a21 * b12 + a22 * b22 + a23 * b32;
238
+ a[11] = a30 * b02 + a31 * b12 + a32 * b22 + a33 * b32;
239
+
240
+ // Column 3
241
+ a[12] = a00 * b03 + a01 * b13 + a02 * b23 + a03 * b33;
242
+ a[13] = a10 * b03 + a11 * b13 + a12 * b23 + a13 * b33;
243
+ a[14] = a20 * b03 + a21 * b13 + a22 * b23 + a23 * b33;
244
+ a[15] = a30 * b03 + a31 * b13 + a32 * b23 + a33 * b33;
245
+
188
246
  return this;
189
247
  }
190
248
 
@@ -202,16 +260,22 @@ export class Mat4x4 {
202
260
  /**
203
261
  * Transform a Vec4 by this matrix
204
262
  * @param {Vec4} v
263
+ * @param {Vec4} [target=null] - Optional target vector to store result
205
264
  * @returns {Vec4} Transformed vector
206
265
  */
207
- multiplyVec4(v) {
266
+ multiplyVec4(v, target = null) {
208
267
  const m = this.data;
209
- return new Vec4(
210
- m[0] * v.x + m[4] * v.y + m[8] * v.z + m[12] * v.w,
211
- m[1] * v.x + m[5] * v.y + m[9] * v.z + m[13] * v.w,
212
- m[2] * v.x + m[6] * v.y + m[10] * v.z + m[14] * v.w,
213
- m[3] * v.x + m[7] * v.y + m[11] * v.z + m[15] * v.w
214
- );
268
+ const out = target || new Vec4();
269
+
270
+ // Cache components to support aliasing (target === v)
271
+ const x = v.x, y = v.y, z = v.z, w = v.w;
272
+
273
+ out.x = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
274
+ out.y = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
275
+ out.z = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
276
+ out.w = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
277
+
278
+ return out;
215
279
  }
216
280
 
217
281
  /**
@@ -253,27 +317,36 @@ export class Mat4x4 {
253
317
  /**
254
318
  * Add another matrix
255
319
  * @param {Mat4x4} m
320
+ * @param {Mat4x4} [target=null] - Optional target matrix
256
321
  * @returns {Mat4x4} New matrix
257
322
  */
258
- add(m) {
259
- const result = new Float32Array(16);
323
+ add(m, target = null) {
324
+ const out = target || new Mat4x4();
325
+ const r = out.data;
326
+ const a = this.data;
327
+ const b = m.data;
328
+
260
329
  for (let i = 0; i < 16; i++) {
261
- result[i] = this.data[i] + m.data[i];
330
+ r[i] = a[i] + b[i];
262
331
  }
263
- return new Mat4x4(result);
332
+ return out;
264
333
  }
265
334
 
266
335
  /**
267
336
  * Multiply by scalar
268
337
  * @param {number} s
338
+ * @param {Mat4x4} [target=null] - Optional target matrix
269
339
  * @returns {Mat4x4} New matrix
270
340
  */
271
- scale(s) {
272
- const result = new Float32Array(16);
341
+ scale(s, target = null) {
342
+ const out = target || new Mat4x4();
343
+ const r = out.data;
344
+ const a = this.data;
345
+
273
346
  for (let i = 0; i < 16; i++) {
274
- result[i] = this.data[i] * s;
347
+ r[i] = a[i] * s;
275
348
  }
276
- return new Mat4x4(result);
349
+ return out;
277
350
  }
278
351
 
279
352
  /**
@@ -490,6 +563,122 @@ export class Mat4x4 {
490
563
  return new Mat4x4(json.data);
491
564
  }
492
565
 
566
+ // ========== IN-PLACE ROTATIONS ==========
567
+
568
+ /**
569
+ * Rotate in XY plane in place
570
+ * @param {number} angle
571
+ * @returns {Mat4x4} this
572
+ */
573
+ rotateXY(angle) {
574
+ const c = Math.cos(angle);
575
+ const s = Math.sin(angle);
576
+ const m = this.data;
577
+
578
+ for (let i = 0; i < 4; i++) {
579
+ const a0 = m[i]; // Col 0
580
+ const a1 = m[i + 4]; // Col 1
581
+ m[i] = a0 * c + a1 * s;
582
+ m[i + 4] = -a0 * s + a1 * c;
583
+ }
584
+ return this;
585
+ }
586
+
587
+ /**
588
+ * Rotate in XZ plane in place
589
+ * @param {number} angle
590
+ * @returns {Mat4x4} this
591
+ */
592
+ rotateXZ(angle) {
593
+ const c = Math.cos(angle);
594
+ const s = Math.sin(angle);
595
+ const m = this.data;
596
+
597
+ for (let i = 0; i < 4; i++) {
598
+ const a0 = m[i]; // Col 0
599
+ const a2 = m[i + 8]; // Col 2
600
+ m[i] = a0 * c - a2 * s;
601
+ m[i + 8] = a0 * s + a2 * c;
602
+ }
603
+ return this;
604
+ }
605
+
606
+ /**
607
+ * Rotate in YZ plane in place
608
+ * @param {number} angle
609
+ * @returns {Mat4x4} this
610
+ */
611
+ rotateYZ(angle) {
612
+ const c = Math.cos(angle);
613
+ const s = Math.sin(angle);
614
+ const m = this.data;
615
+
616
+ for (let i = 0; i < 4; i++) {
617
+ const a1 = m[i + 4]; // Col 1
618
+ const a2 = m[i + 8]; // Col 2
619
+ m[i + 4] = a1 * c + a2 * s;
620
+ m[i + 8] = -a1 * s + a2 * c;
621
+ }
622
+ return this;
623
+ }
624
+
625
+ /**
626
+ * Rotate in XW plane in place
627
+ * @param {number} angle
628
+ * @returns {Mat4x4} this
629
+ */
630
+ rotateXW(angle) {
631
+ const c = Math.cos(angle);
632
+ const s = Math.sin(angle);
633
+ const m = this.data;
634
+
635
+ for (let i = 0; i < 4; i++) {
636
+ const a0 = m[i]; // Col 0
637
+ const a3 = m[i + 12]; // Col 3
638
+ m[i] = a0 * c + a3 * s;
639
+ m[i + 12] = -a0 * s + a3 * c;
640
+ }
641
+ return this;
642
+ }
643
+
644
+ /**
645
+ * Rotate in YW plane in place
646
+ * @param {number} angle
647
+ * @returns {Mat4x4} this
648
+ */
649
+ rotateYW(angle) {
650
+ const c = Math.cos(angle);
651
+ const s = Math.sin(angle);
652
+ const m = this.data;
653
+
654
+ for (let i = 0; i < 4; i++) {
655
+ const a1 = m[i + 4]; // Col 1
656
+ const a3 = m[i + 12]; // Col 3
657
+ m[i + 4] = a1 * c + a3 * s;
658
+ m[i + 12] = -a1 * s + a3 * c;
659
+ }
660
+ return this;
661
+ }
662
+
663
+ /**
664
+ * Rotate in ZW plane in place
665
+ * @param {number} angle
666
+ * @returns {Mat4x4} this
667
+ */
668
+ rotateZW(angle) {
669
+ const c = Math.cos(angle);
670
+ const s = Math.sin(angle);
671
+ const m = this.data;
672
+
673
+ for (let i = 0; i < 4; i++) {
674
+ const a2 = m[i + 8]; // Col 2
675
+ const a3 = m[i + 12]; // Col 3
676
+ m[i + 8] = a2 * c + a3 * s;
677
+ m[i + 12] = -a2 * s + a3 * c;
678
+ }
679
+ return this;
680
+ }
681
+
493
682
  // ========== ROTATION MATRICES FOR ALL 6 PLANES ==========
494
683
 
495
684
  /**
@@ -624,12 +813,12 @@ export class Mat4x4 {
624
813
  static rotationFromAngles(angles) {
625
814
  let result = Mat4x4.identity();
626
815
 
627
- if (angles.xy) result = result.multiply(Mat4x4.rotationXY(angles.xy));
628
- if (angles.xz) result = result.multiply(Mat4x4.rotationXZ(angles.xz));
629
- if (angles.yz) result = result.multiply(Mat4x4.rotationYZ(angles.yz));
630
- if (angles.xw) result = result.multiply(Mat4x4.rotationXW(angles.xw));
631
- if (angles.yw) result = result.multiply(Mat4x4.rotationYW(angles.yw));
632
- if (angles.zw) result = result.multiply(Mat4x4.rotationZW(angles.zw));
816
+ if (angles.xy) result.rotateXY(angles.xy);
817
+ if (angles.xz) result.rotateXZ(angles.xz);
818
+ if (angles.yz) result.rotateYZ(angles.yz);
819
+ if (angles.xw) result.rotateXW(angles.xw);
820
+ if (angles.yw) result.rotateYW(angles.yw);
821
+ if (angles.zw) result.rotateZW(angles.zw);
633
822
 
634
823
  return result;
635
824
  }