@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,661 @@
1
+ /**
2
+ * RenderCommandBuffer - Cross-platform serializable render command buffer
3
+ *
4
+ * Records render operations as serializable commands that can be:
5
+ * - Executed immediately on WebGL/WebGPU backends
6
+ * - Serialized to JSON for WASM/Flutter FFI
7
+ * - Batched to reduce FFI overhead on cross-platform targets
8
+ *
9
+ * Command Types:
10
+ * - CLEAR: Clear color/depth buffers
11
+ * - SET_VIEWPORT: Set viewport dimensions
12
+ * - SET_PIPELINE: Set shader pipeline
13
+ * - SET_UNIFORMS: Update uniform values
14
+ * - BIND_VERTEX_BUFFER: Bind vertex data
15
+ * - BIND_INDEX_BUFFER: Bind index data
16
+ * - DRAW: Draw primitives
17
+ * - DRAW_INDEXED: Draw indexed primitives
18
+ * - DRAW_INSTANCED: Draw instanced primitives
19
+ * - SET_BLEND_MODE: Set blend state
20
+ * - SET_DEPTH_STATE: Set depth test state
21
+ * - PUSH_STATE: Push render state to stack
22
+ * - POP_STATE: Restore render state from stack
23
+ */
24
+
25
+ /**
26
+ * Command type constants
27
+ */
28
+ export const CommandType = {
29
+ CLEAR: 0x01,
30
+ SET_VIEWPORT: 0x02,
31
+ SET_PIPELINE: 0x03,
32
+ SET_UNIFORMS: 0x04,
33
+ BIND_VERTEX_BUFFER: 0x05,
34
+ BIND_INDEX_BUFFER: 0x06,
35
+ DRAW: 0x07,
36
+ DRAW_INDEXED: 0x08,
37
+ DRAW_INSTANCED: 0x09,
38
+ SET_BLEND_MODE: 0x0A,
39
+ SET_DEPTH_STATE: 0x0B,
40
+ PUSH_STATE: 0x0C,
41
+ POP_STATE: 0x0D,
42
+ SET_SCISSOR: 0x0E,
43
+ SET_STENCIL: 0x0F,
44
+ BIND_TEXTURE: 0x10,
45
+ SET_ROTOR: 0x11,
46
+ SET_PROJECTION: 0x12
47
+ };
48
+
49
+ /**
50
+ * Blend mode presets
51
+ */
52
+ export const BlendMode = {
53
+ NONE: 0,
54
+ ALPHA: 1,
55
+ ADDITIVE: 2,
56
+ MULTIPLY: 3,
57
+ SCREEN: 4,
58
+ PREMULTIPLIED: 5
59
+ };
60
+
61
+ /**
62
+ * Depth compare functions
63
+ */
64
+ export const DepthFunc = {
65
+ NEVER: 0,
66
+ LESS: 1,
67
+ EQUAL: 2,
68
+ LEQUAL: 3,
69
+ GREATER: 4,
70
+ NOTEQUAL: 5,
71
+ GEQUAL: 6,
72
+ ALWAYS: 7
73
+ };
74
+
75
+ /**
76
+ * Primitive topology
77
+ */
78
+ export const Topology = {
79
+ POINT_LIST: 0,
80
+ LINE_LIST: 1,
81
+ LINE_STRIP: 2,
82
+ TRIANGLE_LIST: 3,
83
+ TRIANGLE_STRIP: 4,
84
+ TRIANGLE_FAN: 5
85
+ };
86
+
87
+ /**
88
+ * Render command structure
89
+ */
90
+ class RenderCommand {
91
+ /**
92
+ * @param {number} type - CommandType value
93
+ * @param {object} data - Command-specific data
94
+ */
95
+ constructor(type, data = {}) {
96
+ this.type = type;
97
+ this.data = data;
98
+ this.timestamp = performance.now();
99
+ }
100
+
101
+ /**
102
+ * Serialize command to plain object
103
+ * @returns {object}
104
+ */
105
+ toJSON() {
106
+ return {
107
+ type: this.type,
108
+ data: this.data,
109
+ timestamp: this.timestamp
110
+ };
111
+ }
112
+
113
+ /**
114
+ * Create command from plain object
115
+ * @param {object} obj
116
+ * @returns {RenderCommand}
117
+ */
118
+ static fromJSON(obj) {
119
+ const cmd = new RenderCommand(obj.type, obj.data);
120
+ cmd.timestamp = obj.timestamp;
121
+ return cmd;
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Cross-platform render command buffer
127
+ */
128
+ export class RenderCommandBuffer {
129
+ /**
130
+ * @param {object} [options]
131
+ * @param {number} [options.initialCapacity] - Pre-allocate command array
132
+ * @param {boolean} [options.trackStats] - Enable statistics tracking
133
+ */
134
+ constructor(options = {}) {
135
+ this._commands = [];
136
+ this._capacity = options.initialCapacity || 256;
137
+ this._trackStats = options.trackStats !== false;
138
+
139
+ /** @type {Map<number, number>} */
140
+ this._resourceIds = new Map();
141
+ this._nextResourceId = 1;
142
+
143
+ this._stats = {
144
+ commands: 0,
145
+ drawCalls: 0,
146
+ triangles: 0,
147
+ stateChanges: 0,
148
+ uniformUpdates: 0
149
+ };
150
+
151
+ this._sealed = false;
152
+ this._version = 1;
153
+ }
154
+
155
+ /**
156
+ * Check if buffer is sealed (no more recording)
157
+ * @returns {boolean}
158
+ */
159
+ get sealed() {
160
+ return this._sealed;
161
+ }
162
+
163
+ /**
164
+ * Get command count
165
+ * @returns {number}
166
+ */
167
+ get length() {
168
+ return this._commands.length;
169
+ }
170
+
171
+ /**
172
+ * Get buffer version (increments on changes)
173
+ * @returns {number}
174
+ */
175
+ get version() {
176
+ return this._version;
177
+ }
178
+
179
+ /**
180
+ * Clear the command buffer for reuse
181
+ */
182
+ reset() {
183
+ this._commands.length = 0;
184
+ this._sealed = false;
185
+ this._version++;
186
+ this._stats.commands = 0;
187
+ this._stats.drawCalls = 0;
188
+ this._stats.triangles = 0;
189
+ this._stats.stateChanges = 0;
190
+ this._stats.uniformUpdates = 0;
191
+ }
192
+
193
+ /**
194
+ * Seal the buffer (mark as complete, no more recording)
195
+ */
196
+ seal() {
197
+ this._sealed = true;
198
+ }
199
+
200
+ /**
201
+ * Record a command
202
+ * @private
203
+ */
204
+ _record(type, data) {
205
+ if (this._sealed) {
206
+ throw new Error('Cannot record to sealed command buffer');
207
+ }
208
+ this._commands.push(new RenderCommand(type, data));
209
+ this._stats.commands++;
210
+ this._version++;
211
+ }
212
+
213
+ // ========== Recording API ==========
214
+
215
+ /**
216
+ * Record clear command
217
+ * @param {object} options
218
+ * @param {number[]} [options.color] - RGBA clear color [0-1]
219
+ * @param {number} [options.depth] - Depth clear value
220
+ * @param {number} [options.stencil] - Stencil clear value
221
+ * @param {boolean} [options.clearColor] - Clear color buffer
222
+ * @param {boolean} [options.clearDepth] - Clear depth buffer
223
+ * @param {boolean} [options.clearStencil] - Clear stencil buffer
224
+ */
225
+ clear(options = {}) {
226
+ this._record(CommandType.CLEAR, {
227
+ color: options.color || [0, 0, 0, 1],
228
+ depth: options.depth ?? 1.0,
229
+ stencil: options.stencil ?? 0,
230
+ clearColor: options.clearColor !== false,
231
+ clearDepth: options.clearDepth !== false,
232
+ clearStencil: options.clearStencil || false
233
+ });
234
+ }
235
+
236
+ /**
237
+ * Record viewport command
238
+ * @param {number} x
239
+ * @param {number} y
240
+ * @param {number} width
241
+ * @param {number} height
242
+ */
243
+ setViewport(x, y, width, height) {
244
+ this._record(CommandType.SET_VIEWPORT, { x, y, width, height });
245
+ this._stats.stateChanges++;
246
+ }
247
+
248
+ /**
249
+ * Record scissor command
250
+ * @param {number} x
251
+ * @param {number} y
252
+ * @param {number} width
253
+ * @param {number} height
254
+ */
255
+ setScissor(x, y, width, height) {
256
+ this._record(CommandType.SET_SCISSOR, { x, y, width, height });
257
+ this._stats.stateChanges++;
258
+ }
259
+
260
+ /**
261
+ * Record pipeline bind command
262
+ * @param {string} pipelineId - Pipeline identifier
263
+ */
264
+ setPipeline(pipelineId) {
265
+ this._record(CommandType.SET_PIPELINE, { pipelineId });
266
+ this._stats.stateChanges++;
267
+ }
268
+
269
+ /**
270
+ * Record uniform update command
271
+ * @param {object} uniforms - Uniform name/value pairs
272
+ */
273
+ setUniforms(uniforms) {
274
+ this._record(CommandType.SET_UNIFORMS, { values: { ...uniforms } });
275
+ this._stats.uniformUpdates++;
276
+ }
277
+
278
+ /**
279
+ * Record 4D rotor uniform
280
+ * @param {number[]} rotor - 8-component rotor [s, xy, xz, yz, xw, yw, zw, xyzw]
281
+ */
282
+ setRotor(rotor) {
283
+ this._record(CommandType.SET_ROTOR, { rotor: Array.from(rotor) });
284
+ this._stats.uniformUpdates++;
285
+ }
286
+
287
+ /**
288
+ * Record projection parameters
289
+ * @param {object} projection
290
+ * @param {string} projection.type - 'perspective' or 'stereographic'
291
+ * @param {number} projection.dimension - 4D projection distance
292
+ * @param {number} [projection.fov] - Field of view
293
+ * @param {number} [projection.near] - Near plane
294
+ * @param {number} [projection.far] - Far plane
295
+ */
296
+ setProjection(projection) {
297
+ this._record(CommandType.SET_PROJECTION, { ...projection });
298
+ this._stats.uniformUpdates++;
299
+ }
300
+
301
+ /**
302
+ * Record vertex buffer bind command
303
+ * @param {number} slot - Vertex buffer slot
304
+ * @param {number|string} bufferId - Buffer identifier
305
+ * @param {number} [offset] - Byte offset
306
+ */
307
+ bindVertexBuffer(slot, bufferId, offset = 0) {
308
+ this._record(CommandType.BIND_VERTEX_BUFFER, { slot, bufferId, offset });
309
+ this._stats.stateChanges++;
310
+ }
311
+
312
+ /**
313
+ * Record index buffer bind command
314
+ * @param {number|string} bufferId - Buffer identifier
315
+ * @param {string} format - 'uint16' or 'uint32'
316
+ * @param {number} [offset] - Byte offset
317
+ */
318
+ bindIndexBuffer(bufferId, format = 'uint16', offset = 0) {
319
+ this._record(CommandType.BIND_INDEX_BUFFER, { bufferId, format, offset });
320
+ this._stats.stateChanges++;
321
+ }
322
+
323
+ /**
324
+ * Record texture bind command
325
+ * @param {number} slot - Texture slot
326
+ * @param {number|string} textureId - Texture identifier
327
+ * @param {number|string} [samplerId] - Sampler identifier
328
+ */
329
+ bindTexture(slot, textureId, samplerId = null) {
330
+ this._record(CommandType.BIND_TEXTURE, { slot, textureId, samplerId });
331
+ this._stats.stateChanges++;
332
+ }
333
+
334
+ /**
335
+ * Record blend mode command
336
+ * @param {number} mode - BlendMode value
337
+ */
338
+ setBlendMode(mode) {
339
+ this._record(CommandType.SET_BLEND_MODE, { mode });
340
+ this._stats.stateChanges++;
341
+ }
342
+
343
+ /**
344
+ * Record depth state command
345
+ * @param {object} options
346
+ * @param {boolean} options.enabled - Enable depth test
347
+ * @param {boolean} options.write - Enable depth write
348
+ * @param {number} options.func - DepthFunc value
349
+ */
350
+ setDepthState(options) {
351
+ this._record(CommandType.SET_DEPTH_STATE, {
352
+ enabled: options.enabled !== false,
353
+ write: options.write !== false,
354
+ func: options.func ?? DepthFunc.LESS
355
+ });
356
+ this._stats.stateChanges++;
357
+ }
358
+
359
+ /**
360
+ * Record draw command
361
+ * @param {number} vertexCount - Number of vertices
362
+ * @param {number} [firstVertex] - First vertex index
363
+ * @param {number} [topology] - Topology value (default: TRIANGLE_LIST)
364
+ */
365
+ draw(vertexCount, firstVertex = 0, topology = Topology.TRIANGLE_LIST) {
366
+ this._record(CommandType.DRAW, { vertexCount, firstVertex, topology });
367
+ this._stats.drawCalls++;
368
+ if (topology === Topology.TRIANGLE_LIST) {
369
+ this._stats.triangles += vertexCount / 3;
370
+ }
371
+ }
372
+
373
+ /**
374
+ * Record indexed draw command
375
+ * @param {number} indexCount - Number of indices
376
+ * @param {number} [firstIndex] - First index
377
+ * @param {number} [baseVertex] - Base vertex offset
378
+ * @param {number} [topology] - Topology value
379
+ */
380
+ drawIndexed(indexCount, firstIndex = 0, baseVertex = 0, topology = Topology.TRIANGLE_LIST) {
381
+ this._record(CommandType.DRAW_INDEXED, {
382
+ indexCount, firstIndex, baseVertex, topology
383
+ });
384
+ this._stats.drawCalls++;
385
+ if (topology === Topology.TRIANGLE_LIST) {
386
+ this._stats.triangles += indexCount / 3;
387
+ }
388
+ }
389
+
390
+ /**
391
+ * Record instanced draw command
392
+ * @param {number} vertexCount - Vertices per instance
393
+ * @param {number} instanceCount - Number of instances
394
+ * @param {number} [firstVertex] - First vertex
395
+ * @param {number} [firstInstance] - First instance
396
+ * @param {number} [topology] - Topology value
397
+ */
398
+ drawInstanced(vertexCount, instanceCount, firstVertex = 0, firstInstance = 0, topology = Topology.TRIANGLE_LIST) {
399
+ this._record(CommandType.DRAW_INSTANCED, {
400
+ vertexCount, instanceCount, firstVertex, firstInstance, topology
401
+ });
402
+ this._stats.drawCalls++;
403
+ if (topology === Topology.TRIANGLE_LIST) {
404
+ this._stats.triangles += (vertexCount / 3) * instanceCount;
405
+ }
406
+ }
407
+
408
+ /**
409
+ * Push render state to stack
410
+ */
411
+ pushState() {
412
+ this._record(CommandType.PUSH_STATE, {});
413
+ }
414
+
415
+ /**
416
+ * Pop render state from stack
417
+ */
418
+ popState() {
419
+ this._record(CommandType.POP_STATE, {});
420
+ }
421
+
422
+ // ========== Utility API ==========
423
+
424
+ /**
425
+ * Get recorded commands
426
+ * @returns {RenderCommand[]}
427
+ */
428
+ getCommands() {
429
+ return this._commands.slice();
430
+ }
431
+
432
+ /**
433
+ * Get command at index
434
+ * @param {number} index
435
+ * @returns {RenderCommand|undefined}
436
+ */
437
+ getCommand(index) {
438
+ return this._commands[index];
439
+ }
440
+
441
+ /**
442
+ * Iterate over commands
443
+ * @param {function(RenderCommand, number): void} callback
444
+ */
445
+ forEach(callback) {
446
+ this._commands.forEach(callback);
447
+ }
448
+
449
+ /**
450
+ * Get statistics
451
+ * @returns {object}
452
+ */
453
+ getStats() {
454
+ return { ...this._stats };
455
+ }
456
+
457
+ // ========== Serialization API ==========
458
+
459
+ /**
460
+ * Serialize to JSON-compatible object
461
+ * @returns {object}
462
+ */
463
+ toJSON() {
464
+ return {
465
+ version: this._version,
466
+ sealed: this._sealed,
467
+ commands: this._commands.map(cmd => cmd.toJSON()),
468
+ stats: this._stats
469
+ };
470
+ }
471
+
472
+ /**
473
+ * Serialize to JSON string
474
+ * @returns {string}
475
+ */
476
+ serialize() {
477
+ return JSON.stringify(this.toJSON());
478
+ }
479
+
480
+ /**
481
+ * Serialize to binary format (for FFI efficiency)
482
+ * @returns {ArrayBuffer}
483
+ */
484
+ toBinary() {
485
+ const json = this.serialize();
486
+ const encoder = new TextEncoder();
487
+ const data = encoder.encode(json);
488
+
489
+ // Header: magic (4) + version (4) + length (4) = 12 bytes
490
+ const buffer = new ArrayBuffer(12 + data.length);
491
+ const view = new DataView(buffer);
492
+
493
+ // Magic: 'VCB1' (VIB3 Command Buffer v1)
494
+ view.setUint32(0, 0x56434231, false);
495
+ view.setUint32(4, this._version, false);
496
+ view.setUint32(8, data.length, false);
497
+
498
+ // Command data
499
+ new Uint8Array(buffer, 12).set(data);
500
+
501
+ return buffer;
502
+ }
503
+
504
+ /**
505
+ * Create from JSON object
506
+ * @param {object} obj
507
+ * @returns {RenderCommandBuffer}
508
+ */
509
+ static fromJSON(obj) {
510
+ const buffer = new RenderCommandBuffer();
511
+ buffer._version = obj.version || 1;
512
+ buffer._sealed = obj.sealed || false;
513
+ buffer._commands = (obj.commands || []).map(c => RenderCommand.fromJSON(c));
514
+ buffer._stats = obj.stats || buffer._stats;
515
+ return buffer;
516
+ }
517
+
518
+ /**
519
+ * Deserialize from JSON string
520
+ * @param {string} json
521
+ * @returns {RenderCommandBuffer}
522
+ */
523
+ static deserialize(json) {
524
+ return RenderCommandBuffer.fromJSON(JSON.parse(json));
525
+ }
526
+
527
+ /**
528
+ * Deserialize from binary format
529
+ * @param {ArrayBuffer} buffer
530
+ * @returns {RenderCommandBuffer}
531
+ */
532
+ static fromBinary(buffer) {
533
+ const view = new DataView(buffer);
534
+
535
+ // Verify magic
536
+ const magic = view.getUint32(0, false);
537
+ if (magic !== 0x56434231) {
538
+ throw new Error('Invalid command buffer magic');
539
+ }
540
+
541
+ // Read header
542
+ const length = view.getUint32(8, false);
543
+
544
+ // Decode JSON
545
+ const data = new Uint8Array(buffer, 12, length);
546
+ const decoder = new TextDecoder();
547
+ const json = decoder.decode(data);
548
+
549
+ return RenderCommandBuffer.deserialize(json);
550
+ }
551
+
552
+ // ========== Builder Pattern API ==========
553
+
554
+ /**
555
+ * Create a new command buffer with builder pattern
556
+ * @returns {RenderCommandBufferBuilder}
557
+ */
558
+ static builder() {
559
+ return new RenderCommandBufferBuilder();
560
+ }
561
+ }
562
+
563
+ /**
564
+ * Builder for fluent command buffer construction
565
+ */
566
+ class RenderCommandBufferBuilder {
567
+ constructor() {
568
+ this._buffer = new RenderCommandBuffer();
569
+ }
570
+
571
+ clear(options) {
572
+ this._buffer.clear(options);
573
+ return this;
574
+ }
575
+
576
+ viewport(x, y, w, h) {
577
+ this._buffer.setViewport(x, y, w, h);
578
+ return this;
579
+ }
580
+
581
+ pipeline(id) {
582
+ this._buffer.setPipeline(id);
583
+ return this;
584
+ }
585
+
586
+ uniforms(u) {
587
+ this._buffer.setUniforms(u);
588
+ return this;
589
+ }
590
+
591
+ rotor(r) {
592
+ this._buffer.setRotor(r);
593
+ return this;
594
+ }
595
+
596
+ projection(p) {
597
+ this._buffer.setProjection(p);
598
+ return this;
599
+ }
600
+
601
+ vertexBuffer(slot, id, offset) {
602
+ this._buffer.bindVertexBuffer(slot, id, offset);
603
+ return this;
604
+ }
605
+
606
+ indexBuffer(id, format, offset) {
607
+ this._buffer.bindIndexBuffer(id, format, offset);
608
+ return this;
609
+ }
610
+
611
+ texture(slot, id, sampler) {
612
+ this._buffer.bindTexture(slot, id, sampler);
613
+ return this;
614
+ }
615
+
616
+ blend(mode) {
617
+ this._buffer.setBlendMode(mode);
618
+ return this;
619
+ }
620
+
621
+ depth(opts) {
622
+ this._buffer.setDepthState(opts);
623
+ return this;
624
+ }
625
+
626
+ draw(count, first, topo) {
627
+ this._buffer.draw(count, first, topo);
628
+ return this;
629
+ }
630
+
631
+ drawIndexed(count, first, base, topo) {
632
+ this._buffer.drawIndexed(count, first, base, topo);
633
+ return this;
634
+ }
635
+
636
+ drawInstanced(verts, instances, firstV, firstI, topo) {
637
+ this._buffer.drawInstanced(verts, instances, firstV, firstI, topo);
638
+ return this;
639
+ }
640
+
641
+ push() {
642
+ this._buffer.pushState();
643
+ return this;
644
+ }
645
+
646
+ pop() {
647
+ this._buffer.popState();
648
+ return this;
649
+ }
650
+
651
+ seal() {
652
+ this._buffer.seal();
653
+ return this;
654
+ }
655
+
656
+ build() {
657
+ return this._buffer;
658
+ }
659
+ }
660
+
661
+ export default RenderCommandBuffer;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Render Commands Module
3
+ *
4
+ * Cross-platform render command buffer system for VIB3+ engine.
5
+ * Enables serializable render commands that can execute on WebGL, WebGPU,
6
+ * WASM, and Flutter platforms.
7
+ */
8
+
9
+ export {
10
+ RenderCommandBuffer,
11
+ CommandType,
12
+ BlendMode,
13
+ DepthFunc,
14
+ Topology
15
+ } from './RenderCommandBuffer.js';
16
+
17
+ export { CommandBufferExecutor } from './CommandBufferExecutor.js';