WorldRaycast.hitTestWorldMesh
FunctionPerforms a raycast against world meshes from a screen position.
- Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.
hitTestWorldMesh(
screenPos,camera):TrackedMeshHitTestResult[]
Performs a raycast against world meshes from a screen position. The ray starts at the camera's near plane and extends through the camera's far plane at the given screen coordinates.
Parameters
| Parameter | Type | Description |
|---|---|---|
screenPos | vec2 | Screen coordinates in normalized device coordinates ([0-1], [0-1]), where (0,0) is the top-left of the screen and (1,1) is the bottom-right |
camera | Camera | The Camera to use for computing the screen-to-world ray |
Returns
Array of TrackedMeshHitTestResult objects, sorted by distance from camera (nearest first). Returns an empty array if no meshes are hit.
Remarks
- World mesh tracking must be supported by the device (check DeviceTracking.WorldTrackingCapabilities.sceneReconstructionSupported)
- Only available when world mesh tracking is enabled via DeviceTracking.WorldOptions.enableWorldMeshesTracking
- Requires DeviceTracking to be in
Worldtracking mode - Android (ARCore) does not support scene reconstruction; use hitTestPlanes instead
Example
//@input Component.DeviceTracking deviceTracking
//@input Component.Camera camera
script.deviceTracking.worldOptions.enableWorldMeshesTracking = true;
script.deviceTracking.requestDeviceTrackingMode(DeviceTrackingMode.World);
script.createEvent("TapEvent").bind(function (eventData) {
const screenPos = eventData.getTapPosition();
const results = WorldRaycast.hitTestWorldMesh(screenPos, script.camera);
if (results.length > 0) {
print("Hit position: " + results[0].position);
}
});