Browse Source

Examples: add resize event for `webgl_postprocessing_crossfade.html` (#28172)

林炳权 1 year ago
parent
commit
e462f0e7cd
1 changed files with 18 additions and 0 deletions
  1. 18 0
      examples/webgl_postprocessing_crossfade.html

+ 18 - 0
examples/webgl_postprocessing_crossfade.html

@@ -72,6 +72,16 @@
 
 
 				transition = new Transition( sceneA, sceneB );
 				transition = new Transition( sceneA, sceneB );
 
 
+				window.addEventListener( 'resize', onWindowResize );
+
+				function onWindowResize() {
+
+					sceneA.resize();
+					sceneB.resize();
+					renderer.setSize( window.innerWidth, window.innerHeight );
+
+				}
+
 			}
 			}
 
 
 			function animate() {
 			function animate() {
@@ -208,6 +218,14 @@
 
 
 				};
 				};
 
 
+				this.resize = function () {
+
+					camera.aspect = window.innerWidth / window.innerHeight;
+					camera.updateProjectionMatrix();
+					this.fbo.setSize( window.innerWidth, window.innerHeight );
+
+				};
+
 			}
 			}
 
 
 			function Transition( sceneA, sceneB ) {
 			function Transition( sceneA, sceneB ) {