Closed thelucre closed 8 years ago
:+1: Anything preventing getting this merged?
I could use it for sure. Is there any merging planned ?
This would be useful to me as well.
Merge it please
Merged. thanks for your contributions
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 :)
@themushroomsound I suppose you need to create a new Issue about that, aren`t you?
@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.
@jeromeetienne What do you think?
fixes #11