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()