@holoscript/core 1.0.0-alpha.2 → 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 (74) hide show
  1. package/package.json +2 -2
  2. package/src/HoloScript2DParser.js +227 -0
  3. package/src/HoloScript2DParser.ts +5 -0
  4. package/src/HoloScriptCodeParser.js +1102 -0
  5. package/src/HoloScriptCodeParser.ts +145 -20
  6. package/src/HoloScriptDebugger.js +458 -0
  7. package/src/HoloScriptParser.js +338 -0
  8. package/src/HoloScriptPlusParser.js +371 -0
  9. package/src/HoloScriptPlusParser.ts +543 -0
  10. package/src/HoloScriptRuntime.js +1399 -0
  11. package/src/HoloScriptRuntime.test.js +351 -0
  12. package/src/HoloScriptRuntime.ts +17 -3
  13. package/src/HoloScriptTypeChecker.js +356 -0
  14. package/src/__tests__/GraphicsServices.test.js +357 -0
  15. package/src/__tests__/GraphicsServices.test.ts +427 -0
  16. package/src/__tests__/HoloScriptPlusParser.test.js +317 -0
  17. package/src/__tests__/HoloScriptPlusParser.test.ts +392 -0
  18. package/src/__tests__/integration.test.js +336 -0
  19. package/src/__tests__/performance.bench.js +218 -0
  20. package/src/__tests__/type-checker.test.js +60 -0
  21. package/src/__tests__/type-checker.test.ts +73 -0
  22. package/src/index.js +217 -0
  23. package/src/index.ts +158 -18
  24. package/src/interop/Interoperability.js +413 -0
  25. package/src/interop/Interoperability.ts +494 -0
  26. package/src/logger.js +42 -0
  27. package/src/parser/EnhancedParser.js +205 -0
  28. package/src/parser/EnhancedParser.ts +251 -0
  29. package/src/parser/HoloScriptPlusParser.js +928 -0
  30. package/src/parser/HoloScriptPlusParser.ts +1089 -0
  31. package/src/runtime/HoloScriptPlusRuntime.js +674 -0
  32. package/src/runtime/HoloScriptPlusRuntime.ts +861 -0
  33. package/src/runtime/PerformanceTelemetry.js +323 -0
  34. package/src/runtime/PerformanceTelemetry.ts +467 -0
  35. package/src/runtime/RuntimeOptimization.js +361 -0
  36. package/src/runtime/RuntimeOptimization.ts +416 -0
  37. package/src/services/HololandGraphicsPipelineService.js +506 -0
  38. package/src/services/HololandGraphicsPipelineService.ts +662 -0
  39. package/src/services/PlatformPerformanceOptimizer.js +356 -0
  40. package/src/services/PlatformPerformanceOptimizer.ts +503 -0
  41. package/src/state/ReactiveState.js +427 -0
  42. package/src/state/ReactiveState.ts +572 -0
  43. package/src/tools/DeveloperExperience.js +376 -0
  44. package/src/tools/DeveloperExperience.ts +438 -0
  45. package/src/traits/AIDriverTrait.js +322 -0
  46. package/src/traits/AIDriverTrait.test.js +329 -0
  47. package/src/traits/AIDriverTrait.test.ts +357 -0
  48. package/src/traits/AIDriverTrait.ts +474 -0
  49. package/src/traits/LightingTrait.js +313 -0
  50. package/src/traits/LightingTrait.test.js +410 -0
  51. package/src/traits/LightingTrait.test.ts +462 -0
  52. package/src/traits/LightingTrait.ts +505 -0
  53. package/src/traits/MaterialTrait.js +194 -0
  54. package/src/traits/MaterialTrait.test.js +286 -0
  55. package/src/traits/MaterialTrait.test.ts +329 -0
  56. package/src/traits/MaterialTrait.ts +324 -0
  57. package/src/traits/RenderingTrait.js +356 -0
  58. package/src/traits/RenderingTrait.test.js +363 -0
  59. package/src/traits/RenderingTrait.test.ts +427 -0
  60. package/src/traits/RenderingTrait.ts +555 -0
  61. package/src/traits/VRTraitSystem.js +740 -0
  62. package/src/traits/VRTraitSystem.ts +1040 -0
  63. package/src/traits/VoiceInputTrait.js +284 -0
  64. package/src/traits/VoiceInputTrait.test.js +226 -0
  65. package/src/traits/VoiceInputTrait.test.ts +252 -0
  66. package/src/traits/VoiceInputTrait.ts +401 -0
  67. package/src/types/AdvancedTypeSystem.js +226 -0
  68. package/src/types/AdvancedTypeSystem.ts +494 -0
  69. package/src/types/HoloScriptPlus.d.ts +853 -0
  70. package/src/types.js +6 -0
  71. package/src/types.ts +96 -1
  72. package/tsconfig.json +1 -1
  73. package/tsup.config.d.ts +2 -0
  74. package/tsup.config.js +18 -0
