@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.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/dist/chunk-3N67RLQP.cjs +1298 -0
  3. package/dist/chunk-3N67RLQP.cjs.map +1 -0
  4. package/dist/chunk-3X2EGU7Z.cjs +52 -0
  5. package/dist/chunk-3X2EGU7Z.cjs.map +1 -0
  6. package/dist/chunk-4CV4JOE5.js +24 -0
  7. package/dist/chunk-4CV4JOE5.js.map +1 -0
  8. package/dist/chunk-4OHVW4XR.cjs +1027 -0
  9. package/dist/chunk-4OHVW4XR.cjs.map +1 -0
  10. package/dist/chunk-CZLDE2OZ.cjs +28 -0
  11. package/dist/chunk-CZLDE2OZ.cjs.map +1 -0
  12. package/{src/HoloScriptRuntime.ts → dist/chunk-EU6CZMGJ.js} +437 -794
  13. package/dist/chunk-EU6CZMGJ.js.map +1 -0
  14. package/dist/chunk-KWYIVRIH.js +344 -0
  15. package/dist/chunk-KWYIVRIH.js.map +1 -0
  16. package/dist/chunk-MCP6D4LT.js +1025 -0
  17. package/dist/chunk-MCP6D4LT.js.map +1 -0
  18. package/dist/chunk-SATNCODL.js +45 -0
  19. package/dist/chunk-SATNCODL.js.map +1 -0
  20. package/dist/chunk-VMZN4EVR.cjs +347 -0
  21. package/dist/chunk-VMZN4EVR.cjs.map +1 -0
  22. package/{src/HoloScriptDebugger.ts → dist/chunk-VYIDLUCV.js} +118 -257
  23. package/dist/chunk-VYIDLUCV.js.map +1 -0
  24. package/dist/chunk-WFI4T3XB.cjs +424 -0
  25. package/dist/chunk-WFI4T3XB.cjs.map +1 -0
  26. package/dist/debugger.cjs +20 -0
  27. package/dist/debugger.cjs.map +1 -0
  28. package/dist/debugger.d.cts +171 -0
  29. package/dist/debugger.d.ts +171 -0
  30. package/dist/debugger.js +7 -0
  31. package/dist/debugger.js.map +1 -0
  32. package/dist/index.cjs +6006 -0
  33. package/dist/index.cjs.map +1 -0
  34. package/dist/index.d.cts +2482 -0
  35. package/dist/index.d.ts +2482 -0
  36. package/dist/index.js +5926 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/parser.cjs +14 -0
  39. package/dist/parser.cjs.map +1 -0
  40. package/dist/parser.d.cts +139 -0
  41. package/dist/parser.d.ts +139 -0
  42. package/dist/parser.js +5 -0
  43. package/dist/parser.js.map +1 -0
  44. package/dist/runtime.cjs +14 -0
  45. package/dist/runtime.cjs.map +1 -0
  46. package/dist/runtime.d.cts +180 -0
  47. package/dist/runtime.d.ts +180 -0
  48. package/dist/runtime.js +5 -0
  49. package/dist/runtime.js.map +1 -0
  50. package/dist/type-checker.cjs +17 -0
  51. package/dist/type-checker.cjs.map +1 -0
  52. package/dist/type-checker.d.cts +105 -0
  53. package/dist/type-checker.d.ts +105 -0
  54. package/dist/type-checker.js +4 -0
  55. package/dist/type-checker.js.map +1 -0
  56. package/dist/types-D6g4ACjP.d.cts +262 -0
  57. package/dist/types-D6g4ACjP.d.ts +262 -0
  58. package/package.json +11 -8
  59. package/src/HoloScript2DParser.js +0 -227
  60. package/src/HoloScript2DParser.ts +0 -261
  61. package/src/HoloScriptCodeParser.js +0 -1102
  62. package/src/HoloScriptCodeParser.ts +0 -1188
  63. package/src/HoloScriptDebugger.js +0 -458
  64. package/src/HoloScriptParser.js +0 -338
  65. package/src/HoloScriptParser.ts +0 -397
  66. package/src/HoloScriptPlusParser.js +0 -371
  67. package/src/HoloScriptPlusParser.ts +0 -543
  68. package/src/HoloScriptRuntime.js +0 -1399
  69. package/src/HoloScriptRuntime.test.js +0 -351
  70. package/src/HoloScriptRuntime.test.ts +0 -436
  71. package/src/HoloScriptTypeChecker.js +0 -356
  72. package/src/HoloScriptTypeChecker.ts +0 -475
  73. package/src/__tests__/GraphicsServices.test.js +0 -357
  74. package/src/__tests__/GraphicsServices.test.ts +0 -427
  75. package/src/__tests__/HoloScriptPlusParser.test.js +0 -317
  76. package/src/__tests__/HoloScriptPlusParser.test.ts +0 -392
  77. package/src/__tests__/integration.test.js +0 -336
  78. package/src/__tests__/integration.test.ts +0 -416
  79. package/src/__tests__/performance.bench.js +0 -218
  80. package/src/__tests__/performance.bench.ts +0 -262
  81. package/src/__tests__/type-checker.test.js +0 -60
  82. package/src/__tests__/type-checker.test.ts +0 -73
  83. package/src/index.js +0 -217
  84. package/src/index.ts +0 -426
  85. package/src/interop/Interoperability.js +0 -413
  86. package/src/interop/Interoperability.ts +0 -494
  87. package/src/logger.js +0 -42
  88. package/src/logger.ts +0 -57
  89. package/src/parser/EnhancedParser.js +0 -205
  90. package/src/parser/EnhancedParser.ts +0 -251
  91. package/src/parser/HoloScriptPlusParser.js +0 -928
  92. package/src/parser/HoloScriptPlusParser.ts +0 -1089
  93. package/src/runtime/HoloScriptPlusRuntime.js +0 -674
  94. package/src/runtime/HoloScriptPlusRuntime.ts +0 -861
  95. package/src/runtime/PerformanceTelemetry.js +0 -323
  96. package/src/runtime/PerformanceTelemetry.ts +0 -467
  97. package/src/runtime/RuntimeOptimization.js +0 -361
  98. package/src/runtime/RuntimeOptimization.ts +0 -416
  99. package/src/services/HololandGraphicsPipelineService.js +0 -506
  100. package/src/services/HololandGraphicsPipelineService.ts +0 -662
  101. package/src/services/PlatformPerformanceOptimizer.js +0 -356
  102. package/src/services/PlatformPerformanceOptimizer.ts +0 -503
  103. package/src/state/ReactiveState.js +0 -427
  104. package/src/state/ReactiveState.ts +0 -572
  105. package/src/tools/DeveloperExperience.js +0 -376
  106. package/src/tools/DeveloperExperience.ts +0 -438
  107. package/src/traits/AIDriverTrait.js +0 -322
  108. package/src/traits/AIDriverTrait.test.js +0 -329
  109. package/src/traits/AIDriverTrait.test.ts +0 -357
  110. package/src/traits/AIDriverTrait.ts +0 -474
  111. package/src/traits/LightingTrait.js +0 -313
  112. package/src/traits/LightingTrait.test.js +0 -410
  113. package/src/traits/LightingTrait.test.ts +0 -462
  114. package/src/traits/LightingTrait.ts +0 -505
  115. package/src/traits/MaterialTrait.js +0 -194
  116. package/src/traits/MaterialTrait.test.js +0 -286
  117. package/src/traits/MaterialTrait.test.ts +0 -329
  118. package/src/traits/MaterialTrait.ts +0 -324
  119. package/src/traits/RenderingTrait.js +0 -356
  120. package/src/traits/RenderingTrait.test.js +0 -363
  121. package/src/traits/RenderingTrait.test.ts +0 -427
  122. package/src/traits/RenderingTrait.ts +0 -555
  123. package/src/traits/VRTraitSystem.js +0 -740
  124. package/src/traits/VRTraitSystem.ts +0 -1040
  125. package/src/traits/VoiceInputTrait.js +0 -284
  126. package/src/traits/VoiceInputTrait.test.js +0 -226
  127. package/src/traits/VoiceInputTrait.test.ts +0 -252
  128. package/src/traits/VoiceInputTrait.ts +0 -401
  129. package/src/types/AdvancedTypeSystem.js +0 -226
  130. package/src/types/AdvancedTypeSystem.ts +0 -494
  131. package/src/types/HoloScriptPlus.d.ts +0 -853
  132. package/src/types.js +0 -6
  133. package/src/types.ts +0 -369
  134. package/tsconfig.json +0 -23
  135. package/tsup.config.d.ts +0 -2
  136. package/tsup.config.js +0 -18
  137. package/tsup.config.ts +0 -19
