@holoscript/core 1.0.0-alpha.2 → 2.0.0

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,324 @@
1
+ /**
2
+ * @holoscript/core Material Trait
3
+ *
4
+ * Enables advanced material and shader properties for photorealistic rendering
5
+ * Supports PBR (Physically Based Rendering) workflows
6
+ */
7
+
8
+ export type MaterialType = 'pbr' | 'standard' | 'unlit' | 'transparent' | 'custom';
9
+ export type TextureChannel = 'baseColor' | 'normalMap' | 'roughnessMap' | 'metallicMap' | 'ambientOcclusionMap' | 'emissionMap' | 'heightMap';
10
+
11
+ /**
12
+ * Texture map configuration
13
+ */
14
+ export interface TextureMap {
15
+ /** Texture path or URL */
16
+ path: string;
17
+
18
+ /** Channel this texture maps to */
19
+ channel: TextureChannel;
20
+
21
+ /** UV scale (tiling) */
22
+ scale?: { x: number; y: number };
23
+
24
+ /** UV offset */
25
+ offset?: { x: number; y: number };
26
+
27
+ /** Texture filtering: linear, nearest, anisotropic */
28
+ filter?: 'linear' | 'nearest' | 'anisotropic';
29
+
30
+ /** Anisotropic level (1-16) */
31
+ anisotropy?: number;
32
+ }
33
+
34
+ /**
35
+ * PBR Material properties
36
+ */
37
+ export interface PBRMaterial {
38
+ /** Base color in linear space [0-1] */
39
+ baseColor: { r: number; g: number; b: number; a?: number };
40
+
41
+ /** Metallic value 0-1 */
42
+ metallic: number;
43
+
44
+ /** Roughness value 0-1 */
45
+ roughness: number;
46
+
47
+ /** Ambient occlusion 0-1 */
48
+ ambientOcclusion?: number;
49
+
50
+ /** Emission color and intensity */
51
+ emission?: {
52
+ color: { r: number; g: number; b: number };
53
+ intensity: number;
54
+ };
55
+
56
+ /** Normal map strength */
57
+ normalStrength?: number;
58
+
59
+ /** Parallax/height map strength */
60
+ parallaxHeight?: number;
61
+
62
+ /** Index of refraction for transmission */
63
+ ior?: number;
64
+
65
+ /** Transmission amount for transparent materials */
66
+ transmission?: number;
67
+ }
68
+
69
+ /**
70
+ * Material configuration
71
+ */
72
+ export interface MaterialConfig {
73
+ /** Material type */
74
+ type: MaterialType;
75
+
76
+ /** Material name for reuse */
77
+ name?: string;
78
+
79
+ /** PBR properties (for PBR materials) */
80
+ pbr?: PBRMaterial;
81
+
82
+ /** Texture maps */
83
+ textures?: TextureMap[];
84
+
85
+ /** Double-sided rendering */
86
+ doubleSided?: boolean;
87
+
88
+ /** Blend mode for transparency */
89
+ blendMode?: 'opaque' | 'blend' | 'additive' | 'multiply';
90
+
91
+ /** Custom shader code/reference */
92
+ customShader?: {
93
+ vertex?: string;
94
+ fragment?: string;
95
+ shaderLanguage?: 'glsl' | 'hlsl' | 'shadergraph';
96
+ };
97
+
98
+ /** GPU memory optimization hints */
99
+ optimization?: {
100
+ /** Stream textures if needed */
101
+ streamTextures?: boolean;
102
+
103
+ /** Compress textures */
104
+ compression?: 'none' | 'dxt' | 'astc' | 'basis';
105
+
106
+ /** Instance this material */
107
+ instanced?: boolean;
108
+
109
+ /** LOD bias for texture streaming */
110
+ lodBias?: number;
111
+ };
112
+ }
113
+
114
+ /**
115
+ * MaterialTrait - Enables photorealistic material rendering
116
+ */
117
+ export class MaterialTrait {
118
+ private material: MaterialConfig;
119
+ private textureCache: Map<string, any> = new Map();
120
+
121
+ constructor(config: MaterialConfig) {
122
+ this.material = {
123
+ ...{ type: 'pbr' as const },
124
+ ...config,
125
+ };
126
+ }
127
+
128
+ /**
129
+ * Get material properties
130
+ */
131
+ public getMaterial(): MaterialConfig {
132
+ return { ...this.material };
133
+ }
134
+
135
+ /**
136
+ * Update material property
137
+ */
138
+ public setProperty<K extends keyof MaterialConfig>(key: K, value: MaterialConfig[K]): void {
139
+ this.material[key] = value;
140
+ }
141
+
142
+ /**
143
+ * Get PBR properties
144
+ */
145
+ public getPBRProperties(): PBRMaterial | undefined {
146
+ return this.material.pbr;
147
+ }
148
+
149
+ /**
150
+ * Update PBR material
151
+ */
152
+ public updatePBR(pbr: Partial<PBRMaterial>): void {
153
+ if (!this.material.pbr) {
154
+ this.material.pbr = {
155
+ baseColor: { r: 1, g: 1, b: 1 },
156
+ metallic: 0,
157
+ roughness: 0.5,
158
+ };
159
+ }
160
+ this.material.pbr = { ...this.material.pbr, ...pbr };
161
+ }
162
+
163
+ /**
164
+ * Add texture map
165
+ */
166
+ public addTexture(texture: TextureMap): void {
167
+ if (!this.material.textures) {
168
+ this.material.textures = [];
169
+ }
170
+ this.material.textures.push(texture);
171
+ }
172
+
173
+ /**
174
+ * Get all textures
175
+ */
176
+ public getTextures(): TextureMap[] {
177
+ return [...(this.material.textures || [])];
178
+ }
179
+
180
+ /**
181
+ * Clear texture cache (for memory optimization)
182
+ */
183
+ public clearTextureCache(): void {
184
+ this.textureCache.clear();
185
+ }
186
+
187
+ /**
188
+ * Get shader code if custom
189
+ */
190
+ public getCustomShader() {
191
+ return this.material.customShader;
192
+ }
193
+
194
+ /**
195
+ * Set custom shader
196
+ */
197
+ public setCustomShader(shader: MaterialConfig['customShader']): void {
198
+ this.material.customShader = shader;
199
+ }
200
+
201
+ /**
202
+ * Get optimization hints
203
+ */
204
+ public getOptimization(): MaterialConfig['optimization'] {
205
+ return this.material.optimization;
206
+ }
207
+
208
+ /**
209
+ * Enable/disable texture streaming
210
+ */
211
+ public setTextureStreaming(enabled: boolean): void {
212
+ if (!this.material.optimization) {
213
+ this.material.optimization = {};
214
+ }
215
+ this.material.optimization.streamTextures = enabled;
216
+ }
217
+
218
+ /**
219
+ * Set texture compression
220
+ */
221
+ public setCompression(compression: 'none' | 'dxt' | 'astc' | 'basis'): void {
222
+ if (!this.material.optimization) {
223
+ this.material.optimization = {};
224
+ }
225
+ this.material.optimization.compression = compression;
226
+ }
227
+
228
+ /**
229
+ * Enable material instancing for performance
230
+ */
231
+ public setInstanced(instanced: boolean): void {
232
+ if (!this.material.optimization) {
233
+ this.material.optimization = {};
234
+ }
235
+ this.material.optimization.instanced = instanced;
236
+ }
237
+
238
+ /**
239
+ * Dispose and cleanup
240
+ */
241
+ public dispose(): void {
242
+ this.textureCache.clear();
243
+ }
244
+ }
245
+
246
+ /**
247
+ * HoloScript+ @material trait factory
248
+ */
249
+ export function createMaterialTrait(config: MaterialConfig): MaterialTrait {
250
+ return new MaterialTrait(config);
251
+ }
252
+
253
+ /**
254
+ * Preset materials for common use cases
255
+ */
256
+ export const MATERIAL_PRESETS = {
257
+ /** Shiny metal */
258
+ chrome: (): MaterialConfig => ({
259
+ type: 'pbr',
260
+ pbr: {
261
+ baseColor: { r: 0.77, g: 0.77, b: 0.77 },
262
+ metallic: 1.0,
263
+ roughness: 0.1,
264
+ },
265
+ }),
266
+
267
+ /** Rough plastic */
268
+ plastic: (): MaterialConfig => ({
269
+ type: 'pbr',
270
+ pbr: {
271
+ baseColor: { r: 1, g: 1, b: 1 },
272
+ metallic: 0,
273
+ roughness: 0.8,
274
+ },
275
+ }),
276
+
277
+ /** Wood texture */
278
+ wood: (): MaterialConfig => ({
279
+ type: 'pbr',
280
+ pbr: {
281
+ baseColor: { r: 0.6, g: 0.4, b: 0.2 },
282
+ metallic: 0,
283
+ roughness: 0.4,
284
+ },
285
+ }),
286
+
287
+ /** Glass */
288
+ glass: (): MaterialConfig => ({
289
+ type: 'transparent',
290
+ blendMode: 'blend',
291
+ pbr: {
292
+ baseColor: { r: 1, g: 1, b: 1, a: 0.3 },
293
+ metallic: 0,
294
+ roughness: 0.0,
295
+ ior: 1.5,
296
+ transmission: 0.9,
297
+ },
298
+ }),
299
+
300
+ /** Emissive (glowing) */
301
+ emissive: (): MaterialConfig => ({
302
+ type: 'pbr',
303
+ pbr: {
304
+ baseColor: { r: 0, g: 1, b: 0 },
305
+ metallic: 0,
306
+ roughness: 1.0,
307
+ emission: {
308
+ color: { r: 0, g: 1, b: 0 },
309
+ intensity: 2.0,
310
+ },
311
+ },
312
+ }),
313
+
314
+ /** Skin material */
315
+ skin: (): MaterialConfig => ({
316
+ type: 'pbr',
317
+ pbr: {
318
+ baseColor: { r: 1, g: 0.8, b: 0.7 },
319
+ metallic: 0,
320
+ roughness: 0.5,
321
+ ambientOcclusion: 0.8,
322
+ },
323
+ }),
324
+ };
@@ -0,0 +1,356 @@
1
+ /**
2
+ * @holoscript/core Rendering Trait
3
+ *
4
+ * Enables GPU optimization directives, level of detail management,
5
+ * and rendering performance tuning
6
+ */
7
+ /**
8
+ * RenderingTrait - Manages GPU optimization and rendering performance
9
+ */
10
+ export class RenderingTrait {
11
+ constructor(config) {
12
+ this.optimization = {
13
+ lodStrategy: 'automatic',
14
+ culling: {
15
+ mode: 'back',
16
+ frustum: true,
17
+ occlusion: true,
18
+ },
19
+ batching: {
20
+ static: true,
21
+ dynamic: true,
22
+ instancing: true,
23
+ maxInstanceCount: 1000,
24
+ },
25
+ textures: {
26
+ streaming: true,
27
+ compression: 'auto',
28
+ mipmaps: true,
29
+ maxResolution: 2048,
30
+ },
31
+ shaders: {
32
+ simplifiedShaders: true,
33
+ lodBias: 0,
34
+ },
35
+ targetGPUTier: 'high',
36
+ adaptiveQuality: true,
37
+ targetFrameRate: 60,
38
+ ...config,
39
+ };
40
+ }
41
+ /**
42
+ * Get rendering optimization config
43
+ */
44
+ getOptimization() {
45
+ return JSON.parse(JSON.stringify(this.optimization));
46
+ }
47
+ /**
48
+ * Update rendering configuration
49
+ */
50
+ updateOptimization(updates) {
51
+ this.optimization = { ...this.optimization, ...updates };
52
+ }
53
+ /**
54
+ * Setup LOD levels (3 levels is typical)
55
+ */
56
+ setupLODLevels(strategy = 'automatic') {
57
+ const levels = [
58
+ {
59
+ level: 0,
60
+ screenRelativeSize: 0.5,
61
+ polygonReduction: 1.0,
62
+ textureScale: 1.0,
63
+ },
64
+ {
65
+ level: 1,
66
+ screenRelativeSize: 0.25,
67
+ polygonReduction: 0.6,
68
+ disabledFeatures: ['specular'],
69
+ textureScale: 0.5,
70
+ },
71
+ {
72
+ level: 2,
73
+ screenRelativeSize: 0.1,
74
+ polygonReduction: 0.3,
75
+ disabledFeatures: ['specular', 'normals'],
76
+ textureScale: 0.25,
77
+ },
78
+ ];
79
+ this.optimization.lodStrategy = strategy;
80
+ this.optimization.lodLevels = levels;
81
+ }
82
+ /**
83
+ * Get LOD levels
84
+ */
85
+ getLODLevels() {
86
+ return [...(this.optimization.lodLevels || [])];
87
+ }
88
+ /**
89
+ * Configure culling
90
+ */
91
+ setCulling(config) {
92
+ this.optimization.culling = {
93
+ ...this.optimization.culling,
94
+ ...config,
95
+ };
96
+ }
97
+ /**
98
+ * Enable frustum culling
99
+ */
100
+ setFrustumCulling(enabled) {
101
+ if (!this.optimization.culling) {
102
+ this.optimization.culling = { mode: 'back' };
103
+ }
104
+ this.optimization.culling.frustum = enabled;
105
+ }
106
+ /**
107
+ * Enable occlusion culling
108
+ */
109
+ setOcclusionCulling(enabled, distance) {
110
+ if (!this.optimization.culling) {
111
+ this.optimization.culling = { mode: 'back' };
112
+ }
113
+ this.optimization.culling.occlusion = enabled;
114
+ if (distance) {
115
+ this.optimization.culling.occlusionDistance = distance;
116
+ }
117
+ }
118
+ /**
119
+ * Configure batching
120
+ */
121
+ setBatching(config) {
122
+ this.optimization.batching = {
123
+ ...this.optimization.batching,
124
+ ...config,
125
+ };
126
+ }
127
+ /**
128
+ * Enable GPU instancing
129
+ */
130
+ setInstancing(enabled, maxInstances) {
131
+ if (!this.optimization.batching) {
132
+ this.optimization.batching = {};
133
+ }
134
+ this.optimization.batching.instancing = enabled;
135
+ if (maxInstances) {
136
+ this.optimization.batching.maxInstanceCount = maxInstances;
137
+ }
138
+ }
139
+ /**
140
+ * Configure texture optimization
141
+ */
142
+ setTextureOptimization(config) {
143
+ this.optimization.textures = {
144
+ ...this.optimization.textures,
145
+ ...config,
146
+ };
147
+ }
148
+ /**
149
+ * Enable texture streaming
150
+ */
151
+ setTextureStreaming(enabled, budgetMB) {
152
+ if (!this.optimization.textures) {
153
+ this.optimization.textures = {};
154
+ }
155
+ this.optimization.textures.streaming = enabled;
156
+ if (budgetMB) {
157
+ this.optimization.textures.streamingBudget = budgetMB;
158
+ }
159
+ }
160
+ /**
161
+ * Set texture compression
162
+ */
163
+ setTextureCompression(compression) {
164
+ if (!this.optimization.textures) {
165
+ this.optimization.textures = {};
166
+ }
167
+ this.optimization.textures.compression = compression;
168
+ }
169
+ /**
170
+ * Set max texture resolution
171
+ */
172
+ setMaxTextureResolution(resolution) {
173
+ if (!this.optimization.textures) {
174
+ this.optimization.textures = {};
175
+ }
176
+ this.optimization.textures.maxResolution = resolution;
177
+ }
178
+ /**
179
+ * Configure shader optimization
180
+ */
181
+ setShaderOptimization(config) {
182
+ this.optimization.shaders = {
183
+ ...this.optimization.shaders,
184
+ ...config,
185
+ };
186
+ }
187
+ /**
188
+ * Set target GPU tier
189
+ */
190
+ setTargetGPUTier(tier) {
191
+ this.optimization.targetGPUTier = tier;
192
+ }
193
+ /**
194
+ * Enable adaptive quality (adjust based on frame rate)
195
+ */
196
+ setAdaptiveQuality(enabled, targetFrameRate) {
197
+ this.optimization.adaptiveQuality = enabled;
198
+ if (targetFrameRate) {
199
+ this.optimization.targetFrameRate = targetFrameRate;
200
+ }
201
+ }
202
+ /**
203
+ * Set fixed timestep for VR/AR
204
+ */
205
+ setFixedTimestep(timestep) {
206
+ this.optimization.fixedTimestep = timestep;
207
+ }
208
+ /**
209
+ * Get rendering preset for quality level
210
+ */
211
+ getPresetForQuality(quality) {
212
+ const presets = {
213
+ low: {
214
+ targetGPUTier: 'low',
215
+ lodStrategy: 'automatic',
216
+ culling: { mode: 'back', frustum: true, occlusion: false },
217
+ batching: { instancing: true, maxInstanceCount: 500 },
218
+ textures: {
219
+ compression: 'astc',
220
+ maxResolution: 512,
221
+ streaming: true,
222
+ streamingBudget: 128,
223
+ },
224
+ adaptiveQuality: true,
225
+ targetFrameRate: 30,
226
+ },
227
+ medium: {
228
+ targetGPUTier: 'medium',
229
+ lodStrategy: 'automatic',
230
+ culling: { mode: 'back', frustum: true, occlusion: true },
231
+ batching: { instancing: true, maxInstanceCount: 1000 },
232
+ textures: {
233
+ compression: 'basis',
234
+ maxResolution: 1024,
235
+ streaming: true,
236
+ streamingBudget: 256,
237
+ },
238
+ adaptiveQuality: true,
239
+ targetFrameRate: 60,
240
+ },
241
+ high: {
242
+ targetGPUTier: 'high',
243
+ lodStrategy: 'automatic',
244
+ culling: { mode: 'back', frustum: true, occlusion: true },
245
+ batching: { instancing: true, maxInstanceCount: 2000 },
246
+ textures: {
247
+ compression: 'dxt',
248
+ maxResolution: 2048,
249
+ streaming: true,
250
+ streamingBudget: 512,
251
+ },
252
+ adaptiveQuality: false,
253
+ targetFrameRate: 60,
254
+ },
255
+ ultra: {
256
+ targetGPUTier: 'ultra',
257
+ lodStrategy: 'manual',
258
+ culling: {
259
+ mode: 'back',
260
+ frustum: true,
261
+ occlusion: true,
262
+ hierarchicalZ: true,
263
+ },
264
+ batching: { instancing: true, maxInstanceCount: 5000 },
265
+ textures: {
266
+ compression: 'none',
267
+ maxResolution: 4096,
268
+ virtualTexturing: true,
269
+ streaming: true,
270
+ streamingBudget: 1024,
271
+ },
272
+ adaptiveQuality: false,
273
+ targetFrameRate: 120,
274
+ },
275
+ };
276
+ return { ...this.optimization, ...presets[quality] };
277
+ }
278
+ /**
279
+ * Apply quality preset
280
+ */
281
+ applyQualityPreset(quality) {
282
+ const preset = this.getPresetForQuality(quality);
283
+ this.optimization = preset;
284
+ }
285
+ /**
286
+ * Estimate GPU memory usage
287
+ */
288
+ estimateGPUMemory() {
289
+ let textureMemory = 0;
290
+ let vertexBuffers = 0;
291
+ // Estimate texture memory based on max resolution
292
+ // Assuming RGBA format at 4 bytes per pixel
293
+ const maxRes = this.optimization.textures?.maxResolution || 2048;
294
+ textureMemory = (maxRes * maxRes * 4) / (1024 * 1024); // MB
295
+ // Estimate based on instancing
296
+ // Typical mesh: 10K vertices, position (12) + normal (12) + UV (8) + color (4) = 36 bytes
297
+ const instanceCount = this.optimization.batching?.maxInstanceCount || 1000;
298
+ const verticesPerMesh = 10000;
299
+ vertexBuffers = ((verticesPerMesh * 36 * instanceCount) / (1024 * 1024)) * 0.1; // 10% for practical estimate
300
+ return {
301
+ textureMemory: Math.round(textureMemory),
302
+ vertexBuffers: Math.max(1, Math.round(vertexBuffers)), // At least 1MB
303
+ estimatedTotal: Math.round(textureMemory + Math.max(1, vertexBuffers)),
304
+ };
305
+ }
306
+ /**
307
+ * Get rendering statistics/info
308
+ */
309
+ getInfo() {
310
+ const tier = this.optimization.targetGPUTier;
311
+ const lod = this.optimization.lodStrategy;
312
+ const culling = this.optimization.culling?.mode;
313
+ const instancing = this.optimization.batching?.instancing ? 'yes' : 'no';
314
+ const memory = this.estimateGPUMemory();
315
+ return `Rendering: tier=${tier} | LOD=${lod} | culling=${culling} | instancing=${instancing} | ` +
316
+ `memory=${memory.estimatedTotal}MB`;
317
+ }
318
+ /**
319
+ * Optimize for VR/AR (fixed timestep, fast culling)
320
+ */
321
+ optimizeForVRAR(targetFPS = 90) {
322
+ this.optimization.fixedTimestep = 1 / targetFPS;
323
+ this.optimization.targetFrameRate = targetFPS;
324
+ this.setOcclusionCulling(true, 50);
325
+ this.setInstancing(true, 5000);
326
+ this.setAdaptiveQuality(true, targetFPS);
327
+ }
328
+ /**
329
+ * Optimize for mobile (lower resources)
330
+ */
331
+ optimizeForMobile() {
332
+ this.applyQualityPreset('low');
333
+ this.setTextureCompression('astc');
334
+ this.setInstancing(true, 256);
335
+ }
336
+ /**
337
+ * Optimize for desktop (higher resources)
338
+ */
339
+ optimizeForDesktop() {
340
+ this.applyQualityPreset('ultra');
341
+ this.setTextureCompression('none');
342
+ this.setInstancing(true, 5000);
343
+ }
344
+ /**
345
+ * Dispose and cleanup
346
+ */
347
+ dispose() {
348
+ // Cleanup if needed
349
+ }
350
+ }
351
+ /**
352
+ * HoloScript+ @rendering trait factory
353
+ */
354
+ export function createRenderingTrait(config) {
355
+ return new RenderingTrait(config);
356
+ }