|
27 | 27 | import * as THREE from 'three'; |
28 | 28 |
|
29 | 29 | import Stats from 'three/addons/libs/stats.module.js'; |
| 30 | + import { GUI } from 'three/addons/libs/lil-gui.module.min.js'; |
30 | 31 |
|
31 | 32 | import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js'; |
32 | 33 | import { RenderPass } from 'three/addons/postprocessing/RenderPass.js'; |
33 | 34 | import { SMAAPass } from 'three/addons/postprocessing/SMAAPass.js'; |
34 | 35 | import { OutputPass } from 'three/addons/postprocessing/OutputPass.js'; |
35 | 36 |
|
| 37 | + let camera, scene, renderer, composer, stats, smaaPass; |
36 | 38 |
|
37 | | - let camera, scene, renderer, composer, stats; |
| 39 | + const params = { |
| 40 | + enabled: true, |
| 41 | + autoRotate: true |
| 42 | + |
| 43 | + }; |
38 | 44 |
|
39 | 45 | init(); |
40 | 46 | animate(); |
|
66 | 72 | scene.add( mesh1 ); |
67 | 73 |
|
68 | 74 | const texture = new THREE.TextureLoader().load( 'textures/brick_diffuse.jpg' ); |
69 | | - texture.anisotropy = 4; |
| 75 | + texture.anisotropy = renderer.capabilities.getMaxAnisotropy(); |
70 | 76 | texture.colorSpace = THREE.SRGBColorSpace; |
71 | 77 |
|
72 | 78 | const material2 = new THREE.MeshBasicMaterial( { map: texture } ); |
|
80 | 86 | composer = new EffectComposer( renderer ); |
81 | 87 | composer.addPass( new RenderPass( scene, camera ) ); |
82 | 88 |
|
83 | | - const pass = new SMAAPass( window.innerWidth * renderer.getPixelRatio(), window.innerHeight * renderer.getPixelRatio() ); |
84 | | - composer.addPass( pass ); |
| 89 | + smaaPass = new SMAAPass( window.innerWidth * renderer.getPixelRatio(), window.innerHeight * renderer.getPixelRatio() ); |
| 90 | + composer.addPass( smaaPass ); |
85 | 91 |
|
86 | 92 | const outputPass = new OutputPass(); |
87 | 93 | composer.addPass( outputPass ); |
88 | 94 |
|
89 | 95 | window.addEventListener( 'resize', onWindowResize ); |
90 | 96 |
|
| 97 | + const gui = new GUI(); |
| 98 | + |
| 99 | + const smaaFolder = gui.addFolder( 'SMAA' ); |
| 100 | + smaaFolder.add( params, 'enabled' ); |
| 101 | + |
| 102 | + const sceneFolder = gui.addFolder( 'Scene' ); |
| 103 | + sceneFolder.add( params, 'autoRotate' ); |
| 104 | + |
91 | 105 | } |
92 | 106 |
|
93 | 107 | function onWindowResize() { |
|
109 | 123 |
|
110 | 124 | stats.begin(); |
111 | 125 |
|
112 | | - for ( let i = 0; i < scene.children.length; i ++ ) { |
| 126 | + if ( params.autoRotate === true ) { |
113 | 127 |
|
114 | | - const child = scene.children[ i ]; |
| 128 | + for ( let i = 0; i < scene.children.length; i ++ ) { |
115 | 129 |
|
116 | | - child.rotation.x += 0.005; |
117 | | - child.rotation.y += 0.01; |
| 130 | + const child = scene.children[ i ]; |
| 131 | + |
| 132 | + child.rotation.x += 0.005; |
| 133 | + child.rotation.y += 0.01; |
| 134 | + |
| 135 | + } |
118 | 136 |
|
119 | 137 | } |
120 | 138 |
|
| 139 | + smaaPass.enabled = params.enabled; |
| 140 | + |
121 | 141 | composer.render(); |
122 | 142 |
|
123 | 143 | stats.end(); |
|
0 commit comments