rayzee 4.8.9 → 4.8.11
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/README.md +160 -74
- package/dist/rayzee.es.js +368 -86
- package/dist/rayzee.es.js.map +1 -1
- package/dist/rayzee.umd.js +1 -1
- package/dist/rayzee.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/PathTracerApp.js +179 -27
- package/src/api/AnimationAPI.js +87 -0
- package/src/api/CameraAPI.js +109 -0
- package/src/api/DenoisingAPI.js +243 -0
- package/src/api/EnvironmentAPI.js +106 -0
- package/src/api/LightsAPI.js +80 -0
- package/src/api/MaterialsAPI.js +73 -0
- package/src/api/OutputAPI.js +90 -0
- package/src/api/SelectionAPI.js +89 -0
- package/src/api/TransformAPI.js +49 -0
- package/src/api/index.js +16 -0
- package/src/index.js +13 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Animation sub-API — playback controls for GLTF animation clips.
|
|
3
|
+
*
|
|
4
|
+
* Access via `engine.animation`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* engine.animation.play(0);
|
|
8
|
+
* engine.animation.setSpeed(2);
|
|
9
|
+
* console.log(engine.animation.clips);
|
|
10
|
+
*/
|
|
11
|
+
export class AnimationAPI {
|
|
12
|
+
|
|
13
|
+
/** @param {import('../PathTracerApp.js').PathTracerApp} app */
|
|
14
|
+
constructor( app ) {
|
|
15
|
+
|
|
16
|
+
this._app = app;
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Plays an animation clip by index.
|
|
22
|
+
* @param {number} [clipIndex=0]
|
|
23
|
+
*/
|
|
24
|
+
play( clipIndex = 0 ) {
|
|
25
|
+
|
|
26
|
+
this._app.playAnimation( clipIndex );
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Pauses animation, preserving current time position.
|
|
32
|
+
*/
|
|
33
|
+
pause() {
|
|
34
|
+
|
|
35
|
+
this._app.pauseAnimation();
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Resumes animation from paused state.
|
|
41
|
+
*/
|
|
42
|
+
resume() {
|
|
43
|
+
|
|
44
|
+
this._app.resumeAnimation();
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Stops animation and resets to beginning.
|
|
50
|
+
*/
|
|
51
|
+
stop() {
|
|
52
|
+
|
|
53
|
+
this._app.stopAnimationPlayback();
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Sets playback speed multiplier.
|
|
59
|
+
* @param {number} speed - 1.0 = normal speed
|
|
60
|
+
*/
|
|
61
|
+
setSpeed( speed ) {
|
|
62
|
+
|
|
63
|
+
this._app.setAnimationSpeed( speed );
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Sets loop mode for animation playback.
|
|
69
|
+
* @param {boolean} loop - true for repeat, false for play-once
|
|
70
|
+
*/
|
|
71
|
+
setLoop( loop ) {
|
|
72
|
+
|
|
73
|
+
this._app.setAnimationLoop( loop );
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Available animation clips.
|
|
79
|
+
* @returns {{ index: number, name: string, duration: number }[]}
|
|
80
|
+
*/
|
|
81
|
+
get clips() {
|
|
82
|
+
|
|
83
|
+
return this._app.animationClips;
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camera sub-API — camera switching, auto-focus, DOF, and raw Three.js access.
|
|
3
|
+
*
|
|
4
|
+
* Access via `engine.camera`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* engine.camera.switch(1);
|
|
8
|
+
* engine.camera.active.fov = 60;
|
|
9
|
+
* engine.camera.controls.target.set(0, 1, 0);
|
|
10
|
+
*/
|
|
11
|
+
export class CameraAPI {
|
|
12
|
+
|
|
13
|
+
/** @param {import('../PathTracerApp.js').PathTracerApp} app */
|
|
14
|
+
constructor( app ) {
|
|
15
|
+
|
|
16
|
+
this._app = app;
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The active Three.js PerspectiveCamera.
|
|
22
|
+
* @returns {import('three').PerspectiveCamera}
|
|
23
|
+
*/
|
|
24
|
+
get active() {
|
|
25
|
+
|
|
26
|
+
return this._app.cameraManager?.camera ?? this._app._camera;
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The OrbitControls instance.
|
|
32
|
+
* @returns {import('three/addons/controls/OrbitControls.js').OrbitControls}
|
|
33
|
+
*/
|
|
34
|
+
get controls() {
|
|
35
|
+
|
|
36
|
+
return this._app.cameraManager?.controls ?? this._app._controls;
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Switches the active camera by index.
|
|
42
|
+
* @param {number} index
|
|
43
|
+
*/
|
|
44
|
+
switch( index ) {
|
|
45
|
+
|
|
46
|
+
this._app.switchCamera( index );
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Returns display names for all available cameras.
|
|
52
|
+
* @returns {string[]}
|
|
53
|
+
*/
|
|
54
|
+
getNames() {
|
|
55
|
+
|
|
56
|
+
return this._app.getCameraNames();
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Focuses the orbit camera on a world-space point.
|
|
62
|
+
* @param {import('three').Vector3} center
|
|
63
|
+
*/
|
|
64
|
+
focusOn( center ) {
|
|
65
|
+
|
|
66
|
+
this._app.focusOnPoint( center );
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Sets the auto-focus mode.
|
|
72
|
+
* @param {'auto'|'manual'} mode
|
|
73
|
+
*/
|
|
74
|
+
setAutoFocusMode( mode ) {
|
|
75
|
+
|
|
76
|
+
this._app.cameraManager?.setAutoFocusMode( mode );
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Sets the normalized AF screen point (0-1 range).
|
|
82
|
+
* @param {number} x
|
|
83
|
+
* @param {number} y
|
|
84
|
+
*/
|
|
85
|
+
setAFScreenPoint( x, y ) {
|
|
86
|
+
|
|
87
|
+
this._app.cameraManager?.setAFScreenPoint( x, y );
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Enters AF point placement interaction mode.
|
|
93
|
+
*/
|
|
94
|
+
enterAFPointPlacementMode() {
|
|
95
|
+
|
|
96
|
+
this._app.cameraManager?.enterAFPointPlacementMode();
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Exits AF point placement interaction mode.
|
|
102
|
+
*/
|
|
103
|
+
exitAFPointPlacementMode() {
|
|
104
|
+
|
|
105
|
+
this._app.cameraManager?.exitAFPointPlacementMode();
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Denoising sub-API — denoiser strategy, ASVGF, OIDN, upscaler,
|
|
3
|
+
* adaptive sampling, and auto-exposure controls.
|
|
4
|
+
*
|
|
5
|
+
* Access via `engine.denoising`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* engine.denoising.setStrategy('asvgf', 'medium');
|
|
9
|
+
* engine.denoising.setAutoExposure(true);
|
|
10
|
+
* engine.denoising.setASVGFParams({ temporalAlpha: 0.1 });
|
|
11
|
+
*/
|
|
12
|
+
export class DenoisingAPI {
|
|
13
|
+
|
|
14
|
+
/** @param {import('../PathTracerApp.js').PathTracerApp} app */
|
|
15
|
+
constructor( app ) {
|
|
16
|
+
|
|
17
|
+
this._app = app;
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// ── Strategy ──
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Switches the real-time denoiser strategy.
|
|
25
|
+
* @param {'none'|'asvgf'|'ssrc'|'edgeaware'} strategy
|
|
26
|
+
* @param {string} [asvgfPreset] - ASVGF quality preset if strategy is 'asvgf'
|
|
27
|
+
*/
|
|
28
|
+
setStrategy( strategy, asvgfPreset ) {
|
|
29
|
+
|
|
30
|
+
this._app.setDenoiserStrategy( strategy, asvgfPreset );
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Enables or disables the ASVGF denoiser with optional quality preset.
|
|
36
|
+
* @param {boolean} enabled
|
|
37
|
+
* @param {string} [qualityPreset]
|
|
38
|
+
*/
|
|
39
|
+
setASVGFEnabled( enabled, qualityPreset ) {
|
|
40
|
+
|
|
41
|
+
this._app.setASVGFEnabled( enabled, qualityPreset );
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Applies an ASVGF quality preset.
|
|
47
|
+
* @param {'low'|'medium'|'high'} presetName
|
|
48
|
+
*/
|
|
49
|
+
applyASVGFPreset( presetName ) {
|
|
50
|
+
|
|
51
|
+
this._app.applyASVGFPreset( presetName );
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Enables or disables auto-exposure.
|
|
57
|
+
* @param {boolean} enabled
|
|
58
|
+
*/
|
|
59
|
+
setAutoExposure( enabled ) {
|
|
60
|
+
|
|
61
|
+
this._app.setAutoExposureEnabled( enabled );
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Enables or disables adaptive sampling.
|
|
67
|
+
* @param {boolean} enabled
|
|
68
|
+
*/
|
|
69
|
+
setAdaptiveSampling( enabled ) {
|
|
70
|
+
|
|
71
|
+
this._app.setAdaptiveSamplingEnabled( enabled );
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ── Stage Parameters ──
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Updates ASVGF stage parameters.
|
|
79
|
+
* @param {Object} params - { temporalAlpha, phiColor, phiLuminance, atrousIterations, ... }
|
|
80
|
+
*/
|
|
81
|
+
setASVGFParams( params ) {
|
|
82
|
+
|
|
83
|
+
this._app.updateASVGFParameters( params );
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Toggles the ASVGF heatmap debug overlay.
|
|
89
|
+
* @param {boolean} enabled
|
|
90
|
+
*/
|
|
91
|
+
toggleASVGFHeatmap( enabled ) {
|
|
92
|
+
|
|
93
|
+
this._app.toggleASVGFHeatmap( enabled );
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Configures ASVGF for a specific render mode.
|
|
99
|
+
* @param {Object} config - { enabled, temporalAlpha, atrousIterations, ... }
|
|
100
|
+
*/
|
|
101
|
+
configureASVGFForMode( config ) {
|
|
102
|
+
|
|
103
|
+
this._app.configureASVGFForMode( config );
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Updates SSRC stage parameters.
|
|
109
|
+
* @param {Object} params - { temporalAlpha, spatialRadius, spatialWeight }
|
|
110
|
+
*/
|
|
111
|
+
setSSRCParams( params ) {
|
|
112
|
+
|
|
113
|
+
this._app.updateSSRCParameters( params );
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Updates edge-aware filtering parameters.
|
|
119
|
+
* @param {Object} params - { pixelEdgeSharpness, edgeSharpenSpeed, edgeThreshold }
|
|
120
|
+
*/
|
|
121
|
+
setEdgeAwareParams( params ) {
|
|
122
|
+
|
|
123
|
+
this._app.updateEdgeAwareUniforms( params );
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Updates auto-exposure stage parameters.
|
|
129
|
+
* @param {Object} params - { keyValue, minExposure, maxExposure, ... }
|
|
130
|
+
*/
|
|
131
|
+
setAutoExposureParams( params ) {
|
|
132
|
+
|
|
133
|
+
this._app.updateAutoExposureParameters( params );
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ── Adaptive Sampling ──
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Updates adaptive sampling parameters.
|
|
141
|
+
* @param {Object} params
|
|
142
|
+
*/
|
|
143
|
+
setAdaptiveSamplingParams( params ) {
|
|
144
|
+
|
|
145
|
+
this._app.setAdaptiveSamplingParameters( params );
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Toggles the adaptive sampling debug helper.
|
|
151
|
+
* @param {boolean} enabled
|
|
152
|
+
*/
|
|
153
|
+
toggleAdaptiveSamplingHelper( enabled ) {
|
|
154
|
+
|
|
155
|
+
this._app.toggleAdaptiveSamplingHelper( enabled );
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ── OIDN ──
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Enables or disables Intel OIDN denoiser (final render quality).
|
|
163
|
+
* @param {boolean} enabled
|
|
164
|
+
*/
|
|
165
|
+
setOIDNEnabled( enabled ) {
|
|
166
|
+
|
|
167
|
+
this._app.setOIDNEnabled( enabled );
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Sets OIDN denoiser quality.
|
|
173
|
+
* @param {string} quality
|
|
174
|
+
*/
|
|
175
|
+
setOIDNQuality( quality ) {
|
|
176
|
+
|
|
177
|
+
this._app.updateOIDNQuality( quality );
|
|
178
|
+
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Enables or disables the OIDN tile helper overlay.
|
|
183
|
+
* @param {boolean} enabled
|
|
184
|
+
*/
|
|
185
|
+
setOIDNTileHelper( enabled ) {
|
|
186
|
+
|
|
187
|
+
this._app.setOIDNTileHelper( enabled );
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Enables or disables the tile helper overlay.
|
|
193
|
+
* @param {boolean} enabled
|
|
194
|
+
*/
|
|
195
|
+
setTileHelperEnabled( enabled ) {
|
|
196
|
+
|
|
197
|
+
this._app.setTileHelperEnabled( enabled );
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Enables or disables tile highlight.
|
|
203
|
+
* @param {boolean} enabled
|
|
204
|
+
*/
|
|
205
|
+
setTileHighlightEnabled( enabled ) {
|
|
206
|
+
|
|
207
|
+
this._app.setTileHighlightEnabled( enabled );
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ── AI Upscaler ──
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Enables or disables the AI upscaler.
|
|
215
|
+
* @param {boolean} enabled
|
|
216
|
+
*/
|
|
217
|
+
setUpscalerEnabled( enabled ) {
|
|
218
|
+
|
|
219
|
+
this._app.setUpscalerEnabled( enabled );
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Sets the upscaler scale factor.
|
|
225
|
+
* @param {number} factor
|
|
226
|
+
*/
|
|
227
|
+
setUpscalerScaleFactor( factor ) {
|
|
228
|
+
|
|
229
|
+
this._app.setUpscalerScaleFactor( factor );
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Sets the upscaler quality level.
|
|
235
|
+
* @param {string} quality
|
|
236
|
+
*/
|
|
237
|
+
setUpscalerQuality( quality ) {
|
|
238
|
+
|
|
239
|
+
this._app.setUpscalerQuality( quality );
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment sub-API — HDR maps, sky modes, and procedural generation.
|
|
3
|
+
*
|
|
4
|
+
* Access via `engine.environment`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* await engine.environment.setMode('gradient');
|
|
8
|
+
* engine.environment.params.sunElevation = 45;
|
|
9
|
+
* engine.environment.markDirty();
|
|
10
|
+
*/
|
|
11
|
+
export class EnvironmentAPI {
|
|
12
|
+
|
|
13
|
+
/** @param {import('../PathTracerApp.js').PathTracerApp} app */
|
|
14
|
+
constructor( app ) {
|
|
15
|
+
|
|
16
|
+
this._app = app;
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Current environment parameters (sun position, sky colors, etc.).
|
|
22
|
+
* @returns {Object|null}
|
|
23
|
+
*/
|
|
24
|
+
get params() {
|
|
25
|
+
|
|
26
|
+
return this._app.getEnvParams();
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The loaded environment texture.
|
|
32
|
+
* @returns {import('three').Texture|null}
|
|
33
|
+
*/
|
|
34
|
+
get texture() {
|
|
35
|
+
|
|
36
|
+
return this._app.getEnvironmentTexture();
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Loads an HDR/EXR environment map from URL.
|
|
42
|
+
* @param {string} url
|
|
43
|
+
*/
|
|
44
|
+
async load( url ) {
|
|
45
|
+
|
|
46
|
+
await this._app.loadEnvironment( url );
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Sets a custom environment texture directly.
|
|
52
|
+
* @param {import('three').Texture} texture
|
|
53
|
+
*/
|
|
54
|
+
async setTexture( texture ) {
|
|
55
|
+
|
|
56
|
+
await this._app.setEnvironmentMap( texture );
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Switches the sky mode.
|
|
62
|
+
* @param {'hdri'|'procedural'|'gradient'|'color'} mode
|
|
63
|
+
*/
|
|
64
|
+
async setMode( mode ) {
|
|
65
|
+
|
|
66
|
+
await this._app.setEnvironmentMode( mode );
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Generates a procedural Preetham-model sky texture.
|
|
72
|
+
*/
|
|
73
|
+
async generateProcedural() {
|
|
74
|
+
|
|
75
|
+
return this._app.generateProceduralSkyTexture();
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Generates a gradient sky texture.
|
|
81
|
+
*/
|
|
82
|
+
async generateGradient() {
|
|
83
|
+
|
|
84
|
+
return this._app.generateGradientTexture();
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Generates a solid color sky texture.
|
|
90
|
+
*/
|
|
91
|
+
async generateSolid() {
|
|
92
|
+
|
|
93
|
+
return this._app.generateSolidColorTexture();
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Flags the environment texture for GPU re-upload.
|
|
99
|
+
*/
|
|
100
|
+
markDirty() {
|
|
101
|
+
|
|
102
|
+
this._app.markEnvironmentNeedsUpdate();
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lights sub-API — light CRUD, helpers, and GPU sync.
|
|
3
|
+
*
|
|
4
|
+
* Access via `engine.lights`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* engine.lights.add('PointLight');
|
|
8
|
+
* engine.lights.showHelpers(true);
|
|
9
|
+
* engine.lights.getAll();
|
|
10
|
+
*/
|
|
11
|
+
export class LightsAPI {
|
|
12
|
+
|
|
13
|
+
/** @param {import('../PathTracerApp.js').PathTracerApp} app */
|
|
14
|
+
constructor( app ) {
|
|
15
|
+
|
|
16
|
+
this._app = app;
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Adds a light to the scene.
|
|
22
|
+
* @param {'DirectionalLight'|'PointLight'|'SpotLight'|'RectAreaLight'} type
|
|
23
|
+
* @returns {Object|null} Light descriptor
|
|
24
|
+
*/
|
|
25
|
+
add( type ) {
|
|
26
|
+
|
|
27
|
+
return this._app.addLight( type );
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Removes a light by UUID.
|
|
33
|
+
* @param {string} uuid
|
|
34
|
+
* @returns {boolean}
|
|
35
|
+
*/
|
|
36
|
+
remove( uuid ) {
|
|
37
|
+
|
|
38
|
+
return this._app.removeLight( uuid );
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Removes all lights from the scene.
|
|
44
|
+
*/
|
|
45
|
+
clear() {
|
|
46
|
+
|
|
47
|
+
this._app.clearLights();
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Returns descriptors for all lights in the scene.
|
|
53
|
+
* @returns {Object[]}
|
|
54
|
+
*/
|
|
55
|
+
getAll() {
|
|
56
|
+
|
|
57
|
+
return this._app.getLights();
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Re-uploads light data to the GPU.
|
|
63
|
+
*/
|
|
64
|
+
sync() {
|
|
65
|
+
|
|
66
|
+
this._app.updateLights();
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Shows or hides visual light helpers.
|
|
72
|
+
* @param {boolean} show
|
|
73
|
+
*/
|
|
74
|
+
showHelpers( show ) {
|
|
75
|
+
|
|
76
|
+
this._app.setShowLightHelper( show );
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Materials sub-API — material property updates and texture transforms.
|
|
3
|
+
*
|
|
4
|
+
* Access via `engine.materials`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* engine.materials.setProperty(0, 'roughness', 0.5);
|
|
8
|
+
* engine.materials.refresh();
|
|
9
|
+
*/
|
|
10
|
+
export class MaterialsAPI {
|
|
11
|
+
|
|
12
|
+
/** @param {import('../PathTracerApp.js').PathTracerApp} app */
|
|
13
|
+
constructor( app ) {
|
|
14
|
+
|
|
15
|
+
this._app = app;
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Updates a single material property and triggers emissive rebuild if needed.
|
|
21
|
+
* @param {number} materialIndex
|
|
22
|
+
* @param {string} property
|
|
23
|
+
* @param {*} value
|
|
24
|
+
*/
|
|
25
|
+
setProperty( materialIndex, property, value ) {
|
|
26
|
+
|
|
27
|
+
this._app.updateMaterialProperty( materialIndex, property, value );
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Updates a material's texture transform (offset, repeat, rotation).
|
|
33
|
+
* @param {number} materialIndex
|
|
34
|
+
* @param {string} textureName
|
|
35
|
+
* @param {Object} transform
|
|
36
|
+
*/
|
|
37
|
+
setTextureTransform( materialIndex, textureName, transform ) {
|
|
38
|
+
|
|
39
|
+
this._app.updateTextureTransform( materialIndex, textureName, transform );
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Re-uploads all material data to the GPU.
|
|
45
|
+
*/
|
|
46
|
+
refresh() {
|
|
47
|
+
|
|
48
|
+
this._app.refreshMaterial();
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Replaces a material entirely.
|
|
54
|
+
* @param {number} materialIndex
|
|
55
|
+
* @param {import('three').Material} material
|
|
56
|
+
*/
|
|
57
|
+
replace( materialIndex, material ) {
|
|
58
|
+
|
|
59
|
+
this._app.updateMaterial( materialIndex, material );
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Full material rebuild (required after texture changes).
|
|
65
|
+
* @param {import('three').Scene} [scene]
|
|
66
|
+
*/
|
|
67
|
+
async rebuild( scene ) {
|
|
68
|
+
|
|
69
|
+
await this._app.rebuildMaterials( scene );
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|