setThemingColor仅适用于叶节点dbId [英] setThemingColor only working for leaf node dbIds

查看:137
本文介绍了setThemingColor仅适用于叶节点dbId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从文档看来,您应该可以使用任何dbId调用setThemingColor,但它似乎仅在您传递的id是leafnode的情况下有效吗?这样对吗?

From the documentation it looks like you should be able to call setThemingColor with any dbId, but it seems to only work if the id that you pass is a leafnode? Is this correct?

还有什么方法可以批量调用此方法,还是一次仅一个单个叶节点?我想将dbId数组传递给方法.

Also is there any way to bulk call this method, or is it only one single leaf node at a time? I would like to pass an array of dbId's into the method.

推荐答案

是的,根据我的经验,它仅适用于叶节点.但是,可以通过以下方式检索父节点的叶节点:

Yes, it's only working with the leaf nodes in my experience. However, leaf nodes of a parent node can be retrieved in this way:

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

getLeafNodes( viewer.model, [1] )
    .then( ( leafNodes ) => {
      // All leaf dbIds under the dbId 1.
      console.log( leafNodes );
    })
    .catch( ( error ) => console.warn( error ) );

检索所有叶dbId之后,您可以像下面这样简单地编写一个for循环为每个dbId调用setThemingColor:

After retrieving all leaf dbIds, you can simply write a for loop to call setThemingColor for every dbIds like this way:

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

getLeafNodes( viewer.model, [1] )
    .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 ) );

希望获得帮助.

对功能getLeafNodes的引用: https://forge.autodesk.com/blog/hidding-completely-viewer-nodes-no-ghosting

这篇关于setThemingColor仅适用于叶节点dbId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