Jump to content

Scene.pick() problem


Nico
 Share

Recommended Posts

Hi guys,

 

I have been away for a long time, and I have now a little more time to play again with BabylonJS.

I am using RenderPipeline, and I think there is a problem with this feature  :unsure:

 

When I try to use scene.pick there is a shift (I don't know what is the best word to describe this) between my pointer positions and what the pick function returns, I have no problem if I don't use RenderPipeline (so I think the pointer positions values I am sending to the pick function are good).

 

After some investigations I think I found something interesting, inside scene.pick BJS calls createPickingRay function, and I found this code inside :

// Moving coordinates to local viewport worldx = x / this._engine.getHardwareScalingLevel() - viewport.x;y = y / this._engine.getHardwareScalingLevel() - (this._engine.getRenderHeight() - viewport.y - viewport.height);

To get "y" value, it calls engine.getRenderHeight(), here is the code of this function :

public getRenderHeight(): number {    if (this._currentRenderTarget) {        return this._currentRenderTarget._height;    }    return this._renderingCanvas.height;}

So it is returning the height of the renderTarget if it exists, I use in the RenderPipeline so it exists in this case, but I can't use my screen size here (because of the non power of two texture size limitation in WebGL) so I manually set a 2048x2048 texture while my screen resolution is 1920x1080.

 

If I use comment only the getRenderHeight part, I still have a shift, so the getRenderWidth is used too for the picking, but I didn't try to locate this, since using renderingCanvas width and height seems to solve the problem.

 

These parts are causing this shift between my mouse click and the picking result, when I comment this code like that it seems to work :

public getRenderWidth(): number {    /*if (this._currentRenderTarget) {        return this._currentRenderTarget._width;    }*/    return this._renderingCanvas.width;}public getRenderHeight(): number {    /*if (this._currentRenderTarget) {        return this._currentRenderTarget._height;    }*/    return this._renderingCanvas.height;}

I don't know how to solve this problem in a clean way, but I have located the problem  :D

 

Does the pick function should always use the canvas width and height instead of using RenderTarget size ?

 

So in this case a parameter can be sent through this two functions to force to return the canvas width/height instead of renderTarget ones, or should it use directly the "getRenderingCanvas" method to get the canvas, and then retrieve its width and height ?

Link to comment
Share on other sites

Thanks for the answer!  

I tried to call the pick function inside the callbacks (beforeRender, or afterRender), and the result is the same, there is always a WebGLTexture reference inside the _currentTargetRender  :unsure:

Link to comment
Share on other sites

Here it is !

I have to add a line to the bjs version to make the RenderPipeline works.

 

Inside the PostProcessRenderPass constructor, the _renderList property was not setted, so I added this line :

this._renderList = renderList;

You will find my custom bjs version inside the attached zip.

 

I put particles to easy show the pointer position (in the 3D world).

There is no problem if the renderPipelineManager has not yet attached pipeline to camera, the mouse pointer and the particle source are at the "same position", but when I attach the camera to the pipeline, there is this shift  :wacko:

 

You just have to comment the line 46 to see the difference :

postProcessRenderPipelineManager.attachCamerasToRenderPipeline("standardPipeline", camera, false);

I still have a WebGL warning, but I don't know where it come from  :unsure:

 

INVALID_ENUM: activeTexture: texture unit out of range

PostProcesses.zip

Link to comment
Share on other sites

Hello !

 

I have done a repro case using BabylonJS Playground, you can see it here :  http://www.babylonjs...d.com/#2DWHRN#3

 

In this exemple I am not using the pick function, but the engine.getRenderHeight/Width function to show where is the problem.

 

Since the pick function use this function too, the shift is the same in my exemple, so the particles source is the position you will get using the pick function.

 

Edit : I have added picking on mouseup event.

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...