export class ReflectionProbeManager (#14401)

This commit is contained in:
徐兵
2023-03-01 10:00:46 +08:00
committed by GitHub
parent c5b60cb5be
commit 1ef81e4330
4 changed files with 13 additions and 7 deletions
@@ -289,6 +289,7 @@ export class ReflectionProbe extends Component {
public onLoad () {
this._createProbe();
ReflectionProbeManager.probeManager.registerEvent();
}
onEnable () {
+1
View File
@@ -55,6 +55,7 @@ export { DebugView } from './debug-view';
export { ReflectionProbeFlow } from './reflection-probe/reflection-probe-flow';
export { ReflectionProbeStage } from './reflection-probe/reflection-probe-stage';
export { ReflectionProbeManager } from './reflection-probe-manager';
export function createDefaultPipeline () {
const rppl = new ForwardPipeline();
+9 -6
View File
@@ -27,7 +27,6 @@ import { MeshRenderer, ReflectionProbeType } from '../3d/framework/mesh-renderer
import { ImageAsset, Texture2D } from '../asset/assets';
import { PixelFormat } from '../asset/assets/asset-enum';
import { Vec3, geometry, cclegacy } from '../core';
import { director, Director } from '../game';
import { Texture } from '../gfx';
import { Camera, Model } from '../render-scene/scene';
import { ProbeType, ReflectionProbe } from '../render-scene/scene/reflection-probe';
@@ -55,9 +54,7 @@ export class ReflectionProbeManager {
private _usePlanarModels = new Map<Model, ReflectionProbe>();
private _updateForRuntime = true;
private _dataTexture: Texture2D | null = null;
constructor () {
director.on(Director.EVENT_BEFORE_UPDATE, this.onUpdateProbes, this);
}
private _registeredEvent = false;
/**
* @en Set and get whether to detect objects leaving or entering the reflection probe's bounding box at runtime.
* @zh 设置和获取是否在运行时检测物体离开或者进入反射探针的包围盒。
@@ -69,13 +66,19 @@ export class ReflectionProbeManager {
return this._updateForRuntime;
}
public registerEvent () {
if (!this._registeredEvent) {
cclegacy.director.on(cclegacy.Director.EVENT_BEFORE_UPDATE, this.onUpdateProbes, this);
this._registeredEvent = true;
}
}
/**
* @en refresh all reflection probe
* @zh 刷新所有反射探针
*/
public onUpdateProbes (forceUpdate = false) {
if (!this._updateForRuntime || this._probes.length === 0) return;
const scene = director.getScene();
const scene = cclegacy.director.getScene();
if (!scene || !scene.renderScene) {
return;
}
@@ -95,7 +98,7 @@ export class ReflectionProbeManager {
public filterModelsForPlanarReflection () {
if (this._probes.length === 0) return;
const scene = director.getScene();
const scene = cclegacy.director.getScene();
if (!scene || !scene.renderScene) {
return;
}
@@ -84,9 +84,10 @@ export class ReflectionProbeFlow extends RenderFlow {
cclegacy.internal.reflectionProbeManager.updatePlanarMap(probe, probe.realtimePlanarTexture!.getGFXTexture());
} else {
for (let faceIdx = 0; faceIdx < 6; faceIdx++) {
const renderTexture = probe.bakedCubeTextures[faceIdx];
if (!renderTexture) return;
//update camera dirction
probe.updateCameraDir(faceIdx);
const renderTexture = probe.bakedCubeTextures[faceIdx];
probeStage.setUsageInfo(probe, renderTexture.window!.framebuffer);
probeStage.render(camera);
}