Files
bim_engine/docs/ENGINNE_3D/jumpToCamera-使用指南.md
2026-03-26 09:34:21 +08:00

89 lines
1.8 KiB
Markdown
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.

# jumpToCamera 方法使用指南
## 概述
`jumpToCamera` 是 BIM 引擎提供的一个视角跳转方法,允许开发者通过传入相机配置 JSON 数据,将 3D 视图快速定位到指定构件或特定视角。
## 方法签名
```javascript
engine.engine.jumpToCamera(cameraData)
```
### 参数
- `cameraData` - 相机配置 JSON 对象
### 返回值
- `true` - 跳转成功
- `false` - 跳转失败
## 基本使用
```javascript
// 跳转到指定视角
engine.engine.jumpToCamera({
type: "orthographic",
position: { x: 229.68, y: 247.98, z: 233.79 },
target: { x: -4.58, y: 13.72, z: -0.47 },
orthographicHeight: 140.56
});
```
## 配合 getModelPosition 使用
```javascript
// 1. 获取构件位置数据(返回的 modelJson 中包含 cameraRestorePose
const data = engine.engine.getModelPosition({
url: "模型URL",
ids: [465979]
});
// 2. 使用返回的 cameraRestorePose 跳转视角
if (data?.modelJson?.cameraRestorePose) {
engine.engine.jumpToCamera(data.modelJson.cameraRestorePose);
}
```
## 注意事项
1. 调用前确保引擎已初始化
2. 参数为 JSON 对象格式
3. 数据可通过 `getModelPosition` 方法获取
## 完整示例
```javascript
const engine = new BimEngine(container, { theme: 'dark' });
// 初始化引擎
engine.engine.initialize({
version: 'v2',
showStats: false,
showViewCube: true
});
// 加载模型
engine.engine.loadModel(['模型URL'], {
position: [0, 0, 0],
rotation: [0, 0, 0],
scale: [1, 1, 1]
});
// 获取构件位置并跳转
const componentData = engine.engine.getModelPosition({
url: "模型URL",
ids: [465979]
});
if (componentData?.modelJson?.cameraRestorePose) {
const success = engine.engine.jumpToCamera(
componentData.modelJson.cameraRestorePose
);
if (success) {
console.log('跳转成功');
}
}
```