Files
zhengte.babylonjs-sdk/src/babylonjs/AppCamera.ts
2026-01-05 10:14:33 +08:00

53 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 {
}
}