@@ -0,0 +1,555 @@
1
+ /**
2
+ * @holoscript/core Rendering Trait
3
+ *
4
+ * Enables GPU optimization directives, level of detail management,
5
+ * and rendering performance tuning
6
+ */
7
+
8
+ export type CullingMode = 'none' | 'back' | 'front' | 'both';
9
+ export type LodStrategy = 'automatic' | 'manual' | 'disabled';
10
+ export type GPUResourceTier = 'low' | 'medium' | 'high' | 'ultra';
11
+
12
+ /**
13
+ * Level of Detail configuration
14
+ */
15
+ export interface LODLevel {
16
+ /** LOD level (0 = highest detail) */
17
+ level: number;
18
+
19
+ /** Screen-relative size threshold for this LOD */
20
+ screenRelativeSize: number;
21
+
22
+ /** Polygon reduction ratio (0-1) */
23
+ polygonReduction?: number;
24
+
25
+ /** Disable features at this LOD */
26
+ disabledFeatures?: ('shadows' | 'normals' | 'specular' | 'animation')[];
27
+
28
+ /** Texture resolution multiplier (0.25 = 1/4 resolution) */
29
+ textureScale?: number;
30
+ }
31
+
32
+ /**
33
+ * Culling configuration
34
+ */
35
+ export interface CullingConfig {
36
+ /** Face culling mode */
37
+ mode: CullingMode;
38
+
39
+ /** Frustum culling */
40
+ frustum?: boolean;
41
+
42
+ /** Occlusion culling */
43
+ occlusion?: boolean;
44
+
45
+ /** Occlusion query distance in units */
46
+ occlusionDistance?: number;
47
+
48
+ /** Hierarchical Z-buffer culling */
49
+ hierarchicalZ?: boolean;
50
+ }
51
+
52
+ /**
53
+ * Batching configuration
54
+ */
55
+ export interface BatchingConfig {
56
+ /** Static batching (for non-moving objects) */
57
+ static?: boolean;
58
+
59
+ /** Dynamic batching */
60
+ dynamic?: boolean;
61
+
62
+ /** Max batch size in vertices */
63
+ maxBatchSize?: number;
64
+
65
+ /** GPU instancing */
66
+ instancing?: boolean;
67
+
68
+ /** Instancing buffer size */
69
+ maxInstanceCount?: number;
70
+ }
71
+
72
+ /**
73
+ * Texture optimization
74
+ */
75
+ export interface TextureOptimization {
76
+ /** Enable texture streaming */
77
+ streaming?: boolean;
78
+
79
+ /** Streaming budget in MB */
80
+ streamingBudget?: number;
81
+
82
+ /** Virtual texture paging */
83
+ virtualTexturing?: boolean;
84
+
85
+ /** Texture compression */
86
+ compression?: 'none' | 'dxt' | 'astc' | 'basis' | 'auto';
87
+
88
+ /** Mipmap generation */
89
+ mipmaps?: boolean;
90
+
91
+ /** Max texture resolution */
92
+ maxResolution?: 256 | 512 | 1024 | 2048 | 4096;
93
+ }
94
+
95
+ /**
96
+ * Shader optimization
97
+ */
98
+ export interface ShaderOptimization {
99
+ /** Shader LOD bias */
100
+ lodBias?: number;
101
+
102
+ /** Use simplified shaders for distant objects */
103
+ simplifiedShaders?: boolean;
104
+
105
+ /** Compile shader variants for performance */
106
+ variants?: {
107
+ [key: string]: {
108
+ enabled: boolean;
109
+ cost?: 'low' | 'medium' | 'high';
110
+ };
111
+ };
112
+ }
113
+
114
+ /**
115
+ * Rendering optimization hints
116
+ */
117
+ export interface RenderingOptimization {
118
+ /** LOD strategy */
119
+ lodStrategy?: LodStrategy;
120
+
121
+ /** LOD levels */
122
+ lodLevels?: LODLevel[];
123
+
124
+ /** Culling configuration */
125
+ culling?: CullingConfig;
126
+
127
+ /** Batching configuration */
128
+ batching?: BatchingConfig;
129
+
130
+ /** Texture optimization */
131
+ textures?: TextureOptimization;
132
+
133
+ /** Shader optimization */
134
+ shaders?: ShaderOptimization;
135
+
136
+ /** Target GPU tier */
137
+ targetGPUTier?: GPUResourceTier;
138
+
139
+ /** Fixed time-step rendering (for VR/AR) */
140
+ fixedTimestep?: number;
141
+
142
+ /** Enable adaptive quality */
143
+ adaptiveQuality?: boolean;
144
+
145
+ /** Target frame rate */
146
+ targetFrameRate?: number;
147
+ }
148
+
149
+ /**
150
+ * RenderingTrait - Manages GPU optimization and rendering performance
151
+ */
152
+ export class RenderingTrait {
153
+ private optimization: RenderingOptimization;
154
+
155
+ constructor(config?: RenderingOptimization) {
156
+ this.optimization = {
157
+ lodStrategy: 'automatic',
158
+ culling: {
159
+ mode: 'back',
160
+ frustum: true,
161
+ occlusion: true,
162
+ },
163
+ batching: {
164
+ static: true,
165
+ dynamic: true,
166
+ instancing: true,
167
+ maxInstanceCount: 1000,
168
+ },
169
+ textures: {
170
+ streaming: true,
171
+ compression: 'auto',
172
+ mipmaps: true,
173
+ maxResolution: 2048,
174
+ },
175
+ shaders: {
176
+ simplifiedShaders: true,
177
+ lodBias: 0,
178
+ },
179
+ targetGPUTier: 'high',
180
+ adaptiveQuality: true,
181
+ targetFrameRate: 60,
182
+ ...config,
183
+ };
184
+ }
185
+
186
+ /**
187
+ * Get rendering optimization config
188
+ */
189
+ public getOptimization(): RenderingOptimization {
190
+ return JSON.parse(JSON.stringify(this.optimization));
191
+ }
192
+
193
+ /**
194
+ * Update rendering configuration
195
+ */
196
+ public updateOptimization(updates: Partial<RenderingOptimization>): void {
197
+ this.optimization = { ...this.optimization, ...updates };
198
+ }
199
+
200
+ /**
201
+ * Setup LOD levels (3 levels is typical)
202
+ */
203
+ public setupLODLevels(strategy: LodStrategy = 'automatic'): void {
204
+ const levels: LODLevel[] = [
205
+ {
206
+ level: 0,
207
+ screenRelativeSize: 0.5,
208
+ polygonReduction: 1.0,
209
+ textureScale: 1.0,
210
+ },
211
+ {
212
+ level: 1,
213
+ screenRelativeSize: 0.25,
214
+ polygonReduction: 0.6,
215
+ disabledFeatures: ['specular'],
216
+ textureScale: 0.5,
217
+ },
218
+ {
219
+ level: 2,
220
+ screenRelativeSize: 0.1,
221
+ polygonReduction: 0.3,
222
+ disabledFeatures: ['specular', 'normals'],
223
+ textureScale: 0.25,
224
+ },
225
+ ];
226
+
227
+ this.optimization.lodStrategy = strategy;
228
+ this.optimization.lodLevels = levels;
229
+ }
230
+
231
+ /**
232
+ * Get LOD levels
233
+ */
234
+ public getLODLevels(): LODLevel[] {
235
+ return [...(this.optimization.lodLevels || [])];
236
+ }
237
+
238
+ /**
239
+ * Configure culling
240
+ */
241
+ public setCulling(config: Partial<CullingConfig>): void {
242
+ const defaultCulling: CullingConfig = { mode: 'back' };
243
+ this.optimization.culling = {
244
+ ...defaultCulling,
245
+ ...this.optimization.culling,
246
+ ...config,
247
+ };
248
+ }
249
+
250
+ /**
251
+ * Enable frustum culling
252
+ */
253
+ public setFrustumCulling(enabled: boolean): void {
254
+ if (!this.optimization.culling) {
255
+ this.optimization.culling = { mode: 'back' };
256
+ }
257
+ this.optimization.culling.frustum = enabled;
258
+ }
259
+
260
+ /**
261
+ * Enable occlusion culling
262
+ */
263
+ public setOcclusionCulling(
264
+ enabled: boolean,
265
+ distance?: number
266
+ ): void {
267
+ if (!this.optimization.culling) {
268
+ this.optimization.culling = { mode: 'back' };
269
+ }
270
+ this.optimization.culling.occlusion = enabled;
271
+ if (distance) {
272
+ this.optimization.culling.occlusionDistance = distance;
273
+ }
274
+ }
275
+
276
+ /**
277
+ * Configure batching
278
+ */
279
+ public setBatching(config: Partial<BatchingConfig>): void {
280
+ this.optimization.batching = {
281
+ ...this.optimization.batching,
282
+ ...config,
283
+ };
284
+ }
285
+
286
+ /**
287
+ * Enable GPU instancing
288
+ */
289
+ public setInstancing(enabled: boolean, maxInstances?: number): void {
290
+ if (!this.optimization.batching) {
291
+ this.optimization.batching = {};
292
+ }
293
+ this.optimization.batching.instancing = enabled;
294
+ if (maxInstances) {
295
+ this.optimization.batching.maxInstanceCount = maxInstances;
296
+ }
297
+ }
298
+
299
+ /**
300
+ * Configure texture optimization
301
+ */
302
+ public setTextureOptimization(config: Partial<TextureOptimization>): void {
303
+ this.optimization.textures = {
304
+ ...this.optimization.textures,
305
+ ...config,
306
+ };
307
+ }
308
+
309
+ /**
310
+ * Enable texture streaming
311
+ */
312
+ public setTextureStreaming(
313
+ enabled: boolean,
314
+ budgetMB?: number
315
+ ): void {
316
+ if (!this.optimization.textures) {
317
+ this.optimization.textures = {};
318
+ }
319
+ this.optimization.textures.streaming = enabled;
320
+ if (budgetMB) {
321
+ this.optimization.textures.streamingBudget = budgetMB;
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Set texture compression
327
+ */
328
+ public setTextureCompression(
329
+ compression: 'none' | 'dxt' | 'astc' | 'basis' | 'auto'
330
+ ): void {
331
+ if (!this.optimization.textures) {
332
+ this.optimization.textures = {};
333
+ }
334
+ this.optimization.textures.compression = compression;
335
+ }
336
+
337
+ /**
338
+ * Set max texture resolution
339
+ */
340
+ public setMaxTextureResolution(
341
+ resolution: 256 | 512 | 1024 | 2048 | 4096
342
+ ): void {
343
+ if (!this.optimization.textures) {
344
+ this.optimization.textures = {};
345
+ }
346
+ this.optimization.textures.maxResolution = resolution;
347
+ }
348
+
349
+ /**
350
+ * Configure shader optimization
351
+ */
352
+ public setShaderOptimization(config: Partial<ShaderOptimization>): void {
353
+ this.optimization.shaders = {
354
+ ...this.optimization.shaders,
355
+ ...config,
356
+ };
357
+ }
358
+
359
+ /**
360
+ * Set target GPU tier
361
+ */
362
+ public setTargetGPUTier(tier: GPUResourceTier): void {
363
+ this.optimization.targetGPUTier = tier;
364
+ }
365
+
366
+ /**
367
+ * Enable adaptive quality (adjust based on frame rate)
368
+ */
369
+ public setAdaptiveQuality(
370
+ enabled: boolean,
371
+ targetFrameRate?: number
372
+ ): void {
373
+ this.optimization.adaptiveQuality = enabled;
374
+ if (targetFrameRate) {
375
+ this.optimization.targetFrameRate = targetFrameRate;
376
+ }
377
+ }
378
+
379
+ /**
380
+ * Set fixed timestep for VR/AR
381
+ */
382
+ public setFixedTimestep(timestep: number): void {
383
+ this.optimization.fixedTimestep = timestep;
384
+ }
385
+
386
+ /**
387
+ * Get rendering preset for quality level
388
+ */
389
+ public getPresetForQuality(
390
+ quality: 'low' | 'medium' | 'high' | 'ultra'
391
+ ): RenderingOptimization {
392
+ const presets: Record<string, Partial<RenderingOptimization>> = {
393
+ low: {
394
+ targetGPUTier: 'low',
395
+ lodStrategy: 'automatic',
396
+ culling: { mode: 'back', frustum: true, occlusion: false },
397
+ batching: { instancing: true, maxInstanceCount: 500 },
398
+ textures: {
399
+ compression: 'astc',
400
+ maxResolution: 512,
401
+ streaming: true,
402
+ streamingBudget: 128,
403
+ },
404
+ adaptiveQuality: true,
405
+ targetFrameRate: 30,
406
+ },
407
+ medium: {
408
+ targetGPUTier: 'medium',
409
+ lodStrategy: 'automatic',
410
+ culling: { mode: 'back', frustum: true, occlusion: true },
411
+ batching: { instancing: true, maxInstanceCount: 1000 },
412
+ textures: {
413
+ compression: 'basis',
414
+ maxResolution: 1024,
415
+ streaming: true,
416
+ streamingBudget: 256,
417
+ },
418
+ adaptiveQuality: true,
419
+ targetFrameRate: 60,
420
+ },
421
+ high: {
422
+ targetGPUTier: 'high',
423
+ lodStrategy: 'automatic',
424
+ culling: { mode: 'back', frustum: true, occlusion: true },
425
+ batching: { instancing: true, maxInstanceCount: 2000 },
426
+ textures: {
427
+ compression: 'dxt',
428
+ maxResolution: 2048,
429
+ streaming: true,
430
+ streamingBudget: 512,
431
+ },
432
+ adaptiveQuality: false,
433
+ targetFrameRate: 60,
434
+ },
435
+ ultra: {
436
+ targetGPUTier: 'ultra',
437
+ lodStrategy: 'manual',
438
+ culling: {
439
+ mode: 'back',
440
+ frustum: true,
441
+ occlusion: true,
442
+ hierarchicalZ: true,
443
+ },
444
+ batching: { instancing: true, maxInstanceCount: 5000 },
445
+ textures: {
446
+ compression: 'none',
447
+ maxResolution: 4096,
448
+ virtualTexturing: true,
449
+ streaming: true,
450
+ streamingBudget: 1024,
451
+ },
452
+ adaptiveQuality: false,
453
+ targetFrameRate: 120,
454
+ },
455
+ };
456
+
457
+ return { ...this.optimization, ...presets[quality] };
458
+ }
459
+
460
+ /**
461
+ * Apply quality preset
462
+ */
463
+ public applyQualityPreset(quality: 'low' | 'medium' | 'high' | 'ultra'): void {
464
+ const preset = this.getPresetForQuality(quality);
465
+ this.optimization = preset as RenderingOptimization;
466
+ }
467
+
468
+ /**
469
+ * Estimate GPU memory usage
470
+ */
471
+ public estimateGPUMemory(): {
472
+ textureMemory: number;
473
+ vertexBuffers: number;
474
+ estimatedTotal: number;
475
+ } {
476
+ let textureMemory = 0;
477
+ let vertexBuffers = 0;
478
+
479
+ // Estimate texture memory based on max resolution
480
+ // Assuming RGBA format at 4 bytes per pixel
481
+ const maxRes = this.optimization.textures?.maxResolution || 2048;
482
+ textureMemory = (maxRes * maxRes * 4) / (1024 * 1024); // MB
483
+
484
+ // Estimate based on instancing
485
+ // Typical mesh: 10K vertices, position (12) + normal (12) + UV (8) + color (4) = 36 bytes
486
+ const instanceCount = this.optimization.batching?.maxInstanceCount || 1000;
487
+ const verticesPerMesh = 10000;
488
+ vertexBuffers = ((verticesPerMesh * 36 * instanceCount) / (1024 * 1024)) * 0.1; // 10% for practical estimate
489
+
490
+ return {
491
+ textureMemory: Math.round(textureMemory),
492
+ vertexBuffers: Math.max(1, Math.round(vertexBuffers)), // At least 1MB
493
+ estimatedTotal: Math.round(textureMemory + Math.max(1, vertexBuffers)),
494
+ };
495
+ }
496
+
497
+ /**
498
+ * Get rendering statistics/info
499
+ */
500
+ public getInfo(): string {
501
+ const tier = this.optimization.targetGPUTier;
502
+ const lod = this.optimization.lodStrategy;
503
+ const culling = this.optimization.culling?.mode;
504
+ const instancing = this.optimization.batching?.instancing ? 'yes' : 'no';
505
+ const memory = this.estimateGPUMemory();
506
+
507
+ return `Rendering: tier=${tier} | LOD=${lod} | culling=${culling} | instancing=${instancing} | ` +
508
+ `memory=${memory.estimatedTotal}MB`;
509
+ }
510
+
511
+ /**
512
+ * Optimize for VR/AR (fixed timestep, fast culling)
513
+ */
514
+ public optimizeForVRAR(targetFPS: number = 90): void {
515
+ this.optimization.fixedTimestep = 1 / targetFPS;
516
+ this.optimization.targetFrameRate = targetFPS;
517
+ this.setOcclusionCulling(true, 50);
518
+ this.setInstancing(true, 5000);
519
+ this.setAdaptiveQuality(true, targetFPS);
520
+ }
521
+
522
+ /**
523
+ * Optimize for mobile (lower resources)
524
+ */
525
+ public optimizeForMobile(): void {
526
+ this.applyQualityPreset('low');
527
+ this.setTextureCompression('astc');
528
+ this.setInstancing(true, 256);
529
+ }
530
+
531
+ /**
532
+ * Optimize for desktop (higher resources)
533
+ */
534
+ public optimizeForDesktop(): void {
535
+ this.applyQualityPreset('ultra');
536
+ this.setTextureCompression('none');
537
+ this.setInstancing(true, 5000);
538
+ }
539
+
540
+ /**
541
+ * Dispose and cleanup
542
+ */
543
+ public dispose(): void {
544
+ // Cleanup if needed
545
+ }
546
+ }
547
+
548
+ /**
549
+ * HoloScript+ @rendering trait factory
550
+ */
551
+ export function createRenderingTrait(
552
+ config?: RenderingOptimization
553
+ ): RenderingTrait {
554
+ return new RenderingTrait(config);
555
+ }