@@ -1,286 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
- import { MaterialTrait, createMaterialTrait, MATERIAL_PRESETS, } from '../traits/MaterialTrait';
3
- describe('MaterialTrait', () => {
4
- let material;
5
- beforeEach(() => {
6
- const config = {
7
- type: 'pbr',
8
- pbr: {
9
- baseColor: { r: 1, g: 1, b: 1 },
10
- metallic: 0,
11
- roughness: 0.5,
12
- },
13
- };
14
- material = new MaterialTrait(config);
15
- });
16
- describe('initialization', () => {
17
- it('should create material with default PBR type', () => {
18
- const result = material.getMaterial();
19
- expect(result.type).toBe('pbr');
20
- });
21
- it('should initialize with provided configuration', () => {
22
- const config = {
23
- type: 'pbr',
24
- name: 'my-material',
25
- pbr: {
26
- baseColor: { r: 0.5, g: 0.5, b: 0.5 },
27
- metallic: 0.8,
28
- roughness: 0.2,
29
- },
30
- };
31
- const mat = new MaterialTrait(config);
32
- const result = mat.getMaterial();
33
- expect(result.name).toBe('my-material');
34
- expect(result.pbr?.metallic).toBe(0.8);
35
- });
36
- });
37
- describe('getPBRProperties', () => {
38
- it('should return PBR material properties', () => {
39
- const pbr = material.getPBRProperties();
40
- expect(pbr).toBeDefined();
41
- expect(pbr?.baseColor).toEqual({ r: 1, g: 1, b: 1 });
42
- expect(pbr?.metallic).toBe(0);
43
- expect(pbr?.roughness).toBe(0.5);
44
- });
45
- it('should return undefined for non-PBR material types', () => {
46
- const unlit = new MaterialTrait({ type: 'unlit' });
47
- expect(unlit.getPBRProperties()).toBeUndefined();
48
- });
49
- });
50
- describe('setProperty', () => {
51
- it('should update material property', () => {
52
- material.setProperty('type', 'transparent');
53
- const result = material.getMaterial();
54
- expect(result.type).toBe('transparent');
55
- });
56
- it('should update blend mode', () => {
57
- material.setProperty('blendMode', 'additive');
58
- const result = material.getMaterial();
59
- expect(result.blendMode).toBe('additive');
60
- });
61
- it('should toggle double-sided rendering', () => {
62
- material.setProperty('doubleSided', true);
63
- const result = material.getMaterial();
64
- expect(result.doubleSided).toBe(true);
65
- });
66
- });
67
- describe('updatePBR', () => {
68
- it('should update PBR material properties', () => {
69
- material.updatePBR({
70
- metallic: 1,
71
- roughness: 0.1,
72
- });
73
- const pbr = material.getPBRProperties();
74
- expect(pbr?.metallic).toBe(1);
75
- expect(pbr?.roughness).toBe(0.1);
76
- });
77
- it('should preserve existing properties when updating', () => {
78
- material.updatePBR({ metallic: 0.5 });
79
- const pbr = material.getPBRProperties();
80
- expect(pbr?.metallic).toBe(0.5);
81
- expect(pbr?.roughness).toBe(0.5); // Unchanged
82
- });
83
- it('should create default PBR if not exists', () => {
84
- const unlit = new MaterialTrait({ type: 'unlit' });
85
- unlit.updatePBR({ metallic: 0.7 });
86
- const pbr = unlit.getPBRProperties();
87
- expect(pbr).toBeDefined();
88
- expect(pbr?.metallic).toBe(0.7);
89
- });
90
- it('should support emission properties', () => {
91
- material.updatePBR({
92
- emission: {
93
- color: { r: 1, g: 0, b: 0 },
94
- intensity: 2.0,
95
- },
96
- });
97
- const pbr = material.getPBRProperties();
98
- expect(pbr?.emission?.color.r).toBe(1);
99
- expect(pbr?.emission?.intensity).toBe(2.0);
100
- });
101
- });
102
- describe('texture management', () => {
103
- it('should add texture map', () => {
104
- material.addTexture({
105
- path: '/textures/diffuse.png',
106
- channel: 'baseColor',
107
- });
108
- const textures = material.getTextures();
109
- expect(textures).toHaveLength(1);
110
- expect(textures[0].path).toBe('/textures/diffuse.png');
111
- });
112
- it('should support multiple textures', () => {
113
- material.addTexture({ path: '/t1.png', channel: 'baseColor' });
114
- material.addTexture({ path: '/t2.png', channel: 'normalMap' });
115
- material.addTexture({ path: '/t3.png', channel: 'roughnessMap' });
116
- expect(material.getTextures()).toHaveLength(3);
117
- });
118
- it('should preserve texture configuration', () => {
119
- material.addTexture({
120
- path: '/textures/normal.png',
121
- channel: 'normalMap',
122
- scale: { x: 2, y: 2 },
123
- filter: 'anisotropic',
124
- anisotropy: 16,
125
- });
126
- const textures = material.getTextures();
127
- expect(textures[0].scale).toEqual({ x: 2, y: 2 });
128
- expect(textures[0].filter).toBe('anisotropic');
129
- expect(textures[0].anisotropy).toBe(16);
130
- });
131
- it('should clear texture cache', () => {
132
- material.addTexture({ path: '/t1.png', channel: 'baseColor' });
133
- material.clearTextureCache();
134
- // Verify no error and textures still accessible
135
- expect(material.getTextures()).toHaveLength(1);
136
- });
137
- });
138
- describe('custom shaders', () => {
139
- it('should set custom shader code', () => {
140
- const shader = {
141
- fragment: 'void main() { gl_FragColor = vec4(1.0); }',
142
- shaderLanguage: 'glsl',
143
- };
144
- material.setCustomShader(shader);
145
- const result = material.getCustomShader();
146
- expect(result?.fragment).toBe(shader.fragment);
147
- expect(result?.shaderLanguage).toBe('glsl');
148
- });
149
- it('should support vertex and fragment shaders', () => {
150
- const shader = {
151
- vertex: 'void main() { gl_Position = vec4(1.0); }',
152
- fragment: 'void main() { gl_FragColor = vec4(1.0); }',
153
- shaderLanguage: 'glsl',
154
- };
155
- material.setCustomShader(shader);
156
- const result = material.getCustomShader();
157
- expect(result?.vertex).toBeDefined();
158
- expect(result?.fragment).toBeDefined();
159
- });
160
- });
161
- describe('optimization hints', () => {
162
- it('should enable texture streaming', () => {
163
- material.setTextureStreaming(true);
164
- const result = material.getMaterial();
165
- expect(result.optimization?.streamTextures).toBe(true);
166
- });
167
- it('should set texture compression', () => {
168
- material.setCompression('astc');
169
- const result = material.getMaterial();
170
- expect(result.optimization?.compression).toBe('astc');
171
- });
172
- it('should enable material instancing', () => {
173
- material.setInstanced(true);
174
- const result = material.getMaterial();
175
- expect(result.optimization?.instanced).toBe(true);
176
- });
177
- it('should get optimization configuration', () => {
178
- material.setTextureStreaming(true);
179
- material.setCompression('dxt');
180
- const opt = material.getOptimization();
181
- expect(opt?.streamTextures).toBe(true);
182
- expect(opt?.compression).toBe('dxt');
183
- });
184
- });
185
- describe('material presets', () => {
186
- it('should create chrome material', () => {
187
- const chrome = MATERIAL_PRESETS.chrome();
188
- expect(chrome.pbr?.metallic).toBe(1.0);
189
- expect(chrome.pbr?.roughness).toBe(0.1);
190
- });
191
- it('should create plastic material', () => {
192
- const plastic = MATERIAL_PRESETS.plastic();
193
- expect(plastic.pbr?.metallic).toBe(0);
194
- expect(plastic.pbr?.roughness).toBe(0.8);
195
- });
196
- it('should create wood material', () => {
197
- const wood = MATERIAL_PRESETS.wood();
198
- expect(wood.pbr?.baseColor.r).toBe(0.6);
199
- expect(wood.pbr?.roughness).toBe(0.4);
200
- });
201
- it('should create glass material', () => {
202
- const glass = MATERIAL_PRESETS.glass();
203
- expect(glass.type).toBe('transparent');
204
- expect(glass.blendMode).toBe('blend');
205
- expect(glass.pbr?.transmission).toBe(0.9);
206
- });
207
- it('should create emissive material', () => {
208
- const emissive = MATERIAL_PRESETS.emissive();
209
- expect(emissive.pbr?.emission).toBeDefined();
210
- expect(emissive.pbr?.emission?.intensity).toBe(2.0);
211
- });
212
- it('should create skin material', () => {
213
- const skin = MATERIAL_PRESETS.skin();
214
- expect(skin.pbr?.roughness).toBe(0.5);
215
- expect(skin.pbr?.ambientOcclusion).toBe(0.8);
216
- });
217
- });
218
- describe('factory function', () => {
219
- it('should create material via factory', () => {
220
- const config = {
221
- type: 'pbr',
222
- pbr: {
223
- baseColor: { r: 0.8, g: 0.8, b: 0.8 },
224
- metallic: 0.5,
225
- roughness: 0.5,
226
- },
227
- };
228
- const mat = createMaterialTrait(config);
229
- expect(mat.getMaterial().type).toBe('pbr');
230
- });
231
- });
232
- describe('disposal', () => {
233
- it('should dispose and cleanup', () => {
234
- material.addTexture({ path: '/t.png', channel: 'baseColor' });
235
- material.dispose();
236
- // Verify no error after disposal
237
- expect(() => material.clearTextureCache()).not.toThrow();
238
- });
239
- });
240
- describe('material copying', () => {
241
- it('should create independent material copy', () => {
242
- const original = material.getMaterial();
243
- const copy = new MaterialTrait(original);
244
- copy.updatePBR({ metallic: 0.9 });
245
- const originalAfter = material.getMaterial();
246
- expect(originalAfter.pbr?.metallic).toBe(0); // Unchanged
247
- expect(copy.getPBRProperties()?.metallic).toBe(0.9);
248
- });
249
- });
250
- describe('complex material setup', () => {
251
- it('should configure full PBR material with all properties', () => {
252
- const config = {
253
- type: 'pbr',
254
- name: 'realistic-paint',
255
- pbr: {
256
- baseColor: { r: 0.8, g: 0.2, b: 0.2, a: 1 },
257
- metallic: 0.1,
258
- roughness: 0.6,
259
- ambientOcclusion: 0.9,
260
- emission: { color: { r: 0, g: 0, b: 0 }, intensity: 0 },
261
- normalStrength: 1.0,
262
- parallaxHeight: 0.02,
263
- ior: 1.5,
264
- },
265
- textures: [
266
- { path: '/diffuse.png', channel: 'baseColor' },
267
- { path: '/normal.png', channel: 'normalMap', normalStrength: 1.5 },
268
- { path: '/roughness.png', channel: 'roughnessMap' },
269
- ],
270
- doubleSided: false,
271
- blendMode: 'opaque',
272
- optimization: {
273
- compression: 'dxt',
274
- instanced: true,
275
- lodBias: 0.5,
276
- },
277
- };
278
- const mat = new MaterialTrait(config);
279
- const result = mat.getMaterial();
280
- expect(result.name).toBe('realistic-paint');
281
- expect(result.pbr?.baseColor.r).toBe(0.8);
282
- expect(result.textures).toHaveLength(3);
283
- expect(result.optimization?.compression).toBe('dxt');
284
- });
285
- });
286
- });
@@ -1,329 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
- import {
3
- MaterialTrait,
4
- createMaterialTrait,
5
- MATERIAL_PRESETS,
6
- type MaterialConfig,
7
- type PBRMaterial,
8
- } from '../traits/MaterialTrait';
9
-
10
- describe('MaterialTrait', () => {
11
- let material: MaterialTrait;
12
-
13
- beforeEach(() => {
14
- const config: MaterialConfig = {
15
- type: 'pbr',
16
- pbr: {
17
- baseColor: { r: 1, g: 1, b: 1 },
18
- metallic: 0,
19
- roughness: 0.5,
20
- },
21
- };
22
- material = new MaterialTrait(config);
23
- });
24
-
25
- describe('initialization', () => {
26
- it('should create material with default PBR type', () => {
27
- const result = material.getMaterial();
28
- expect(result.type).toBe('pbr');
29
- });
30
-
31
- it('should initialize with provided configuration', () => {
32
- const config: MaterialConfig = {
33
- type: 'pbr',
34
- name: 'my-material',
35
- pbr: {
36
- baseColor: { r: 0.5, g: 0.5, b: 0.5 },
37
- metallic: 0.8,
38
- roughness: 0.2,
39
- },
40
- };
41
- const mat = new MaterialTrait(config);
42
- const result = mat.getMaterial();
43
- expect(result.name).toBe('my-material');
44
- expect(result.pbr?.metallic).toBe(0.8);
45
- });
46
- });
47
-
48
- describe('getPBRProperties', () => {
49
- it('should return PBR material properties', () => {
50
- const pbr = material.getPBRProperties();
51
- expect(pbr).toBeDefined();
52
- expect(pbr?.baseColor).toEqual({ r: 1, g: 1, b: 1 });
53
- expect(pbr?.metallic).toBe(0);
54
- expect(pbr?.roughness).toBe(0.5);
55
- });
56
-
57
- it('should return undefined for non-PBR material types', () => {
58
- const unlit = new MaterialTrait({ type: 'unlit' });
59
- expect(unlit.getPBRProperties()).toBeUndefined();
60
- });
61
- });
62
-
63
- describe('setProperty', () => {
64
- it('should update material property', () => {
65
- material.setProperty('type', 'transparent');
66
- const result = material.getMaterial();
67
- expect(result.type).toBe('transparent');
68
- });
69
-
70
- it('should update blend mode', () => {
71
- material.setProperty('blendMode', 'additive');
72
- const result = material.getMaterial();
73
- expect(result.blendMode).toBe('additive');
74
- });
75
-
76
- it('should toggle double-sided rendering', () => {
77
- material.setProperty('doubleSided', true);
78
- const result = material.getMaterial();
79
- expect(result.doubleSided).toBe(true);
80
- });
81
- });
82
-
83
- describe('updatePBR', () => {
84
- it('should update PBR material properties', () => {
85
- material.updatePBR({
86
- metallic: 1,
87
- roughness: 0.1,
88
- });
89
- const pbr = material.getPBRProperties();
90
- expect(pbr?.metallic).toBe(1);
91
- expect(pbr?.roughness).toBe(0.1);
92
- });
93
-
94
- it('should preserve existing properties when updating', () => {
95
- material.updatePBR({ metallic: 0.5 });
96
- const pbr = material.getPBRProperties();
97
- expect(pbr?.metallic).toBe(0.5);
98
- expect(pbr?.roughness).toBe(0.5); // Unchanged
99
- });
100
-
101
- it('should create default PBR if not exists', () => {
102
- const unlit = new MaterialTrait({ type: 'unlit' });
103
- unlit.updatePBR({ metallic: 0.7 });
104
- const pbr = unlit.getPBRProperties();
105
- expect(pbr).toBeDefined();
106
- expect(pbr?.metallic).toBe(0.7);
107
- });
108
-
109
- it('should support emission properties', () => {
110
- material.updatePBR({
111
- emission: {
112
- color: { r: 1, g: 0, b: 0 },
113
- intensity: 2.0,
114
- },
115
- });
116
- const pbr = material.getPBRProperties();
117
- expect(pbr?.emission?.color.r).toBe(1);
118
- expect(pbr?.emission?.intensity).toBe(2.0);
119
- });
120
- });
121
-
122
- describe('texture management', () => {
123
- it('should add texture map', () => {
124
- material.addTexture({
125
- path: '/textures/diffuse.png',
126
- channel: 'baseColor',
127
- });
128
- const textures = material.getTextures();
129
- expect(textures).toHaveLength(1);
130
- expect(textures[0].path).toBe('/textures/diffuse.png');
131
- });
132
-
133
- it('should support multiple textures', () => {
134
- material.addTexture({ path: '/t1.png', channel: 'baseColor' });
135
- material.addTexture({ path: '/t2.png', channel: 'normalMap' });
136
- material.addTexture({ path: '/t3.png', channel: 'roughnessMap' });
137
- expect(material.getTextures()).toHaveLength(3);
138
- });
139
-
140
- it('should preserve texture configuration', () => {
141
- material.addTexture({
142
- path: '/textures/normal.png',
143
- channel: 'normalMap',
144
- scale: { x: 2, y: 2 },
145
- filter: 'anisotropic',
146
- anisotropy: 16,
147
- });
148
- const textures = material.getTextures();
149
- expect(textures[0].scale).toEqual({ x: 2, y: 2 });
150
- expect(textures[0].filter).toBe('anisotropic');
151
- expect(textures[0].anisotropy).toBe(16);
152
- });
153
-
154
- it('should clear texture cache', () => {
155
- material.addTexture({ path: '/t1.png', channel: 'baseColor' });
156
- material.clearTextureCache();
157
- // Verify no error and textures still accessible
158
- expect(material.getTextures()).toHaveLength(1);
159
- });
160
- });
161
-
162
- describe('custom shaders', () => {
163
- it('should set custom shader code', () => {
164
- const shader = {
165
- fragment: 'void main() { gl_FragColor = vec4(1.0); }',
166
- shaderLanguage: 'glsl' as const,
167
- };
168
- material.setCustomShader(shader);
169
- const result = material.getCustomShader();
170
- expect(result?.fragment).toBe(shader.fragment);
171
- expect(result?.shaderLanguage).toBe('glsl');
172
- });
173
-
174
- it('should support vertex and fragment shaders', () => {
175
- const shader = {
176
- vertex: 'void main() { gl_Position = vec4(1.0); }',
177
- fragment: 'void main() { gl_FragColor = vec4(1.0); }',
178
- shaderLanguage: 'glsl' as const,
179
- };
180
- material.setCustomShader(shader);
181
- const result = material.getCustomShader();
182
- expect(result?.vertex).toBeDefined();
183
- expect(result?.fragment).toBeDefined();
184
- });
185
- });
186
-
187
- describe('optimization hints', () => {
188
- it('should enable texture streaming', () => {
189
- material.setTextureStreaming(true);
190
- const result = material.getMaterial();
191
- expect(result.optimization?.streamTextures).toBe(true);
192
- });
193
-
194
- it('should set texture compression', () => {
195
- material.setCompression('astc');
196
- const result = material.getMaterial();
197
- expect(result.optimization?.compression).toBe('astc');
198
- });
199
-
200
- it('should enable material instancing', () => {
201
- material.setInstanced(true);
202
- const result = material.getMaterial();
203
- expect(result.optimization?.instanced).toBe(true);
204
- });
205
-
206
- it('should get optimization configuration', () => {
207
- material.setTextureStreaming(true);
208
- material.setCompression('dxt');
209
- const opt = material.getOptimization();
210
- expect(opt?.streamTextures).toBe(true);
211
- expect(opt?.compression).toBe('dxt');
212
- });
213
- });
214
-
215
- describe('material presets', () => {
216
- it('should create chrome material', () => {
217
- const chrome = MATERIAL_PRESETS.chrome();
218
- expect(chrome.pbr?.metallic).toBe(1.0);
219
- expect(chrome.pbr?.roughness).toBe(0.1);
220
- });
221
-
222
- it('should create plastic material', () => {
223
- const plastic = MATERIAL_PRESETS.plastic();
224
- expect(plastic.pbr?.metallic).toBe(0);
225
- expect(plastic.pbr?.roughness).toBe(0.8);
226
- });
227
-
228
- it('should create wood material', () => {
229
- const wood = MATERIAL_PRESETS.wood();
230
- expect(wood.pbr?.baseColor.r).toBe(0.6);
231
- expect(wood.pbr?.roughness).toBe(0.4);
232
- });
233
-
234
- it('should create glass material', () => {
235
- const glass = MATERIAL_PRESETS.glass();
236
- expect(glass.type).toBe('transparent');
237
- expect(glass.blendMode).toBe('blend');
238
- expect(glass.pbr?.transmission).toBe(0.9);
239
- });
240
-
241
- it('should create emissive material', () => {
242
- const emissive = MATERIAL_PRESETS.emissive();
243
- expect(emissive.pbr?.emission).toBeDefined();
244
- expect(emissive.pbr?.emission?.intensity).toBe(2.0);
245
- });
246
-
247
- it('should create skin material', () => {
248
- const skin = MATERIAL_PRESETS.skin();
249
- expect(skin.pbr?.roughness).toBe(0.5);
250
- expect(skin.pbr?.ambientOcclusion).toBe(0.8);
251
- });
252
- });
253
-
254
- describe('factory function', () => {
255
- it('should create material via factory', () => {
256
- const config: MaterialConfig = {
257
- type: 'pbr',
258
- pbr: {
259
- baseColor: { r: 0.8, g: 0.8, b: 0.8 },
260
- metallic: 0.5,
261
- roughness: 0.5,
262
- },
263
- };
264
- const mat = createMaterialTrait(config);
265
- expect(mat.getMaterial().type).toBe('pbr');
266
- });
267
- });
268
-
269
- describe('disposal', () => {
270
- it('should dispose and cleanup', () => {
271
- material.addTexture({ path: '/t.png', channel: 'baseColor' });
272
- material.dispose();
273
- // Verify no error after disposal
274
- expect(() => material.clearTextureCache()).not.toThrow();
275
- });
276
- });
277
-
278
- describe('material copying', () => {
279
- it('should create independent material copy', () => {
280
- const original = material.getMaterial();
281
- const copy = new MaterialTrait(original);
282
-
283
- copy.updatePBR({ metallic: 0.9 });
284
- const originalAfter = material.getMaterial();
285
-
286
- expect(originalAfter.pbr?.metallic).toBe(0); // Unchanged
287
- expect(copy.getPBRProperties()?.metallic).toBe(0.9);
288
- });
289
- });
290
-
291
- describe('complex material setup', () => {
292
- it('should configure full PBR material with all properties', () => {
293
- const config: MaterialConfig = {
294
- type: 'pbr',
295
- name: 'realistic-paint',
296
- pbr: {
297
- baseColor: { r: 0.8, g: 0.2, b: 0.2, a: 1 },
298
- metallic: 0.1,
299
- roughness: 0.6,
300
- ambientOcclusion: 0.9,
301
- emission: { color: { r: 0, g: 0, b: 0 }, intensity: 0 },
302
- normalStrength: 1.0,
303
- parallaxHeight: 0.02,
304
- ior: 1.5,
305
- },
306
- textures: [
307
- { path: '/diffuse.png', channel: 'baseColor' },
308
- { path: '/normal.png', channel: 'normalMap', normalStrength: 1.5 },
309
- { path: '/roughness.png', channel: 'roughnessMap' },
310
- ],
311
- doubleSided: false,
312
- blendMode: 'opaque',
313
- optimization: {
314
- compression: 'dxt',
315
- instanced: true,
316
- lodBias: 0.5,
317
- },
318
- };
319
-
320
- const mat = new MaterialTrait(config);
321
- const result = mat.getMaterial();
322
-
323
- expect(result.name).toBe('realistic-paint');
324
- expect(result.pbr?.baseColor.r).toBe(0.8);
325
- expect(result.textures).toHaveLength(3);
326
- expect(result.optimization?.compression).toBe('dxt');
327
- });
328
- });
329
- });