Cesium 模型移动旋转控制-丝滑版

加 QQ 1760723197 发完整源码

import * as Cesium from 'cesium'

 

import ArrowPolyline from './ArrowPolyline'

import EventConstant from './EventConstant'

import { cartesian3ToQuaternion, normalizingQuaternion, projectOnPlane, rayPlaneIntersection } from './Math'

import AxisSphere from './AxisSphere'

import EventManager from './EventManager'

 

export default class TranslationController {

  /**

   * 视图

   * @type {Viewer}

   */

  viewer = null

 

  /**

   * 模型

   * @type {Cesium.Model}

   */

  model = null

 

  /**

   * 模型位置

   * @type {Cesium.Cartesian3}

   */

  position = null

 

  /**

   * z轴

   * @type {ArrowPolyline}

   */

  axisZ = null

 

  /**

   * x轴

   * @type {ArrowPolyline}

   */

  axisX = null

 

  /**

   * y轴

   * @type {ArrowPolyline}

   */

  axisY = null

 

  /**

   * 操作杆集合

   * @type {Cesium.PrimitiveCollection}

   */

  primitives = null

 

  /**

   * 从摄像头发出与视窗上一点相交的射线

   */

  pickRay = new Cesium.Ray()

 

  /**

   * 拾取到的位置

   * @type {Cesium.Cartesian3}

   */

  pickPoint = null

 

  /**

   * 当前操作轴

   * @type {ArrowPolyline}

   */

  axis = null

 

  /**

   * Z旋转轴

   * @type {AxisSphere}

   */

  axisSphereZ = null

 

  /**

   * X旋转轴

   * @type {AxisSphere}

   */

  axisSphereX = null

 

  /**

   * Y旋转轴

   * @type {AxisSphere}

   */

  axisSphereY = null

 

  /**

   * 辅助球

   * @type {Cesium.Primitive}

   */

  auxiliaryBall = null

  //模型半径

  radius = null

  //模型原始矩阵

  orgModelMatrix = null

  //是否允许旋转

  rotateEnable = null

  //是否允许移动

  moveEnable = null

 

  constructor(viewer, model) {

    this.viewer = viewer

    this.model = model

    this.rotateEnable = false

    this.moveEnable = false

    this.orgModelMatrix = this.model.root.transform.clone(new Cesium.Matrix4())

    this.position = Cesium.Matrix4.getTranslation(model.root.transform, new Cesium.Cartesian3())

    this.primitives = new Cesium.PrimitiveCollection()

    this.viewer.scene.primitives.add(this.primitives)

 

    // 创建平移轴

    this._createRod()

    // 旋转平移轴

    this._rotationRod()

    // 添加平移轴

    this._addRod()

 

    // 创建旋转轴

    this._createSphereAxis()

    // 旋转旋转轴

    this._rotationSphereAxis()

    // 添加旋转轴

    this._addSphereAxis()

 

    // 添加辅助球

    this.auxiliaryBall = {

      show: false

    }

 

    this.addAuxiliaryBall((this.radius * 2) / 3, Cesium.Color.RED.withAlpha(0.1))

    this._initEventManager()

 

    // 添加监听器

    this._addListener()

  }

 

  //复原model

  resetModel() {

    this.model.root.transform = this.orgModelMatrix

    this._resetMaterial()

  }

 

  //初始化监听

  _initEventManager() {

    this.viewer.eventManager = new EventManager(this.viewer)

  }

 

  // 添加监听器

  _addListener() {

    this.viewer.eventManager.addEventListener(EventConstant.LEFT_DOWN, this._clickListener)

    this.viewer.eventManager.addEventListener(EventConstant.LEFT_UP, this._clickUpListener)

    this.viewer.eventManager.addEventListener(EventConstant.MOUSE_MOVE, this._moveListener)

  }

 

  // 清除操纵杆, 监听器

  destroy() {

    if (this.primitives) {

      this.primitives.removeA

  • 7
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值