Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ray picking precision #1105

Closed
Kurtil opened this issue Jul 18, 2023 · 4 comments
Closed

Fix ray picking precision #1105

Kurtil opened this issue Jul 18, 2023 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@Kurtil
Copy link
Contributor

Kurtil commented Jul 18, 2023

I'm developing a plugin to measure distances between objects.

bbbf204df94bada3ce9e8e0efc994eb1

However, ray picking is not precise enough to consider my plugin as usable.

First, it is not possible to ray picking precision surface with matrix instead of origin & direction. Indeed, worldRayOrigin & worldRayDir are not set if a matrix is provided in pick params. See here. Is this an oversight or it is intended to does not work with matrix ?

Second, I used picking with matrix because it seems to be more precise. Indeed, the matrix ray picking example seems way more stable than the surface ray picking example. Comparing the code of both examples and the code on the Renderer.js, I saw that the only difference to go from origin & direction to matrix is this part:

randomVec3[0] = Math.random();
randomVec3[1] = Math.random();
randomVec3[2] = Math.random();

math.normalizeVec3(randomVec3);
math.cross3Vec3(worldRayDir, randomVec3, up);

Maybe these lines are responsible for the lack of precision when picking with origin & direction...

Measuring the Duplex roof is a good place to show the ray picking limitations:

No Precision

  • origin & direction:
    8b0b929e0155c8a0ac031f874d734d71
  • matrix:
    6776d57f2d08e712a143fd823ea901bf

I seems better with matrix but in both no precision cases, the measure stops like 10cm before the wall...

For this kind of plugin, precision is key, precision picking needs to be enabled.

Precision

  • origin & direction:
    6d5ef8a03f0ccf49040f49786d1a6044

It hardly catches the other wall :/

I did not manage to get a fix for this. Maybe the provided example code below can be used as a sandbox to improve the precision of the ray picking. In the example, there is two checkboxes as the top of the document to quickly enable precision ray picking and switching between matrix or origin & direction.

The following zip file is the measurements_distance_modelWithMeasurements example updated with the spacing measurement plugin.

measurements_distance_modelWithMeasurements.html.zip

@xeolabs
Copy link
Member

xeolabs commented Jul 19, 2023

Won;t be able to look at this until perhaps next week, unfortunately

@Kurtil
Copy link
Contributor Author

Kurtil commented Jul 21, 2023

Won;t be able to look at this until perhaps next week, unfortunately

No problem. I updated the entire issue content as it was not really relevant.

@tmarti
Copy link
Contributor

tmarti commented Aug 6, 2023

@Kurtil @xeolabs I've been doing an experiment on top of DTX (data-textures) as the memory layout does not have precision loss in normals due to octencoding.

super-stable-measurements.mov

The measurement is 100% stable and its precision only bounded by the quantization error during XKT compression, which in many models just means sub-mm error 🥂.

I need to debug and profile this a bit more before pushing the code, so please have patience 🍿

@Kurtil
Copy link
Contributor Author

Kurtil commented Oct 13, 2023

Fixed by this commit on the 1 x 1 picking viewport PR #1168 and the 32 bit picking normal PR #1172.

@Kurtil Kurtil closed this as completed Oct 13, 2023
@xeolabs xeolabs added this to the 2.4.0 milestone Oct 13, 2023
@xeolabs xeolabs added the bug Something isn't working label Oct 13, 2023
@xeolabs xeolabs changed the title Ray picking precision Fix ray picking precision Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants