LCCObject::intersectsSphere
球体碰撞测试。
版本要求
SDK v0.4.1+
引擎支持
Three.js
API
LCCObject::intersectsSphere(param: IntersectsSphereParam): IntersectsSphereResult
参数
| 参数 | 类型 | 必选 | 默认值 | 描述 |
|---|---|---|---|---|
param.center | { x: number, y: number, z: number } | 是 | - | 球体中心位置。 |
param.radius | number | 是 | - | 球体半径。 |
param.noDelta | boolean | 否 | - | 设置为 true 时不计算碰撞偏移量,检测速度更快;设置为 false 时计算碰撞偏移量。 |
返回值
| 属性 | 类型 | 描述 |
|---|---|---|
hit | boolean | 是否发生碰撞。 |
delta | { x: number, y: number, z: number } | 碰撞偏移量,可用于调整数字人位置。偏移量方向朝向碰撞体。仅在 noDelta 为 false 时有效。 |
使用示例
const ret = lccObject.hasCollision();
if (ret) {
const center = { x: 10, y: 10, z: 10 };
const radius = 1;
const noDelta = true;
let intersectResult = lccObject.intersectsSphere({ center, radius, noDelta });
if (intersectResult.hit) {
console.log('Collision occurs');
}
} else {
// Collision function not supported
}
注意事项
- 此接口需在
LCCRender.load()的成功回调函数触发后调用。 - 使用前应先通过
hasCollision()查询是否支持碰撞检测。 - SDK 只加载相机位置附近范围的碰撞数据。
相关 API
LCCObject::hasCollision()LCCObject::intersectsCapsule()