Picked point at wrong position

OS: windows 10
Browser: chromium 120 x64
GPU: nv gtx 1050 2gb
Version: 7.13.1
Desc: Using scene.pick to pick a point of a mesh loaded from a glb model, but the point is on the camera instead of on mesh.
Playground:

Expected:
Picked point (shown by a box in the playground) on the mesh
Actual:
Picked point at somewhere on the camera

screenrecording

Another playground (click to pick and create instance there):

new screenrecording

I can’t see any issue here. Red - no pick, Green - pick.

1 Like

To the point of your playground - the box is simply too large, which gives the wrong perspective. Try this:

glb load and pick | Babylon.js Playground (babylonjs.com)

1 Like

I saw a 15 km wide phone booth today on the forum :smiley:

@roland @RaananW
In the example, the size of the box is not some random fixed value, but computed from scene world extends, so the size should not be an issue here.
To futher confirm that, I’ve made a new playground here, which spawns an instance on pointer up (click):

The screenrecording is also updated to the main thread.

There is something wrong with your mesh. I replaced your mesh with a torus know and your picking code works:

Can you post the glb file here. The zip loader produces an error.

The model looks good in playground, rendered the same thing as in blender.
theglbfile.zip (283.9 KB)

You had a scale of 0.01 on the parent of the mesh. I’ve applied the scale in Blender and now the picking works:

1 Like

It works, so this is something related to scaling? But why didn’t babylon.js support picking mesh with scaling in parents?

It does:

Refer to Picked point at wrong position - #3 by RaananW why might it not work correctly.

I’ve took a deeper look into the picking algos, and found that positions in babylon.js greatly differs from in blender. Any ideas on this?

https://www.reddit.com/r/unrealengine/comments/bieng1/what_is_the_difference_between_local_and_world/

Hmm, it’s geometry._positions, not mesh, so both should be local.

Edit: Nevermind, I found it, I’ll start a pr to see if it works

Both environments could have absolutely diferent coordinate systems with different unit sizes so I think this is not an issue.

Check this in Blender:

image

It’s something related to data alignment, gpu renders everything correctly, but VertexBuffer.GetFloatData aligns pointer instead of data.

The pr:

1 Like

I don’t see a relation here. Picking is done on the CPU side.

Yes, it’s done on cpu, the data used for picking is extracted from geometry using VertexBuffer.GetFloatData, and the model contains some unaligned buffer, instead of copying data to a new buffer, VertexBuffer.GetFloatData aligns pointer, so it reads wrong data from buffer.

1 Like

Now I understand what you are talking about :slight_smile:

Fixed:

Unfortunately, I am totally unsure of this PR and we will need to wait for @bghgary to be back as it looks like a regression from his PR from last week. he ll be back on Monday.

1 Like