简体   繁体   English

如何在 Autodesk Forge 查看器中将点击事件添加到图钉?

[英]How can i add click event to pushpin in autodesk forge viewer?

How can I add a click event on pushpins to autodesk forge?如何将图钉上的单击事件添加到 Autodesk forge? In an existing extension , he opens the content for pushpin using the camera focus on it.现有扩展中,他使用相机焦点打开图钉的内容。 I want to open it with click on pushpin.我想通过点击图钉打开它。

But I add the pushpini to the model manually and translate the coordinates with the following code但我手动将 pushpini 添加到 model 并使用以下代码转换坐标

var setData = function (event) {      
      var screenPoint = {
        x: event.clientX,
        y: event.clientY
      };
      if (screenPoint) {
        var n = normalize(screenPoint);
        var dbId = /*_viewer.utilities.getHitPoint*/ getHitDbId(n.x, n.y);
        if (dbId == null) return;
      }
    }

    function getHitDbId(x, y) {
      y = 1.0 - y;
      x = x * 2.0 - 1.0;
      y = y * 2.0 - 1.0;

      var vpVec = new THREE.Vector3(x, y, 1);
      var result = viewer.impl.hitTestViewport(vpVec, false);
      console.log(result);

      if (result) {
        dummyData.push({
          icon: Math.round(Math.random() * 3),
          x: result.point.x,
          y: result.point.y,
          z: result.point.z,
        });
        window.dispatchEvent(new CustomEvent('newData', {
          'detail': dummyData
        }))
      } else {
        return
      }
      return result ? result.dbId : null;
    };

    function normalize(screenPoint) {
      var viewport = viewer.navigation.getScreenViewport();
      var n = {
        x: (screenPoint.x - viewport.left) / viewport.width,
        y: (screenPoint.y - viewport.top) / viewport.height
      };
      return n;
    }

Is this even possible?这甚至可能吗?

This has already been taken care of in the original plugin - simply append your own handler in the click callbacks below where hit test on the markups is performed:这已经在原始插件中得到处理 - 只需 append 您自己的处理程序在下面的点击回调中执行标记的命中测试:

    this.onMouseMove = function(event) {
      if(this.line3d){
        this.update_DivLabel('onMarkupMove');
        this.updateHitTest(event);
      }
    }

    this.onClick = function(event) {
        this.updateHitTest(event);
        if (!this.hovered) return;
        this.selected = this.hovered; //
        //your own callback goes here
    }

And adjust here to fine tune hit test accuracy:并在此处调整以微调命中测试精度:

function markup3d(viewer, options) {
    this.raycaster.params.PointCloud.threshold = 5; // hit-test markup size.  Change this if markup 'hover' doesn't work
    this.size = 150.0; // markup size.  Change this if markup size is too big or small

The original live sample handles click as well by displaying a hoevering label:原始的实时样本也通过显示悬停的 label 来处理点击:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM