This commit is contained in:
yinsx
2026-01-05 10:14:33 +08:00
commit cf0b049abf
33 changed files with 3130 additions and 0 deletions

View File

@ -0,0 +1,52 @@
import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
import { Vector3 } from '@babylonjs/core/Maths/math.vector';
import { Tools } from '@babylonjs/core/Misc/tools';
import { Monobehiver } from '../base/Monobehiver';
/**
* 相机控制类- 负责创建和控制弧形旋转相机
*/
export class AppCamera extends Monobehiver {
object: ArcRotateCamera | null;
constructor(mainApp: any) {
super(mainApp);
this.object = null;
}
/** 初始化相机 */
Awake(): void {
const scene = this.mainApp.appScene.object;
const canvas = this.mainApp.appDom.renderDom;
if (!scene || !canvas) return;
// 创建弧形旋转相机水平角70度垂直角80度距离5目标点(0,1,0)
this.object = new ArcRotateCamera('Camera', Tools.ToRadians(70), Tools.ToRadians(80), 5, new Vector3(0, 0, 0), scene);
this.object.attachControl(canvas, true);
this.object.minZ = 0.01; // 近裁剪面
this.object.wheelPrecision =999999; // 滚轮缩放精度
this.object.panningSensibility = 0;
this.object.position = new Vector3(-0, 0, 100);
this.setTarget(0, 2, 0);
}
/** 设置相机目标点 */
setTarget(x: number, y: number, z: number): void {
if (this.object) {
this.object.target = new Vector3(x, y, z);
}
}
/** 重置相机到默认位置 */
reset(): void {
if (!this.object) return;
this.object.radius = 2; this.setTarget(0, 0, 0);
this.object.position = new Vector3(0, 1.5, 2);
}
update(): void {
}
}