From dd096b02efd1e02bf026c5841273913fb42f4441 Mon Sep 17 00:00:00 2001 From: GengineJS <476393671@qq.com> Date: Thu, 5 Dec 2024 12:55:16 +0800 Subject: [PATCH] To fix the issue of image stretching after resizing a reflection probe. (#18004) --- .../reflection-probe-component.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cocos/3d/reflection-probe/reflection-probe-component.ts b/cocos/3d/reflection-probe/reflection-probe-component.ts index b0737c95ab3..c94af42f17f 100644 --- a/cocos/3d/reflection-probe/reflection-probe-component.ts +++ b/cocos/3d/reflection-probe/reflection-probe-component.ts @@ -23,7 +23,7 @@ */ import { ccclass, executeInEditMode, help, menu, playOnFocus, serializable, tooltip, type, visible } from 'cc.decorator'; import { EDITOR, EDITOR_NOT_IN_PREVIEW } from 'internal:constants'; -import { CCBoolean, CCObject, Color, Enum, Vec3, warn } from '../../core'; +import { CCBoolean, CCObject, Color, screen, Enum, Vec3, warn } from '../../core'; import { TextureCube } from '../../asset/assets'; import { scene } from '../../render-scene'; @@ -105,10 +105,6 @@ export class ReflectionProbe extends Component { private _position = new Vec3(0, 0, 0); - constructor () { - super(); - } - /** * @en * Gets or sets the size of the box @@ -327,6 +323,12 @@ export class ReflectionProbe extends Component { } } + private _handleResize$ (): void { + if (this.probe && this.sourceCamera && this.probeType === ProbeType.PLANAR) { + this.probe.renderPlanarReflection(this.sourceCamera.camera); + } + } + onEnable (): void { if (this._probe) { const probe = ReflectionProbeManager.probeManager.getProbeById(this._probeId); @@ -338,12 +340,16 @@ export class ReflectionProbe extends Component { ReflectionProbeManager.probeManager.onUpdateProbes(); this._probe.enable(); } + screen.on('window-resize', this._handleResize$, this); + screen.on('fullscreen-change', this._handleResize$, this); } onDisable (): void { if (this._probe) { ReflectionProbeManager.probeManager.unregister(this._probe); this._probe.disable(); } + screen.off('window-resize', this._handleResize$, this); + screen.off('fullscreen-change', this._handleResize$, this); } public start (): void {