Jump to content

Multi views and actionManager triggers


garidan
 Share

Recommended Posts

I have a multiview, 3 cameras and viewports, and switching from "old way" to manage actions to the actionmanager one.
I use ExecuteCodeAction with trigger OnLeftPickTrigger and it does activate an event only on one of the views, so one camera only.
RegisterAction has no camera parameter thus I would expect babylon manages the right camera for picking meshes, based on viewports and mouse coordinates, but it does not seem the case.
Any clue or suggestion?

 

Thanks

Link to comment
Share on other sites

OK, I see "cameraToUseForPointers" in source code of scene.....

this.cameraToUseForPointers = null; // Define this parameter if you are using multiple cameras and you want to specify which one should be used for pointer position

Using multiviews, and perhaps in other multi camera usecases, this cameraToUseForPointers should be dynamically determined, in my case based on pointer coordinates.
Any clue, or any idea for a patch/future enhancements ?


 

Link to comment
Share on other sites

I think the right place where I could override and change behaviour is _updatePointerPosition:
 

        Scene.prototype._updatePointerPosition = function (evt) {            var canvasRect = this._engine.getRenderingCanvasClientRect();            this._pointerX = evt.clientX - canvasRect.left;            this._pointerY = evt.clientY - canvasRect.top;            if (this.cameraToUseForPointers) {                this._pointerX = this._pointerX - this.cameraToUseForPointers.viewport.x * this._engine.getRenderWidth();                this._pointerY = this._pointerY - this.cameraToUseForPointers.viewport.y * this._engine.getRenderHeight();            }        };

Here I could change cameraToUseForPointers dynamically, with no side effects (?) right ?

Link to comment
Share on other sites

  • 2 weeks later...

OK, I did it this way:

var createScene = function() { BABYLON.Scene.prototype._updatePointerPosition = function (evt) {	var canvasRect = this._engine.getRenderingCanvasClientRect();        this._pointerX = evt.clientX - canvasRect.left;        this._pointerY = evt.clientY - canvasRect.top;	this.cameraToUseForPointers=getViewportCamera(this._pointerX, this._pointerY); }......
var getViewportCamera = function(x0,y0) {	var canvas =  engine.getRenderingCanvas();	// reverse y axis, apply scale -> xy origin in lower left corner	y = (perspectiveGlobalView.height - y0/engine.getHardwareScalingLevel());	x = x0/engine.getHardwareScalingLevel();        // logic hereafter depends on your cameras layout, code could be generalized here	// default camera	res = sideCamera;	if (x > perspectiveGlobalView.x && x < (perspectiveGlobalView.x+perspectiveGlobalView.width)) {		if (y > perspectiveGlobalView.y && y < (perspectiveGlobalView.y+perspectiveGlobalView.height))	{			res = camera;		}	} else if (x > topGlobalView.x && x < (topGlobalView.x+topGlobalView.width)) {		if (y > topGlobalView.y && y < (topGlobalView.y+topGlobalView.height))	{			res = topCamera;		}	}		return res;}
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...