Skip to main content

WorldRaycast.hitTestWorldMesh

Function

Performs 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.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • 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

ParameterTypeDescription
screenPosvec2Screen 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
cameraCameraThe Camera to use for computing the screen-to-world ray

Returns

TrackedMeshHitTestResult[]

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 World tracking 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);
}
});