LCCObject::raycastFromOrigin
Custom origin and direction raycasting.
Supports custom origin and direction for raycasting against LCC model data in world space.
Version Requirement
SDK v0.3.0+
Engine Support
Three.js / CesiumJS
API
LCCObject::raycastFromOrigin(param: RaycastFromOriginParam): IPoint3 | null
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
param.origin | { x: number, y: number, z: number } | Yes | - | Ray origin in world space coordinates. |
param.direction | { x: number, y: number, z: number } | Yes | - | Ray direction; can be normalized or unnormalized. |
param.maxDistance | number | Yes | - | Detection distance, in meters. |
param.radius | number | Yes | - | Detection precision, in meters. |
param.opacityThreshold | number | No | 0.5 | Opacity threshold for high-precision detection, range [0, 1]. Only effective when usePrecisionRaycast is true. SDK v0.6.3+ |
Return Value
IPoint3 | null — Detected point coordinates (x, y, z) in world space. Returns null if no point is detected.
Usage Example
const origin = { x: 10, y: 10, z: 10 };
const startPos = { x: 10, y: 10, z: 10 };
const endPos = { x: 50, y: 50, z: 50 };
const direction = {
x: endPos.x - startPos.x,
y: endPos.y - startPos.y,
z: endPos.z - startPos.z
};
const maxDistance = 100;
const radius = 0.01;
let checkPos = lccObject.raycastFromOrigin({ origin, direction, maxDistance, radius });
if (checkPos) {
console.log('checkPos: ', checkPos.x, checkPos.y, checkPos.z);
} else {
// No point detected
}
Notes
- This method must be called after the success callback of
LCCRender.load()has been triggered. directioncan be a normalized or unnormalized vector.- If a
radiusvalue of 0.01 does not detect data, try increasing it, e.g., to 0.1.
Related APIs
LCCObject::raycast()LCCObject::intersectsRayFromOriginExt()