Skip to content

Commit

Permalink
Change raycastAll sorting default to false (#5181)
Browse files Browse the repository at this point in the history
* Make an option to not sort raycast results

* Clarified JSDoc

* Changed raycast sorting into default false

* Removed useless `=== true`
  • Loading branch information
MushAsterion committed Mar 22, 2023
1 parent 57a9835 commit 776f3c4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/framework/components/rigid-body/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,12 @@ class RigidBodyComponentSystem extends ComponentSystem {
*
* @param {Vec3} start - The world space point where the ray starts.
* @param {Vec3} end - The world space point where the ray ends.
* @param {object} [options] - The additional options for the raycasting.
* @param {boolean} [options.sort] - Whether to sort raycast results based on distance with closest
* first. Defaults to false.
* @returns {RaycastResult[]} An array of raycast hit results (0 length if there were no hits).
* Results are sorted by distance with closest first.
*/
raycastAll(start, end) {
raycastAll(start, end, options = {}) {
Debug.assert(Ammo.AllHitsRayResultCallback, 'pc.RigidBodyComponentSystem#raycastAll: Your version of ammo.js does not expose Ammo.AllHitsRayResultCallback. Update it to latest.');

const results = [];
Expand Down Expand Up @@ -561,7 +563,9 @@ class RigidBodyComponentSystem extends ComponentSystem {
}
}

results.sort((a, b) => a.hitFraction - b.hitFraction);
if (options.sort) {
results.sort((a, b) => a.hitFraction - b.hitFraction);
}
}

Ammo.destroy(rayCallback);
Expand Down

0 comments on commit 776f3c4

Please sign in to comment.