有什么方法可以解决这个问题吗?
Short answer is "Yes, but it's not using a standard version OrbitControls.js".
请继续阅读我的详细推理....
我花了一些时间来查看 OrbitControls.js (r87)的源代码,考虑到实现增强功能的想法,该增强功能允许您提供可用作相机目标的可选第二点 .
然而,在探索代码之后,我认为这将是添加到标准公共版本的一个不好的功能 . OrbitControls有许多功能,例如限制视角,最小和最大旋转以及假设摄像机和轨道中心相同的小车距离 . 如果有第二个摄像机标签选项,则需要修改它们以使用轨道中心或摄像机目标,或者使用可配置参数来切换它使用的那个 . 这将增加数百个额外的代码行,使其更难理解,并且所有这些代码都非常适合 .
所以... The solution :
因为你正在构建一个技术工具,我怀疑你不关心有限的视角,距离或旋转所以如果我是你,我会将 OrbitControls.js 复制到你的项目中,将其重命名为 OrbitControls_customised.js 并进行所需的更改:
在 this.target 下面添加2个新参数,名为 this.cameraTarget 和 this.coupleCenters
// "target" sets the location of focus, where the object orbits around
this.target = new THREE.Vector3();
// "cameraTarget" is where the camera is looking (by default the same as target
this.cameraTarget = new THREE.Vector3();
// Whether the camera should be locked to the orbit center
this.coupleCenters = true;
在它指示相机看中心的线上......
scope.object.lookAt( scope.target );
...改变它,以便当coupleCenters为真时它只更新相机...
if( scope.coupleCenters ){
scope.cameraTarget = scope.target;
}
scope.object.lookAt( scope.cameraTarget );
现在,通过这些更改,您可以使用 onMouseDown 事件使用RayCasting来查找对象上的点,将 controls.decoupleCenters 设置为 false 并将 controls.target 设置为光线投射的交叉点/交叉点 . 然后 onMouseUp 事件将 controls.target 设置回 controls.cameraTarget 以允许它正常运行 .
我希望能回答你的问题,并为你提供一些粗略的路线图 .