我需要使用Autodesk Forge从IFC文件中获取尺寸,以便我可以计算建筑物的面积,质量和其他属性(建筑层)。 Autodesk Forge可以实现这一点吗?
答案 0 :(得分:2)
不幸的是,Forge Viewer会将任何支持的几何表示转换为基于Mesh的几何表示,因此您无法从Forge Viewer片段中获取任何可靠的信息。
如果原始源模型来自任何受支持的BIM软件,则IFC文件中的每个元素都应包含区域,质量和构建层(级别)的数据,并且您可以通过Viewer API读取这些属性:
viewer.search(text, onSuccessCallback, onErrorCallback, attributeNames)
viewer.model.getBulkProperties(dbIds, options, onSuccessCallback, onErrorCallback)
组合使用这些API:
viewer.search('Steel',
function( dbIds ){
viewer.model.getBulkProperties(dbIds, ['Mass'],
function(elements){
var totalMass = 0;
for(var i=0; i<elements.length; i++){
totalMass += elements[i].properties[0].displayValue;
}
console.log(totalMass);
})
}, null, ['Material'])
然而,
您可以通过访问Forge Viewer片段的网格数据来计算面积,体积和质量。 Here是一个显示如何访问网格的博客,其关键内容如下所示。这些代码用于重建扁平化数组中三角形网格的关系:
var fragProxy = viewer.impl.getFragmentProxy(
viewer.model,
fragId);
var renderProxy = viewer.impl.getRenderProxy(
viewer.model,
fragId);
fragProxy.updateAnimTransform();
var matrix = new THREE.Matrix4();
fragProxy.getWorldMatrix(matrix);
var geometry = renderProxy.geometry;
var attributes = geometry.attributes;
var vA = new THREE.Vector3();
var vB = new THREE.Vector3();
var vC = new THREE.Vector3();
if (attributes.index !== undefined) {
var indices = attributes.index.array || geometry.ib;
var positions = geometry.vb ? geometry.vb : attributes.position.array;
var stride = geometry.vb ? geometry.vbstride : 3;
var offsets = geometry.offsets;
if (!offsets || offsets.length === 0) {
offsets = [{start: 0, count: indices.length, index: 0}];
}
for (var oi = 0, ol = offsets.length; oi < ol; ++oi) {
var start = offsets[oi].start;
var count = offsets[oi].count;
var index = offsets[oi].index;
for (var i = start, il = start + count; i < il; i += 3) {
var a = index + indices[i];
var b = index + indices[i + 1];
var c = index + indices[i + 2];
vA.fromArray(positions, a * stride);
vB.fromArray(positions, b * stride);
vC.fromArray(positions, c * stride);
vA.applyMatrix4(matrix);
vB.applyMatrix4(matrix);
vC.applyMatrix4(matrix);
}
}
} else {
var positions = geometry.vb ? geometry.vb : attributes.position.array;
var stride = geometry.vb ? geometry.vbstride : 3;
for (var i = 0, j = 0, il = positions.length; i < il; i += 3, j += 9)
{
var a = i;
var b = i + 1;
var c = i + 2;
vA.fromArray(positions, a * stride);
vB.fromArray(positions, b * stride);
vC.fromArray(positions, c * stride);
vA.applyMatrix4(matrix);
vB.applyMatrix4(matrix);
vC.applyMatrix4(matrix);
}
}
此外,
有一个很棒的演示,展示了如何通过建筑层分割模型(级别:https://forge-rcdb.autodesk.io/configurator?id=5a7185a92a0a7aeb152725d5
此演示的主要概念是: