修改
This commit is contained in:
@ -9,5 +9,10 @@ export const AppConfig = {
|
||||
container: 'renderDom',
|
||||
modelUrlList: [] as string[],
|
||||
success: null as OptionalCallback,
|
||||
error: null as ErrorCallback
|
||||
error: null as ErrorCallback,
|
||||
env: {
|
||||
hdrPath:"",
|
||||
intensity: 1,
|
||||
rotationY: 0
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { CubeTexture } from '@babylonjs/core/Materials/Textures/cubeTexture';
|
||||
import { Monobehiver } from '../base/Monobehiver';
|
||||
import { AppConfig } from './AppConfig';
|
||||
|
||||
/**
|
||||
* 环境管理类- 负责创建和管理HDR环境贴图
|
||||
@ -14,18 +15,26 @@ export class AppEnv extends Monobehiver {
|
||||
|
||||
/** 初始化 - 创建默认HDR环境 */
|
||||
Awake(): void {
|
||||
this.createHDR();
|
||||
this.createHDR(AppConfig.env);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建HDR环境贴图
|
||||
* @param hdrPath HDR文件路径
|
||||
*/
|
||||
createHDR(hdrPath = '/hdr/sanGiuseppeBridge.env'): void {
|
||||
createHDR(options?: { hdrPath?: string; intensity?: number; rotationY?: number }): void {
|
||||
const hdrPath = options?.hdrPath || AppConfig.env.hdrPath || '/hdr/sanGiuseppeBridge.env';
|
||||
const intensity = options?.intensity ?? AppConfig.env.intensity ?? 1.5;
|
||||
const rotationY = options?.rotationY ?? AppConfig.env.rotationY ?? 0;
|
||||
const scene = this.mainApp.appScene.object;
|
||||
if (!scene) return;
|
||||
if (this.object) {
|
||||
this.object.dispose();
|
||||
this.object = null;
|
||||
}
|
||||
const reflectionTexture = CubeTexture.CreateFromPrefilteredData(hdrPath, scene);
|
||||
scene.environmentIntensity = 1.5;
|
||||
reflectionTexture.rotationY = rotationY;
|
||||
scene.environmentIntensity = intensity;
|
||||
scene.environmentTexture = reflectionTexture;
|
||||
this.object = reflectionTexture;
|
||||
}
|
||||
@ -48,6 +57,13 @@ export class AppEnv extends Monobehiver {
|
||||
if (this.object) this.object.rotationY = angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新环境配置
|
||||
*/
|
||||
updateEnvironment(options: { hdrPath?: string; intensity?: number; rotationY?: number }): void {
|
||||
this.createHDR(options);
|
||||
}
|
||||
|
||||
/** 清理资源 */
|
||||
clean(): void {
|
||||
if (this.object) {
|
||||
|
||||
@ -47,6 +47,7 @@ export class MainApp {
|
||||
AppConfig.modelUrlList = config.modelUrlList || [];
|
||||
AppConfig.success = config.success;
|
||||
AppConfig.error = config.error;
|
||||
AppConfig.env = config.env
|
||||
}
|
||||
|
||||
loadModel(): void {
|
||||
|
||||
Reference in New Issue
Block a user