本文介绍了Three.js& Dat.gui-TrackballControls renderer.domElement禁用旋转和平移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个非常简单的three.js(r73)场景中使用dat.gui,但是在将 renderer.domElement添加到trackballControls初始化后,出现了旋转和平移不起作用的问题。缩放按预期方式工作。

I am trying to use dat.gui with a very simple three.js (r73) scene but am running into an issue with rotate and pan not working after adding "renderer.domElement" to the trackballControls initialization. Zoom works as expected.

没有renderer.domElement,我可以使用旋转,缩放,平移功能,但是单击dat.gui界面滑块会闩锁,这是只是烦人而不起作用。此处描述的问题:。

Without renderer.domElement, I get a working rotate, zoom, pan functionality but the dat.gui interface sliders "latch" when clicked, which is just annoying and not functional. The issue as described here: Issue while using dat.GUI in a three.js example.

在此处查看了更多信息,但没有找到很好的解决方法:

Looked over more info here but didn't see a great resolution: https://github.com/mrdoob/three.js/issues/828

也发现了此问题。定义容器元素aka renderer.domElement不起作用。如果场景不旋转,则无法在画布区域之外单击。

Also found this issue. Defining the container element aka renderer.domElement doesn't work. I am unable to click within outside of the canvas area without the scene rotating.Allow mouse control of three.js scene only when mouse is over canvas

最近有人遇到过同样的事情吗?如果是这样,可能有什么解决方法?感谢所有帮助。

Has anyone run into the same thing recently? If so, what workarounds are possible? Any help is appreciated.

-

代码设置如下:

// setup scene
// setup camera
// setup renderer
// ..

var trackballControls = new THREE.TrackballControls(camera, renderer.domElement);
trackballControls.rotateSpeed = 3.0;
trackballControls.zoomSpeed = 1.0;
trackballControls.panSpeed = 1.0;

// ..

// render loop

var clock = new THREE.Clock();

function render() {
  stats.update();
  var delta = clock.getDelta();
  trackballControls.update(delta);

  requestAnimationFrame( render );
  renderer.render( scene, camera );
}


推荐答案

我用这篇文章的帮助:。

I debugged the issue with the help of this post: Three.js Restrict the mouse movement to Scene only.

显然,如果在初始化trackballControls之后追加renderer.domElement子级,则它对renderer.domElement对象一无所知。如前所述,这对dat.gui也有一些奇怪的事情。

Apparently, if you append the renderer.domElement child after initializing the trackballControls, it doesn't know anything about the renderer.domElement object. This also does something strange to dat.gui as described previously.

基本上,请确保以下行:

Basically, make sure this line:

document.getElementById("WebGL-output").appendChild(renderer.domElement);

在此行之前出现:

var trackballControls = new THREE.TrackballControls(camera, renderer.domElement);

这篇关于Three.js& Dat.gui-TrackballControls renderer.domElement禁用旋转和平移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 07:42