You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Forge Viewer捕捉选项设置:如何禁用顶点/中点等捕捉类型?

Forge Viewer 禁用部分捕捉类型的实现方案

不用重新创建Snapper实例,直接修改Viewer默认的Snapper工具配置即可实现需求,以下是具体步骤和代码示例:

  • 获取已有Snapper实例:通过Viewer的toolController获取默认的snapper工具,无需手动新建
  • 配置允许的捕捉类型:修改enabledSnapTypes属性,只保留你需要的捕捉类型,即可自动禁用其他类型

代码示例

// 确保Viewer已初始化完成后执行
const snapper = viewer.toolController.getTool('snapper');
if (snapper) {
    // 示例:仅保留端点和边的捕捉,禁用顶点、中点等类型
    snapper.enabledSnapTypes = [
        Autodesk.Viewing.Snapper.SNAP_TYPES.ENDPOINT,
        Autodesk.Viewing.Snapper.SNAP_TYPES.EDGE
    ];

    // 另一种方式:从默认类型中排除不需要的(比如顶点、中点)
    // const allowedTypes = snapper.enabledSnapTypes.filter(type => 
    //     type !== Autodesk.Viewing.Snapper.SNAP_TYPES.VERTEX && 
    //     type !== Autodesk.Viewing.Snapper.SNAP_TYPES.MIDPOINT
    // );
    // snapper.enabledSnapTypes = allowedTypes;
}

常见捕捉类型常量参考

  • Autodesk.Viewing.Snapper.SNAP_TYPES.VERTEX:顶点捕捉
  • Autodesk.Viewing.Snapper.SNAP_TYPES.MIDPOINT:中点捕捉
  • Autodesk.Viewing.Snapper.SNAP_TYPES.ENDPOINT:端点捕捉
  • Autodesk.Viewing.Snapper.SNAP_TYPES.EDGE:边捕捉
  • Autodesk.Viewing.Snapper.SNAP_TYPES.FACE:面捕捉

关于创建新Snapper实例失败的说明

Viewer的toolController会默认管理snapper工具,手动新建实例需要先移除旧工具再注册新工具,步骤繁琐且没必要。直接修改现有实例的配置是更高效的方案。如果一定要尝试替换实例,可参考以下代码:

const newSnapper = new Autodesk.Viewing.Snapper(viewer);
newSnapper.enabledSnapTypes = [Autodesk.Viewing.Snapper.SNAP_TYPES.ENDPOINT];

// 移除旧工具并注册新工具
viewer.toolController.removeTool('snapper');
viewer.toolController.registerTool(newSnapper);
viewer.toolController.activateTool('snapper');

内容的提问来源于stack exchange,提问作者Igor Barcelos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 04:19:55