Three.js Mobile iOS v8.4 how to treat touchEvents as mouseEvents? - mobile

According to caniuse.com webgl is supported by Safari and Chrome browsers for iOS versions 8.1 thru 8.4.
From an iPad (which runs the mobile version of iOS 8.4) it seems that many of the official Three.js webgl demos run alright. For example on this draggable cubes demo the trackball works by (finger) touch & drag. However I cannot get it to react to a finger tap, or finger touch/hold/release as a mouseclick (to be fair nor does that work on my Android 4.1 device). This interactive voxel painter doesn't run at all on the iPad (but works fine on my Android 4.1 device).
Surprisingly this three.js mouseclick demo by Lee Stemkoski does work as desired in terms of finger tap --> (interpreted as) --> mouseclick, but unfortunately it uses an old (unsupported) version of Three.js (r60 from year 2013).
So my question: "Is there a way to code an app using latest version of Three.js so that a finger tap on a mobile iOS (8.4) device is treated as a mouse-click?
EDIT
After hunting around a bit I found a useful source of information on processing touch events.

This solution is just a workaround but it does the job for me. It intercepts and handles touchstart events in Android 4.1 and iPad/iOS 8.
The "official" way seems to be to catch the touch event and then create a mouse click event and dispatch it. The synthetic click event should then be picked up by our Click event listener and passed to the chosen click handler function. But I cannot get it to work so that the click handler receives the client x,y coordinates of the touch.
So I simply handled the touch event in the touch catcher function (in my case 'touchstart' is all I am interested in), and extracted the touch client x,y coordinates, and processed them, and passed the results to a touch position handler (which is where the mouse click handler would have passed on to).
//... 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().
//=================================================================

Related

Updating WPF UI with BeginInvoke for Highspeed camera

