jeromeetienne / threex.domevents

three.js extension which provide dom events inside your 3d scene.
http://jeromeetienne.github.io/threex.domevents/examples/demo.html
MIT License
246 stars 113 forks source link

Programmatically click on object #21

Open ernistkg opened 8 years ago

ernistkg commented 8 years ago

Is there any way to programmatically click object with domEvent plugin or pure THREEjs?

weiserhei commented 8 years ago

mesh._3xDomEvent.clickHandlers[ 0 ].callback();

jeromeetienne commented 8 years ago

this may work... but wow this is kludgy :)

jpdesignerrio commented 5 years ago

Hey there! EventListener not working on mobile only (Android and Chrome for Windows using mobile view [developer tools]). Curiously, when I change from 'click' to 'mouseover', and I click and drag, it recognizes the "mouse over"

jpdesignerrio commented 5 years ago

I saw in threex.domevents.js the code:

this._domElement.addEventListener( 'touchmove'  , this._$onTouchMove    , false );
this._domElement.addEventListener( 'touchstart' , this._$onTouchStart   , false );
this._domElement.addEventListener( 'touchend'   , this._$onTouchEnd , false );

this is not in README ...

So I change 'click' to 'touchstart' and it works. 👍

jpdesignerrio commented 5 years ago

In web and mobile handle click and touch are different. So, I do that:

var mouseEventHandle = 'click';
if('ontouchstart' in document.documentElement === true)
    mouseEventHandle = 'touchstart';

domEvents.addEventListener(meshObject, mouseEventHandle, callbackFunction());

Hope help someone!