How to get coordinates i.e vertices from an object

大城市里の小女人 提交于 2019-12-11 07:36:44

问题


I am trying to get geometry data one element at a time such as vertices. What I tried so far:

  • fragproxy = viewer.gui.impl.getFragmentProxy(model,fragid) gives me some kind of geometry, but not any vertices, which I can access by dbId

  • frags = viewer.gui.model.getFragmentList() gives me a fragId to dbId map but no no connection from dbId to geometry

Does anyone know a method to get the geometry with the vertices ?


回答1:


The positions value of the following code snippets is the vertices what you want.

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

Since this information of the Forge fragment is stored in a flatten storage, please check the demo extension Autodesk.ADN.Viewing.Extension.MeshData.js if you want to rebuild the meshing relationship.

Hope it helps!



来源:https://stackoverflow.com/questions/50513656/how-to-get-coordinates-i-e-vertices-from-an-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!