Trackball在我的three.js程序以及onMouseClick和onMouseUp事件侦听器中运行得很好。我使用以下线路启用Trackball:-
controls = new THREE.TrackballControls( scene01camera02 , DOM_container);但是onMouseDown事件侦听器无法工作。
如果我禁用trackball (通过注释掉上面所示的代码行)并禁用任何其他相关代码,那么onMouseDown可以正常工作。
有什么方法同时使用onMouseDown和Trackball控制吗?
原因是,当鼠标向下的事件发生时,我可以在屏幕上检测它发生的位置,然后切换controls变量,这样Trackball就可以控制A固有的scene_camera_container。
In HTML
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<div id="ThreeJScontainer" style="position: absolute; left:0px; top:0px"></div>
In F_Init()
renderer = new THREE.WebGLRenderer( {antialias:true} );
DOM_container = document.getElementById( 'ThreeJScontainer' );
DOM_container.appendChild( renderer.domElement );
renderer.setSize( window.innerWidth, window.innerHeight );
controls = new THREE.TrackballControls( scene01camera02 , DOM_container);
document.addEventListener( 'mousemove', onDocumentMouseMove, false ); //works OK
document.addEventListener( 'mousedown', onDocumentMouseDown, false );
document.addEventListener('click', SOW_onDocumentMouseClick, false); //works OK
//in SOW_onDocumentMouseClick event handler
// I reset the controls to point to a new scene_camera according to the viewport clicked on.
//Example:-
controls = new THREE.TrackballControls( scene01camera01 , DOM_container);
//if onDocumentMouseDown was working as I expected I would do the resetting in there
In F_Update()
controls.update();
In F_Render()
renderer.setViewport( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
renderer.clear();
//...BOTTOM STRIP (DASHBOARD)
renderer.setViewport( bottomPanelXmin, bottomPanelYmin, bottomPanelWidth, bottomPanelHeight );
renderer.render( scene02, scene02camera04 );
// etc
// etc for other "Panels" (my name for viewports)示例原型运行于:- VP.html (最好在Chrome或Opera中运行,在Firefox中存在对齐问题)。
发布于 2016-02-03 10:51:40
我知道这是老生常谈,但目前还没有人回答这个问题,但我最近遇到了同样的问题。
在container.append(renderer.domElement);初始化THREE.TrackballControls( camera, renderer.domElement );之前,确保已执行THREE.TrackballControls( camera, renderer.domElement );
发布于 2017-07-06 02:48:56
我发现trackball控件模块假设一个动画循环正在运行,但在我的例子中,并非如此。在处理事件时,我需要修改代码以调用_this.update(); (几乎每次它调用_this.dispatchEvent时都是如此,例如在mousewheel和其他事件处理函数的末尾)。
发布于 2020-06-04 06:26:16
对于有此问题的其他任何人:简单地编辑TrackballControls.js并删除
function mousedown( event ) {函数。这样,所有进一步鼠标向下的事件侦听器都会保持激活。
https://stackoverflow.com/questions/18813481
复制相似问题