2017-12-26 15 views
-1

ありまね質問です: How to get location with dbid in 2D2DビューでDBIDと場所を取得する方法

はなく、anwseredされていません。

私は同じ質問があります.2Dビューでdbidを使用してオブジェクトの位置情報を取得する方法はありますか?

私たちは、特定のオブジェクトにマークを付けてdbidsを外部データベースに保存する必要があります。次にモデルを開くときには、これらのIDを使用して位置を見つけて、カスタムシェイプを描画する必要がありますそれらのオブジェクトを強調表示します。

私はviewer.impl.highlightObjectNodeを使用しようとしましたが、選択されたオブジェクトのみを表示できます。カスタムビジュアライゼーションには非常に制限があります。

答えて

0

Forgeフラグメントのメッシュ情報にアクセスするためのコードスニペットがあります。特定のForgeビューアdbIdの場所を見つけるのに役立ちます。詳細については、このエクステンションを参照することができます:https://github.com/Autodesk-Forge/library-javascript-viewer-extensions/blob/master/src/Autodesk.ADN.Viewing.Extension.MeshData/Autodesk.ADN.Viewing.Extension.MeshData.js

さらに、ハイライト要素の場合のみviewer.impl.highlightObjectNode、それは私のexperinceとして他の目的に使用することはできません。あなたもviewer3D.jsで「viewer.impl.fitToView」を確認することができます

function getLeafFragIds(model, leafId) { 
    const instanceTree = model.getData().instanceTree; 
    const fragIds = []; 

    instanceTree.enumNodeFragments(leafId, function(fragId) { 
     fragIds.push(fragId); 
    }); 

    return fragIds; 
    } 

    function getComponentGeometry(viewer, dbId) { 

    const fragIds = getLeafFragIds(viewer.model, dbId); 

    let matrixWorld = null; 

    const meshes = fragIds.map(function(fragId) { 

     const renderProxy = viewer.impl.getRenderProxy(viewer.model, fragId); 

     const geometry = renderProxy.geometry; 
     const attributes = geometry.attributes; 
     const positions = geometry.vb ? geometry.vb : attributes.position.array; 

     const indices = attributes.index.array || geometry.ib; 
     const stride = geometry.vb ? geometry.vbstride : 3; 
     const offsets = geometry.offsets; 

     matrixWorld = matrixWorld || renderProxy.matrixWorld.elements; 

     return { 
     positions, 
     indices, 
     offsets, 
     stride 
     }; 
    }); 

    return { 
     matrixWorld, 
     meshes 
    }; 
    } 

    var meshInfo = getComponentGeometry(viewer, 1234); 
0

、この機能は、選択したオブジェクト組合のバウンディングボックスを計算し、表示するためにそれらに合うので、私は、オブジェクトのバウンディングボックスの中心部を取得するには、この関数からコードを抽出しますそれとdbidの座標

function getObjectBound2D(viewer, objectId) { 
    var model = viewer.model; 
    // This doesn't guarantee that an object tree will be created but it will be pretty likely 
    var bounds, bc, i; 
    if (model.is2d()) { 
     bounds = new THREE.Box3(); 
     // move this next one up into the calling method 
     bc = new avp.BoundsCallback(bounds); 

     var dbId2fragId = model.getData().fragments.dbId2fragId; 

     var fragIds = dbId2fragId[objectId]; 
     // fragId is either a single vertex buffer or an array of vertex buffers 
     if (Array.isArray(fragIds)) { 
      for (var j = 0; j < fragIds.length; j++) { 
       // go through each vertex buffer, looking for the object id 
       find2DBounds(model, fragIds[j], objectId, bc); 
      } 
     } else if (typeof fragIds === 'number') { 
      // go through the specific vertex buffer, looking for the object id 
      find2DBounds(model, fragIds, objectId, bc); 
     } 

     // should have some real box at this point; check 
     if (!bounds.empty()) { 
      return bounds; 
     } 
    } 

    function find2DBounds(model, fragId, dbId, bc) { 
     var mesh = model.getFragmentList().getVizmesh(fragId); 
     var vbr = new avp.VertexBufferReader(mesh.geometry); 
     vbr.enumGeomsForObject(dbId, bc); 
    } 

    function find2DLayerBounds(model, fragId, bc) { 
     var mesh = model.getFragmentList().getVizmesh(fragId); 
     var vbr = new avp.VertexBufferReader(mesh.geometry); 
     var visibleLayerIds = that.getVisibleLayerIds(); 
     vbr.enumGeomsForVisibleLayer(visibleLayerIds, bc); 
    } 
}; 

var objBoundingbox = getObjectBound2D(viewer,dbid); 

var objCenterCoordinates = objBoundingbox.center(); 
関連する問題