garidan Posted August 27, 2015 Share Posted August 27, 2015 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 Quote Link to comment Share on other sites More sharing options...
garidan Posted August 27, 2015 Author Share Posted August 27, 2015 The "working" camera is the last one pushed as active Quote Link to comment Share on other sites More sharing options...
garidan Posted August 27, 2015 Author Share Posted August 27, 2015 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 positionUsing 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 ? Quote Link to comment Share on other sites More sharing options...
garidan Posted August 27, 2015 Author Share Posted August 27, 2015 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 ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 27, 2015 Share Posted August 27, 2015 Sounds good to me:) garidan 1 Quote Link to comment Share on other sites More sharing options...
garidan Posted September 10, 2015 Author Share Posted September 10, 2015 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;} Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.