Skip to content

剖切

viewer.section 提供剖切(裁剪)能力:一个 Section 容纳至多 6 个裁剪平面,按布尔方式组合出「保留区域」,激活后参与裁剪;切口默认有盖面(capping),平面带 gizmo 可直接拖拽。典型流程是 create()addPlane()activate() 三步。

下面的 demo 默认带一个 Z 轴平面,可用底部面板加平面、切布尔方式、开关盖面与 gizmo,或直接拖拽画布里的控制杆:

可交互 demo · 拖拽 gizmo 控制杆移动剖切面,鼠标拖拽旋转,空格键 fit在新窗口打开 ↗

核心 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