@vib3code/sdk 2.0.1 → 2.0.3-canary.0a63e71

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 (192) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/DOCS/AGENT_HARNESS_ARCHITECTURE.md +245 -0
  3. package/DOCS/ANDROID_DEPLOYMENT.md +59 -0
  4. package/DOCS/ARCHITECTURE.md +1 -0
  5. package/DOCS/CI_TESTING.md +2 -0
  6. package/DOCS/CLI_ONBOARDING.md +3 -1
  7. package/DOCS/CONTROL_REFERENCE.md +2 -0
  8. package/DOCS/CROSS_SITE_DESIGN_PATTERNS.md +119 -0
  9. package/DOCS/ENV_SETUP.md +2 -0
  10. package/DOCS/EPIC_SCROLL_EVENTS.md +775 -0
  11. package/DOCS/EXPANSION_DESIGN.md +979 -0
  12. package/DOCS/EXPANSION_DESIGN_ULTRA.md +389 -0
  13. package/DOCS/EXPORT_FORMATS.md +2 -0
  14. package/DOCS/GPU_DISPOSAL_GUIDE.md +2 -0
  15. package/DOCS/HANDOFF_LANDING_PAGE.md +156 -0
  16. package/DOCS/HANDOFF_SDK_DEVELOPMENT.md +495 -0
  17. package/DOCS/LICENSING_TIERS.md +2 -0
  18. package/DOCS/MASTER_PLAN_2026-01-31.md +4 -2
  19. package/DOCS/MULTIVIZ_CHOREOGRAPHY_PATTERNS.md +939 -0
  20. package/DOCS/OBS_SETUP_GUIDE.md +2 -0
  21. package/DOCS/OPTIMIZATION_PLAN_MATH.md +119 -0
  22. package/DOCS/PRODUCT_STRATEGY.md +65 -0
  23. package/DOCS/PROJECT_SETUP.md +2 -0
  24. package/DOCS/README.md +105 -0
  25. package/DOCS/REFERENCE_SCROLL_ANALYSIS.md +99 -0
  26. package/DOCS/RENDERER_LIFECYCLE.md +2 -0
  27. package/DOCS/REPO_MANIFEST.md +2 -0
  28. package/DOCS/ROADMAP.md +113 -0
  29. package/DOCS/SCROLL_TIMELINE_v3.md +271 -0
  30. package/DOCS/SITE_REFACTOR_PLAN.md +102 -0
  31. package/DOCS/STATUS.md +26 -0
  32. package/DOCS/SYSTEM_INVENTORY.md +37 -32
  33. package/DOCS/TELEMETRY_EXPORTS.md +2 -0
  34. package/DOCS/VISUAL_ANALYSIS_CLICKERSS.md +87 -0
  35. package/DOCS/VISUAL_ANALYSIS_FACETAD.md +135 -0
  36. package/DOCS/VISUAL_ANALYSIS_SIMONE.md +97 -0
  37. package/DOCS/VISUAL_ANALYSIS_TABLESIDE.md +88 -0
  38. package/DOCS/WEBGPU_STATUS.md +121 -38
  39. package/DOCS/XR_BENCHMARKS.md +2 -0
  40. package/DOCS/archive/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md +1 -0
  41. package/DOCS/archive/DEV_TRACK_ANALYSIS.md +1 -0
  42. package/DOCS/archive/DEV_TRACK_PLAN_2026-01-07.md +1 -0
  43. package/DOCS/archive/SESSION_014_PLAN.md +1 -0
  44. package/DOCS/archive/SESSION_LOG_2026-01-07.md +1 -0
  45. package/DOCS/archive/STRATEGIC_BLUEPRINT_2026-01-07.md +1 -0
  46. package/DOCS/archive/SYSTEM_AUDIT_2026-01-30.md +1 -0
  47. package/DOCS/archive/WEBGPU_STATUS_2026-02-15_STALE.md +1 -0
  48. package/DOCS/{DEV_TRACK_SESSION_2026-01-31.md → dev-tracks/DEV_TRACK_SESSION_2026-01-31.md} +3 -1
  49. package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-06.md +233 -0
  50. package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-13.md +129 -0
  51. package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-15.md +144 -0
  52. package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-16.md +110 -0
  53. package/DOCS/dev-tracks/PERF_UPGRADE_2026-02-16.md +310 -0
  54. package/DOCS/dev-tracks/README.md +12 -0
  55. package/README.md +26 -13
  56. package/cpp/CMakeLists.txt +236 -0
  57. package/cpp/bindings/embind.cpp +269 -0
  58. package/cpp/build.sh +129 -0
  59. package/cpp/geometry/Crystal.cpp +103 -0
  60. package/cpp/geometry/Fractal.cpp +136 -0
  61. package/cpp/geometry/GeometryGenerator.cpp +262 -0
  62. package/cpp/geometry/KleinBottle.cpp +71 -0
  63. package/cpp/geometry/Sphere.cpp +134 -0
  64. package/cpp/geometry/Tesseract.cpp +94 -0
  65. package/cpp/geometry/Tetrahedron.cpp +83 -0
  66. package/cpp/geometry/Torus.cpp +65 -0
  67. package/cpp/geometry/WarpFunctions.cpp +238 -0
  68. package/cpp/geometry/Wave.cpp +85 -0
  69. package/cpp/include/vib3_ffi.h +238 -0
  70. package/cpp/math/Mat4x4.cpp +409 -0
  71. package/cpp/math/Mat4x4.hpp +209 -0
  72. package/cpp/math/Projection.cpp +142 -0
  73. package/cpp/math/Projection.hpp +148 -0
  74. package/cpp/math/Rotor4D.cpp +322 -0
  75. package/cpp/math/Rotor4D.hpp +204 -0
  76. package/cpp/math/Vec4.cpp +303 -0
  77. package/cpp/math/Vec4.hpp +225 -0
  78. package/cpp/src/vib3_ffi.cpp +607 -0
  79. package/cpp/tests/Geometry_test.cpp +213 -0
  80. package/cpp/tests/Mat4x4_test.cpp +494 -0
  81. package/cpp/tests/Projection_test.cpp +298 -0
  82. package/cpp/tests/Rotor4D_test.cpp +423 -0
  83. package/cpp/tests/Vec4_test.cpp +489 -0
  84. package/docs/webgpu-live.html +1 -1
  85. package/package.json +41 -30
  86. package/src/agent/index.js +1 -3
  87. package/src/agent/mcp/MCPServer.js +1220 -144
  88. package/src/agent/mcp/index.js +1 -1
  89. package/src/agent/mcp/stdio-server.js +264 -0
  90. package/src/agent/mcp/tools.js +498 -31
  91. package/src/cli/index.js +431 -47
  92. package/src/core/CanvasManager.js +97 -204
  93. package/src/core/ErrorReporter.js +1 -1
  94. package/src/core/Parameters.js +1 -1
  95. package/src/core/VIB3Engine.js +93 -4
  96. package/src/core/VitalitySystem.js +53 -0
  97. package/src/core/index.js +18 -0
  98. package/src/core/renderers/FacetedRendererAdapter.js +10 -9
  99. package/src/core/renderers/HolographicRendererAdapter.js +13 -9
  100. package/src/core/renderers/QuantumRendererAdapter.js +11 -7
  101. package/src/creative/AestheticMapper.js +628 -0
  102. package/src/creative/ChoreographyPlayer.js +481 -0
  103. package/src/creative/index.js +11 -0
  104. package/src/experimental/GameLoop.js +72 -0
  105. package/src/experimental/LatticePhysics.js +100 -0
  106. package/src/experimental/LiveDirector.js +143 -0
  107. package/src/experimental/PlayerController4D.js +154 -0
  108. package/src/experimental/VIB3Actor.js +138 -0
  109. package/src/experimental/VIB3Compositor.js +117 -0
  110. package/src/experimental/VIB3Link.js +122 -0
  111. package/src/experimental/VIB3Orchestrator.js +146 -0
  112. package/src/experimental/VIB3Universe.js +109 -0
  113. package/src/experimental/demos/CrystalLabyrinth.js +202 -0
  114. package/src/export/TradingCardManager.js +3 -4
  115. package/src/export/index.js +11 -1
  116. package/src/faceted/FacetedSystem.js +260 -394
  117. package/src/games/glyph-war/GlyphWarVisualizer.js +641 -0
  118. package/src/geometry/generators/Crystal.js +2 -2
  119. package/src/geometry/warp/HypersphereCore.js +53 -24
  120. package/src/holograms/HolographicVisualizer.js +84 -98
  121. package/src/holograms/RealHolographicSystem.js +194 -43
  122. package/src/math/Mat4x4.js +308 -105
  123. package/src/math/Rotor4D.js +124 -40
  124. package/src/math/Vec4.js +200 -103
  125. package/src/math/index.js +7 -7
  126. package/src/polychora/PolychoraSystem.js +77 -0
  127. package/src/quantum/QuantumEngine.js +103 -66
  128. package/src/quantum/QuantumVisualizer.js +31 -22
  129. package/src/reactivity/index.js +3 -5
  130. package/src/render/LayerPresetManager.js +372 -0
  131. package/src/render/LayerReactivityBridge.js +344 -0
  132. package/src/render/LayerRelationshipGraph.js +610 -0
  133. package/src/render/MultiCanvasBridge.js +148 -25
  134. package/src/render/ShaderLoader.js +38 -0
  135. package/src/render/ShaderProgram.js +4 -4
  136. package/src/render/UnifiedRenderBridge.js +4 -1
  137. package/src/render/backends/WebGPUBackend.js +8 -4
  138. package/src/render/index.js +27 -2
  139. package/src/scene/Node4D.js +74 -24
  140. package/src/scene/index.js +4 -4
  141. package/src/shaders/common/geometry24.glsl +65 -0
  142. package/src/shaders/common/geometry24.wgsl +54 -0
  143. package/src/shaders/common/rotation4d.glsl +4 -4
  144. package/src/shaders/common/rotation4d.wgsl +2 -2
  145. package/src/shaders/common/uniforms.wgsl +15 -8
  146. package/src/shaders/faceted/faceted.frag.glsl +220 -80
  147. package/src/shaders/faceted/faceted.frag.wgsl +144 -90
  148. package/src/shaders/holographic/holographic.frag.glsl +28 -9
  149. package/src/shaders/holographic/holographic.frag.wgsl +112 -41
  150. package/src/shaders/quantum/quantum.frag.glsl +1 -0
  151. package/src/shaders/quantum/quantum.frag.wgsl +6 -4
  152. package/src/testing/ParallelTestFramework.js +2 -2
  153. package/src/ui/adaptive/renderers/webgpu/WebGPURenderer.ts +2 -2
  154. package/src/viewer/GalleryUI.js +17 -0
  155. package/src/viewer/ViewerPortal.js +2 -2
  156. package/src/viewer/index.js +1 -1
  157. package/tools/headless-renderer.js +258 -0
  158. package/tools/shader-sync-verify.js +14 -8
  159. package/tools/site-analysis/all-reports.json +32 -0
  160. package/tools/site-analysis/combined-analysis.md +50 -0
  161. package/tools/site-analyzer.mjs +779 -0
  162. package/tools/visual-catalog/capture.js +276 -0
  163. package/tools/visual-catalog/composite.js +138 -0
  164. package/types/adaptive-sdk.d.ts +204 -5
  165. package/types/agent/cli.d.ts +78 -0
  166. package/types/agent/index.d.ts +18 -0
  167. package/types/agent/mcp.d.ts +87 -0
  168. package/types/agent/telemetry.d.ts +190 -0
  169. package/types/core/VIB3Engine.d.ts +26 -0
  170. package/types/core/index.d.ts +261 -0
  171. package/types/creative/AestheticMapper.d.ts +72 -0
  172. package/types/creative/ChoreographyPlayer.d.ts +96 -0
  173. package/types/creative/index.d.ts +17 -0
  174. package/types/export/index.d.ts +243 -0
  175. package/types/geometry/index.d.ts +164 -0
  176. package/types/math/index.d.ts +214 -0
  177. package/types/render/LayerPresetManager.d.ts +78 -0
  178. package/types/render/LayerReactivityBridge.d.ts +85 -0
  179. package/types/render/LayerRelationshipGraph.d.ts +174 -0
  180. package/types/render/index.d.ts +3 -0
  181. package/types/scene/index.d.ts +204 -0
  182. package/types/systems/index.d.ts +244 -0
  183. package/types/variations/index.d.ts +62 -0
  184. package/types/viewer/index.d.ts +225 -0
  185. package/DOCS/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md +0 -34
  186. package/DOCS/DEV_TRACK_ANALYSIS.md +0 -77
  187. package/DOCS/DEV_TRACK_PLAN_2026-01-07.md +0 -42
  188. package/DOCS/SESSION_014_PLAN.md +0 -195
  189. package/DOCS/SESSION_LOG_2026-01-07.md +0 -56
  190. package/DOCS/STRATEGIC_BLUEPRINT_2026-01-07.md +0 -72
  191. package/DOCS/SYSTEM_AUDIT_2026-01-30.md +0 -738
  192. /package/src/viewer/{ReactivityManager.js → ViewerInputHandler.js} +0 -0
