I’m currently developing a 3D editor using Babylon.js, where users can drag and drop landmarks onto meshes. During this, I encountered an issue where the pickedPoint (from scene.pick()) seems to significantly differ depending on the zoom level of the camera, even when dropping on the exact same screen position (i.e., same canvas pixel coordinate).
Context
I’m using scene.pick(x, y) with coordinates derived from a DragEvent.
The red dot at (0,0,0) is a known mesh.
When dragging and dropping onto the center of the mesh, the pickedPoint differs significantly depending on the zoom level.
Why is there such a large difference in pickedPoint between zoom levels?
Is this a precision issue or camera-related ray generation problem?
How can I get consistent results regardless of zoom level for drag & drop?
Any advice or direction would be much appreciated. Thanks in advance!
When you change the camera zoom, any 2D points of the canvas will map to a different 3D points, except only 1 point, the one which is exactly at center of the camera. Are you picking the exact center ? If not, then the result is expected, I would say
Better would be to use
scene.pick(scene.pointerX, scene.pointerY)
To make sure you are using the right mouse coordinates
Your words and description do not give us any idea about the environment within the project you have implemented.
So you need to repro it and make it functional in a simple way.
Can you make a PG with add drag-and-drop function
I felt while making it, will the camera panning that moves the camera’s position have a lot of influence on the coordinates you get by clicking on the mouse pointer?
It doesn’t seem to be happening in this example pg, but I’m still having issues with my project.
I think we would be glad to help but your description of the issue is quite incomplete, for example when you say :
Without giving the “error”, impossible to answer to the “Why ?”
Also, I had a look at your PG, adding a cube target as debug on drop seems to be ok :
Did you try to use scene.pick(scene.pointerX, scene.pointerY) in your project ? As I said, it more reliable than any compute on the canvas object within a custom complex Dom…
Also, just a comment about your grid :
You could create this with a simple plane and use a Grid Material
I read the comments from the community and checked what’s wrong with my code,
I found the reason.
The reason is that within the dom video, canvas does not start at top and left at 0,0 but as in the image below
There’s about a top 50, a left 50, and the problem was using boundingClientRect() for the whole of the dom, not the canvas.
hmm..
When I heard what you said, I thought I could use that and applied it, but there was an error. Theoretically, it should be, but it’s weird not to.
Congratulations on solving the problem, but as @Tricotou said, it seems like the projected scene should have the same values, but if the size of the components on the left and top are changed a bit, will an error in the position values occur proportionally?
The event for drag is expected to have the same scene.pointerX and scene.pointerY values regardless of whether it is triggered on DOM, canvas, or engine.