Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To fix the issue of image stretching after resizing a reflection probe. #18004

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

private _position = new Vec3(0, 0, 0);

constructor () {
super();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the default constructor will make the package size bigger. So don't remove it.


/**
* @en
* Gets or sets the size of the box
Expand Down Expand Up @@ -180,7 +176,7 @@
* @en set render texture size
* @zh 设置渲染纹理大小
*/
@visible(function (this: ReflectionProbe) { return this.probeType === ProbeType.CUBE; })

Check warning on line 179 in cocos/3d/reflection-probe/reflection-probe-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@type(Enum(ProbeResolution))
set resolution (value: number) {
this._resolution = value;
Expand All @@ -196,7 +192,7 @@
* @zh 相机的缓冲清除标志位,指定帧缓冲的哪部分要每帧清除。
*/
@type(Enum(ProbeClearFlag))
@visible(function (this: ReflectionProbe) { return this.probeType === ProbeType.CUBE; })

Check warning on line 195 in cocos/3d/reflection-probe/reflection-probe-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
set clearFlag (value: number) {
this._clearFlag = value;
this.probe.clearFlag = this._clearFlag;
Expand All @@ -209,7 +205,7 @@
* @en Clearing color of the camera.
* @zh 相机的颜色缓冲默认值。
*/
@visible(function (this: ReflectionProbe) { return this._clearFlag === ProbeClearFlag.SOLID_COLOR && this.probeType === ProbeType.CUBE; })

Check warning on line 208 in cocos/3d/reflection-probe/reflection-probe-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@type(Color)
set backgroundColor (val: Color) {
this._backgroundColor = val;
Expand Down Expand Up @@ -237,7 +233,7 @@
* @en The camera to render planar reflections, specified by the user
* @zh 需要渲染平面反射的相机,由用户指定
*/
@visible(function (this: ReflectionProbe) { return this.probeType === ProbeType.PLANAR; })

Check warning on line 236 in cocos/3d/reflection-probe/reflection-probe-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@type(Camera)
set sourceCamera (camera: Camera) {
this._sourceCamera = camera;
Expand All @@ -258,7 +254,7 @@
* @en fast bake no convolution.
* @zh 快速烘焙不会进行卷积。
*/
@visible(function (this: ReflectionProbe) { return this.probeType === ProbeType.CUBE; })

Check warning on line 257 in cocos/3d/reflection-probe/reflection-probe-component.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@type(CCBoolean)
@tooltip('i18n:reflection_probe.fastBake')
get fastBake (): boolean {
Expand Down Expand Up @@ -327,6 +323,12 @@
}
}

private _handleResize$ (): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add $ now since we will write a babel plugin to mangle the private variables.

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 @@
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
Loading