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
base: main
Are you sure you want to change the base?
Conversation
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.
Nice PR! Two comments:
|
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. |
@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... |
// Ammo.js variable for performance saving. | ||
let ammoRayStart, ammoRayEnd, ammoVec3, ammoQuat, ammoTransform, ammoTransform2; | ||
|
||
// RigidBody for shape tests. Permanent to save performance. | ||
let shapeTestBody; |
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.
Any concerns with what happens if two instances of playcanvas are on the same page? They'll share the same objects
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.
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?
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.
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
Unfortunately tested only sphere cast |
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 |
You can simply use latest version from kripken/ammo.js |
Tested just now, seems good |
Deprecated
RaycastResult
forHitResult
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 higherhitFraction
(for example a side of the cylinder will be closest in distance than its other tip. (#5179)Added test for shapes using
shapeTestAll
andshapeTestFirst
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 ofAmmo.ConcreteContactResultCallback
. As for raycasting (#5179, #5181),shapeTestAll
functions return values ordered by distance with closest first ifoptions.sort
is set totrue
.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
andshapeCastFirst
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.