放大查看器中的房间

时间:2018-06-06 20:26:16

标签: autodesk-forge

现在,我可以列出级别。我正在尝试放大特定级别的特定房间。

我有房间dbId,但当我这样做时:

v.fitToView(34969, v.model)(v => viewer / 34969 dbId的房间)

相机即将走向:

enter image description here

我试图完成相同的相机移动,而不是点击modelStructureTool > Room

中的子项目时

关于房间的颜色

以下是我的修正代码:

var ulRoom = document.createElement('ul');
ulRoom.setAttribute('id','levelsList');
el.children.forEach(function(l){
var liRoom = document.createElement('li');
liRoom.setAttribute('class','room');
liRoom.setAttribute('style','cursor:pointer;color:  #000; font-weigth: bold');
liRoom.onclick = function () {
    console.log("l ====>", l);
    viewer.fitToView( [l.dbId], viewer.model);
    viewer.setThemingColor( l.dbId, viewer.model);
    };
    ulRoom.appendChild(liRoom);
    liRoom.innerHTML = l.name;
});

viewer.fitToView工作得很好。

在我的forEach中,l是房间:

enter image description here

1 个答案:

答案 0 :(得分:1)

第一个参数必须是数组,因此必须将函数调用更改为viewer.fitToView( [ 34969 ], viewer.model )。第二个参数model是可选的,因此在单个模型用例中它将变为viewer.fitToView( [ 34969 ] )

如果您在多个模型中使用Viewer,则必须从viewer.impl.modelQueue().getModels()找到该房间的相应模型和Viewer3D#fitToView的第二个参数。

希望它有所帮助。

修改

用于更改元素颜色的查看器API为viewer.setThemingColor( dbId, color ),它仅适用于叶节点。在调查您提供给Forge Helpdesk的模型后,我发现dbId 34969的房间不是Viewer实例树的叶节点。因此,这就是为什么在API适合事件时颜色没有变化的原因。

function getLeafNodes( model, dbIds ) {

      return new Promise( ( resolve, reject ) => {

        try {

          const instanceTree = model.getData().instanceTree

          dbIds = dbIds || instanceTree.getRootId();

          const dbIdArray = Array.isArray( dbIds ) ? dbIds : [dbIds]
          let leafIds = [];

          const getLeafNodesRec = ( id ) => {
            let childCount = 0;

            instanceTree.enumNodeChildren( id, ( childId ) => {
                getLeafNodesRec( childId );

                ++childCount;
              })

            if( childCount == 0 ) {
              leafIds.push( id );
            }
          }

          for( let i = 0; i < dbIdArray.length; ++i ) {
            getLeafNodesRec( dbIdArray[i] );
          }

          return resolve( leafIds );

        } catch (ex) {

          return reject(ex)
        }
    })
}

let color = new THREE.Vector4( 255/255, 0/255, 0/255, 1 );

getLeafNodes( viewer.model, [ 34969 ] )
    .then( ( leafNodes ) => {

      // Call setThemingColor for every leaf node.
      for( let i = 0; i < leafNodes.length; i++ ) {
          viewer.setThemingColor( leafNodes[i], color );
      }
    })
    .catch( ( error ) => console.warn( error ) );

以下是Viewer文档:https://developer.autodesk.com/en/docs/viewer/v2/reference/javascript/viewer3d/