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

support touchstart/touchend with domevents & linkify #12

Closed thelucre closed 8 years ago

thelucre commented 9 years ago

fixes #11

simonihmig commented 9 years ago

:+1: Anything preventing getting this merged?

mhicauber commented 8 years ago

I could use it for sure. Is there any merging planned ?

heyjoeway commented 8 years ago

This would be useful to me as well.

Ohar commented 8 years ago

Merge it please

jeromeetienne commented 8 years ago

Merged. thanks for your contributions

themushroomsound commented 7 years ago

Hi all, I'm trying to use this but I stumbled upon an issue: touchend events are not triggered either on my iPhone or in Firefox simulating a touch screen. Looking more closely, I see this line in THREEx.DomEvents.prototype._onTouchEvent :

if( domEvent.touches.length != 1 ) return undefined;

In Firefox (at least, can't debug on Safari iOS, no console...), a touchend event always carries 0 touch points and the function returns. Any ideas of a fix/workaround?

Thanks :)

Ohar commented 7 years ago

@themushroomsound I suppose you need to create a new Issue about that, aren`t you?

themushroomsound commented 7 years ago

@Ohar I don't know, this one is called "support touchstart/touchend" and it seems touchend is not supported, so I guess that makes this issue still relevent?

Anyway, I found out that the touchend event has a "changedTouches" property that remembers the pageX/Y of the touchstart event, so I modified the code like so:

THREEx.DomEvents.prototype._onTouchEvent    = function(eventName, domEvent)
{
    console.log("_onTouchEvent - touches: " + domEvent.touches.length);

    if (domEvent.touches.length != 1 && eventName != "touchend")
        return undefined;

    domEvent.preventDefault();
    var touches = eventName != "touchend" ? domEvent.touches : domEvent.changedTouches;
    var mouseX = +(touches[0].pageX / window.innerWidth) * 2 - 1;
    var mouseY = -(touches[0].pageY / window.innerHeight) * 2 + 1;
    this._onEvent(eventName, mouseX, mouseY, domEvent); 
}

Now both touchstart and touchend seem to work on firefox/iPhone. Not sure about potential side effects though.

Ohar commented 7 years ago

@jeromeetienne What do you think?