@vib3code/sdk 2.0.1

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 (258) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/DOCS/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md +34 -0
  3. package/DOCS/CI_TESTING.md +38 -0
  4. package/DOCS/CLI_ONBOARDING.md +75 -0
  5. package/DOCS/CONTROL_REFERENCE.md +64 -0
  6. package/DOCS/DEV_TRACK_ANALYSIS.md +77 -0
  7. package/DOCS/DEV_TRACK_PLAN_2026-01-07.md +42 -0
  8. package/DOCS/DEV_TRACK_SESSION_2026-01-31.md +220 -0
  9. package/DOCS/ENV_SETUP.md +189 -0
  10. package/DOCS/EXPORT_FORMATS.md +417 -0
  11. package/DOCS/GPU_DISPOSAL_GUIDE.md +21 -0
  12. package/DOCS/LICENSING_TIERS.md +275 -0
  13. package/DOCS/MASTER_PLAN_2026-01-31.md +570 -0
  14. package/DOCS/OBS_SETUP_GUIDE.md +98 -0
  15. package/DOCS/PROJECT_SETUP.md +66 -0
  16. package/DOCS/RENDERER_LIFECYCLE.md +40 -0
  17. package/DOCS/REPO_MANIFEST.md +121 -0
  18. package/DOCS/SESSION_014_PLAN.md +195 -0
  19. package/DOCS/SESSION_LOG_2026-01-07.md +56 -0
  20. package/DOCS/STRATEGIC_BLUEPRINT_2026-01-07.md +72 -0
  21. package/DOCS/SYSTEM_AUDIT_2026-01-30.md +738 -0
  22. package/DOCS/SYSTEM_INVENTORY.md +520 -0
  23. package/DOCS/TELEMETRY_EXPORTS.md +34 -0
  24. package/DOCS/WEBGPU_STATUS.md +38 -0
  25. package/DOCS/XR_BENCHMARKS.md +608 -0
  26. package/LICENSE +21 -0
  27. package/README.md +426 -0
  28. package/docs/.nojekyll +0 -0
  29. package/docs/01-dissolution_of_euclidean_hegemony.html +346 -0
  30. package/docs/02-hyperspatial_ego_death.html +346 -0
  31. package/docs/03-post_cartesian_sublime.html +346 -0
  32. package/docs/04-crystalline_void_meditation.html +346 -0
  33. package/docs/05-quantum_decoherence_ballet.html +346 -0
  34. package/docs/06-dissolution_of_euclidean_hegemony.html +346 -0
  35. package/docs/07-hyperspatial_ego_death.html +346 -0
  36. package/docs/08-post_cartesian_sublime.html +346 -0
  37. package/docs/09-crystalline_void_meditation.html +346 -0
  38. package/docs/10-quantum_decoherence_ballet.html +346 -0
  39. package/docs/11-dissolution_of_euclidean_hegemony.html +346 -0
  40. package/docs/12-hyperspatial_ego_death.html +346 -0
  41. package/docs/13-post_cartesian_sublime.html +346 -0
  42. package/docs/index.html +794 -0
  43. package/docs/test-hub.html +441 -0
  44. package/docs/url-state.js +102 -0
  45. package/docs/vib3-exports/01-quantum-quantum-tetrahedron-lattice.html +489 -0
  46. package/docs/vib3-exports/02-quantum-quantum-hypersphere-matrix.html +489 -0
  47. package/docs/vib3-exports/03-quantum-quantum-hypertetra-fractal.html +489 -0
  48. package/docs/vib3-exports/04-faceted-faceted-crystal-structure.html +407 -0
  49. package/docs/vib3-exports/05-faceted-faceted-klein-bottle.html +407 -0
  50. package/docs/vib3-exports/06-faceted-faceted-hypertetra-torus.html +407 -0
  51. package/docs/vib3-exports/07-holographic-holographic-wave-field.html +457 -0
  52. package/docs/vib3-exports/08-holographic-holographic-hypersphere-sphere.html +457 -0
  53. package/docs/vib3-exports/09-holographic-holographic-hypertetra-crystal.html +457 -0
  54. package/docs/vib3-exports/index.html +238 -0
  55. package/docs/webgpu-live.html +702 -0
  56. package/package.json +367 -0
  57. package/src/advanced/AIPresetGenerator.js +777 -0
  58. package/src/advanced/MIDIController.js +703 -0
  59. package/src/advanced/OffscreenWorker.js +1051 -0
  60. package/src/advanced/WebGPUCompute.js +1051 -0
  61. package/src/advanced/WebXRRenderer.js +680 -0
  62. package/src/agent/cli/AgentCLI.js +615 -0
  63. package/src/agent/cli/index.js +14 -0
  64. package/src/agent/index.js +73 -0
  65. package/src/agent/mcp/MCPServer.js +950 -0
  66. package/src/agent/mcp/index.js +9 -0
  67. package/src/agent/mcp/tools.js +548 -0
  68. package/src/agent/telemetry/EventStream.js +669 -0
  69. package/src/agent/telemetry/Instrumentation.js +618 -0
  70. package/src/agent/telemetry/TelemetryExporters.js +427 -0
  71. package/src/agent/telemetry/TelemetryService.js +464 -0
  72. package/src/agent/telemetry/index.js +52 -0
  73. package/src/benchmarks/BenchmarkRunner.js +381 -0
  74. package/src/benchmarks/MetricsCollector.js +299 -0
  75. package/src/benchmarks/index.js +9 -0
  76. package/src/benchmarks/scenes.js +259 -0
  77. package/src/cli/index.js +675 -0
  78. package/src/config/ApiConfig.js +88 -0
  79. package/src/core/CanvasManager.js +217 -0
  80. package/src/core/ErrorReporter.js +117 -0
  81. package/src/core/ParameterMapper.js +333 -0
  82. package/src/core/Parameters.js +396 -0
  83. package/src/core/RendererContracts.js +200 -0
  84. package/src/core/UnifiedResourceManager.js +370 -0
  85. package/src/core/VIB3Engine.js +636 -0
  86. package/src/core/renderers/FacetedRendererAdapter.js +32 -0
  87. package/src/core/renderers/HolographicRendererAdapter.js +29 -0
  88. package/src/core/renderers/QuantumRendererAdapter.js +29 -0
  89. package/src/core/renderers/RendererLifecycleManager.js +63 -0
  90. package/src/creative/ColorPresetsSystem.js +980 -0
  91. package/src/creative/ParameterTimeline.js +1061 -0
  92. package/src/creative/PostProcessingPipeline.js +1113 -0
  93. package/src/creative/TransitionAnimator.js +683 -0
  94. package/src/export/CSSExporter.js +226 -0
  95. package/src/export/CardGeneratorBase.js +279 -0
  96. package/src/export/ExportManager.js +580 -0
  97. package/src/export/FacetedCardGenerator.js +279 -0
  98. package/src/export/HolographicCardGenerator.js +543 -0
  99. package/src/export/LottieExporter.js +552 -0
  100. package/src/export/QuantumCardGenerator.js +315 -0
  101. package/src/export/SVGExporter.js +519 -0
  102. package/src/export/ShaderExporter.js +903 -0
  103. package/src/export/TradingCardGenerator.js +3055 -0
  104. package/src/export/TradingCardManager.js +181 -0
  105. package/src/export/VIB3PackageExporter.js +559 -0
  106. package/src/export/index.js +14 -0
  107. package/src/export/systems/TradingCardSystemFaceted.js +494 -0
  108. package/src/export/systems/TradingCardSystemHolographic.js +452 -0
  109. package/src/export/systems/TradingCardSystemQuantum.js +411 -0
  110. package/src/faceted/FacetedSystem.js +963 -0
  111. package/src/features/CollectionManager.js +433 -0
  112. package/src/gallery/CollectionManager.js +240 -0
  113. package/src/gallery/GallerySystem.js +485 -0
  114. package/src/geometry/GeometryFactory.js +314 -0
  115. package/src/geometry/GeometryLibrary.js +72 -0
  116. package/src/geometry/buffers/BufferBuilder.js +338 -0
  117. package/src/geometry/buffers/index.js +18 -0
  118. package/src/geometry/generators/Crystal.js +420 -0
  119. package/src/geometry/generators/Fractal.js +298 -0
  120. package/src/geometry/generators/KleinBottle.js +197 -0
  121. package/src/geometry/generators/Sphere.js +192 -0
  122. package/src/geometry/generators/Tesseract.js +160 -0
  123. package/src/geometry/generators/Tetrahedron.js +225 -0
  124. package/src/geometry/generators/Torus.js +304 -0
  125. package/src/geometry/generators/Wave.js +341 -0
  126. package/src/geometry/index.js +142 -0
  127. package/src/geometry/warp/HypersphereCore.js +211 -0
  128. package/src/geometry/warp/HypertetraCore.js +386 -0
  129. package/src/geometry/warp/index.js +57 -0
  130. package/src/holograms/HolographicVisualizer.js +1073 -0
  131. package/src/holograms/RealHolographicSystem.js +966 -0
  132. package/src/holograms/variantRegistry.js +69 -0
  133. package/src/integrations/FigmaPlugin.js +854 -0
  134. package/src/integrations/OBSMode.js +754 -0
  135. package/src/integrations/ThreeJsPackage.js +660 -0
  136. package/src/integrations/TouchDesignerExport.js +552 -0
  137. package/src/integrations/frameworks/Vib3React.js +591 -0
  138. package/src/integrations/frameworks/Vib3Svelte.js +654 -0
  139. package/src/integrations/frameworks/Vib3Vue.js +628 -0
  140. package/src/llm/LLMParameterInterface.js +240 -0
  141. package/src/llm/LLMParameterUI.js +577 -0
  142. package/src/math/Mat4x4.js +708 -0
  143. package/src/math/Projection.js +341 -0
  144. package/src/math/Rotor4D.js +637 -0
  145. package/src/math/Vec4.js +476 -0
  146. package/src/math/constants.js +164 -0
  147. package/src/math/index.js +68 -0
  148. package/src/math/projections.js +54 -0
  149. package/src/math/rotations.js +196 -0
  150. package/src/quantum/QuantumEngine.js +906 -0
  151. package/src/quantum/QuantumVisualizer.js +1103 -0
  152. package/src/reactivity/ReactivityConfig.js +499 -0
  153. package/src/reactivity/ReactivityManager.js +586 -0
  154. package/src/reactivity/SpatialInputSystem.js +1783 -0
  155. package/src/reactivity/index.js +93 -0
  156. package/src/render/CommandBuffer.js +465 -0
  157. package/src/render/MultiCanvasBridge.js +340 -0
  158. package/src/render/RenderCommand.js +514 -0
  159. package/src/render/RenderResourceRegistry.js +523 -0
  160. package/src/render/RenderState.js +552 -0
  161. package/src/render/RenderTarget.js +512 -0
  162. package/src/render/ShaderLoader.js +253 -0
  163. package/src/render/ShaderProgram.js +599 -0
  164. package/src/render/UnifiedRenderBridge.js +496 -0
  165. package/src/render/backends/WebGLBackend.js +1108 -0
  166. package/src/render/backends/WebGPUBackend.js +1409 -0
  167. package/src/render/commands/CommandBufferExecutor.js +607 -0
  168. package/src/render/commands/RenderCommandBuffer.js +661 -0
  169. package/src/render/commands/index.js +17 -0
  170. package/src/render/index.js +367 -0
  171. package/src/scene/Disposable.js +498 -0
  172. package/src/scene/MemoryPool.js +618 -0
  173. package/src/scene/Node4D.js +697 -0
  174. package/src/scene/ResourceManager.js +599 -0
  175. package/src/scene/Scene4D.js +540 -0
  176. package/src/scene/index.js +98 -0
  177. package/src/schemas/error.schema.json +84 -0
  178. package/src/schemas/extension.schema.json +88 -0
  179. package/src/schemas/index.js +214 -0
  180. package/src/schemas/parameters.schema.json +142 -0
  181. package/src/schemas/tool-pack.schema.json +44 -0
  182. package/src/schemas/tool-response.schema.json +127 -0
  183. package/src/shaders/common/fullscreen.vert.glsl +5 -0
  184. package/src/shaders/common/fullscreen.vert.wgsl +17 -0
  185. package/src/shaders/common/geometry24.glsl +65 -0
  186. package/src/shaders/common/geometry24.wgsl +54 -0
  187. package/src/shaders/common/rotation4d.glsl +85 -0
  188. package/src/shaders/common/rotation4d.wgsl +86 -0
  189. package/src/shaders/common/uniforms.glsl +44 -0
  190. package/src/shaders/common/uniforms.wgsl +48 -0
  191. package/src/shaders/faceted/faceted.frag.glsl +129 -0
  192. package/src/shaders/faceted/faceted.frag.wgsl +164 -0
  193. package/src/shaders/holographic/holographic.frag.glsl +406 -0
  194. package/src/shaders/holographic/holographic.frag.wgsl +185 -0
  195. package/src/shaders/quantum/quantum.frag.glsl +513 -0
  196. package/src/shaders/quantum/quantum.frag.wgsl +361 -0
  197. package/src/testing/ParallelTestFramework.js +519 -0
  198. package/src/testing/__snapshots__/exportFormats.test.js.snap +24 -0
  199. package/src/testing/exportFormats.test.js +8 -0
  200. package/src/testing/projections.test.js +14 -0
  201. package/src/testing/rotations.test.js +37 -0
  202. package/src/ui/InteractivityMenu.js +516 -0
  203. package/src/ui/StatusManager.js +96 -0
  204. package/src/ui/adaptive/renderers/webgpu/BufferLayout.ts +252 -0
  205. package/src/ui/adaptive/renderers/webgpu/PolytopeInstanceBuffer.ts +144 -0
  206. package/src/ui/adaptive/renderers/webgpu/TripleBufferedUniform.ts +170 -0
  207. package/src/ui/adaptive/renderers/webgpu/WebGPURenderer.ts +735 -0
  208. package/src/ui/adaptive/renderers/webgpu/index.ts +112 -0
  209. package/src/variations/VariationManager.js +431 -0
  210. package/src/viewer/AudioReactivity.js +505 -0
  211. package/src/viewer/CardBending.js +481 -0
  212. package/src/viewer/GalleryUI.js +832 -0
  213. package/src/viewer/ReactivityManager.js +590 -0
  214. package/src/viewer/TradingCardExporter.js +600 -0
  215. package/src/viewer/ViewerPortal.js +374 -0
  216. package/src/viewer/index.js +12 -0
  217. package/src/wasm/WasmLoader.js +296 -0
  218. package/src/wasm/index.js +132 -0
  219. package/tools/agentic/mcpTools.js +88 -0
  220. package/tools/cli/agent-cli.js +92 -0
  221. package/tools/export/formats.js +24 -0
  222. package/tools/math/rotation-baseline.mjs +64 -0
  223. package/tools/shader-sync-verify.js +937 -0
  224. package/tools/telemetry/manifestPipeline.js +141 -0
  225. package/tools/telemetry/telemetryEvents.js +35 -0
  226. package/types/adaptive-sdk.d.ts +185 -0
  227. package/types/advanced/AIPresetGenerator.d.ts +81 -0
  228. package/types/advanced/MIDIController.d.ts +100 -0
  229. package/types/advanced/OffscreenWorker.d.ts +82 -0
  230. package/types/advanced/WebGPUCompute.d.ts +52 -0
  231. package/types/advanced/WebXRRenderer.d.ts +77 -0
  232. package/types/advanced/index.d.ts +46 -0
  233. package/types/core/ErrorReporter.d.ts +50 -0
  234. package/types/core/VIB3Engine.d.ts +204 -0
  235. package/types/creative/ColorPresetsSystem.d.ts +91 -0
  236. package/types/creative/ParameterTimeline.d.ts +74 -0
  237. package/types/creative/PostProcessingPipeline.d.ts +109 -0
  238. package/types/creative/TransitionAnimator.d.ts +71 -0
  239. package/types/creative/index.d.ts +35 -0
  240. package/types/integrations/FigmaPlugin.d.ts +46 -0
  241. package/types/integrations/OBSMode.d.ts +74 -0
  242. package/types/integrations/ThreeJsPackage.d.ts +62 -0
  243. package/types/integrations/TouchDesignerExport.d.ts +36 -0
  244. package/types/integrations/Vib3React.d.ts +74 -0
  245. package/types/integrations/Vib3Svelte.d.ts +63 -0
  246. package/types/integrations/Vib3Vue.d.ts +55 -0
  247. package/types/integrations/index.d.ts +52 -0
  248. package/types/reactivity/SpatialInputSystem.d.ts +173 -0
  249. package/types/reactivity/index.d.ts +394 -0
  250. package/types/render/CommandBuffer.d.ts +169 -0
  251. package/types/render/RenderCommand.d.ts +312 -0
  252. package/types/render/RenderState.d.ts +279 -0
  253. package/types/render/RenderTarget.d.ts +254 -0
  254. package/types/render/ShaderProgram.d.ts +277 -0
  255. package/types/render/UnifiedRenderBridge.d.ts +143 -0
  256. package/types/render/WebGLBackend.d.ts +168 -0
  257. package/types/render/WebGPUBackend.d.ts +186 -0
  258. package/types/render/index.d.ts +141 -0
