Three.js Mobile iOS v8.4如何将touchEvents视为鼠标事件?

Three.js Mobile iOS v8.4如何将touchEvents视为鼠标事件?,mobile,ios8,three.js,Mobile,Ios8,Three.js,根据webgl,iOS版本8.1至8.4的Safari和Chrome浏览器支持webgl 从iPad(运行iOS 8.4的移动版)上看,似乎很多都运行正常。例如,在此轨迹球通过(手指)触摸和拖动工作。然而,我无法让它对手指敲击或手指触摸/按住/释放鼠标点击做出反应(公平地说,这在我的Android 4.1设备上也不起作用)。这在iPad上根本不运行(但在我的Android 4.1设备上运行良好) 令人惊讶的是,finger tap-->(解释为-->mouseclick)确实可以按预期工作,但不

根据webgl,iOS版本8.1至8.4的Safari和Chrome浏览器支持webgl

从iPad(运行iOS 8.4的移动版)上看,似乎很多都运行正常。例如,在此轨迹球通过(手指)触摸和拖动工作。然而,我无法让它对手指敲击或手指触摸/按住/释放鼠标点击做出反应(公平地说,这在我的Android 4.1设备上也不起作用)。这在iPad上根本不运行(但在我的Android 4.1设备上运行良好)

令人惊讶的是,finger tap-->(解释为-->mouseclick)确实可以按预期工作,但不幸的是,它使用了Three.js(2013年的r60)的旧版本(不受支持)

因此,我的问题是:“有没有一种方法可以使用最新版本的Three.js编写应用程序,从而将手指轻触移动iOS(8.4)设备视为鼠标点击?

编辑


在四处搜寻之后,我发现了一个有用的信息来源。

这个解决方案只是一个解决方案,但它为我做了这项工作。它拦截并处理Android 4.1和iPad/iOS 8中的touchstart事件

“官方”的方式似乎是捕捉触摸事件,然后创建鼠标点击事件并发送它。然后,我们的点击事件侦听器应拾取合成点击事件,并将其传递给所选的点击处理程序函数。但我无法让它工作,以便点击处理程序接收触摸的客户端x,y坐标

因此,我只需在touch catcher函数中处理触摸事件(在我的例子中,“touchstart”是我感兴趣的全部),然后提取触摸客户端的x、y坐标,并对其进行处理,然后将结果传递给触摸位置处理程序(鼠标单击处理程序将传递到该处理程序)


我还没有测试所有的设备,但是你说的演示似乎没有任何与触摸事件相关的特殊代码。它使用OrbitControls和“mousedown”事件监听器。
  //... You need to put this line, or similar, in F_Init:-

 document.addEventListener( 'touchstart', F_event_Touch_onDocument_handle, false ); 

//===========================================================================================

function  F_event_Touch_onDocument_handle( evt ) 
{

  evt.preventDefault();  //... this prevents window from sliding about.

  //------------------------------------------------------------------------------------

  if (evt.touches.length > 1 || (evt.type == "touchend" && evt.touches.length > 0))
    //... if more than 1 touch detected then ignore.
    return;

    //------------------------------------------------------------------------------------

  var reaction_type = null;
  var touch = null;

  //... see here for event types  http://www.w3schools.com/jsref/dom_obj_event.asp  

  switch (evt.type) 
  {
    case "touchstart": 
      touch = evt.changedTouches[0]; //... specify which touch for later extraction of XY position values.
      reaction_type = "onclick"; 
      break;
    case "touchmove": // I don't use this
      reaction_type = "mousemove";
      touch = evt.changedTouches[0];
      break;
    case "touchend":  // I don't use this     
      reaction_type = "mouseup";
      touch = evt.changedTouches[0];
      break;
  }

  if (reaction_type == "onclick")
  {
        //----------------------------------------------------------------

        // METHOD A (WORKAROUND)  //
        // Works OK
        // instead of dispatching a click event and letting our mouseClick event handler catch it
        //  we determine the touch x and y coordinates
        //  then pass them to the next function in the chain after the mouseClick event handler.

        thisTouch.x =   ( touch.clientX / window.innerWidth ) * 2 - 1;
        thisTouch.y = - ( touch.clientY / window.innerHeight ) * 2 + 1;

        xxx = F_see_if_Click_was_on_a_ThreeJS_Object( thisTouch.x, thisTouch.y );

        //----------------------------------------------------------------

        // METHOD B (OLD MOZILLA) //
        //  copied from "Handling Clicks" tutorial: https://developer.mozilla.org/en-US/docs/Web/API/Touch_events#Example
        // * does not work, our Click event handler does not pickup touch.clientX and touch.clientY as numbers.
        // * initMouseEvent is deprecated... see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/initMouseEvent 
        if {1 == 2)
        {
            var newEvt = document.createEvent("MouseEvents");

            newEvt.initMouseEvent( reaction_type, true, true, evt.originalTarget.ownerDocument.defaultView, 0, touch.screenX, touch.screenY, touch.clientX, touch.clientY, evt.ctrlKey, evt.altKey, evt.shiftKey, evt.metaKey, 0, null);

            evt.originalTarget.dispatchEvent(newEvt);
        }

      //----------------------------------------------------------------

    } // if (reaction_type == "onclick").
}
//... EOF F_event_Touch_onDocument_handle().

//=================================================================