当按住 ctrl/shift/alt 瞄准已预选的子组件时,hitTest 返回 null

问题描述 投票:0回答:1

在已预选的节点组上调用

hitTest
时,即之前使用
select
预选的父/子关系中的节点,同时按住 Shift、Alt 或 Ctrl 键,
hitTest
调用将返回
 null

当按住修饰符(shift、alt、ctrl)键时,是否有另一种方法可以从光标下预选的节点子组中获取节点的

dbId

    private getDbIdAtCoords(x: number, y: number) {
        const viewport = this.viewerWrapper.viewer.container.getBoundingClientRect();
        const result = this.viewerWrapper.viewer.impl.hitTest(
            x - viewport.left,
            y - viewport.top,
            false,
        );
        return result ? result.dbId : 0;
    }
    ...
    this.viewer.canvas.onclick = evt => {
        this.getDbIdAtCoords(evt.clientX, evt.clientY);
    }
autodesk-forge autodesk-viewer
1个回答
0
投票

不需要按住任何键,我们需要存储所选的dbid并在hitTest后管理选择。

//  vc is viewer container reference
let selectiondbids = new Set([914]); // 914 is group dbid or parent dbid
vc.addEventListener('click', function (ev) {
  let screenPoint = {x: ev.clientX,y: ev.clientY};
  var hitTest = viewer.impl.hitTest(screenPoint.x,screenPoint.y,true);
  if(hitTest){
    console.log(hitTest.dbId)
    selectiondbids.add(hitTest.dbId); // add only if the object is outside the group/parent dbid and you want it to be selected.
  }else{
    return
  }
  viewer.clearSelection()
  viewer.select(Array.from(selectiondbids)) 
});
© www.soinside.com 2019 - 2024. All rights reserved.