WorldRaycast.raycastWorldMesh
FunctionPerforms 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.
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
| Parameter | Type | Description |
|---|---|---|
from | vec3 | Starting point of the ray in world space coordinates |
to | vec3 | Ending point of the ray in world space coordinates |
Returns
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
Worldtracking 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);
}
});