Appearance
剖切
viewer.section 提供剖切(裁剪)能力:一个 Section 容纳至多 6 个裁剪平面,按布尔方式组合出「保留区域」,激活后参与裁剪;切口默认有盖面(capping),平面带 gizmo 可直接拖拽。典型流程是 create() → addPlane() → activate() 三步。
下面的 demo 默认带一个 Z 轴平面,可用底部面板加平面、切布尔方式、开关盖面与 gizmo,或直接拖拽画布里的控制杆:
核心 API
ts
// 三步:建 section → 加平面 → 激活
const section = viewer.section.create({ boolean: "intersection" });
section.addPlane(viewer.section.planeFromAxis("z")); // 轴对齐平面,过包围盒中心
section.addPlane(viewer.section.planeFromAxis("x", 50)); // 沿 +X 偏移 50(世界单位)
section.activate();
// 盖面与 gizmo
viewer.section.setCappingStyle({ visible: true, faceColor: { r: 0.8, g: 0.82, b: 0.88 } });
viewer.section.setInteractive(true); // gizmo 拖拽,默认开
// 拖拽过程可订阅
viewer.on("section-plane-drag", (e) => console.log(e.planeId, e.plane.normal));
// 全部撤掉
viewer.section.clear();行为要点
create/addPlane:create()新建 section(初始无平面、未激活);addPlane(planeSpec)返回SectionPlane句柄(可setPlane/flip/setStyle),单个 section 上限 6 个平面,超出抛ViewerError。无平面的 section 不能activate()。planeFromAxis(axis, offset?):便捷构造轴对齐平面——过模型包围盒中心、法向沿指定世界轴(Z-up / CATIA 约定,"x"…"-z"六个取值),再沿该轴偏移offset(世界单位,即模型文件的原始坐标单位,默认 0)。平面PlaneSpec的语义是「法向负侧被裁掉」。- 布尔组合:section 内多平面按
CuttingBoolean组合保留区域——"intersection"保留所有平面内侧的交集(半切 / 盒切,最常见);"union"仅切掉所有平面共同覆盖的区域(楔形切)。经create({ boolean })或section.setBoolean()设置。 - 多 section 语义:最多同时激活 4 个 section(超出抛
ViewerError),最终可见区域是各 active section 保留区的交集——每多激活一个 section 只会切掉更多。 - 盖面(capping):切口默认填充盖面;
setCappingStyle({ visible, faceColor, lineColor })部分字段合并更新,立即重算。 - gizmo 拖拽:
setInteractive开关平面 gizmo(默认开),拖拽过程依次触发section-plane-drag-start/section-plane-drag(每次平面更新)/section-plane-drag-end,payload 带sectionId/planeId/ 当前plane;每个平面的参考四边形与控制杆可经plane.setReferenceVisible/setHandleVisible单独显隐。 - 撤销与清理:
section.deactivate()退出裁剪(平面保留,可再激活);viewer.section.remove(section)移除单个;viewer.section.clear()反激活并移除全部。
相关 API
- 概览:viewer.section — 剖切域的设计意图与典型用法。
- 坐标系与单位 — 剖切轴的 Z-up 方向语义与世界单位。
- 事件系统 —
section-changed/section-plane-drag*等事件参考。 SectionManager—create/planeFromAxis/ 盖面与 gizmo 开关。Section/SectionPlane— 平面增删、布尔、翻转与样式。PlaneSpec/CappingStyle— 平面与盖面的类型定义。