Jump to content

How to prevent page scrolling while manipulating webgl by touch events


Vousk-prod.
 Share

Recommended Posts

Hello you,

When my WebGL canvas is in the middle of a long HTML page, the touch events which rotate the camera also scroll the HTML page.

I know the CSS command "touch-action: non" applied on canvas should prevent this behaviour, but this line has no effect in the mobile browsers I tested (android default browser, Firefox, Chrome beta).

 

Do you know how to prevent the page from scrolling when user touches the canvas (but still rotating the camera) ?

Link to comment
Share on other sites

Up, please.

 

Knowing that I'm using a standard ArcRotateCamera and my code to attach control is simply :

orbitalCamera.attachControl(canvas, true);

(true option is to be able to scroll the website with the mousewheel)

 

how can I use preventDefault method to prevent web page scrolling while manipulating something in the canvas, but still maintaining the ability to scroll the web page when user swipes his finger outside the canvas ?

(for now, when user rotates the camera with touch events, the whole web page is scrolling up and down at the same time, not very convenient...)

 

Can I do this simply there, or do I need to change some code in ArcRotateCamera or somewhere else ?

Link to comment
Share on other sites

Sorry, I'm pretty new to html5 and javascript concepts, I'm certainly missing some obvious things but when I do :

<script src="hand.minified-1.3.4.js"></script><script src="babylon.1.10.0.js"></script><script src="babylon.arcRotateCamera.js"></script>
var engine = new BABYLON.Engine(canvas, true);(...)BABYLON.SceneLoader.Load(objectPath, babylonObjectName, engine, function (scene) {scene.executeWhenReady( function () {(...)   var orbitalCamera = new BABYLON.ArcRotateCamera("CameraOrbit", (Math.PI * cam_startRoll / 180), (Math.PI * cam_startPitch / 180), 8, targetCam, scene);   orbitalCamera.attachControl(canvas, false);

I get :

 

TypeError: this.getEngine is not a function - babylon.arcRotateCamera.js:83

 

Concerned lines in arcRotateCamera :

ArcRotateCamera.prototype.attachControl = function (element, noPreventDefault) {            var _this = this;            var previousPosition;            var pointerId;            if (this._attachedElement) {                return;            }            this._attachedElement = element;line 83     var engine = this.getEngine();(...)

What is the problem ?

Link to comment
Share on other sites

I tried to do what you suggest :

 

I replaced each occurrence of ArcRotateCamera by ArcRotateCamera2 in a babylon.arcRotateCamera2.js.

I included this new file in HTML and instanciated my orbital camera with new BABYLON.ArcRotateCamera2(...)

 

but exact same error in console...

 

It would be interesting for me to manage to solve this (for my own understanding of javascript behaviours), but I have many other things to do so for now I think I will simply wait for the next babylon release containing your fix.

Link to comment
Share on other sites

  • 2 weeks later...

I'm now using BJS 1.11, where wheel event is attached to element and not to window anymore in arcRotateCamera, but there still are problems :(

 

Little recap :

  •  orbitalCamera.attachControl(canvas, false);

- on PC : interactions inside canvas are correct (we can rotate with mouse drag and zoom with mouse wheel) but mouse wheel does not scroll html page (neither inside nor outside canvas) and wheel outside canvas also zoom the camera

- on touch devices : everything is ok, we can scroll html page with swipes outside the canvas and rotate camera with swipes inside the canvas (without scrolling html page)

 

( test scene with attachControl set to false )

 

  •  orbitalCamera.attachControl(canvas, true);

- on PC : interactions inside canvas are correct (we can rotate with mouse drag and zoom with mouse wheel) and mouse wheel outside canvas scrolls the html page, but mouse wheel outside canvas also zoom the camera

- on touch devices : swipes outside canvas scroll the html page, swipes inside canvas also scroll html page and rotate camera on randomly wrong axes (in fact, on vertical swipes sometimes the way the camera rotates is ok, sometimes it's inverted, and on horizontal swipes it seems that there is a conflict as if the camera wanted to turn simultaneously both ways, resulting in not rolling the scene at all or very little, in one or other way randomly)

 

( test scene with attachControl set to true)

Link to comment
Share on other sites

(I know that to prevent zooming I can specifiy camera's lower and upper radius limits, but I need to be able to zoom inside canvas, and also this wouldn't fix the fact that swipes to rotate camera on touch devices also scroll html page)

Link to comment
Share on other sites

  • 3 years later...
On 01/05/2014 at 2:36 AM, Deltakosh said:

you then use orbitalCamera.attachControl(canvas, false);

--> I add this Problem with my UniversalCamera : The arrows keys moved both:

- the 3D Camera forward in my 3D scene (in may 3D canvs)  (good)

- But also the html panel up and down, thus the 3D-canves moved up ans down (bad).

 

And,as you said I changed this line :

  orbitalCamera.attachControl(canvas, true);

to

orbitalCamera.attachControl(canvas,

On 01/05/2014 at 2:36 AM, Deltakosh said:

you then use orbitalCamera.attachControl(canvas, false);

 

false means that the canvas won't transmit to window events handle by the camera but only INSIDE the canvas

);

 

And now When I have the focus on my 3D-canvas, the arrows keys does not move the panel html-up or down anymore.

This is wonderfull !

Tanks for the tip !

 

 

T

On 01/05/2014 at 2:36 AM, Deltakosh said:

 

 

 

 

false means that the canvas won't transmit to window events handle by the camera but only INSIDE the canvas

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...