跳至主要內容

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将锁定不生效
  • 返回:无

setInteract

设置交互方式

  • setInteract(option)
  • 类型:Function
  • 参数:
    • mouseButtonLeft {String} 左键模式,可选:rotate、pan、dolly
    • mouseButtonRight {String} 右键模式, 可选:rotate、pan、dolly
    • mouseButtonMiddle {String} 中间键点击模式, 可选:rotate、pan、dolly
    • mouseButtonWheel {String} 中间滚动键模式, 可选:dolly
  • 返回:无

disableRotate

禁止旋转

  • disableRotate(option)
  • 类型:Function
  • 参数:
    • option {Object} 禁止旋转参数,可选
      • disableAzimuthAngle {Boolean} 禁止水平方向旋转
      • disablePolarAngle {Boolean} 禁止垂直方向旋转
  • 返回:无

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} 是否渐移
  • 返回:无

truck

平移

  • truck(x, y, enableTransition)
  • 类型:Function
  • 参数:
    • x {Number} 平移x距离
    • y {Number} 平移y距离
    • enableTransition {Boolean} 是否渐移
  • 返回:无

forward

向前移动

  • pan(distance, enableTransition)
  • 类型:Function
  • 参数:
    • distance {Number} 移动距离
    • enableTransition {Boolean} 是否渐移
  • 返回:无

moveTo

移动到某个点

  • moveTo(x, y, z, enableTransition)
  • 类型:Function
  • 参数:
    • x {Number} x距离
    • y {Number} y距离
    • z {Number} z距离
    • enableTransition {Boolean} 是否渐移
  • 返回:无

fitTo

移动到某个物体

  • fitTo(target, enableTransition)
  • 类型:Function
  • 参数:
    • target {THREE.Object3D} 物体
    • enableTransition {Boolean} 是否渐移
  • 返回:无

lookAt

相机一直看向某个点位

  • lookAt(target, position, enableTransition)
  • 类型:Function
  • 参数:
    • target {THREE.Vector3} 点位
    • position {THREE.Vector3} 相机位置,可选
    • enableTransition {Boolean} 是否渐移
  • 返回:无

rotate

相机旋转

  • rotate(azimuthAngle, polarAngle, options)
  • 类型:Function
  • 参数:
    • azimuthAngle {Number} 水平角度
    • polarAngle {Number} 垂直角度
    • options {Object} 选项
      • enableTransition {Boolean} 是否渐移
      • unit {String} 角度单位,默认角度 degree, degreeradian
  • 返回:无

rotateTo

相机旋转到指定角度

  • rotateTo(azimuthAngle, polarAngle, options)
  • 类型:Function
  • 参数:
    • azimuthAngle {Number} 水平角度
    • polarAngle {Number} 垂直角度
    • options {Object} 选项
      • enableTransition {Boolean} 是否渐移
      • unit {String} 角度单位,默认角度 degree, degreeradian
  • 返回:无

setFirstPersonMode

设置第一人称

  • setFirstPersonMode(enable, options)
  • 类型:Function
  • 参数:
    • enable {Boolean} 是否第一人称
    • options {Object} 选项
      • offsetX {Number} 相机X轴偏移值
      • offsetY {Number} 相机Y轴偏移值
      • offsetZ {Number} 相机Z轴偏移值
  • 返回:无

setOrtho

设置是否正射投影模式

  • setOrtho(isOrtho)
  • 类型:Function
  • 参数:
    • isOrtho {Boolean} 是否正射投影模式
  • 返回:this

updateProjectionMatrix

更新投影矩阵

  • updateProjectionMatrix()
  • 类型:Function
  • 参数:无
  • 返回:无

事件

事件名事件说明
dragstart拖拽开始
dragging拖拽
dragend拖拽结束
rotatestart相机旋转
rotate相机旋转
rotateend相机旋转
dolly缩放
// 监听拖拽
viewer.cameraControl.addEventListener("dragging", (event) => {
    // 响应代码
});
上次编辑于:
贡献者: dashun