@@ -0,0 +1,494 @@
1
+ /**
2
+ * TradingCardSystemFaceted.js - Complete Faceted System for Trading Cards
3
+ * Extracted from monolithic TradingCardGenerator.js for better maintainability
4
+ *
5
+ * Contains:
6
+ * - Complete WebGL shaders matching main engine
7
+ * - 5-layer canvas rendering system
8
+ * - Full interactivity (mouse, touch, scroll)
9
+ * - Parameter-driven visualization
10
+ */
11
+
12
+ export class TradingCardSystemFaceted {
13
+ /**
14
+ * Generate the complete HTML/JS code for a live faceted trading card
15
+ * @param {Object} state - Card state with parameters and metadata
16
+ * @returns {string} Complete JavaScript code for the card
17
+ */
18
+ static generateLiveSystem(state) {
19
+ return `
20
+ // LIVE VIB34D Faceted System - 5 Layer WebGL Rendering
21
+ class LiveTradingCardSystem {
22
+ constructor() {
23
+ this.layers = ['background', 'shadow', 'content', 'highlight', 'accent'];
24
+ this.visualizers = [];
25
+ this.params = ${JSON.stringify(state.parameters)};
26
+ this.startTime = Date.now();
27
+
28
+ this.initializeAllLayers();
29
+ this.startRenderLoop();
30
+ }
31
+
32
+ initializeAllLayers() {
33
+ // Create 5 canvases dynamically
34
+ this.layers.forEach((role, index) => {
35
+ const canvas = document.createElement('canvas');
36
+ canvas.id = 'card-' + role + '-canvas';
37
+ canvas.style.position = 'absolute';
38
+ canvas.style.top = '0';
39
+ canvas.style.left = '0';
40
+ canvas.style.width = '100%';
41
+ canvas.style.height = '100%';
42
+ canvas.style.zIndex = index;
43
+
44
+ // Set layer-specific blend modes and opacity
45
+ if (role === 'background') {
46
+ canvas.style.opacity = '0.4';
47
+ } else if (role === 'shadow') {
48
+ canvas.style.mixBlendMode = 'multiply';
49
+ canvas.style.opacity = '0.6';
50
+ } else if (role === 'content') {
51
+ canvas.style.opacity = '1.0';
52
+ } else if (role === 'highlight') {
53
+ canvas.style.mixBlendMode = 'screen';
54
+ } else if (role === 'accent') {
55
+ canvas.style.mixBlendMode = 'overlay';
56
+ canvas.style.opacity = '0.8';
57
+ }
58
+
59
+ document.getElementById('vib34dCanvas').parentElement.appendChild(canvas);
60
+
61
+ // Create WebGL visualizer for this layer
62
+ const visualizer = new LayerVisualizer(canvas, role, this.params);
63
+ this.visualizers.push(visualizer);
64
+ });
65
+
66
+ // Hide the original canvas
67
+ document.getElementById('vib34dCanvas').style.display = 'none';
68
+ }
69
+
70
+ startRenderLoop() {
71
+ const render = () => {
72
+ const time = Date.now() - this.startTime;
73
+ this.visualizers.forEach(visualizer => {
74
+ visualizer.render(time);
75
+ });
76
+ requestAnimationFrame(render);
77
+ };
78
+ render();
79
+ }
80
+ }
81
+
82
+ class LayerVisualizer {
83
+ constructor(canvas, role, params) {
84
+ this.canvas = canvas;
85
+ this.role = role;
86
+ this.params = params;
87
+ this.gl = canvas.getContext('webgl');
88
+
89
+ const roleIntensities = {
90
+ 'background': 0.3, 'shadow': 0.5, 'content': 0.8,
91
+ 'highlight': 1.0, 'accent': 1.2
92
+ };
93
+ this.roleIntensity = roleIntensities[role] || 1.0;
94
+
95
+ this.initShaders();
96
+ this.initBuffers();
97
+ this.resize();
98
+ }
99
+
100
+ resize() {
101
+ this.canvas.width = this.canvas.clientWidth;
102
+ this.canvas.height = this.canvas.clientHeight;
103
+ this.gl.viewport(0, 0, this.canvas.width, this.canvas.height);
104
+ }
105
+
106
+ initShaders() {
107
+ const vertexShaderSource = \`attribute vec2 a_position;
108
+ void main() {
109
+ gl_Position = vec4(a_position, 0.0, 1.0);
110
+ }\`;
111
+
112
+ // EXACT FRAGMENT SHADER FROM FACETED SYSTEM
113
+ const fragmentShaderSource = \`precision highp float;
114
+ uniform vec2 u_resolution;
115
+ uniform float u_time;
116
+ uniform vec2 u_mouse;
117
+ uniform float u_geometry;
118
+ uniform float u_gridDensity;
119
+ uniform float u_morphFactor;
120
+ uniform float u_chaos;
121
+ uniform float u_speed;
122
+ uniform float u_hue;
123
+ uniform float u_intensity;
124
+ uniform float u_saturation;
125
+ uniform float u_dimension;
126
+ uniform float u_rot4dXW;
127
+ uniform float u_rot4dYW;
128
+ uniform float u_rot4dZW;
129
+ uniform float u_mouseIntensity;
130
+ uniform float u_clickIntensity;
131
+ uniform float u_roleIntensity;
132
+
133
+ // 4D rotation matrices
134
+ mat4 rotateXW(float theta) {
135
+ float c = cos(theta);
136
+ float s = sin(theta);
137
+ return mat4(c, 0.0, 0.0, -s, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, s, 0.0, 0.0, c);
138
+ }
139
+ mat4 rotateYW(float theta) {
140
+ float c = cos(theta);
141
+ float s = sin(theta);
142
+ return mat4(1.0, 0.0, 0.0, 0.0, 0.0, c, 0.0, -s, 0.0, 0.0, 1.0, 0.0, 0.0, s, 0.0, c);
143
+ }
144
+ mat4 rotateZW(float theta) {
145
+ float c = cos(theta);
146
+ float s = sin(theta);
147
+ return mat4(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, c, -s, 0.0, 0.0, s, c);
148
+ }
149
+ vec3 project4Dto3D(vec4 p) {
150
+ float w = 2.5 / (2.5 + p.w);
151
+ return vec3(p.x * w, p.y * w, p.z * w);
152
+ }
153
+
154
+ float geometryFunction(vec4 p) {
155
+ int geomType = int(u_geometry);
156
+
157
+ if (geomType == 0) {
158
+ vec4 pos = fract(p * u_gridDensity * 0.08);
159
+ vec4 dist = min(pos, 1.0 - pos);
160
+ return min(min(dist.x, dist.y), min(dist.z, dist.w)) * u_morphFactor;
161
+ }
162
+ else if (geomType == 1) {
163
+ vec4 pos = fract(p * u_gridDensity * 0.08);
164
+ vec4 dist = min(pos, 1.0 - pos);
165
+ float minDist = min(min(dist.x, dist.y), min(dist.z, dist.w));
166
+ return minDist * u_morphFactor;
167
+ }
168
+ else if (geomType == 2) {
169
+ float r = length(p);
170
+ float density = u_gridDensity * 0.08;
171
+ float spheres = abs(fract(r * density) - 0.5) * 2.0;
172
+ float theta = atan(p.y, p.x);
173
+ float harmonics = sin(theta * 3.0) * 0.2;
174
+ return (spheres + harmonics) * u_morphFactor;
175
+ }
176
+ else if (geomType == 3) {
177
+ float r1 = length(p.xy) - 2.0;
178
+ float torus = length(vec2(r1, p.z)) - 0.8;
179
+ float lattice = sin(p.x * u_gridDensity * 0.08) * sin(p.y * u_gridDensity * 0.08);
180
+ return (torus + lattice * 0.3) * u_morphFactor;
181
+ }
182
+ else if (geomType == 4) {
183
+ float u = atan(p.y, p.x);
184
+ float v = atan(p.w, p.z);
185
+ float dist = length(p) - 2.0;
186
+ float lattice = sin(u * u_gridDensity * 0.08) * sin(v * u_gridDensity * 0.08);
187
+ return (dist + lattice * 0.4) * u_morphFactor;
188
+ }
189
+ else if (geomType == 5) {
190
+ vec4 pos = fract(p * u_gridDensity * 0.08);
191
+ pos = abs(pos * 2.0 - 1.0);
192
+ float dist = length(max(abs(pos) - 1.0, 0.0));
193
+ return dist * u_morphFactor;
194
+ }
195
+ else if (geomType == 6) {
196
+ float freq = u_gridDensity * 0.08;
197
+ float time = u_time * 0.001 * u_speed;
198
+ float wave1 = sin(p.x * freq + time);
199
+ float wave2 = sin(p.y * freq + time * 1.3);
200
+ float wave3 = sin(p.z * freq * 0.8 + time * 0.7);
201
+ float interference = wave1 * wave2 * wave3;
202
+ return interference * u_morphFactor;
203
+ }
204
+ else if (geomType == 7) {
205
+ vec4 pos = fract(p * u_gridDensity * 0.08) - 0.5;
206
+ float cube = max(max(abs(pos.x), abs(pos.y)), max(abs(pos.z), abs(pos.w)));
207
+ return cube * u_morphFactor;
208
+ }
209
+ else {
210
+ vec4 pos = fract(p * u_gridDensity * 0.08);
211
+ vec4 dist = min(pos, 1.0 - pos);
212
+ return min(min(dist.x, dist.y), min(dist.z, dist.w)) * u_morphFactor;
213
+ }
214
+ }
215
+
216
+ void main() {
217
+ vec2 uv = (gl_FragCoord.xy - u_resolution.xy * 0.5) / min(u_resolution.x, u_resolution.y);
218
+
219
+ float timeSpeed = u_time * 0.0001 * u_speed;
220
+ vec4 pos = vec4(uv * 3.0, sin(timeSpeed * 3.0), cos(timeSpeed * 2.0));
221
+ pos.xy += (u_mouse - 0.5) * u_mouseIntensity * 2.0;
222
+
223
+ pos = rotateXW(u_rot4dXW) * pos;
224
+ pos = rotateYW(u_rot4dYW) * pos;
225
+ pos = rotateZW(u_rot4dZW) * pos;
226
+
227
+ float value = geometryFunction(pos);
228
+
229
+ float noise = sin(pos.x * 7.0) * cos(pos.y * 11.0) * sin(pos.z * 13.0);
230
+ value += noise * u_chaos;
231
+
232
+ float geometryIntensity = 1.0 - clamp(abs(value), 0.0, 1.0);
233
+ geometryIntensity += u_clickIntensity * 0.3;
234
+
235
+ float finalIntensity = geometryIntensity * u_intensity;
236
+
237
+ float hue = u_hue / 360.0 + value * 0.1;
238
+
239
+ vec3 baseColor = vec3(
240
+ sin(hue * 6.28318 + 0.0) * 0.5 + 0.5,
241
+ sin(hue * 6.28318 + 2.0943) * 0.5 + 0.5,
242
+ sin(hue * 6.28318 + 4.1887) * 0.5 + 0.5
243
+ );
244
+
245
+ float gray = (baseColor.r + baseColor.g + baseColor.b) / 3.0;
246
+ vec3 color = mix(vec3(gray), baseColor, u_saturation) * finalIntensity;
247
+
248
+ gl_FragColor = vec4(color, finalIntensity * u_roleIntensity);
249
+ }\`;
250
+
251
+ this.program = this.createProgram(vertexShaderSource, fragmentShaderSource);
252
+ this.uniforms = {
253
+ resolution: this.gl.getUniformLocation(this.program, 'u_resolution'),
254
+ time: this.gl.getUniformLocation(this.program, 'u_time'),
255
+ mouse: this.gl.getUniformLocation(this.program, 'u_mouse'),
256
+ geometry: this.gl.getUniformLocation(this.program, 'u_geometry'),
257
+ gridDensity: this.gl.getUniformLocation(this.program, 'u_gridDensity'),
258
+ morphFactor: this.gl.getUniformLocation(this.program, 'u_morphFactor'),
259
+ chaos: this.gl.getUniformLocation(this.program, 'u_chaos'),
260
+ speed: this.gl.getUniformLocation(this.program, 'u_speed'),
261
+ hue: this.gl.getUniformLocation(this.program, 'u_hue'),
262
+ intensity: this.gl.getUniformLocation(this.program, 'u_intensity'),
263
+ saturation: this.gl.getUniformLocation(this.program, 'u_saturation'),
264
+ dimension: this.gl.getUniformLocation(this.program, 'u_dimension'),
265
+ rot4dXW: this.gl.getUniformLocation(this.program, 'u_rot4dXW'),
266
+ rot4dYW: this.gl.getUniformLocation(this.program, 'u_rot4dYW'),
267
+ rot4dZW: this.gl.getUniformLocation(this.program, 'u_rot4dZW'),
268
+ mouseIntensity: this.gl.getUniformLocation(this.program, 'u_mouseIntensity'),
269
+ clickIntensity: this.gl.getUniformLocation(this.program, 'u_clickIntensity'),
270
+ roleIntensity: this.gl.getUniformLocation(this.program, 'u_roleIntensity')
271
+ };
272
+ }
273
+
274
+ createProgram(vertexSource, fragmentSource) {
275
+ const vertexShader = this.createShader(this.gl.VERTEX_SHADER, vertexSource);
276
+ const fragmentShader = this.createShader(this.gl.FRAGMENT_SHADER, fragmentSource);
277
+
278
+ const program = this.gl.createProgram();
279
+ this.gl.attachShader(program, vertexShader);
280
+ this.gl.attachShader(program, fragmentShader);
281
+ this.gl.linkProgram(program);
282
+
283
+ if (!this.gl.getProgramParameter(program, this.gl.LINK_STATUS)) {
284
+ console.error('Program linking failed:', this.gl.getProgramInfoLog(program));
285
+ return null;
286
+ }
287
+
288
+ return program;
289
+ }
290
+
291
+ createShader(type, source) {
292
+ const shader = this.gl.createShader(type);
293
+ this.gl.shaderSource(shader, source);
294
+ this.gl.compileShader(shader);
295
+
296
+ if (!this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS)) {
297
+ console.error('Shader compilation failed:', this.gl.getShaderInfoLog(shader));
298
+ return null;
299
+ }
300
+
301
+ return shader;
302
+ }
303
+
304
+ initBuffers() {
305
+ const positions = new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]);
306
+
307
+ this.buffer = this.gl.createBuffer();
308
+ this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.buffer);
309
+ this.gl.bufferData(this.gl.ARRAY_BUFFER, positions, this.gl.STATIC_DRAW);
310
+
311
+ const positionLocation = this.gl.getAttribLocation(this.program, 'a_position');
312
+ this.gl.enableVertexAttribArray(positionLocation);
313
+ this.gl.vertexAttribPointer(positionLocation, 2, this.gl.FLOAT, false, 0, 0);
314
+ }
315
+
316
+ render(time) {
317
+ if (!this.program) return;
318
+
319
+ this.resize();
320
+ this.gl.useProgram(this.program);
321
+
322
+ this.gl.uniform2f(this.uniforms.resolution, this.canvas.width, this.canvas.height);
323
+ this.gl.uniform1f(this.uniforms.time, time);
324
+ this.gl.uniform2f(this.uniforms.mouse, 0.5, 0.5);
325
+ this.gl.uniform1f(this.uniforms.geometry, this.params.geometry || 0);
326
+ this.gl.uniform1f(this.uniforms.gridDensity, this.params.gridDensity || 15);
327
+ this.gl.uniform1f(this.uniforms.morphFactor, this.params.morphFactor || 1.0);
328
+ this.gl.uniform1f(this.uniforms.chaos, this.params.chaos || 0.2);
329
+ this.gl.uniform1f(this.uniforms.speed, this.params.speed || 1.0);
330
+ this.gl.uniform1f(this.uniforms.hue, this.params.hue || 200);
331
+ this.gl.uniform1f(this.uniforms.intensity, this.params.intensity || 0.5);
332
+ this.gl.uniform1f(this.uniforms.saturation, this.params.saturation || 0.8);
333
+ this.gl.uniform1f(this.uniforms.dimension, this.params.dimension || 3.8);
334
+ this.gl.uniform1f(this.uniforms.rot4dXW, this.params.rot4dXW || 0.0);
335
+ this.gl.uniform1f(this.uniforms.rot4dYW, this.params.rot4dYW || 0.0);
336
+ this.gl.uniform1f(this.uniforms.rot4dZW, this.params.rot4dZW || 0.0);
337
+ this.gl.uniform1f(this.uniforms.mouseIntensity, this.mouseIntensity || 0.0);
338
+ this.gl.uniform1f(this.uniforms.clickIntensity, this.clickIntensity || 0.0);
339
+ this.gl.uniform1f(this.uniforms.roleIntensity, this.roleIntensity);
340
+
341
+ this.gl.drawArrays(this.gl.TRIANGLE_STRIP, 0, 4);
342
+ }
343
+ }
344
+
345
+ // Enhanced interactivity system - FIXED CANVAS SCOPE
346
+ const canvas = document.getElementById('vib34dCanvas');
347
+ if (!canvas) {
348
+ console.error('Canvas not found for interactivity');
349
+ return;
350
+ }
351
+
352
+ let mouseX = 0.5, mouseY = 0.5, mouseIntensity = 0.0;
353
+ let clickIntensity = 0.0;
354
+ let currentTouch = null;
355
+
356
+ // Mouse interactions
357
+ canvas.addEventListener('mousemove', (e) => {
358
+ const rect = canvas.getBoundingClientRect();
359
+ mouseX = (e.clientX - rect.left) / rect.width;
360
+ mouseY = 1.0 - (e.clientY - rect.top) / rect.height;
361
+ mouseIntensity = Math.min(1.0, Math.sqrt(e.movementX*e.movementX + e.movementY*e.movementY) / 40);
362
+
363
+ // Update all layer visualizers
364
+ if (typeof layers !== 'undefined') {
365
+ layers.forEach(layer => {
366
+ if (layer.visualizer) {
367
+ layer.visualizer.mouseX = mouseX;
368
+ layer.visualizer.mouseY = mouseY;
369
+ layer.visualizer.mouseIntensity = mouseIntensity;
370
+ }
371
+ });
372
+ }
373
+ });
374
+
375
+ canvas.addEventListener('click', (e) => {
376
+ clickIntensity = 1.0;
377
+ if (typeof layers !== 'undefined') {
378
+ layers.forEach(layer => {
379
+ if (layer.visualizer) {
380
+ layer.visualizer.clickIntensity = clickIntensity;
381
+ }
382
+ });
383
+ }
384
+ setTimeout(() => {
385
+ clickIntensity = 0.0;
386
+ if (typeof layers !== 'undefined') {
387
+ layers.forEach(layer => {
388
+ if (layer.visualizer) {
389
+ layer.visualizer.clickIntensity = 0.0;
390
+ }
391
+ });
392
+ }
393
+ }, 500);
394
+ });
395
+
396
+ // Touch interactions
397
+ canvas.addEventListener('touchstart', (e) => {
398
+ e.preventDefault();
399
+ if (e.touches.length > 0) {
400
+ currentTouch = e.touches[0];
401
+ const rect = canvas.getBoundingClientRect();
402
+ mouseX = (currentTouch.clientX - rect.left) / rect.width;
403
+ mouseY = 1.0 - (currentTouch.clientY - rect.top) / rect.height;
404
+ clickIntensity = 1.0;
405
+
406
+ if (typeof layers !== 'undefined') {
407
+ layers.forEach(layer => {
408
+ if (layer.visualizer) {
409
+ layer.visualizer.mouseX = mouseX;
410
+ layer.visualizer.mouseY = mouseY;
411
+ layer.visualizer.clickIntensity = clickIntensity;
412
+ }
413
+ });
414
+ }
415
+ }
416
+ }, { passive: false });
417
+
418
+ canvas.addEventListener('touchmove', (e) => {
419
+ e.preventDefault();
420
+ if (e.touches.length > 0) {
421
+ const touch = e.touches[0];
422
+ const rect = canvas.getBoundingClientRect();
423
+ mouseX = (touch.clientX - rect.left) / rect.width;
424
+ mouseY = 1.0 - (touch.clientY - rect.top) / rect.height;
425
+ mouseIntensity = 0.8;
426
+ currentTouch = touch;
427
+
428
+ if (typeof layers !== 'undefined') {
429
+ layers.forEach(layer => {
430
+ if (layer.visualizer) {
431
+ layer.visualizer.mouseX = mouseX;
432
+ layer.visualizer.mouseY = mouseY;
433
+ layer.visualizer.mouseIntensity = mouseIntensity;
434
+ }
435
+ });
436
+ }
437
+ }
438
+ }, { passive: false });
439
+
440
+ canvas.addEventListener('touchend', (e) => {
441
+ clickIntensity = 0.0;
442
+ mouseIntensity = 0.0;
443
+ currentTouch = null;
444
+
445
+ if (typeof layers !== 'undefined') {
446
+ layers.forEach(layer => {
447
+ if (layer.visualizer) {
448
+ layer.visualizer.clickIntensity = 0.0;
449
+ layer.visualizer.mouseIntensity = 0.0;
450
+ }
451
+ });
452
+ }
453
+ }, { passive: false });
454
+
455
+ // Scroll interactions
456
+ canvas.addEventListener('wheel', (e) => {
457
+ e.preventDefault();
458
+ clickIntensity = Math.min(1.0, Math.abs(e.deltaY) / 100);
459
+
460
+ if (typeof layers !== 'undefined') {
461
+ layers.forEach(layer => {
462
+ if (layer.visualizer) {
463
+ layer.visualizer.clickIntensity = clickIntensity;
464
+ }
465
+ });
466
+ }
467
+
468
+ setTimeout(() => {
469
+ clickIntensity = 0.0;
470
+ if (typeof layers !== 'undefined') {
471
+ layers.forEach(layer => {
472
+ if (layer.visualizer) {
473
+ layer.visualizer.clickIntensity = 0.0;
474
+ }
475
+ });
476
+ }
477
+ }, 300);
478
+ }, { passive: false });`;
479
+ }
480
+
481
+ /**
482
+ * Get system metadata for the faceted system
483
+ */
484
+ static getSystemInfo() {
485
+ return {
486
+ name: 'Faceted',
487
+ type: 'faceted',
488
+ description: 'Clean 2D geometric patterns with 4D mathematical foundations',
489
+ features: ['5-layer rendering', '8 geometry types', '4D rotations', 'Interactive mouse/touch'],
490
+ shaderComplexity: 'medium',
491
+ layers: 5
492
+ };
493
+ }
494
+ }