@holoscript/core 2.0.1 → 2.0.2
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.
- package/LICENSE +21 -0
- package/dist/chunk-3N67RLQP.cjs +1298 -0
- package/dist/chunk-3N67RLQP.cjs.map +1 -0
- package/dist/chunk-3X2EGU7Z.cjs +52 -0
- package/dist/chunk-3X2EGU7Z.cjs.map +1 -0
- package/dist/chunk-4CV4JOE5.js +24 -0
- package/dist/chunk-4CV4JOE5.js.map +1 -0
- package/dist/chunk-4OHVW4XR.cjs +1027 -0
- package/dist/chunk-4OHVW4XR.cjs.map +1 -0
- package/dist/chunk-CZLDE2OZ.cjs +28 -0
- package/dist/chunk-CZLDE2OZ.cjs.map +1 -0
- package/{src/HoloScriptRuntime.ts → dist/chunk-EU6CZMGJ.js} +437 -794
- package/dist/chunk-EU6CZMGJ.js.map +1 -0
- package/dist/chunk-KWYIVRIH.js +344 -0
- package/dist/chunk-KWYIVRIH.js.map +1 -0
- package/dist/chunk-MCP6D4LT.js +1025 -0
- package/dist/chunk-MCP6D4LT.js.map +1 -0
- package/dist/chunk-SATNCODL.js +45 -0
- package/dist/chunk-SATNCODL.js.map +1 -0
- package/dist/chunk-VMZN4EVR.cjs +347 -0
- package/dist/chunk-VMZN4EVR.cjs.map +1 -0
- package/{src/HoloScriptDebugger.ts → dist/chunk-VYIDLUCV.js} +118 -257
- package/dist/chunk-VYIDLUCV.js.map +1 -0
- package/dist/chunk-WFI4T3XB.cjs +424 -0
- package/dist/chunk-WFI4T3XB.cjs.map +1 -0
- package/dist/debugger.cjs +20 -0
- package/dist/debugger.cjs.map +1 -0
- package/dist/debugger.d.cts +171 -0
- package/dist/debugger.d.ts +171 -0
- package/dist/debugger.js +7 -0
- package/dist/debugger.js.map +1 -0
- package/dist/index.cjs +6006 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2482 -0
- package/dist/index.d.ts +2482 -0
- package/dist/index.js +5926 -0
- package/dist/index.js.map +1 -0
- package/dist/parser.cjs +14 -0
- package/dist/parser.cjs.map +1 -0
- package/dist/parser.d.cts +139 -0
- package/dist/parser.d.ts +139 -0
- package/dist/parser.js +5 -0
- package/dist/parser.js.map +1 -0
- package/dist/runtime.cjs +14 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +180 -0
- package/dist/runtime.d.ts +180 -0
- package/dist/runtime.js +5 -0
- package/dist/runtime.js.map +1 -0
- package/dist/type-checker.cjs +17 -0
- package/dist/type-checker.cjs.map +1 -0
- package/dist/type-checker.d.cts +105 -0
- package/dist/type-checker.d.ts +105 -0
- package/dist/type-checker.js +4 -0
- package/dist/type-checker.js.map +1 -0
- package/dist/types-D6g4ACjP.d.cts +262 -0
- package/dist/types-D6g4ACjP.d.ts +262 -0
- package/package.json +11 -8
- package/src/HoloScript2DParser.js +0 -227
- package/src/HoloScript2DParser.ts +0 -261
- package/src/HoloScriptCodeParser.js +0 -1102
- package/src/HoloScriptCodeParser.ts +0 -1188
- package/src/HoloScriptDebugger.js +0 -458
- package/src/HoloScriptParser.js +0 -338
- package/src/HoloScriptParser.ts +0 -397
- package/src/HoloScriptPlusParser.js +0 -371
- package/src/HoloScriptPlusParser.ts +0 -543
- package/src/HoloScriptRuntime.js +0 -1399
- package/src/HoloScriptRuntime.test.js +0 -351
- package/src/HoloScriptRuntime.test.ts +0 -436
- package/src/HoloScriptTypeChecker.js +0 -356
- package/src/HoloScriptTypeChecker.ts +0 -475
- package/src/__tests__/GraphicsServices.test.js +0 -357
- package/src/__tests__/GraphicsServices.test.ts +0 -427
- package/src/__tests__/HoloScriptPlusParser.test.js +0 -317
- package/src/__tests__/HoloScriptPlusParser.test.ts +0 -392
- package/src/__tests__/integration.test.js +0 -336
- package/src/__tests__/integration.test.ts +0 -416
- package/src/__tests__/performance.bench.js +0 -218
- package/src/__tests__/performance.bench.ts +0 -262
- package/src/__tests__/type-checker.test.js +0 -60
- package/src/__tests__/type-checker.test.ts +0 -73
- package/src/index.js +0 -217
- package/src/index.ts +0 -426
- package/src/interop/Interoperability.js +0 -413
- package/src/interop/Interoperability.ts +0 -494
- package/src/logger.js +0 -42
- package/src/logger.ts +0 -57
- package/src/parser/EnhancedParser.js +0 -205
- package/src/parser/EnhancedParser.ts +0 -251
- package/src/parser/HoloScriptPlusParser.js +0 -928
- package/src/parser/HoloScriptPlusParser.ts +0 -1089
- package/src/runtime/HoloScriptPlusRuntime.js +0 -674
- package/src/runtime/HoloScriptPlusRuntime.ts +0 -861
- package/src/runtime/PerformanceTelemetry.js +0 -323
- package/src/runtime/PerformanceTelemetry.ts +0 -467
- package/src/runtime/RuntimeOptimization.js +0 -361
- package/src/runtime/RuntimeOptimization.ts +0 -416
- package/src/services/HololandGraphicsPipelineService.js +0 -506
- package/src/services/HololandGraphicsPipelineService.ts +0 -662
- package/src/services/PlatformPerformanceOptimizer.js +0 -356
- package/src/services/PlatformPerformanceOptimizer.ts +0 -503
- package/src/state/ReactiveState.js +0 -427
- package/src/state/ReactiveState.ts +0 -572
- package/src/tools/DeveloperExperience.js +0 -376
- package/src/tools/DeveloperExperience.ts +0 -438
- package/src/traits/AIDriverTrait.js +0 -322
- package/src/traits/AIDriverTrait.test.js +0 -329
- package/src/traits/AIDriverTrait.test.ts +0 -357
- package/src/traits/AIDriverTrait.ts +0 -474
- package/src/traits/LightingTrait.js +0 -313
- package/src/traits/LightingTrait.test.js +0 -410
- package/src/traits/LightingTrait.test.ts +0 -462
- package/src/traits/LightingTrait.ts +0 -505
- package/src/traits/MaterialTrait.js +0 -194
- package/src/traits/MaterialTrait.test.js +0 -286
- package/src/traits/MaterialTrait.test.ts +0 -329
- package/src/traits/MaterialTrait.ts +0 -324
- package/src/traits/RenderingTrait.js +0 -356
- package/src/traits/RenderingTrait.test.js +0 -363
- package/src/traits/RenderingTrait.test.ts +0 -427
- package/src/traits/RenderingTrait.ts +0 -555
- package/src/traits/VRTraitSystem.js +0 -740
- package/src/traits/VRTraitSystem.ts +0 -1040
- package/src/traits/VoiceInputTrait.js +0 -284
- package/src/traits/VoiceInputTrait.test.js +0 -226
- package/src/traits/VoiceInputTrait.test.ts +0 -252
- package/src/traits/VoiceInputTrait.ts +0 -401
- package/src/types/AdvancedTypeSystem.js +0 -226
- package/src/types/AdvancedTypeSystem.ts +0 -494
- package/src/types/HoloScriptPlus.d.ts +0 -853
- package/src/types.js +0 -6
- package/src/types.ts +0 -369
- package/tsconfig.json +0 -23
- package/tsup.config.d.ts +0 -2
- package/tsup.config.js +0 -18
- package/tsup.config.ts +0 -19
|
@@ -1,324 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,356 +0,0 @@
|
|
|
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
|
-
}
|