Elffuss BraidHub

kikocis/VibeCodeViewer public

main · 1.7 KiBRawPermalink
1import {
2 BufferGeometry,
3 Float32BufferAttribute,
4 OrthographicCamera,
5 Mesh
6} from 'three';
7
8class Pass {
9
10 constructor() {
11
12 this.isPass = true;
13
14 // if set to true, the pass is processed by the composer
15 this.enabled = true;
16
17 // if set to true, the pass indicates to swap read and write buffer after rendering
18 this.needsSwap = true;
19
20 // if set to true, the pass clears its buffer before rendering
21 this.clear = false;
22
23 // if set to true, the result of the pass is rendered to screen. This is set automatically by EffectComposer.
24 this.renderToScreen = false;
25
26 }
27
28 setSize( /* width, height */ ) {}
29
30 render( /* renderer, writeBuffer, readBuffer, deltaTime, maskActive */ ) {
31
32 console.error( 'THREE.Pass: .render() must be implemented in derived pass.' );
33
34 }
35
36 dispose() {}
37
38}
39
40// Helper for passes that need to fill the viewport with a single quad.
41
42const _camera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
43
44// https://github.com/mrdoob/three.js/pull/21358
45
46class FullscreenTriangleGeometry extends BufferGeometry {
47
48 constructor() {
49
50 super();
51
52 this.setAttribute( 'position', new Float32BufferAttribute( [ - 1, 3, 0, - 1, - 1, 0, 3, - 1, 0 ], 3 ) );
53 this.setAttribute( 'uv', new Float32BufferAttribute( [ 0, 2, 0, 0, 2, 0 ], 2 ) );
54
55 }
56
57}
58
59const _geometry = new FullscreenTriangleGeometry();
60
61class FullScreenQuad {
62
63 constructor( material ) {
64
65 this._mesh = new Mesh( _geometry, material );
66
67 }
68
69 dispose() {
70
71 this._mesh.geometry.dispose();
72
73 }
74
75 render( renderer ) {
76
77 renderer.render( this._mesh, _camera );
78
79 }
80
81 get material() {
82
83 return this._mesh.material;
84
85 }
86
87 set material( value ) {
88
89 this._mesh.material = value;
90
91 }
92
93}
94
95export { Pass, FullScreenQuad };