From 959f86eb2370c8189b2163443df1d5d2008b9b02 Mon Sep 17 00:00:00 2001 From: XiangKuiZheng <476393671@qq.com> Date: Thu, 5 Dec 2024 11:42:46 +0800 Subject: [PATCH] To fix the issue of image stretching after resizing a reflection probe. --- .../reflection-probe/reflection-probe-component.ts | 14 +++++++++----- 1 file changed, 9 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..c28556d034b 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 @@ -325,6 +321,14 @@ export class ReflectionProbe extends Component { if (EDITOR) { ReflectionProbeManager.probeManager.registerEvent(); } + screen.on('window-resize', this._handleResize$, this); + screen.on('fullscreen-change', this._handleResize$, this); + } + + private _handleResize$(): void { + if (this.probe && this.sourceCamera && this.probeType === ProbeType.PLANAR) { + this.probe.renderPlanarReflection(this.sourceCamera.camera); + } } onEnable (): void {