opencode-agent-flow 0.0.0-stage → 0.1.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.
@@ -0,0 +1,363 @@
1
+ import {
2
+ Clock,
3
+ HalfFloatType,
4
+ NoBlending,
5
+ Vector2,
6
+ WebGLRenderTarget
7
+ } from 'three';
8
+ import { CopyShader } from '../shaders/CopyShader.js';
9
+ import { ShaderPass } from './ShaderPass.js';
10
+ import { ClearMaskPass, MaskPass } from './MaskPass.js';
11
+
12
+ /**
13
+ * Used to implement post-processing effects in three.js.
14
+ * The class manages a chain of post-processing passes to produce the final visual result.
15
+ * Post-processing passes are executed in order of their addition/insertion.
16
+ * The last pass is automatically rendered to screen.
17
+ *
18
+ * This module can only be used with {@link WebGLRenderer}.
19
+ *
20
+ * ```js
21
+ * const composer = new EffectComposer( renderer );
22
+ *
23
+ * // adding some passes
24
+ * const renderPass = new RenderPass( scene, camera );
25
+ * composer.addPass( renderPass );
26
+ *
27
+ * const glitchPass = new GlitchPass();
28
+ * composer.addPass( glitchPass );
29
+ *
30
+ * const outputPass = new OutputPass()
31
+ * composer.addPass( outputPass );
32
+ *
33
+ * function animate() {
34
+ *
35
+ * composer.render(); // instead of renderer.render()
36
+ *
37
+ * }
38
+ * ```
39
+ *
40
+ * @three_import import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
41
+ */
42
+ class EffectComposer {
43
+
44
+ /**
45
+ * Constructs a new effect composer.
46
+ *
47
+ * @param {WebGLRenderer} renderer - The renderer.
48
+ * @param {WebGLRenderTarget} [renderTarget] - This render target and a clone will
49
+ * be used as the internal read and write buffers. If not given, the composer creates
50
+ * the buffers automatically.
51
+ */
52
+ constructor( renderer, renderTarget ) {
53
+
54
+ /**
55
+ * The renderer.
56
+ *
57
+ * @type {WebGLRenderer}
58
+ */
59
+ this.renderer = renderer;
60
+
61
+ this._pixelRatio = renderer.getPixelRatio();
62
+
63
+ if ( renderTarget === undefined ) {
64
+
65
+ const size = renderer.getSize( new Vector2() );
66
+ this._width = size.width;
67
+ this._height = size.height;
68
+
69
+ renderTarget = new WebGLRenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio, { type: HalfFloatType } );
70
+ renderTarget.texture.name = 'EffectComposer.rt1';
71
+
72
+ } else {
73
+
74
+ this._width = renderTarget.width;
75
+ this._height = renderTarget.height;
76
+
77
+ }
78
+
79
+ this.renderTarget1 = renderTarget;
80
+ this.renderTarget2 = renderTarget.clone();
81
+ this.renderTarget2.texture.name = 'EffectComposer.rt2';
82
+
83
+ /**
84
+ * A reference to the internal write buffer. Passes usually write
85
+ * their result into this buffer.
86
+ *
87
+ * @type {WebGLRenderTarget}
88
+ */
89
+ this.writeBuffer = this.renderTarget1;
90
+
91
+ /**
92
+ * A reference to the internal read buffer. Passes usually read
93
+ * the previous render result from this buffer.
94
+ *
95
+ * @type {WebGLRenderTarget}
96
+ */
97
+ this.readBuffer = this.renderTarget2;
98
+
99
+ /**
100
+ * Whether the final pass is rendered to the screen (default framebuffer) or not.
101
+ *
102
+ * @type {boolean}
103
+ * @default true
104
+ */
105
+ this.renderToScreen = true;
106
+
107
+ /**
108
+ * An array representing the (ordered) chain of post-processing passes.
109
+ *
110
+ * @type {Array<Pass>}
111
+ */
112
+ this.passes = [];
113
+
114
+ /**
115
+ * A copy pass used for internal swap operations.
116
+ *
117
+ * @private
118
+ * @type {ShaderPass}
119
+ */
120
+ this.copyPass = new ShaderPass( CopyShader );
121
+ this.copyPass.material.blending = NoBlending;
122
+
123
+ /**
124
+ * The internal clock for managing time data.
125
+ *
126
+ * @private
127
+ * @type {Clock}
128
+ */
129
+ this.clock = new Clock();
130
+
131
+ }
132
+
133
+ /**
134
+ * Swaps the internal read/write buffers.
135
+ */
136
+ swapBuffers() {
137
+
138
+ const tmp = this.readBuffer;
139
+ this.readBuffer = this.writeBuffer;
140
+ this.writeBuffer = tmp;
141
+
142
+ }
143
+
144
+ /**
145
+ * Adds the given pass to the pass chain.
146
+ *
147
+ * @param {Pass} pass - The pass to add.
148
+ */
149
+ addPass( pass ) {
150
+
151
+ this.passes.push( pass );
152
+ pass.setSize( this._width * this._pixelRatio, this._height * this._pixelRatio );
153
+
154
+ }
155
+
156
+ /**
157
+ * Inserts the given pass at a given index.
158
+ *
159
+ * @param {Pass} pass - The pass to insert.
160
+ * @param {number} index - The index into the pass chain.
161
+ */
162
+ insertPass( pass, index ) {
163
+
164
+ this.passes.splice( index, 0, pass );
165
+ pass.setSize( this._width * this._pixelRatio, this._height * this._pixelRatio );
166
+
167
+ }
168
+
169
+ /**
170
+ * Removes the given pass from the pass chain.
171
+ *
172
+ * @param {Pass} pass - The pass to remove.
173
+ */
174
+ removePass( pass ) {
175
+
176
+ const index = this.passes.indexOf( pass );
177
+
178
+ if ( index !== - 1 ) {
179
+
180
+ this.passes.splice( index, 1 );
181
+
182
+ }
183
+
184
+ }
185
+
186
+ /**
187
+ * Returns `true` if the pass for the given index is the last enabled pass in the pass chain.
188
+ *
189
+ * @param {number} passIndex - The pass index.
190
+ * @return {boolean} Whether the pass for the given index is the last pass in the pass chain.
191
+ */
192
+ isLastEnabledPass( passIndex ) {
193
+
194
+ for ( let i = passIndex + 1; i < this.passes.length; i ++ ) {
195
+
196
+ if ( this.passes[ i ].enabled ) {
197
+
198
+ return false;
199
+
200
+ }
201
+
202
+ }
203
+
204
+ return true;
205
+
206
+ }
207
+
208
+ /**
209
+ * Executes all enabled post-processing passes in order to produce the final frame.
210
+ *
211
+ * @param {number} deltaTime - The delta time in seconds. If not given, the composer computes
212
+ * its own time delta value.
213
+ */
214
+ render( deltaTime ) {
215
+
216
+ // deltaTime value is in seconds
217
+
218
+ if ( deltaTime === undefined ) {
219
+
220
+ deltaTime = this.clock.getDelta();
221
+
222
+ }
223
+
224
+ const currentRenderTarget = this.renderer.getRenderTarget();
225
+
226
+ let maskActive = false;
227
+
228
+ for ( let i = 0, il = this.passes.length; i < il; i ++ ) {
229
+
230
+ const pass = this.passes[ i ];
231
+
232
+ if ( pass.enabled === false ) continue;
233
+
234
+ pass.renderToScreen = ( this.renderToScreen && this.isLastEnabledPass( i ) );
235
+ pass.render( this.renderer, this.writeBuffer, this.readBuffer, deltaTime, maskActive );
236
+
237
+ if ( pass.needsSwap ) {
238
+
239
+ if ( maskActive ) {
240
+
241
+ const context = this.renderer.getContext();
242
+ const stencil = this.renderer.state.buffers.stencil;
243
+
244
+ //context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff );
245
+ stencil.setFunc( context.NOTEQUAL, 1, 0xffffffff );
246
+
247
+ this.copyPass.render( this.renderer, this.writeBuffer, this.readBuffer, deltaTime );
248
+
249
+ //context.stencilFunc( context.EQUAL, 1, 0xffffffff );
250
+ stencil.setFunc( context.EQUAL, 1, 0xffffffff );
251
+
252
+ }
253
+
254
+ this.swapBuffers();
255
+
256
+ }
257
+
258
+ if ( MaskPass !== undefined ) {
259
+
260
+ if ( pass instanceof MaskPass ) {
261
+
262
+ maskActive = true;
263
+
264
+ } else if ( pass instanceof ClearMaskPass ) {
265
+
266
+ maskActive = false;
267
+
268
+ }
269
+
270
+ }
271
+
272
+ }
273
+
274
+ this.renderer.setRenderTarget( currentRenderTarget );
275
+
276
+ }
277
+
278
+ /**
279
+ * Resets the internal state of the EffectComposer.
280
+ *
281
+ * @param {WebGLRenderTarget} [renderTarget] - This render target has the same purpose like
282
+ * the one from the constructor. If set, it is used to setup the read and write buffers.
283
+ */
284
+ reset( renderTarget ) {
285
+
286
+ if ( renderTarget === undefined ) {
287
+
288
+ const size = this.renderer.getSize( new Vector2() );
289
+ this._pixelRatio = this.renderer.getPixelRatio();
290
+ this._width = size.width;
291
+ this._height = size.height;
292
+
293
+ renderTarget = this.renderTarget1.clone();
294
+ renderTarget.setSize( this._width * this._pixelRatio, this._height * this._pixelRatio );
295
+
296
+ }
297
+
298
+ this.renderTarget1.dispose();
299
+ this.renderTarget2.dispose();
300
+ this.renderTarget1 = renderTarget;
301
+ this.renderTarget2 = renderTarget.clone();
302
+
303
+ this.writeBuffer = this.renderTarget1;
304
+ this.readBuffer = this.renderTarget2;
305
+
306
+ }
307
+
308
+ /**
309
+ * Resizes the internal read and write buffers as well as all passes. Similar to {@link WebGLRenderer#setSize},
310
+ * this method honors the current pixel ration.
311
+ *
312
+ * @param {number} width - The width in logical pixels.
313
+ * @param {number} height - The height in logical pixels.
314
+ */
315
+ setSize( width, height ) {
316
+
317
+ this._width = width;
318
+ this._height = height;
319
+
320
+ const effectiveWidth = this._width * this._pixelRatio;
321
+ const effectiveHeight = this._height * this._pixelRatio;
322
+
323
+ this.renderTarget1.setSize( effectiveWidth, effectiveHeight );
324
+ this.renderTarget2.setSize( effectiveWidth, effectiveHeight );
325
+
326
+ for ( let i = 0; i < this.passes.length; i ++ ) {
327
+
328
+ this.passes[ i ].setSize( effectiveWidth, effectiveHeight );
329
+
330
+ }
331
+
332
+ }
333
+
334
+ /**
335
+ * Sets device pixel ratio. This is usually used for HiDPI device to prevent blurring output.
336
+ * Setting the pixel ratio will automatically resize the composer.
337
+ *
338
+ * @param {number} pixelRatio - The pixel ratio to set.
339
+ */
340
+ setPixelRatio( pixelRatio ) {
341
+
342
+ this._pixelRatio = pixelRatio;
343
+
344
+ this.setSize( this._width, this._height );
345
+
346
+ }
347
+
348
+ /**
349
+ * Frees the GPU-related resources allocated by this instance. Call this
350
+ * method whenever the composer is no longer used in your app.
351
+ */
352
+ dispose() {
353
+
354
+ this.renderTarget1.dispose();
355
+ this.renderTarget2.dispose();
356
+
357
+ this.copyPass.dispose();
358
+
359
+ }
360
+
361
+ }
362
+
363
+ export { EffectComposer };
@@ -0,0 +1,195 @@
1
+ import { Pass } from './Pass.js';
2
+
3
+ /**
4
+ * This pass can be used to define a mask during post processing.
5
+ * Meaning only areas of subsequent post processing are affected
6
+ * which lie in the masking area of this pass. Internally, the masking
7
+ * is implemented with the stencil buffer.
8
+ *
9
+ * ```js
10
+ * const maskPass = new MaskPass( scene, camera );
11
+ * composer.addPass( maskPass );
12
+ * ```
13
+ *
14
+ * @augments Pass
15
+ * @three_import import { MaskPass } from 'three/addons/postprocessing/MaskPass.js';
16
+ */
17
+ class MaskPass extends Pass {
18
+
19
+ /**
20
+ * Constructs a new mask pass.
21
+ *
22
+ * @param {Scene} scene - The 3D objects in this scene will define the mask.
23
+ * @param {Camera} camera - The camera.
24
+ */
25
+ constructor( scene, camera ) {
26
+
27
+ super();
28
+
29
+ /**
30
+ * The scene that defines the mask.
31
+ *
32
+ * @type {Scene}
33
+ */
34
+ this.scene = scene;
35
+
36
+ /**
37
+ * The camera.
38
+ *
39
+ * @type {Camera}
40
+ */
41
+ this.camera = camera;
42
+
43
+ /**
44
+ * Overwritten to perform a clear operation by default.
45
+ *
46
+ * @type {boolean}
47
+ * @default true
48
+ */
49
+ this.clear = true;
50
+
51
+ /**
52
+ * Overwritten to disable the swap.
53
+ *
54
+ * @type {boolean}
55
+ * @default false
56
+ */
57
+ this.needsSwap = false;
58
+
59
+ /**
60
+ * Whether to inverse the mask or not.
61
+ *
62
+ * @type {boolean}
63
+ * @default false
64
+ */
65
+ this.inverse = false;
66
+
67
+ }
68
+
69
+ /**
70
+ * Performs a mask pass with the configured scene and camera.
71
+ *
72
+ * @param {WebGLRenderer} renderer - The renderer.
73
+ * @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
74
+ * destination for the pass.
75
+ * @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
76
+ * previous pass from this buffer.
77
+ * @param {number} deltaTime - The delta time in seconds.
78
+ * @param {boolean} maskActive - Whether masking is active or not.
79
+ */
80
+ render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
81
+
82
+ const context = renderer.getContext();
83
+ const state = renderer.state;
84
+
85
+ // don't update color or depth
86
+
87
+ state.buffers.color.setMask( false );
88
+ state.buffers.depth.setMask( false );
89
+
90
+ // lock buffers
91
+
92
+ state.buffers.color.setLocked( true );
93
+ state.buffers.depth.setLocked( true );
94
+
95
+ // set up stencil
96
+
97
+ let writeValue, clearValue;
98
+
99
+ if ( this.inverse ) {
100
+
101
+ writeValue = 0;
102
+ clearValue = 1;
103
+
104
+ } else {
105
+
106
+ writeValue = 1;
107
+ clearValue = 0;
108
+
109
+ }
110
+
111
+ state.buffers.stencil.setTest( true );
112
+ state.buffers.stencil.setOp( context.REPLACE, context.REPLACE, context.REPLACE );
113
+ state.buffers.stencil.setFunc( context.ALWAYS, writeValue, 0xffffffff );
114
+ state.buffers.stencil.setClear( clearValue );
115
+ state.buffers.stencil.setLocked( true );
116
+
117
+ // draw into the stencil buffer
118
+
119
+ renderer.setRenderTarget( readBuffer );
120
+ if ( this.clear ) renderer.clear();
121
+ renderer.render( this.scene, this.camera );
122
+
123
+ renderer.setRenderTarget( writeBuffer );
124
+ if ( this.clear ) renderer.clear();
125
+ renderer.render( this.scene, this.camera );
126
+
127
+ // unlock color and depth buffer and make them writable for subsequent rendering/clearing
128
+
129
+ state.buffers.color.setLocked( false );
130
+ state.buffers.depth.setLocked( false );
131
+
132
+ state.buffers.color.setMask( true );
133
+ state.buffers.depth.setMask( true );
134
+
135
+ // only render where stencil is set to 1
136
+
137
+ state.buffers.stencil.setLocked( false );
138
+ state.buffers.stencil.setFunc( context.EQUAL, 1, 0xffffffff ); // draw if == 1
139
+ state.buffers.stencil.setOp( context.KEEP, context.KEEP, context.KEEP );
140
+ state.buffers.stencil.setLocked( true );
141
+
142
+ }
143
+
144
+ }
145
+
146
+ /**
147
+ * This pass can be used to clear a mask previously defined with {@link MaskPass}.
148
+ *
149
+ * ```js
150
+ * const clearPass = new ClearMaskPass();
151
+ * composer.addPass( clearPass );
152
+ * ```
153
+ *
154
+ * @augments Pass
155
+ */
156
+ class ClearMaskPass extends Pass {
157
+
158
+ /**
159
+ * Constructs a new clear mask pass.
160
+ */
161
+ constructor() {
162
+
163
+ super();
164
+
165
+ /**
166
+ * Overwritten to disable the swap.
167
+ *
168
+ * @type {boolean}
169
+ * @default false
170
+ */
171
+ this.needsSwap = false;
172
+
173
+ }
174
+
175
+ /**
176
+ * Performs the clear of the currently defined mask.
177
+ *
178
+ * @param {WebGLRenderer} renderer - The renderer.
179
+ * @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
180
+ * destination for the pass.
181
+ * @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
182
+ * previous pass from this buffer.
183
+ * @param {number} deltaTime - The delta time in seconds.
184
+ * @param {boolean} maskActive - Whether masking is active or not.
185
+ */
186
+ render( renderer /*, writeBuffer, readBuffer, deltaTime, maskActive */ ) {
187
+
188
+ renderer.state.buffers.stencil.setLocked( false );
189
+ renderer.state.buffers.stencil.setTest( false );
190
+
191
+ }
192
+
193
+ }
194
+
195
+ export { MaskPass, ClearMaskPass };
@@ -0,0 +1,139 @@
1
+ import {
2
+ ColorManagement,
3
+ RawShaderMaterial,
4
+ UniformsUtils,
5
+ LinearToneMapping,
6
+ ReinhardToneMapping,
7
+ CineonToneMapping,
8
+ AgXToneMapping,
9
+ ACESFilmicToneMapping,
10
+ NeutralToneMapping,
11
+ CustomToneMapping,
12
+ SRGBTransfer
13
+ } from 'three';
14
+ import { Pass, FullScreenQuad } from './Pass.js';
15
+ import { OutputShader } from '../shaders/OutputShader.js';
16
+
17
+ /**
18
+ * This pass is responsible for including tone mapping and color space conversion
19
+ * into your pass chain. In most cases, this pass should be included at the end
20
+ * of each pass chain. If a pass requires sRGB input (e.g. like FXAA), the pass
21
+ * must follow `OutputPass` in the pass chain.
22
+ *
23
+ * The tone mapping and color space settings are extracted from the renderer.
24
+ *
25
+ * ```js
26
+ * const outputPass = new OutputPass();
27
+ * composer.addPass( outputPass );
28
+ * ```
29
+ *
30
+ * @augments Pass
31
+ * @three_import import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
32
+ */
33
+ class OutputPass extends Pass {
34
+
35
+ /**
36
+ * Constructs a new output pass.
37
+ */
38
+ constructor() {
39
+
40
+ super();
41
+
42
+ /**
43
+ * The pass uniforms.
44
+ *
45
+ * @type {Object}
46
+ */
47
+ this.uniforms = UniformsUtils.clone( OutputShader.uniforms );
48
+
49
+ /**
50
+ * The pass material.
51
+ *
52
+ * @type {RawShaderMaterial}
53
+ */
54
+ this.material = new RawShaderMaterial( {
55
+ name: OutputShader.name,
56
+ uniforms: this.uniforms,
57
+ vertexShader: OutputShader.vertexShader,
58
+ fragmentShader: OutputShader.fragmentShader
59
+ } );
60
+
61
+ // internals
62
+
63
+ this._fsQuad = new FullScreenQuad( this.material );
64
+
65
+ this._outputColorSpace = null;
66
+ this._toneMapping = null;
67
+
68
+ }
69
+
70
+ /**
71
+ * Performs the output pass.
72
+ *
73
+ * @param {WebGLRenderer} renderer - The renderer.
74
+ * @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
75
+ * destination for the pass.
76
+ * @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
77
+ * previous pass from this buffer.
78
+ * @param {number} deltaTime - The delta time in seconds.
79
+ * @param {boolean} maskActive - Whether masking is active or not.
80
+ */
81
+ render( renderer, writeBuffer, readBuffer/*, deltaTime, maskActive */ ) {
82
+
83
+ this.uniforms[ 'tDiffuse' ].value = readBuffer.texture;
84
+ this.uniforms[ 'toneMappingExposure' ].value = renderer.toneMappingExposure;
85
+
86
+ // rebuild defines if required
87
+
88
+ if ( this._outputColorSpace !== renderer.outputColorSpace || this._toneMapping !== renderer.toneMapping ) {
89
+
90
+ this._outputColorSpace = renderer.outputColorSpace;
91
+ this._toneMapping = renderer.toneMapping;
92
+
93
+ this.material.defines = {};
94
+
95
+ if ( ColorManagement.getTransfer( this._outputColorSpace ) === SRGBTransfer ) this.material.defines.SRGB_TRANSFER = '';
96
+
97
+ if ( this._toneMapping === LinearToneMapping ) this.material.defines.LINEAR_TONE_MAPPING = '';
98
+ else if ( this._toneMapping === ReinhardToneMapping ) this.material.defines.REINHARD_TONE_MAPPING = '';
99
+ else if ( this._toneMapping === CineonToneMapping ) this.material.defines.CINEON_TONE_MAPPING = '';
100
+ else if ( this._toneMapping === ACESFilmicToneMapping ) this.material.defines.ACES_FILMIC_TONE_MAPPING = '';
101
+ else if ( this._toneMapping === AgXToneMapping ) this.material.defines.AGX_TONE_MAPPING = '';
102
+ else if ( this._toneMapping === NeutralToneMapping ) this.material.defines.NEUTRAL_TONE_MAPPING = '';
103
+ else if ( this._toneMapping === CustomToneMapping ) this.material.defines.CUSTOM_TONE_MAPPING = '';
104
+
105
+ this.material.needsUpdate = true;
106
+
107
+ }
108
+
109
+ //
110
+
111
+ if ( this.renderToScreen === true ) {
112
+
113
+ renderer.setRenderTarget( null );
114
+ this._fsQuad.render( renderer );
115
+
116
+ } else {
117
+
118
+ renderer.setRenderTarget( writeBuffer );
119
+ if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
120
+ this._fsQuad.render( renderer );
121
+
122
+ }
123
+
124
+ }
125
+
126
+ /**
127
+ * Frees the GPU-related resources allocated by this instance. Call this
128
+ * method whenever the pass is no longer used in your app.
129
+ */
130
+ dispose() {
131
+
132
+ this.material.dispose();
133
+ this._fsQuad.dispose();
134
+
135
+ }
136
+
137
+ }
138
+
139
+ export { OutputPass };