【问题标题】:change axis of rotation改变旋转轴
【发布时间】:2018-03-28 23:00:11
【问题描述】:

我正在使用Transform tutorial 的示例代码进行旋转和位置更改。我面临几个问题。

  1. 我想对门窗进行旋转。当前旋转轴通过中心。如何更改从通过其侧面的轴旋转对象。

  2. 对于位置更改 > 当我更改位置时,可以说是任何方向的窗口,它会移动,但在墙上可见。我希望它在窗户与墙壁碰撞时隐藏。

【问题讨论】:

    标签: autodesk-forge autodesk-viewer


    【解决方案1】:

    1/ 这里是一个代码 sn-p,它说明了如何旋转元素(片段),更完整的示例请看这篇文章:Rotate Components Control for the Viewer

    rotateFragments (model, fragIdsArray, axis, angle, center) {
    
      var quaternion = new THREE.Quaternion()
    
      quaternion.setFromAxisAngle(axis, angle)
    
      fragIdsArray.forEach((fragId, idx) => {
    
        var fragProxy = this.viewer.impl.getFragmentProxy(
          model, fragId)
    
        fragProxy.getAnimTransform()
    
        var position = new THREE.Vector3(
          fragProxy.position.x - center.x,
          fragProxy.position.y - center.y,
          fragProxy.position.z - center.z)
    
        position.applyQuaternion(quaternion)
    
        position.add(center)
    
        fragProxy.position = position
    
        fragProxy.quaternion.multiplyQuaternions(
          quaternion, fragProxy.quaternion)
    
        if (idx === 0) {
    
          var euler = new THREE.Euler()
    
          euler.setFromQuaternion(
            fragProxy.quaternion, 0)
    
          this.emit('rotate', {
            dbIds: this.selection.dbIdArray,
            fragIds: fragIdsArray,
            rotation: euler,
            model
          })
        }
    
        fragProxy.updateAnimTransform()
      })
    }
    

    2/ 当你变换几何体时,你只是在移动三角形,没有内置逻辑会隐藏组件,因为它们重叠,你需要自己实现。您应该能够找到计算两个网格是否相交(三角形-三角形相交算法)的 Three.js 代码,并针对您正在移动的组件和周围的所有墙壁运行该代码。这里有一些可以让你走上正轨的东西:How to detect collision in three.js?

    希望有帮助

    【讨论】:

      猜你喜欢
      • 2019-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-09
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多