I use ConcurrentQueue<Action> FrameActions where I add image frames that come from a high-speed camera - (60-90 FPS)
The Action contains methods to update the WritableBitmap image in UI.
For updating frames I use a separate thread which code is below
void FrameUIThread()
{
do
{
if (FrameActions.TryDequeue(out Action currentAction))
{
Application.Current.Dispatcher?.BeginInvoke(DispatcherPriority.Loaded, currentAction);
}
else
{
// DoEvents
Application.Current.Dispatcher?.Invoke(DispatcherPriority.Loaded, new Action(() => { }));
}
} while (true);
}
There was a problem that sometimes WritableBitmap is updated and a new image comes in, but the rest of the application - (all the buttons, counters and stuff are completely blocked, I can't click anything).
Found that using DoEvents - helps in this situation.
But now the flow of images is not smooth, but interrupted and goes spurts in some moments of time.
Is there any way to solve this problem?
Or could there be a better solution?

From iOS Objective-C code and Android Java code to a Codename One PeerComponent

At the page https://www.wowza.com/docs/how-to-build-a-basic-app-with-gocoder-sdk-for-ios there are the following examples:
if (self.goCoder != nil) {
// Associate the U/I view with the SDK camera preview
self.goCoder.cameraView = self.view;
// Start the camera preview
[self.goCoder.cameraPreview startPreview];
}
// Start streaming
[self.goCoder startStreaming:self];
// Stop the broadcast that is currently running
[self.goCoder endStreaming:self];
The equivalent Java code for Android is reported at the page https://www.wowza.com/docs/how-to-build-a-basic-app-with-gocoder-sdk-for-android#start-the-camera-preview, it is:
// Associate the WOWZCameraView defined in the U/I layout with the corresponding class member
goCoderCameraView = (WOWZCameraView) findViewById(R.id.camera_preview);
// Start the camera preview display
if (mPermissionsGranted && goCoderCameraView != null) {
if (goCoderCameraView.isPreviewPaused())
goCoderCameraView.onResume();
else
goCoderCameraView.startPreview();
}
// Start streaming
goCoderBroadcaster.startBroadcast(goCoderBroadcastConfig, this);
// Stop the broadcast that is currently running
goCoderBroadcaster.endBroadcast(this);
The code is self-explaining: the first blocks start a camera preview, the second blocks start a streaming and the third blocks stop it. I want the preview and the streaming inside a Codename One PeerComponent, but I didn't remember / understand how I have to modify both these native code examples to return a PeerComponent to the native interface.
(I tried to read again the developer guide but I'm a bit confused on this point).
Thank you
This is the key line in the iOS instructions:
self.goCoder.cameraView = self.view;
Here you define the view that you need to return to the peer and that we can place. You need to change it from self.view to a view object you create. I think you can just allocate a UIView and assign/return that.
For the Android code instead of using the XML code they use there you can use the WOWZCameraView directly and return that as far as I can tell.

Finding eye position on camera using camera2 api android

Below are my code snippet to get faces on camera using camera2 api. In that I am able to get eye position only for few devices. Rest of them returning NULL values. Is there a way to find eye position in camera using camera2 api?
Integer mode = result.get(CaptureResult.STATISTICS_FACE_DETECT_MODE);
Face[] faces = result.get(CaptureResult.STATISTICS_FACES);
if(faces != null && mode != null) {
if (faces.length > 0) {
Rect rect = faces[0].getBounds();
Log.e("tag", "faces : leftEye" + faces[0].getLeftEyePosition());
Log.e("tag", "faces : RightEye" + faces[0].getRightEyePosition());
}
}
Face detection is a feature that needs to be supported by the underlying camera module and is not related with Android frameworks. Hence your code works in certain devices and fails in rest. I believe Android framework doesn't have any explicit API for Face Detection.

How to avoid memory leak in code of Win 7 - Onscreen keyboard while clicking in textbox inside web browser control in wpf (C#)

I am developing WPF - Web browser control based kiosk application.
I have implemented the feature like when somebody clicks on any textbox inside the page rendered in wpf web browser control then onscreen keyboard will open.
But the code which I have implemented is causing the continuous memory leak.
please find sample files here
Please refer below document to get more detail on issue.
for more detail on issue click here
whenever you will continuously browse www.google.com for 15 minutes in wpf web browser control then memory utilization of application keeps on increasing and it will never decrease, you can see increase in memory usage from task manager also.
please wait till 15 - 20 seconds after clicking inside the textbox, after 15-20 seconds onscreen keyboard will display.
Please help to avoid memory leak.
Thanks,
Pritesh
public static void LaunchOnScreenKeyboard()
{
try
{
//This is used to get the osk.exe process and enable On screen keyboard
var processes = Process.GetProcessesByName("osk").ToArray();
if (processes.Any())
return;
var keyboardManagerPath = "osk.exe";
Process.Start(keyboardManagerPath);
}
catch (Exception ex)
{
}
}
This Method is also GetProcessesByName(processname)utilizing more memory
This line of code is causing the memory leak, when I comment this code then memory leak stops.
#region On screen keyboard
//Get the HTML of current page and cast as HTMLDocument
HTMLDocument document = (mshtml.HTMLDocument)webBrowser.Document;
//For each loop to access all the HTML tags in the current page
foreach (IHTMLElement links in document.all)
{
//If condition to access all the Input, Iframe and TextArea in the current page and attach focus event to it
if (links.tagName.Contains("INPUT") || links.tagName.Contains("IFRAME") || links.tagName.Contains("TEXTAREA"))
{
HTMLInputTextElement textinput = links as HTMLInputTextElement;
if (textinput != null)
{
HTMLInputTextElementEvents_Event handler = textinput as HTMLInputTextElementEvents_Event;
if (handler != null)
{
handler.onfocus += new HTMLInputTextElementEvents_onfocusEventHandler(delegate()
{
IHTMLElement2 pwInput = null;
pwInput = (IHTMLElement2)textinput;
pwInput.focus();
//This calls the LaunchOnScreenKeyboard() to show On screen keyboard on the screen when Input, Iframe and TextArea tags are present in current page
KeyboardManager.LaunchOnScreenKeyboard();
});
}
}
}
}
#endregion

Manipulation and Touch events not firing, but mouse events do?

I have a Samsung LD220Z multi touch monitor, and when I'm experimenting with some WPF and touch features the touch events arent firing. The mouse down event seems to be firing however.
Does this mean that I have to take into account that not all touch screen behave the same, and how do I get the touch inputs on my screen? I've tried the Windows 7 Touch pack that microsoft released. And the multi touch features seems to work there.
Any suggestion on how to proceed with this?
Event touchstart WORKS but touchend not. You can use onmouseup="SOMEfun()"
Even the Samsung Galaxy 3 is a problem with the trigger event.
Add the first event and thay will be working on but
Two scenario :
1)first add onmouseup and than tauchstart or better
2)check mobile or desktop and than add proper events
You can use my detectbrowser function , its very nice (give a name of browser type like mobile_chrome_android_tablet or firefox_desktop , safari_ipad)
Make NOMOBILE global , you can simply replace var NOMOBILE =0; with window["NOMOBILE"]=0;
download browser and device detector :
detect browser and device also class
Class name is DETECTBROWSER()
(on first line in script)
var BROWSER = new DETECTBROWSER()
Check this BROWSER.NAME
This is even crazy't script . Track 10 fingers at same time (in canvas2d)
link : https://github.com/zlatnaspirala/multi-touch-canvas-handler
example for 1)
document.getElementById('myCanvas').addEventListener('touchstart', function(event) {
event.preventDefault();
var touch = event.touches[0];
/* Avatar go left */
if (touch.pageX < 235) {
if (backgroundX < 0){
left = 1;
}
/* Avatar go right */
if (touch.pageX > 470) {
right=1;
}
/* Avatar go lower distance */
if (touch.pageX > 235 && touch.pageX < 470 && touch.pageY >250 ) {
distance--;
}
/* Avatar go to high distance */
if (touch.pageX > 235 && touch.pageX < 470 && touch.pageY <250 ) {
distance++;
}
} ,false);
// solution for touchend
function ENDoff(){
if (moveLEFT==1) { moveLEFT=0; }
if (moveRIGHT==1) { moveRIGHT=0; }
}
HTML CODE
<canvas id="myCanvas" width="480" height="960" onmouseup="touch_UP();"></canvas>

Resources