@@ -0,0 +1,238 @@
1
+ /**
2
+ * WarpFunctions.cpp - Core Type Warp Functions
3
+ *
4
+ * Provides warp transformations that modify base geometries to create
5
+ * the three core type variants (Base, Hypersphere, Hypertetrahedron).
6
+ *
7
+ * Core type 0 (Base, index 0-7): No warp, pure base geometry.
8
+ * Core type 1 (Hypersphere, 8-15): Project onto 3-sphere surface.
9
+ * Core type 2 (Hypertetra, 16-23): Warp toward pentatope vertices.
10
+ */
11
+
12
+ #include "math/Vec4.hpp"
13
+ #include <vector>
14
+ #include <cmath>
15
+ #include <numbers>
16
+ #include <algorithm>
17
+
18
+ namespace vib3 {
19
+
20
+ /**
21
+ * Project a 4D point onto the 3-sphere of given radius.
22
+ *
23
+ * Normalizes the point to lie on S3, then scales by `radius`.
24
+ * If the point is at the origin, returns a default point on the sphere.
25
+ *
26
+ * @param point Input 4D point
27
+ * @param radius Radius of the target 3-sphere
28
+ * @return Point projected onto S3 * radius
29
+ */
30
+ Vec4 warpHypersphere(Vec4 point, float radius) noexcept {
31
+ float len = point.length();
32
+
33
+ if (len < 1e-8f) {
34
+ // Degenerate case: return a default point on the sphere
35
+ return Vec4(radius, 0.0f, 0.0f, 0.0f);
36
+ }
37
+
38
+ return point * (radius / len);
39
+ }
40
+
41
+ /**
42
+ * Inverse stereographic projection from R3 to S3.
43
+ *
44
+ * Maps a 3D point (interpreted as x,y,z with w=0) onto the 3-sphere
45
+ * using inverse stereographic projection from the north pole (0,0,0,1).
46
+ *
47
+ * @param point Input 4D point (only x,y,z used)
48
+ * @return Point on unit S3
49
+ */
50
+ Vec4 inverseStereographicToHypersphere(Vec4 point) noexcept {
51
+ float r2 = point.x * point.x + point.y * point.y + point.z * point.z;
52
+ float denom = 1.0f + r2;
53
+
54
+ return Vec4(
55
+ 2.0f * point.x / denom,
56
+ 2.0f * point.y / denom,
57
+ 2.0f * point.z / denom,
58
+ (r2 - 1.0f) / denom
59
+ );
60
+ }
61
+
62
+ /**
63
+ * Apply Hopf fibration mapping.
64
+ *
65
+ * Given a point on S3, returns its base point on S2 (the Hopf projection)
66
+ * and the fiber angle. This is used to visualize toroidal structures
67
+ * inherent in the 3-sphere.
68
+ *
69
+ * @param point Point on S3
70
+ * @return Projected point (x,y,z = S2 base point, w = fiber angle)
71
+ */
72
+ Vec4 hopfProject(Vec4 point) noexcept {
73
+ // Normalize to ensure on S3
74
+ Vec4 p = point.normalized();
75
+
76
+ // Hopf map S3 -> S2:
77
+ // n1 = 2(x*z + y*w)
78
+ // n2 = 2(y*z - x*w)
79
+ // n3 = x^2 + y^2 - z^2 - w^2
80
+ float n1 = 2.0f * (p.x * p.z + p.y * p.w);
81
+ float n2 = 2.0f * (p.y * p.z - p.x * p.w);
82
+ float n3 = p.x * p.x + p.y * p.y - p.z * p.z - p.w * p.w;
83
+
84
+ // Fiber angle
85
+ float fiberAngle = std::atan2(p.y, p.x) - std::atan2(p.w, p.z);
86
+
87
+ return Vec4(n1, n2, n3, fiberAngle);
88
+ }
89
+
90
+ /**
91
+ * Batch warp: project all points in a geometry onto S3.
92
+ *
93
+ * @param points Input geometry vertices
94
+ * @param radius Radius of the target 3-sphere
95
+ * @return Warped vertices on the 3-sphere
96
+ */
97
+ std::vector<Vec4> warpHypersphereBatch(const std::vector<Vec4>& points,
98
+ float radius) noexcept {
99
+ std::vector<Vec4> result;
100
+ result.reserve(points.size());
101
+
102
+ for (const auto& p : points) {
103
+ result.push_back(warpHypersphere(p, radius));
104
+ }
105
+
106
+ return result;
107
+ }
108
+
109
+ // ---- Hypertetrahedron (Pentatope) Warp ----
110
+
111
+ namespace {
112
+
113
+ /**
114
+ * The 5 vertices of a regular 5-cell (pentatope) in R4.
115
+ *
116
+ * These are the vertices of the simplest regular 4D polytope,
117
+ * the analogue of the tetrahedron in 4D.
118
+ */
119
+ constexpr int kPentatopeVertexCount = 5;
120
+
121
+ Vec4 getPentatopeVertex(int index) noexcept {
122
+ // Standard regular 5-cell vertices
123
+ // Constructed so that all pairwise distances are equal.
124
+ const float s = std::sqrt(2.0f / 5.0f);
125
+ const float t = std::sqrt(2.0f / 3.0f);
126
+ const float u = 1.0f / std::sqrt(3.0f);
127
+ const float v = 1.0f / std::sqrt(15.0f);
128
+
129
+ switch (index) {
130
+ case 0: return Vec4( t, 0.0f, 0.0f, -v);
131
+ case 1: return Vec4(-u, u, 0.0f, -v);
132
+ case 2: return Vec4(-u, -u, 0.0f, -v);
133
+ case 3: return Vec4( 0.0f, 0.0f, t, -v);
134
+ case 4: return Vec4( 0.0f, 0.0f, 0.0f, 4.0f * v);
135
+ default: return Vec4::zero();
136
+ }
137
+ }
138
+
139
+ } // anonymous namespace
140
+
141
+ /**
142
+ * Warp a 4D point toward the nearest pentatope vertex.
143
+ *
144
+ * Finds the closest vertex of the regular 5-cell and interpolates
145
+ * the point toward it, creating a tetrahedral clustering effect.
146
+ * The interpolation factor is based on the inverse distance to
147
+ * the nearest vertex, producing a gravitational pull effect.
148
+ *
149
+ * @param point Input 4D point
150
+ * @return Warped point attracted toward nearest pentatope vertex
151
+ */
152
+ Vec4 warpHypertetra(Vec4 point) noexcept {
153
+ // Find nearest pentatope vertex
154
+ int nearestIdx = 0;
155
+ float nearestDist = point.distanceSquaredTo(getPentatopeVertex(0));
156
+
157
+ for (int i = 1; i < kPentatopeVertexCount; ++i) {
158
+ float dist = point.distanceSquaredTo(getPentatopeVertex(i));
159
+ if (dist < nearestDist) {
160
+ nearestDist = dist;
161
+ nearestIdx = i;
162
+ }
163
+ }
164
+
165
+ Vec4 nearest = getPentatopeVertex(nearestIdx);
166
+
167
+ // Warp factor based on distance (closer = stronger pull)
168
+ float dist = std::sqrt(nearestDist);
169
+ float warpStrength = 1.0f / (1.0f + dist * 2.0f);
170
+
171
+ // Interpolate toward the nearest pentatope vertex
172
+ return point.lerp(nearest, warpStrength);
173
+ }
174
+
175
+ /**
176
+ * Warp a 4D point onto the edges of the pentatope.
177
+ *
178
+ * Projects the point to the nearest edge of the 5-cell,
179
+ * producing a skeletal wireframe appearance.
180
+ *
181
+ * @param point Input 4D point
182
+ * @return Point projected onto nearest pentatope edge
183
+ */
184
+ Vec4 warpToEdges(Vec4 point) noexcept {
185
+ // 10 edges of the pentatope (all pairs of 5 vertices)
186
+ constexpr int edgePairs[10][2] = {
187
+ {0, 1}, {0, 2}, {0, 3}, {0, 4},
188
+ {1, 2}, {1, 3}, {1, 4},
189
+ {2, 3}, {2, 4},
190
+ {3, 4}
191
+ };
192
+
193
+ Vec4 bestProjection = point;
194
+ float bestDist = 1e10f;
195
+
196
+ for (const auto& pair : edgePairs) {
197
+ Vec4 a = getPentatopeVertex(pair[0]);
198
+ Vec4 b = getPentatopeVertex(pair[1]);
199
+ Vec4 edge = b - a;
200
+ Vec4 toPoint = point - a;
201
+
202
+ // Project onto edge (clamped to [0,1])
203
+ float edgeLenSq = edge.dot(edge);
204
+ if (edgeLenSq < 1e-10f) continue;
205
+
206
+ float t = toPoint.dot(edge) / edgeLenSq;
207
+ t = std::max(0.0f, std::min(1.0f, t));
208
+
209
+ Vec4 projected = a.lerp(b, t);
210
+ float dist = point.distanceSquaredTo(projected);
211
+
212
+ if (dist < bestDist) {
213
+ bestDist = dist;
214
+ bestProjection = projected;
215
+ }
216
+ }
217
+
218
+ return bestProjection;
219
+ }
220
+
221
+ /**
222
+ * Batch warp: apply hypertetra warp to all points.
223
+ *
224
+ * @param points Input geometry vertices
225
+ * @return Warped vertices attracted toward pentatope vertices
226
+ */
227
+ std::vector<Vec4> warpHypertetraBatch(const std::vector<Vec4>& points) noexcept {
228
+ std::vector<Vec4> result;
229
+ result.reserve(points.size());
230
+
231
+ for (const auto& p : points) {
232
+ result.push_back(warpHypertetra(p));
233
+ }
234
+
235
+ return result;
236
+ }
237
+
238
+ } // namespace vib3
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Wave.cpp - Sinusoidal Interference Pattern in 4D
3
+ *
4
+ * Generates a grid of 4D points with sinusoidal wave displacement.
5
+ * The base grid lies in the XZ plane, with Y and W components driven
6
+ * by interference of multiple wave sources.
7
+ */
8
+
9
+ #include "math/Vec4.hpp"
10
+ #include <vector>
11
+ #include <cmath>
12
+ #include <numbers>
13
+
14
+ namespace vib3 {
15
+
16
+ /**
17
+ * Generate a 4D sinusoidal interference pattern.
18
+ *
19
+ * Creates a resolution x resolution grid in the XZ plane, centered at
20
+ * the origin. The Y component is displaced by the sum of three wave
21
+ * sources with different frequencies, and the W component uses a
22
+ * cross-wave pattern, producing a rich 4D interference field.
23
+ *
24
+ * @param resolution Number of grid points along each axis (total = resolution^2)
25
+ * @return Vector of 4D points with wave displacement
26
+ */
27
+ std::vector<Vec4> generateWave(int resolution) noexcept {
28
+ if (resolution < 4) resolution = 4;
29
+
30
+ constexpr float pi = std::numbers::pi_v<float>;
31
+
32
+ // Grid extends from -gridExtent to +gridExtent
33
+ constexpr float gridExtent = 2.0f;
34
+
35
+ // Wave parameters: {frequency, amplitude, phase offset X, phase offset Z}
36
+ struct WaveSource {
37
+ float freq;
38
+ float ampY;
39
+ float ampW;
40
+ float phaseX;
41
+ float phaseZ;
42
+ };
43
+
44
+ constexpr WaveSource waves[] = {
45
+ { 1.0f, 0.5f, 0.3f, 0.0f, 0.0f }, // Primary wave
46
+ { 2.3f, 0.25f, 0.15f, pi * 0.5f, pi * 0.25f }, // Secondary wave
47
+ { 3.7f, 0.125f, 0.1f, pi * 0.75f, pi * 0.6f }, // Tertiary wave
48
+ };
49
+ constexpr int numWaves = 3;
50
+
51
+ std::vector<Vec4> vertices;
52
+ vertices.reserve(static_cast<size_t>(resolution) * static_cast<size_t>(resolution));
53
+
54
+ float step = (2.0f * gridExtent) / static_cast<float>(resolution - 1);
55
+
56
+ for (int ix = 0; ix < resolution; ++ix) {
57
+ float x = -gridExtent + static_cast<float>(ix) * step;
58
+
59
+ for (int iz = 0; iz < resolution; ++iz) {
60
+ float z = -gridExtent + static_cast<float>(iz) * step;
61
+
62
+ float y = 0.0f;
63
+ float w = 0.0f;
64
+
65
+ // Sum contributions from all wave sources
66
+ for (int wi = 0; wi < numWaves; ++wi) {
67
+ const auto& ws = waves[wi];
68
+ float phX = ws.freq * x * pi + ws.phaseX;
69
+ float phZ = ws.freq * z * pi + ws.phaseZ;
70
+
71
+ // Y displacement: circular wave pattern
72
+ y += ws.ampY * std::sin(phX) * std::cos(phZ);
73
+
74
+ // W displacement: cross-interference pattern
75
+ w += ws.ampW * std::cos(phX + phZ);
76
+ }
77
+
78
+ vertices.emplace_back(x, y, z, w);
79
+ }
80
+ }
81
+
82
+ return vertices;
83
+ }
84
+
85
+ } // namespace vib3
@@ -0,0 +1,238 @@
1
+ /**
2
+ * VIB3+ FFI Header
3
+ *
4
+ * C interface for cross-platform FFI bindings.
5
+ * Used by Flutter, React Native, and other FFI-capable frameworks.
6
+ */
7
+
8
+ #ifndef VIB3_FFI_H
9
+ #define VIB3_FFI_H
10
+
11
+ #include <stdint.h>
12
+ #include <stdbool.h>
13
+
14
+ #ifdef __cplusplus
15
+ extern "C" {
16
+ #endif
17
+
18
+ // Platform export macros
19
+ #if defined(_WIN32) || defined(_WIN64)
20
+ #define VIB3_EXPORT __declspec(dllexport)
21
+ #else
22
+ #define VIB3_EXPORT __attribute__((visibility("default")))
23
+ #endif
24
+
25
+ // ============================================================================
26
+ // Types
27
+ // ============================================================================
28
+
29
+ /**
30
+ * 4D Vector (16-byte aligned)
31
+ */
32
+ typedef struct VIB3_EXPORT Vib3Vec4 {
33
+ float x, y, z, w;
34
+ } Vib3Vec4;
35
+
36
+ /**
37
+ * 4D Rotor (8 components for proper 4D rotation)
38
+ */
39
+ typedef struct VIB3_EXPORT Vib3Rotor4D {
40
+ float s; // Scalar
41
+ float xy; // Bivector XY
42
+ float xz; // Bivector XZ
43
+ float yz; // Bivector YZ
44
+ float xw; // Bivector XW
45
+ float yw; // Bivector YW
46
+ float zw; // Bivector ZW
47
+ float xyzw; // Pseudoscalar
48
+ } Vib3Rotor4D;
49
+
50
+ /**
51
+ * 4x4 Matrix (column-major)
52
+ */
53
+ typedef struct VIB3_EXPORT Vib3Mat4x4 {
54
+ float data[16];
55
+ } Vib3Mat4x4;
56
+
57
+ /**
58
+ * Rotation plane enumeration
59
+ */
60
+ typedef enum VIB3_EXPORT Vib3RotationPlane {
61
+ VIB3_PLANE_XY = 0,
62
+ VIB3_PLANE_XZ = 1,
63
+ VIB3_PLANE_YZ = 2,
64
+ VIB3_PLANE_XW = 3,
65
+ VIB3_PLANE_YW = 4,
66
+ VIB3_PLANE_ZW = 5
67
+ } Vib3RotationPlane;
68
+
69
+ /**
70
+ * Projection type enumeration
71
+ */
72
+ typedef enum VIB3_EXPORT Vib3ProjectionType {
73
+ VIB3_PROJ_PERSPECTIVE = 0,
74
+ VIB3_PROJ_STEREOGRAPHIC = 1,
75
+ VIB3_PROJ_ORTHOGRAPHIC = 2,
76
+ VIB3_PROJ_OBLIQUE = 3
77
+ } Vib3ProjectionType;
78
+
79
+ /**
80
+ * Command batch result
81
+ */
82
+ typedef struct VIB3_EXPORT Vib3BatchResult {
83
+ int32_t success_count;
84
+ int32_t error_count;
85
+ int32_t result_size;
86
+ } Vib3BatchResult;
87
+
88
+ /**
89
+ * Engine handle (opaque)
90
+ */
91
+ typedef struct Vib3Engine* Vib3EngineHandle;
92
+
93
+ /**
94
+ * Texture handle for rendering
95
+ */
96
+ typedef struct {
97
+ void* native_handle; // Platform-specific texture handle
98
+ int32_t width;
99
+ int32_t height;
100
+ int32_t format;
101
+ } Vib3TextureHandle;
102
+
103
+ // ============================================================================
104
+ // Vec4 Functions
105
+ // ============================================================================
106
+
107
+ VIB3_EXPORT Vib3Vec4* vib3_vec4_create(float x, float y, float z, float w);
108
+ VIB3_EXPORT void vib3_vec4_free(Vib3Vec4* v);
109
+ VIB3_EXPORT float vib3_vec4_dot(const Vib3Vec4* a, const Vib3Vec4* b);
110
+ VIB3_EXPORT float vib3_vec4_length(const Vib3Vec4* v);
111
+ VIB3_EXPORT void vib3_vec4_normalize(Vib3Vec4* v);
112
+ VIB3_EXPORT Vib3Vec4* vib3_vec4_add(const Vib3Vec4* a, const Vib3Vec4* b);
113
+ VIB3_EXPORT Vib3Vec4* vib3_vec4_sub(const Vib3Vec4* a, const Vib3Vec4* b);
114
+ VIB3_EXPORT Vib3Vec4* vib3_vec4_scale(const Vib3Vec4* v, float s);
115
+ VIB3_EXPORT Vib3Vec4* vib3_vec4_lerp(const Vib3Vec4* a, const Vib3Vec4* b, float t);
116
+
117
+ // ============================================================================
118
+ // Rotor4D Functions
119
+ // ============================================================================
120
+
121
+ VIB3_EXPORT Vib3Rotor4D* vib3_rotor4d_identity(void);
122
+ VIB3_EXPORT Vib3Rotor4D* vib3_rotor4d_from_plane_angle(Vib3RotationPlane plane, float angle);
123
+ VIB3_EXPORT Vib3Rotor4D* vib3_rotor4d_from_euler6(
124
+ float xy, float xz, float yz,
125
+ float xw, float yw, float zw
126
+ );
127
+ VIB3_EXPORT void vib3_rotor4d_free(Vib3Rotor4D* r);
128
+ VIB3_EXPORT Vib3Rotor4D* vib3_rotor4d_multiply(const Vib3Rotor4D* a, const Vib3Rotor4D* b);
129
+ VIB3_EXPORT Vib3Vec4* vib3_rotor4d_rotate(const Vib3Rotor4D* r, const Vib3Vec4* v);
130
+ VIB3_EXPORT Vib3Rotor4D* vib3_rotor4d_slerp(const Vib3Rotor4D* a, const Vib3Rotor4D* b, float t);
131
+ VIB3_EXPORT void vib3_rotor4d_normalize(Vib3Rotor4D* r);
132
+ VIB3_EXPORT Vib3Mat4x4* vib3_rotor4d_to_matrix(const Vib3Rotor4D* r);
133
+
134
+ // ============================================================================
135
+ // Mat4x4 Functions
136
+ // ============================================================================
137
+
138
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_identity(void);
139
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_xy(float angle);
140
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_xz(float angle);
141
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_yz(float angle);
142
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_xw(float angle);
143
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_yw(float angle);
144
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_zw(float angle);
145
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_from_angles(
146
+ float xy, float xz, float yz,
147
+ float xw, float yw, float zw
148
+ );
149
+ VIB3_EXPORT void vib3_mat4x4_free(Vib3Mat4x4* m);
150
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_multiply(const Vib3Mat4x4* a, const Vib3Mat4x4* b);
151
+ VIB3_EXPORT Vib3Vec4* vib3_mat4x4_multiply_vec4(const Vib3Mat4x4* m, const Vib3Vec4* v);
152
+ VIB3_EXPORT void vib3_mat4x4_get_data(const Vib3Mat4x4* m, float* out);
153
+
154
+ // ============================================================================
155
+ // Projection Functions
156
+ // ============================================================================
157
+
158
+ VIB3_EXPORT Vib3Vec4* vib3_project_perspective(const Vib3Vec4* v, float distance);
159
+ VIB3_EXPORT Vib3Vec4* vib3_project_stereographic(const Vib3Vec4* v);
160
+ VIB3_EXPORT Vib3Vec4* vib3_project_orthographic(const Vib3Vec4* v);
161
+ VIB3_EXPORT Vib3Vec4* vib3_project_oblique(const Vib3Vec4* v, float shear_x, float shear_y);
162
+
163
+ // Batch projection (for geometry arrays)
164
+ VIB3_EXPORT int32_t vib3_project_batch(
165
+ const float* positions, // Input: [x,y,z,w, x,y,z,w, ...]
166
+ int32_t count, // Number of Vec4s
167
+ Vib3ProjectionType type,
168
+ float param, // Distance for perspective, unused for others
169
+ float* out // Output: [x,y,z, x,y,z, ...]
170
+ );
171
+
172
+ // ============================================================================
173
+ // Command Batching
174
+ // ============================================================================
175
+
176
+ /**
177
+ * Process a batch of commands
178
+ *
179
+ * @param commands Binary command buffer
180
+ * @param size Size of command buffer in bytes
181
+ * @param results Output buffer for results
182
+ * @return Number of bytes written to results
183
+ */
184
+ VIB3_EXPORT int32_t vib3_process_command_batch(
185
+ const uint8_t* commands,
186
+ uint32_t size,
187
+ uint8_t* results
188
+ );
189
+
190
+ // ============================================================================
191
+ // Engine Functions
192
+ // ============================================================================
193
+
194
+ VIB3_EXPORT Vib3EngineHandle vib3_engine_create(void);
195
+ VIB3_EXPORT void vib3_engine_destroy(Vib3EngineHandle engine);
196
+
197
+ VIB3_EXPORT bool vib3_engine_initialize(
198
+ Vib3EngineHandle engine,
199
+ int32_t width,
200
+ int32_t height
201
+ );
202
+
203
+ VIB3_EXPORT void vib3_engine_set_system(Vib3EngineHandle engine, const char* system);
204
+ VIB3_EXPORT void vib3_engine_set_geometry(Vib3EngineHandle engine, int32_t index);
205
+ VIB3_EXPORT void vib3_engine_set_rotation(
206
+ Vib3EngineHandle engine,
207
+ Vib3RotationPlane plane,
208
+ float angle
209
+ );
210
+ VIB3_EXPORT void vib3_engine_set_all_rotations(
211
+ Vib3EngineHandle engine,
212
+ float xy, float xz, float yz,
213
+ float xw, float yw, float zw
214
+ );
215
+ VIB3_EXPORT void vib3_engine_reset_rotation(Vib3EngineHandle engine);
216
+
217
+ VIB3_EXPORT void vib3_engine_set_visual_param(
218
+ Vib3EngineHandle engine,
219
+ const char* param,
220
+ float value
221
+ );
222
+
223
+ VIB3_EXPORT void vib3_engine_render(Vib3EngineHandle engine);
224
+ VIB3_EXPORT Vib3TextureHandle vib3_engine_get_texture(Vib3EngineHandle engine);
225
+
226
+ // ============================================================================
227
+ // Utility Functions
228
+ // ============================================================================
229
+
230
+ VIB3_EXPORT const char* vib3_version(void);
231
+ VIB3_EXPORT const char* vib3_geometry_name(int32_t index);
232
+ VIB3_EXPORT bool vib3_has_simd(void);
233
+
234
+ #ifdef __cplusplus
235
+ }
236
+ #endif
237
+
238
+ #endif // VIB3_FFI_H