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

Change raycastAll sorting default to false #5181

Merged
merged 4 commits into from
Mar 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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