deep-engine-demo/packages/docs/api/parametric/ParametricArch.md
2026-04-19 18:46:28 +08:00

274 lines
7.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
outline: [2, 3]
---
# ParametricArch
- 源文件:`packages/sdk/src/parametric/ParametricArch.ts`
- 文档位置:`packages/docs/api/parametric/ParametricArch.md`
## 类:`ParametricArch`
- 作用:高性能参数化城门洞 (基于 PathArchGeometry) 使用增量更新而非重建几何体,性能更优
- 继承/实现:`extends ParametricGeometryBaseimplements IParametricGeometry`
### 构造函数
#### `new ParametricArch(viewer: Viewer, options: IArchOptions = {})`
- 作用:创建参数化城门洞
- 入参:
| 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `viewer` | `Viewer` | 是 | 关联的 Viewer 实例。 |
| `options` | `IArchOptions` | 否 | - 城门洞配置选项 |
- 出参:`ParametricArch`
- 返回说明:返回当前类实例。
### 属性
| 属性名 | 可见性 | 类型 | 作用 |
| --- | --- | --- | --- |
| `geometry` | `public` | `PathArchGeometry` | 用于保存 `geometry` 对应的数据。 |
| `material` | `public` | `THREE.Material` | 材质参数。 |
| `options` | `public` | `Required<IArchOptions>` | 用于保存 `options` 对应的数据。 |
| `isAnimating` | `public` | `boolean` | 动画相关属性 |
| `animationRequestId` | `public` | `number \| null` | 用于保存 `animationRequestId` 对应的数据。 |
| `originalExtrudePathPoints` | `public` | `any[] \| null` | 用于保存 `originalExtrudePathPoints` 的集合数据。 |
| `pathPointList` | `public` | `PathPointList \| null` | 用于保存 `pathPointList` 对应的数据。 |
| `spline` | `public` | `THREE.CatmullRomCurve3 \| null` | 用于保存 `spline` 对应的数据。 |
| `animationDuration` | `public` | `number` | 用于保存 `animationDuration` 对应的数据。 |
| `animationDelay` | `public` | `number` | 用于保存 `animationDelay` 对应的数据。 |
| `animationProgress` | `public` | `number` | 用于保存 `animationProgress` 对应的数据。 |
| `followMesh` | `public` | `THREE.Mesh \| THREE.Object3D \| null` | 跟随动画的 mesh |
| `viewer` | `public` | `Viewer \| null` | 用于保存 `viewer` 对应的数据。 |
| `collisionProxyMesh` | `public` | `THREE.Mesh \| null` | 碰撞代理 mesh |
| `outerShape` | `public` | `THREE.Shape \| null` | 用于创建碰撞代理的形状 |
### 方法
#### `createGeometry(): PathArchGeometry`
- 作用:创建城门洞几何体
- 入参:无
- 出参:`PathArchGeometry`
- 返回说明:返回 `PathArchGeometry`
#### `updateParameters(options: Partial<IArchOptions>): void`
- 作用:更新城门洞参数
- 入参:
| 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `options` | `Partial<IArchOptions>` | 是 | 当前功能对应的配置项。 |
- 出参:`void`
- 返回说明:无返回值。
#### `updateGeometry(): void`
- 作用:更新几何体
- 入参:无
- 出参:`void`
- 返回说明:无返回值。
#### `startAnimation(): void`
- 作用:开始动画
- 入参:无
- 出参:`void`
- 返回说明:无返回值。
#### `stopAnimation(): void`
- 作用:停止动画
- 入参:无
- 出参:`void`
- 返回说明:无返回值。
#### `resetAnimation(): void`
- 作用:重置动画
- 入参:无
- 出参:`void`
- 返回说明:无返回值。
#### `setAnimationDuration(duration: number): void`
- 作用:设置动画时长
- 入参:
| 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `duration` | `number` | 是 | 参数 `duration`,类型为 `number`。 |
- 出参:`void`
- 返回说明:无返回值。
#### `setAnimationDelay(delay: number): void`
- 作用:设置动画延迟
- 入参:
| 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `delay` | `number` | 是 | 参数 `delay`,类型为 `number`。 |
- 出参:`void`
- 返回说明:无返回值。
#### `createDebugPanel(): void`
- 作用:创建调试面板
- 入参:无
- 出参:`void`
- 返回说明:无返回值。
#### `dispose(): void`
- 作用:销毁资源
- 入参:无
- 出参:`void`
- 返回说明:无返回值。
#### `createShapes(): void`
- 作用:创建形状(外轮廓,用于碰撞代理)
- 入参:无
- 出参:`void`
- 返回说明:无返回值。
#### `createCollisionProxyMesh(): void`
- 作用:创建碰撞代理 mesh 使用前两个路径点创建简化的城门洞几何体
- 入参:无
- 出参:`void`
- 返回说明:无返回值。
#### `updateCollisionProxyTransform(p1: THREE.Vector3, p2: THREE.Vector3): void`
- 作用:更新碰撞代理 mesh 的位置和旋转
- 入参:
| 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `p1` | `THREE.Vector3` | 是 | - 第一个点 |
| `p2` | `THREE.Vector3` | 是 | - 第二个点 |
- 出参:`void`
- 返回说明:无返回值。
#### `loadFollowMesh(url: string): Promise<void>`
- 作用:加载跟随动画的模型
- 入参:
| 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `url` | `string` | 是 | 资源地址。 |
- 出参:`Promise<void>`
- 返回说明:返回 Promise解析结果类型为 `void`
#### `animate(data: RenderEventData): void`
- 作用:动画循环
- 入参:
| 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `data` | `RenderEventData` | 是 | 输入数据。 |
- 出参:`void`
- 返回说明:无返回值。
#### `subtractMesh(): number`
- 作用:直接对所有已添加的碰撞目标执行 CSG 减法操作 使用 addCollisionTarget 添加的目标
- 入参:无
- 出参:`number`
- 返回说明:成功处理的目标数量
## 构造示例
- 来源:`packages/demo/src/panels/TunnelScene/RobotExcavationPanel.vue`
```ts
// 底部
topEnabled: true,
followMeshUrl: "/model/机器人.glb",
followMeshOffset: new THREE.Vector3(0, -0.2, 0.1),
// extrudePathPoints: straightPathPoints,
extrudePathPoints: straightPathPoints1,
enableCSGOperation: true,
animate: true,
// animate: false,
// debugCollisionProxy: true,
};
excavationTunnel = new ParametricArch(viewer, geometrySettings);
Tool.defineMaterialOpacityMapping(excavationTunnel);
excavationTunnel.name = "机器人开挖隧道";
```
- 来源:`packages/demo/src/panels/TunnelScene/RobotExcavationPanel.vue`
```ts
excavationTunnel = new ParametricArch(viewer, geometrySettings);
Tool.defineMaterialOpacityMapping(excavationTunnel);
excavationTunnel.name = "机器人开挖隧道";
let defaultExcavationTunnel = new ParametricArch(viewer, {
...geometrySettings,
animate:false
});
defaultExcavationTunnel.name = "机器人开挖隧道碰撞体";
defaultExcavationTunnel.visible = false;
Tool.setExcludeAll(defaultExcavationTunnel)
viewer.rangeCullingManager.add(defaultExcavationTunnel);
```
## 函数示例
- 当前 Demo 中没有直接展示 `ParametricArch` 的公开方法调用。
## Demo 参考
### `ParametricArch`
以下示例文件中可以看到该 API 的实际调用方式:
- `packages/demo/src/panels/TunnelScene/RobotExcavationPanel.vue`
- `packages/demo/src/views/TunnelScene.vue`