Three.js: Inconsistent raycast precision API

Created on 10 Feb 2020  路  9Comments  路  Source: mrdoob/three.js

Description of the problem

Both Points and Line implement a raycast() function/method. They both use a threshold/precision:

https://github.com/mrdoob/three.js/blob/138d25dbd138f9feedbb20ade26f104155a50d8f/src/objects/Points.js#L37-L59

https://github.com/mrdoob/three.js/blob/138d25dbd138f9feedbb20ade26f104155a50d8f/src/objects/Line.js#L94-L117

I think the API is a bit inconsistent and they could both be named either threshold or precision and also they could both be set in the Raycaster in the same way. Right now you have to:

raycaster.linePrecision = 42;
raycaster.params.Points.threshold = 42;

Also, only linePrecision is documented.

Proposal

Same API for all thresholds/precisions. It seems the .params attribute is more complete/flexible, so I would say:

raycaster.params.Line.threshold = 42;
raycaster.params.Points.threshold = 42;

That means removing the linePrecision attribute.

Three.js version
  • [x] Dev
  • [x] r113
Suggestion

Most helpful comment

@Mugen87 I have very little experience with JS, but I will try. It is the least I can do for this project and the community behind it, who already helped me a couple of times when I felt lost. :heart:

Hopefully, I will be able to find some time to work on this before next week.

All 9 comments

Related #5366.

Just to be clear, I am not suggesting changing the units of the raycaster precision. I think world units are just fine. :blush:

Agreed, a common approach for Points and Lines is desirable. I think I vote for enhancing Raycaster.params, too. And deprecating Raycaster.linePrecision.

So will the convention be to house class-specific raycast parameters at Raycaster.params.<classname>? I'm thinking about Line2 raycasting which currently doesn't respect linePrecision because it's in world units. So it would be nice to support something like Raycaster.params.line2.pixelPrecision.

Maybe a topic for another issue but it might be nice to provide worldPrecision and pixelPrecision for something like Points considering they can be rendered with and without perspective attenuation.

So will the convention be to house class-specific raycast parameters at Raycaster.params.?

I would say yes.

Agreed, a common approach for Points and Lines is desirable. I think I vote for enhancing Raycaster.params, too. And deprecating Raycaster.linePrecision.

馃憤

@Peque Do you want to make a PR with your proposed change? 馃槆

@Mugen87 I have very little experience with JS, but I will try. It is the least I can do for this project and the community behind it, who already helped me a couple of times when I felt lost. :heart:

Hopefully, I will be able to find some time to work on this before next week.

Opened https://github.com/mrdoob/three.js/pull/18648. All feedback is welcome. :heart:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Horray picture Horray  路  3Comments

yqrashawn picture yqrashawn  路  3Comments

seep picture seep  路  3Comments

ghost picture ghost  路  3Comments

fuzihaofzh picture fuzihaofzh  路  3Comments