Skip to main content

WorldRaycast.raycastWorldMesh

Function

Performs a raycast against world meshes along a ray from world position from to world position to.

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

raycastWorldMesh(from, to): TrackedMeshHitTestResult[]

Performs a raycast against world meshes along a ray from world position from to world position to. Returns detailed intersection information for each mesh surface hit by the ray.

Parameters

ParameterTypeDescription
fromvec3Starting point of the ray in world space coordinates
tovec3Ending point of the ray in world space coordinates

Returns

TrackedMeshHitTestResult[]

Array of TrackedMeshHitTestResult objects, sorted by distance from from (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 raycastPlanes instead

Example

//@input Component.DeviceTracking deviceTracking

script.deviceTracking.worldOptions.enableWorldMeshesTracking = true;
script.deviceTracking.requestDeviceTrackingMode(DeviceTrackingMode.World);

script.createEvent("TapEvent").bind(function () {
const from = new vec3(0, 0, 0);
const to = new vec3(0, 0, -600);
const results = WorldRaycast.raycastWorldMesh(from, to);

if (results.length > 0) {
print("Hit position: " + results[0].position);
}
});