-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
add optionalTarget parameter to Raycaster.intersectObject(s) to allow array reuse #12872
Conversation
This PR has implications for #12231. |
Cool, that looks agreeable, I always try to pass in a target. Does this look good in the mean time so it can get picked up as part of that overhaul? |
Can you please explain your use case? What is the compelling reason for this change? |
We have raycasters that raycast frequently for a VR app (10 to potentially 90 times a second each). Saving unnecessary arrays will reduce GC and memory usage to increase performance. Not much different from wanting to save memory in the other optionalTarget-type patterns. |
How are you clearing out the array between raycast calls so previous intersections are not sorted? |
I'm using |
I can change the PR to automatically clear the optional target with |
Ugh... I was confused because I do not have a problem with this PR as written, but I'll defer to others. Thank you for the suggestion. If this is merged, please update the docs. |
f30093e
to
fa8d2ab
Compare
I've updated the docs and made it clear the array/optional target if specified (since there's no reason not to clear the array). r? @Mugen87 |
fa8d2ab
to
e320a0a
Compare
src/core/Raycaster.js
Outdated
var intersects = []; | ||
var intersects = optionalTarget || []; | ||
|
||
// Clear target array if specified. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would prefer if the clearing logic was in the application (ie. aframe) layer instead.
e320a0a
to
a97bfff
Compare
Updated to not clear the array automatically. |
a97bfff
to
323bb33
Compare
Merge conflicts fixed. |
docs/api/core/Raycaster.html
Outdated
<div> | ||
<p> | ||
[page:Object3D object] — The object to check for intersection with the ray.<br /> | ||
[page:Boolean recursive] — If true, it also checks all descendants. Otherwise it only checks intersecton with the object. Default is false. | ||
[page:Boolean recursive] — If true, it also checks all descendants. Otherwise it only checks intersecton with the object. Default is false.<br /> | ||
[page:Array optionalTarget] — (optional) target to set the result. Otherwise a new [page:Array] is instantiated. Application is responsible for clearing this array on each call (e.g., array.length = 0;). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of
Application is responsible for clearing this array on each call (e.g., array.length = 0;).
It may be more clear like so:
If set, you must clear this array prior to each call (e.g., array.length = 0;).
323bb33
to
81389ed
Compare
Updated the docs comment. |
I think this is fine. |
Thanks! |
Description of the Problem
Allow
optionalTarget
forraycaster.intersectObject
andraycaster.intersectObjects
. This lets developers reuse array and reduce array instantiations.For A-Frame/WebVR, an application often has two raycasters, one for each hand, updating up to 90 times a second. Two hands would have 180 raycaster intersects per second. So this could save 180 array instantiations per second for us.