Skip to content

Commit

Permalink
To fix the issue of image stretching after resizing a reflection prob…
Browse files Browse the repository at this point in the history
…e. (#18004)
  • Loading branch information
GengineJS authored Dec 5, 2024
1 parent 52af114 commit dd096b0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions cocos/3d/reflection-probe/reflection-probe-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down

0 comments on commit dd096b0

Please sign in to comment.