CameraControl
大约 3 分钟
CameraControl
相机控件,控制相机位置、旋转、中心点等参数,实现三维场景的交互。
属性成员
enabled
- 类型:
{Boolean}是否为开启状态 
keypress
- 类型:
{Boolean}是否开始键盘快捷键,支持的快捷键: 
| 名称 | 说明 | 
|---|---|
| A | 左移 | 
| W | 前进 | 
| S | 后退 | 
| D | 右移 | 
| 左箭头 | 向左旋转 | 
| 右箭头 | 向右旋转 | 
| 下箭头 | 下移 | 
| 上箭头 | 上移 | 
camera
- 类型:
{THREE.Camera}当前相机 
control
- 类型:
{Object}当前相机控制实例 
far
- 类型:
{Number}视锥最远距离 
fov
- 类型:
{Number}视锥夹角 
near
- 类型:
{Number}视锥最近距离 
center
- 类型:
{THREE.Vector3}相机镜头中心点 
position
- 类型:
{THREE.Vector3}相机位置 
isOrtho
- 类型:
{Boolean}当前相机是否为正射投影 
type
- 类型:
{String}视图模式,2d、3d,默认3d 
moveStep
- 类型:
{Number}移动步长 
rotateAngle
- 类型:
{Number}旋转每角度 
orthographicCamera
- 类型:
{THREE.OrthographicCamera}正射投影相机 
perspectiveCamera
- 类型:
{THREE.PerspectiveCamera}透视投影相机 
方法
setEnabled
设置是否生效
- setEnabled(enable)
 - 类型:
Function - 参数: 
- enable 
{Boolean}是否开启,为false,cameraControl将锁定不生效 
 - enable 
 - 返回:无
 
setInteract
设置交互方式
- setInteract(option)
 - 类型:
Function - 参数: 
- mouseButtonLeft 
{String}左键模式,可选:rotate、pan、dolly - mouseButtonRight 
{String}右键模式, 可选:rotate、pan、dolly - mouseButtonMiddle 
{String}中间键点击模式, 可选:rotate、pan、dolly - mouseButtonWheel 
{String}中间滚动键模式, 可选:dolly 
 - mouseButtonLeft 
 - 返回:无
 
disableRotate
禁止旋转
- disableRotate(option)
 - 类型:
Function - 参数: 
- option 
{Object}禁止旋转参数,可选- disableAzimuthAngle 
{Boolean}禁止水平方向旋转 - disablePolarAngle 
{Boolean}禁止垂直方向旋转 
 - disableAzimuthAngle 
 
 - option 
 - 返回:无
 
enableRotate
允许旋转
- enableRotate()
 - 类型:
Function - 参数:无
 - 返回:无
 
toFrontView
切换前视图
- toFrontView()
 - 类型:
Function - 参数:无
 - 返回:无
 
toBackView
切换后视图
- toBackView()
 - 类型:
Function - 参数:无
 - 返回:无
 
toLeftView
切换左视图
- toLeftView()
 - 类型:
Function - 参数:无
 - 返回:无
 
toRightView
切换右视图
- toRightView()
 - 类型:
Function - 参数:无
 - 返回:无
 
toTopView
切换顶视图
- toTopView()
 - 类型:
Function - 参数:无
 - 返回:无
 
toBottomView
切换底视图
- toBottomView()
 - 类型:
Function - 参数:无
 - 返回:无
 
pan
平移
- pan(x, y, enableTransition)
 - 类型:
Function - 参数: 
- x 
{Number}平移x距离 - y 
{Number}平移y距离 - enableTransition 
{Boolean}是否渐移 
 - x 
 - 返回:无
 
truck
平移
- truck(x, y, enableTransition)
 - 类型:
Function - 参数: 
- x 
{Number}平移x距离 - y 
{Number}平移y距离 - enableTransition 
{Boolean}是否渐移 
 - x 
 - 返回:无
 
forward
向前移动
- pan(distance, enableTransition)
 - 类型:
Function - 参数: 
- distance 
{Number}移动距离 - enableTransition 
{Boolean}是否渐移 
 - distance 
 - 返回:无
 
moveTo
移动到某个点
- moveTo(x, y, z, enableTransition)
 - 类型:
Function - 参数: 
- x 
{Number}x距离 - y 
{Number}y距离 - z 
{Number}z距离 - enableTransition 
{Boolean}是否渐移 
 - x 
 - 返回:无
 
fitTo
移动到某个物体
- fitTo(target, enableTransition)
 - 类型:
Function - 参数: 
- target 
{THREE.Object3D}物体 - enableTransition 
{Boolean}是否渐移 
 - target 
 - 返回:无
 
lookAt
相机一直看向某个点位
- lookAt(target, position, enableTransition)
 - 类型:
Function - 参数: 
- target 
{THREE.Vector3}点位 - position 
{THREE.Vector3}相机位置,可选 - enableTransition 
{Boolean}是否渐移 
 - target 
 - 返回:无
 
rotate
相机旋转
- rotate(azimuthAngle, polarAngle, options)
 - 类型:
Function - 参数: 
- azimuthAngle 
{Number}水平角度 - polarAngle 
{Number}垂直角度 - options 
{Object}选项- enableTransition 
{Boolean}是否渐移 - unit 
{String}角度单位,默认角度 degree,degree、radian 
 - enableTransition 
 
 - azimuthAngle 
 - 返回:无
 
rotateTo
相机旋转到指定角度
- rotateTo(azimuthAngle, polarAngle, options)
 - 类型:
Function - 参数: 
- azimuthAngle 
{Number}水平角度 - polarAngle 
{Number}垂直角度 - options 
{Object}选项- enableTransition 
{Boolean}是否渐移 - unit 
{String}角度单位,默认角度 degree,degree、radian 
 - enableTransition 
 
 - azimuthAngle 
 - 返回:无
 
setFirstPersonMode
设置第一人称
- setFirstPersonMode(enable, options)
 - 类型:
Function - 参数: 
- enable 
{Boolean}是否第一人称 - options 
{Object}选项- offsetX 
{Number}相机X轴偏移值 - offsetY 
{Number}相机Y轴偏移值 - offsetZ 
{Number}相机Z轴偏移值 
 - offsetX 
 
 - enable 
 - 返回:无
 
setOrtho
设置是否正射投影模式
- setOrtho(isOrtho)
 - 类型:
Function - 参数: 
- isOrtho 
{Boolean}是否正射投影模式 
 - isOrtho 
 - 返回:
this 
updateProjectionMatrix
更新投影矩阵
- updateProjectionMatrix()
 - 类型:
Function - 参数:无
 - 返回:无
 
事件
| 事件名 | 事件说明 | 
|---|---|
| dragstart | 拖拽开始 | 
| dragging | 拖拽 | 
| dragend | 拖拽结束 | 
| rotatestart | 相机旋转 | 
| rotate | 相机旋转 | 
| rotateend | 相机旋转 | 
| dolly | 缩放 | 
// 监听拖拽
viewer.cameraControl.addEventListener("dragging", (event) => {
    // 响应代码
});