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 shapeCast and merged raycastFirst and raycastAll into raycast #5039

Open
wants to merge 100 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
ac625fc
Added shape casts
MushAsterion Feb 3, 2023
4fd6099
Fixed ESLint
MushAsterion Feb 3, 2023
c5f8fc8
Fixed halfExtends into halfExtents
MushAsterion Feb 3, 2023
36d500a
Added shapecast shape destroying
MushAsterion Feb 3, 2023
624c8da
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Feb 3, 2023
0e51d63
Reduced debug assets into one
MushAsterion Feb 3, 2023
2ace6a3
Removed variable type change from shapeCasts
MushAsterion Feb 3, 2023
2b1e039
Fixed JSDoc for optional parameters
MushAsterion Feb 3, 2023
0cdc17a
Added default position and rotation for _shapecast
MushAsterion Feb 3, 2023
052e8f8
Removed shapecast body world addition
MushAsterion Feb 3, 2023
7eff8db
Shape casts now return Entity array
MushAsterion Feb 3, 2023
5de3fef
Removed unused variables
MushAsterion Feb 3, 2023
9133182
Added Entity import
MushAsterion Feb 3, 2023
1e4415e
Fixed Entity JSDoc
MushAsterion Feb 3, 2023
53cb43f
Updated shape.type eval to switch
MushAsterion Feb 3, 2023
b4f005b
Fixed docs
MushAsterion Feb 3, 2023
502994c
Fix shape on boxCast
MushAsterion Feb 4, 2023
c8adb46
Added HitResult to shapecast
MushAsterion Feb 4, 2023
fd907d5
Fixed inconsistent documentation
MushAsterion Feb 4, 2023
9566b60
Fixed ESLint
MushAsterion Feb 4, 2023
6c2d55b
Changed naming from cast to test
MushAsterion Feb 4, 2023
9027bf3
Added Quat rotation for shape tests
MushAsterion Feb 4, 2023
c294abb
Fixed ESLint
MushAsterion Feb 4, 2023
845fb0a
Added sphereCast and boxCast
MushAsterion Feb 4, 2023
34d83b3
Fixed typo
MushAsterion Feb 4, 2023
a448e62
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Feb 4, 2023
fcb70ea
Fixed sphereCast length
MushAsterion Feb 4, 2023
6213685
Added vector for shapecast position
MushAsterion Feb 5, 2023
a444069
Fixed boxCast shape halfExtents
MushAsterion Feb 5, 2023
3ae5522
Fixed typo
MushAsterion Feb 5, 2023
dc69842
Renamed boxCastAll and sphereCastAll
MushAsterion Feb 5, 2023
2d8149a
Fixed sphereCast length
MushAsterion Feb 5, 2023
8134d3f
Removed boxCastAll
MushAsterion Feb 5, 2023
87451da
Removed shapetest body deactivation
MushAsterion Feb 6, 2023
d66eaaf
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Feb 6, 2023
bf5c384
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Feb 8, 2023
73b10a7
Rename shape casts into shapeCastAll
MushAsterion Feb 8, 2023
2fc5fa8
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Feb 10, 2023
3df7a28
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Feb 11, 2023
d6d4539
Changed RaycastResult into HitResult
MushAsterion Feb 11, 2023
a9ea632
Changed RaycastResult into HitResult
MushAsterion Feb 11, 2023
db8274b
Changed RaycastResult into HitResult
MushAsterion Feb 11, 2023
faf1f00
Deprecated RaycastResult
MushAsterion Feb 11, 2023
6474880
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Feb 12, 2023
e084be1
Added shapeCastFirst functions
MushAsterion Feb 22, 2023
c344241
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Feb 22, 2023
2759da4
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Feb 22, 2023
cf21ed8
Changed T and C to lowercase from Test and Cast
MushAsterion Feb 22, 2023
f5d91b6
Reverted previous commit
MushAsterion Feb 22, 2023
8ca124e
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Feb 22, 2023
00d2d67
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Feb 24, 2023
1ccc26a
Reduced code length
MushAsterion Feb 24, 2023
a4a8305
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Mar 4, 2023
54518b1
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Mar 10, 2023
73b751c
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Mar 11, 2023
77b3ed0
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Mar 17, 2023
956fd3e
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Mar 18, 2023
377f5ae
Added support for `shapeTestFirst`
MushAsterion Mar 19, 2023
383e9ad
Resolve conflicts from source
MushAsterion Mar 21, 2023
390bac6
Merge remote-tracking branch 'upstream/main' into shapecasts
MushAsterion Mar 21, 2023
e5c7a09
Match latest features from raycasting
MushAsterion Mar 21, 2023
9802d4c
Added sorting documentation.
MushAsterion Mar 21, 2023
6bd474b
Merge remote-tracking branch 'upstream/main' into shapecasts
MushAsterion Mar 22, 2023
ea47f72
Merge remote-tracking branch 'upstream/main' into shapecasts
MushAsterion Mar 22, 2023
969ab5b
Added filtering to shape testing and casting
MushAsterion Mar 22, 2023
290a35d
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Mar 25, 2023
7c1b2c1
Merge remote-tracking branch 'upstream/main' into shapecasts
MushAsterion Apr 2, 2023
20f6377
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Apr 8, 2023
6fc799a
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Apr 13, 2023
4c70791
Fixed tags filtering issue
MushAsterion Apr 17, 2023
e6a47a3
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Apr 17, 2023
230e1fa
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Apr 18, 2023
f0ab87b
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Apr 26, 2023
79a67ee
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Apr 29, 2023
ecf1583
Merge branch 'playcanvas:main' into shapecasts
MushAsterion May 10, 2023
74f509a
Merge branch 'playcanvas:main' into shapecasts
MushAsterion May 12, 2023
f23587a
Merge branch 'playcanvas:main' into shapecasts
MushAsterion May 28, 2023
3c3fa50
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Jun 20, 2023
13a7c28
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Jun 28, 2023
fa155c4
Merge remote-tracking branch 'upstream/main' into shapecasts
MushAsterion Jul 24, 2023
f373ac7
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Jul 28, 2023
f955f64
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Jul 31, 2023
ff3906b
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Aug 10, 2023
b96694a
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Aug 17, 2023
ece932e
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Oct 16, 2023
d442376
Merge remote-tracking branch 'upstream/main' into shapecasts
MushAsterion Oct 31, 2023
a1a5473
Merge branch 'playcanvas:main' into shapecasts
MushAsterion Feb 14, 2024
8c7a842
Merge remote-tracking branch 'upstream/main' into shapecasts
MushAsterion Mar 29, 2024
2b2b643
Fixed trailing space
MushAsterion Mar 29, 2024
654794e
Merge branch 'playcanvas:main' into shapecasts
MushAsterion May 11, 2024
02e33bf
Merge branch 'playcanvas:main' into shapecasts
MushAsterion May 29, 2024
7bae7dc
Merge branch 'main' into shapecasts
MushAsterion May 30, 2024
c5e35d6
Reduced public API functions
MushAsterion May 31, 2024
ba29b58
Used Object assign instead of ...
MushAsterion May 31, 2024
8c67c9f
Fixed documentation disclaimers
MushAsterion May 31, 2024
b3f213d
Changed raycastFirst/raycastAll occurrences
MushAsterion May 31, 2024
7a642a8
Removed extra Ammo.destroy
MushAsterion May 31, 2024
972c1f7
Fixed documentation and line width
MushAsterion May 31, 2024
ec7aa86
Merge branch 'main' into shapecasts
MushAsterion May 31, 2024
bae27b7
Merge branch 'main' into shapecasts
MushAsterion Jun 4, 2024
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
2 changes: 1 addition & 1 deletion examples/src/examples/animation/locomotion.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ assetListLoader.load(() => {
const cameraEntity = app.root.findByName('Camera');
const near = cameraEntity.camera.screenToWorld(event.x, event.y, cameraEntity.camera.nearClip);
const far = cameraEntity.camera.screenToWorld(event.x, event.y, cameraEntity.camera.farClip);
const result = app.systems.rigidbody.raycastFirst(far, near);
const result = app.systems.rigidbody.raycast(far, near)[0];
if (result) {
targetPosition = new pc.Vec3(result.point.x, 0, result.point.z);
characterEntity.anim.setInteger('speed', data.get('jogToggle') ? 2 : 1);
Expand Down
8 changes: 4 additions & 4 deletions examples/src/examples/physics/raycast.example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ assetListLoader.load(() => {
// Render the ray used in the raycast
app.drawLine(start, end, white);

const result = app.systems.rigidbody.raycastFirst(start, end);
const result = app.systems.rigidbody.raycast(start, end)[0];
if (result) {
result.entity.render.material = red;

Expand All @@ -183,7 +183,7 @@ assetListLoader.load(() => {
// Render the ray used in the raycast
app.drawLine(start, end, white);

const results = app.systems.rigidbody.raycastAll(start, end);
const results = app.systems.rigidbody.raycast(start, end, { findAll: true });
results.forEach(function (result) {
result.entity.render.material = red;

Expand Down Expand Up @@ -217,8 +217,8 @@ assetListLoader.load(() => {
app.root.addChild(text);
};

createText(assets.font, 'raycastFirst', 0.5, 3.75, 0, 0);
createText(assets.font, 'raycastAll', 0.5, -0.25, 0, 0);
createText(assets.font, 'raycast', 0.5, 3.75, 0, 0);
createText(assets.font, 'raycast (with findAll)', 0.5, -0.25, 0, 0);
});

export { app };
2 changes: 1 addition & 1 deletion scripts/camera/first-person-camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@
const start = this.entity.getPosition();
const end = tmpV1.copy(start).add(Vec3.DOWN);
end.y -= 0.1;
this._grounded = !!this._rigidbody.system.raycastFirst(start, end);
this._grounded = !!this._rigidbody.system.raycast(start, end)[0];
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/deprecated/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ import {
BODYTYPE_DYNAMIC, BODYTYPE_KINEMATIC, BODYTYPE_STATIC
} from '../framework/components/rigid-body/constants.js';
import { RigidBodyComponent } from '../framework/components/rigid-body/component.js';
import { RigidBodyComponentSystem } from '../framework/components/rigid-body/system.js';
import { RigidBodyComponentSystem, HitResult } from '../framework/components/rigid-body/system.js';
import { basisInitialize } from '../framework/handlers/basis.js';
import { LitShader } from '../scene/shader-lib/programs/lit-shader.js';
import { Geometry } from '../scene/geometry/geometry.js';
Expand Down Expand Up @@ -1384,6 +1384,7 @@ Object.defineProperty(MouseEvent.prototype, 'wheel', {

// FRAMEWORK

export const RaycastResult = HitResult;
export const RIGIDBODY_TYPE_STATIC = BODYTYPE_STATIC;
export const RIGIDBODY_TYPE_DYNAMIC = BODYTYPE_DYNAMIC;
export const RIGIDBODY_TYPE_KINEMATIC = BODYTYPE_KINEMATIC;
Expand Down Expand Up @@ -1660,6 +1661,15 @@ RigidBodyComponentSystem.prototype.setGravity = function () {
}
};

RigidBodyComponentSystem.prototype.raycastFirst = function (start, end, options) {
Debug.deprecated('pc.RigidBodyComponentSystem#raycastFirst is deprecated. Use pc.RigidBodyComponentSystem#raycast instead.');
return this.raycast(start, end, options)[0] ?? null;
};

RigidBodyComponentSystem.prototype.raycastAll = function (start, end, options = {}) {
Debug.deprecated('pc.RigidBodyComponentSystem#raycastAll is deprecated. Use pc.RigidBodyComponentSystem#raycast with findAll option instead.');
return this.raycast(start, end, Object.assign(options, { findAll: true }));
};

export function basisSetDownloadConfig(glueUrl, wasmUrl, fallbackUrl) {
Debug.deprecated('pc.basisSetDownloadConfig is deprecated. Use pc.basisInitialize instead.');
Expand Down
5 changes: 3 additions & 2 deletions src/framework/components/camera/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,10 @@ class CameraComponent extends Component {
* const end = entity.camera.screenToWorld(clickX, clickY, entity.camera.farClip);
*
* // Use the ray coordinates to perform a raycast
* app.systems.rigidbody.raycastFirst(start, end, function (result) {
* const result = app.systems.rigidbody.raycast(start, end)[0];
* if (result) {
* console.log("Entity " + result.entity.name + " was selected");
* });
* }
* @returns {import('../../../core/math/vec3.js').Vec3} The world space coordinate.
*/
screenToWorld(screenx, screeny, cameraz, worldCoord) {
Expand Down