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

162 lines
5.5 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]
---
# ParametricCylinder
- 源文件:`packages/sdk/src/parametric/ParametricCylinder.ts`
- 文档位置:`packages/docs/api/parametric/ParametricCylinder.md`
## 类:`ParametricCylinder`
- 作用:高精度参数化圆柱体 支持完全自定义的圆柱体生成,包括顶部/底部半径、高度、分段数等参数 可以创建圆柱、圆锥、圆台等多种形状
- 继承/实现:`extends Mesh<BufferGeometry, Material>implements IParametricGeometry`
### 构造函数
#### `new ParametricCylinder(options: ICylinderOptions = {})`
- 作用:创建参数化圆柱体
- 入参:
| 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `options` | `ICylinderOptions` | 否 | - 圆柱体配置选项 |
- 出参:`ParametricCylinder`
- 返回说明:返回当前类实例。
### 属性
| 属性名 | 可见性 | 类型 | 作用 |
| --- | --- | --- | --- |
| `options` | `public` | `Required<ICylinderOptions>` | 用于保存 `options` 对应的数据。 |
### 方法
#### `createCone(radius: number = 1, height: number = 2, radialSegments: number = 64): ParametricCylinder`
- 作用创建圆锥体顶部半径为0的圆柱体
- 入参:
| 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `radius` | `number` | 否 | - 底部半径 |
| `height` | `number` | 否 | - 高度 |
| `radialSegments` | `number` | 否 | - 径向分段数 |
- 出参:`ParametricCylinder`
- 返回说明:圆锥体实例
#### `createGeometry(): CylinderGeometry`
- 作用:创建圆柱体几何体 作用:基于当前实例的 `options` 构造并返回一个新的 `THREE.CylinderGeometry`。 入参:无 出参:`CylinderGeometry` 行为说明:读取 `options`(包括 `radiusTop`、`radiusBottom`、`height`、`radialSegments` 等)并以这些参数构造 `THREE.CylinderGeometry`,用于初始化或替换实例的 `geometry`
- 入参:无
- 出参:`CylinderGeometry`
- 返回说明:返回 `CylinderGeometry`
#### `updateParameters(options: Partial<ICylinderOptions>): void`
- 作用:更新圆柱体参数并触发几何体重建 作用:合并并应用提供的参数到内部 `options`,随后重新生成几何体。 入参:
- 入参:
| 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `options` | `Partial<ICylinderOptions>` | 是 | - `Partial<ICylinderOptions>` 要更新的参数字段集合 出参:`void` 行为说明:仅覆盖提供的字段,然后调用 `updateGeometry()` 以使几何体反映新的参数。 |
- 出参:`void`
- 返回说明:无返回值。
#### `updateGeometry(): void`
- 作用:更新几何体 作用:根据当前 `options` 重新生成并替换网格的几何体。 入参:无 出参:`void` 行为说明:销毁现有几何体(调用 `dispose()`),调用 `createGeometry()` 创建新几何并赋值给 `this.geometry`
- 入参:无
- 出参:`void`
- 返回说明:无返回值。
#### `dispose(): void`
- 作用:销毁资源 作用:释放几何体与材质占用的 GPU/内存资源并断开引用。 入参:无 出参:`void` 行为说明:依次调用 `geometry.dispose()``material.dispose()`(若材质支持),并清理内部引用,便于垃圾回收。
- 入参:无
- 出参:`void`
- 返回说明:无返回值。
## 构造示例
- 来源:`packages/demo/src/disasterFormationPanel/GeothermalScene/GeothermalCasingDamageDisasterPanel.vue`
```ts
const position = {x: 0, y: 0.5, z: 0};
const cylinder = new ParametricCylinder({
radiusTop: 0.21,
radiusBottom: 0.21,
height: 0.2,
//------ 圆柱上下不闭合 开始------
openEnded: true,
//------ 圆柱上下不闭合 结束------
//------ 圆柱细分优化 开始------
radialSegments: 96,
//------ 圆柱细分优化 结束------
material: new THREE.MeshBasicMaterial({
color: '#ff0000',
side: THREE.DoubleSide,
}),
});
cylinder.renderOrder = 1;
cylinder.position.set(position.x, position.y, position.z);
viewer!.scene.add(cylinder);
```
- 来源:`packages/demo/src/disasterFormationPanel/GeothermalScene/GeothermalWellboreInstabilityDisasterPanel.vue`
```ts
const position = {x: 1.5019181086420077, y: 1.1203964954097632, z: 1.5};
const cylinder = new ParametricCylinder({
radiusTop: 0.21,
radiusBottom: 0.21,
height: 0.2,
//------ 圆柱上下不闭合 开始------
openEnded: true,
//------ 圆柱上下不闭合 结束------
//------ 圆柱细分优化 开始------
radialSegments: 96,
//------ 圆柱细分优化 结束------
material: new THREE.MeshBasicMaterial({
color: '#ffff00',
side: THREE.DoubleSide,
}),
});
cylinder.renderOrder = 1;
cylinder.name = 'WellboreInstability_1';
cylinder.position.set(position.x, position.y, position.z);
viewer!.scene.add(cylinder);
```
## 函数示例
- 当前 Demo 中没有直接展示 `ParametricCylinder` 的公开方法调用。
## Demo 参考
### `ParametricCylinder`
以下示例文件中可以看到该 API 的实际调用方式:
- `packages/demo/src/disasterFormationPanel/GeothermalScene/GeothermalCasingDamageDisasterPanel.vue`
- `packages/demo/src/disasterFormationPanel/GeothermalScene/GeothermalWellboreInstabilityDisasterPanel.vue`
- `packages/demo/src/disasterFormationPanel/OilGasScene/CasingDamageDisasterPanel.vue`
- `packages/demo/src/disasterFormationPanel/OilGasScene/WellboreInstabilityDisasterPanel.vue`
- `packages/demo/src/panels/TunnelScene/StressApplicationPanel.vue`