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

Added support for shapeTestFirst, shapeTestAll and shapeCastFirst #5039

Open
wants to merge 90 commits into
base: main
Choose a base branch
from

Conversation

MushAsterion
Copy link
Collaborator

@MushAsterion MushAsterion commented Feb 3, 2023

  • Requires to update Ammo.js to latest version. (which is not a breaking change)
  • No custom IDL for Ammo.js required.

Deprecated RaycastResult for HitResult as it is now returned by shape testing and shape casting.

Added the following property for HitResult public API:

  • distance: The distance at which the hit occurred from the starting point.

As shape may have lower hitFraction but be more distant than another hit with higher hitFraction (for example a side of the cylinder will be closest in distance than its other tip. (#5179)

Added test for shapes using shapeTestAll and shapeTestFirst and by configuring the shape. It also provides API for each primitive shapes:

  • shapeTestAll(options, position, rotation, options)
  • shapeTestFirst(options, position, rotation, options)
  • boxTestAll(halfExtents, position, rotation, options)
  • boxTestFirst(halfExtents, position, rotation, options)
  • capsuleTestAll(radius, heigh, axis, position, rotation, options)
  • capsuleTestFirst(radius, heigh, axis, position, rotation, options)
  • coneTestAll(radius, heigh, axis, position, rotation, options)
  • coneTestFirst(radius, heigh, axis, position, rotation, options)
  • cylinderTestAll(radius, heigh, axis, position, rotation, options)
  • cylinderTestFirst(radius, heigh, axis, position, rotation, options)
  • sphereTestAll(radius, position, rotation, options)
  • sphereTestFirst(radius, position, rotation, options)

There is also are also ignored functions _shapeTestAll(shape, position, rotation, options) and _shapeTestFirst(shape, position, rotation, options) if you wish to use your own shape (Ammo.btCollisionShape). Include full comments and docs. Include assertion of Ammo.ConcreteContactResultCallback. As for raycasting (#5179, #5181), shapeTestAll functions return values ordered by distance with closest first if options.sort is set to true.

Added sweeping for shapes using shapeCastFirst and by configuring the shape. It also provides API for each primitive shapes:

  • shapeCastFirst(shape, startPosition, endPosition, startRotation, endRotation, options)
  • boxCastFirst(halfExtents, startPosition, endPosition, startRotation, endRotation, options)
  • capsuleCastFirst(radius, height, axis, startPosition, endPosition, startRotation, endRotation, options)
  • coneCastFirst(radius, height, axis, startPosition, endPosition, startRotation, endRotation, options)
  • cylinderCastFirst(radius, height, axis, startPosition, endPosition, startRotation, endRotation, options)
  • sphereCastFirst(radius, startPosition, endPosition, options)

There is also a private function as well _shapeCastFirst(shape, startPosition, endPosition, startRotation, endRotation, options) if you wish to use your own shape (Ammo.btCollisionShape).

As for raycasting (#5180), shapeTestAll, shapeTestFirst and shapeCastFirst accept filtering. For shape casting only collision group and mask are available.

Fixes #2094

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

Added cast for shapes using `shapeCast` and by configuring the shape. It also provide API for each primitive shapes:
- `boxCast(halfExtends, position, rotation)`
- `capsuleCast(radius, heigh, axis, position, rotation)`
- `coneCast(radius, heigh, axis, position, rotation)`
- `cylinderCast(radius, heigh, axis, position, rotation)`
- `sphereCast(radius, position, rotation)`

There is also a private function `_shapecast(shape, collision, rotation)` if you wish to use your own shape (Ammo.btCollisionShape).
Include full comments and docs. Include assertion of `Ammo.ConcreteContactResultCallback` for every public function. No assertion on private function to reduce function calls.
@mvaligursky
Copy link
Contributor

Nice PR! Two comments:

@MushAsterion
Copy link
Collaborator Author

MushAsterion commented Feb 3, 2023

Thanks! And thank you for your review.

Regarding your questions @mvaligursky,

I tested it within the production version from online editor and re-checked after with engine-only to make sure it was working. Here is the project I made to do it: https://playcanvas.com/project/1034600.

To be completely honest with you I'm far from being the best on creating full project, I'll leave this to someone else.

@willeastcott willeastcott self-assigned this Feb 3, 2023
@willeastcott
Copy link
Contributor

@MushAsterion I think it's OK to skip the example if you're not confident about putting one together. We can maybe open another issue requesting that...

@GSterbrant GSterbrant added the open source contribution Issues related to contributions from people outside the PlayCanvas team label May 12, 2023
Comment on lines +15 to +19
// Ammo.js variable for performance saving.
let ammoRayStart, ammoRayEnd, ammoVec3, ammoQuat, ammoTransform, ammoTransform2;

// RigidBody for shape tests. Permanent to save performance.
let shapeTestBody;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any concerns with what happens if two instances of playcanvas are on the same page? They'll share the same objects

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many other files contain global variables to the module, I don't see the difference or problem here considering those variables are initialized once then every time a value is assigned to it, it is immediately used.

Do you suggest it could conflict with anything? And if so, why would it conflict here and not in any other module?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We previously had issues with them hanging around an not being cleaned up properly. More of a general point to be careful about module scope variables as they live forever and are shared between different instances. I think in this case they are purely temporary variables so it should be fine but I thought it worth pointing out just in case

@OlegGedzjuns
Copy link
Contributor

Unfortunately tested only sphere cast
Definitely some test and example projects are needed

@mvaligursky
Copy link
Contributor

This PR is waiting for up to date ammo .. I wonder if somebody is keen to compile the wasm we need here?

@OlegGedzjuns
Copy link
Contributor

This PR is waiting for up to date ammo .. I wonder if somebody is keen to compile the wasm we need here?

I used ammo wasm from https://playcanvas.com/project/1034600
Ammo.ClosestConvexResultCallback and Ammo.ClosestConvexResultCallback.get_m_hitCollisionObject are exposed as expected

@MushAsterion
Copy link
Collaborator Author

This PR is waiting for up to date ammo .. I wonder if somebody is keen to compile the wasm we need here?

You can simply use latest version from kripken/ammo.js

@OlegGedzjuns
Copy link
Contributor

This PR is waiting for up to date ammo .. I wonder if somebody is keen to compile the wasm we need here?

You can simply use latest version from kripken/ammo.js

Tested just now, seems good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: physics Physics related issue feature request open source contribution Issues related to contributions from people outside the PlayCanvas team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for spherecast
9 participants