LCCObject::intersectsRayFromOriginExt
基于碰撞体的射线检测,支持自定义起点和方向。
版本要求
SDK v0.5.0+
引擎支持
Three.js
API
LCCObject::intersectsRayFromOriginExt(param: IntersectsRayFromOriginExtParam): IntersectsResult | null
参数
| 参数 | 类型 | 必选 | 默认值 | 描述 |
|---|---|---|---|---|
param.origin | { x: number, y: number, z: number } | 是 | - | 射线原点。 |
param.direction | { x: number, y: number, z: number } | 是 | - | 射线方向。 |
param.maxDistance | number | 是 | - | 检测距离,单位为米。 |
返回值
检测成功时返回包含 point 和 normal 的对象;检测失败时返回 null。
| 属性 | 类型 | 描述 |
|---|---|---|
point | { x: number, y: number, z: number } | 碰撞点坐标,世界坐标空间的值。 |
normal | { x: number, y: number, z: number } | 碰撞点法线,世界坐标空间的值。 |
使用示例
const ret = lccObject.hasCollision();
if (ret) {
const origin = { x: 10, y: 10, z: 10 };
const direction = { x: 1, y: 0, z: 0 };
const maxDistance = 10;
let result = lccObject.intersectsRayFromOriginExt({ origin, direction, maxDistance });
if (result) {
console.log('point: ', result.point.x, result.point.y, result.point.z);
console.log('normal: ', result.normal.x, result.normal.y, result.normal.z);
} else {
// No point detected
}
} else {
// Collision function not supported
}
注意事项
- 此接口需在
LCCRender.load()的成功回调函数触发后调用。 - 使用前应先通过
hasCollision()查询是否支持碰撞检测。 - SDK 只加载相机位置附近范围的碰撞数据。
相关 API
LCCObject::hasCollision()LCCObject::intersectsRayExt()LCCObject::raycastFromOrigin()