【问题标题】:Show icon snap on Forge Viewer 3D在 Forge Viewer 3D 上显示图标捕捉
【发布时间】:2020-11-11 21:07:42
【问题描述】:

当光标悬停在 3d 模型上时,我尝试显示捕捉图标(一些黄色图标与光标一起出现在进行测量时)。这是我的功能,它根本不适合我。我错过了什么吗?

onMouseMove = (event) => {
  const snapper = new Autodesk.Viewing.Extensions.Snapping.Snapper(this.viewer);
  const worldCoordinate = this.viewer.impl.hitTest(event.clientX, event.clientY);

  if (worldCoordinate === null) return;
  const hitTestResult = this.viewer.impl.snappingHitTest(
    worldCoordinate.x,
    worldCoordinate.y,
    worldCoordinate.z
  );
  if (hitTestResult === null) return;
  snapper.snapping3D(hitTestResult);
  const result = snapper.getSnapResult();
}

我也参考了其中一些主题,但不适用于我。 How to use Forge Viewer Snapper? How to activate Autodesk Forge Snapper? https://autodeskviewer.com/viewers/latest/docs/extensions_Measure_Measure.js.html .提前致谢!

【问题讨论】:

    标签: autodesk-forge autodesk-viewer


    【解决方案1】:

    我认为这个问题是由于缺少查看器的容器偏移量造成的。无法正确测试世界坐标。如果有帮助,请检查下面的代码。 如果我误解了这个问题,您能否分享更多关于它不起作用的信息?

    更新

    onMouseMove = (event) => {
    
      const snapper = new Autodesk.Viewing.Extensions.Snapping.Snapper(this.viewer);
    
      const viewer_pos = this.viewer.container.getBoundingClientRect();   
    
      const worldCoordinate = this.viewer.impl.hitTest(event.clientX-viewer_pos.x, event.clientY-viewer_pos.y); 
     if (worldCoordinate === null) return;
    
     // const hitTestResult = this.viewer.impl.snappingHitTest(
     //   worldCoordinate.point.x,
     //   worldCoordinate.point.y,
     //   worldCoordinate.point.z
     // );    
     //if (hitTestResult === null) return;
    
     snapper.snapping3D(worldCoordinate);
     const result = snapper.getSnapResult(); 
     snapper.indicator.render()
     }
    

    【讨论】:

    • 嗨小东,当我的鼠标悬停在模型上时,我想显示像这样image 的捕捉标记。我尝试用你的新建议进行测试,但对我也不起作用。
    • 嗨,Trung,刚才我没有检查为什么需要 snappingHitTest。并且 worldCoordinate 没有 x,y,z,而 worldCoordinate.point 有。我猜这些代码来自旧版本的 Viewer。所以我检查了最新版本(v7.23)的Measurement Extension代码。我认为来自 hitTest 的数据足以说明几何和交点。通过这些, snapper 将计算点并渲染指标。我更新了代码并上传了一段关于它如何在我身边工作的测试视频:youtu.be/iDd9E2SBVe0
    猜你喜欢
    • 2022-01-13
    • 2019-11-14
    • 2020-07-22
    • 2018-01-16
    • 2021-06-16
    • 2017-10-25
    • 2018-04-12
    • 2019-07-22
    • 2018-12-06
    相关资源
    最近更新 更多