javascript Threejs 在使用变换控制时禁用轨道相机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20058579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
threejs disable orbit camera while using transform control
提问by rastafermo
I have a scene with multiple meshes, each one of them associated to a different transformControl; in order to select different objects, I'm using raycasting techniques. I'm also using an orbit camera in order to navigate the scene.
我有一个包含多个网格的场景,每个网格都与不同的变换控件相关联;为了选择不同的对象,我使用了光线投射技术。我还使用轨道相机来导航场景。
Whenever I modify the position/rotation/scale of the selected object using transform control, I want to disable orbit camera, because sometimes while I'm clicking on a picker, I'm also picking on the background of the scene, so the orbit camera moves.
每当我使用变换控制修改所选对象的位置/旋转/缩放时,我想禁用轨道相机,因为有时当我点击选择器时,我也在选择场景的背景,所以轨道相机移动。
I'd like to stop this behavior and I've already tried to handle it with raycasting techniques, but it doesn't work.
我想停止这种行为,我已经尝试使用光线投射技术来处理它,但它不起作用。
回答by schlenger
Stumbled over this and thought it would be helpful to see the answer (credits to BuildingJarl):
偶然发现了这一点,并认为看到答案会有所帮助(归功于 BuildingJarl):
// if youre definition is like
var controls = new THREE.OrbitControls( camera );
// you can easily disable it by using
controls.enabled = false;
In my case I was using a UI overlay and I got issues with getting the focus to it. Disabling the controls solved my problems.
就我而言,我使用的是 UI 叠加层,但在获得焦点时遇到了问题。禁用控件解决了我的问题。
Greetings Mat
问候垫
回答by Stranger in the Q
Taken from three.js editor's code:
取自three.js 编辑器的代码:
var orbitControls= new THREE.EditorControls(camera, renderer.domElement);
orbitControls.addEventListener('change', render);
var transformControls = new THREE.TransformControls(camera, renderer.domElement);
transformControls.addEventListener('change', render);
transformControls.attach(mesh);
transformControls.addEventListener('mouseDown', function () {
orbitControls.enabled = false;
});
transformControls.addEventListener('mouseUp', function () {
orbitControls.enabled = true;
});