在 Forge Viewer 3D 上显示图标捕捉

Show icon snap on Forge Viewer 3D

我尝试在光标悬停在 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();
}

我也参考了其中一些主题,但对我不起作用。 https://autodeskviewer.com/viewers/latest/docs/extensions_Measure_Measure.js.html .提前致谢!

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

更新:

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()
 }