问题描述
我正在尝试一次获得一个顶点等几何数据.到目前为止,我尝试过的事情:
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)
给了我某种几何形状,但没有任何顶点,我可以通过dbId来访问
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()
给了我一个从fragId到dbId的映射,但没有从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 ?
推荐答案
以下代码段的positions值是您想要的顶点.
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 );
由于Forge片段的此信息存储在扁平存储器中,因此请检查演示扩展 Autodesk.ADN.Viewing.Extension.MeshData.js (如果需要)重建网格关系.
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.
希望有帮助!
这篇关于如何从对象获取坐标,即顶点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!