当将VertexBufferReader与GeometryCallback一起使用时-我怎么知道枚举何时完成?

时间:2019-02-11 02:39:44

标签: autodesk-forge

我正在解析基于2DWG的几何。线,折线,简单的东西。基于https://stackoverflow.com/a/50693640/2337681,我使用VertexBufferReader的enumGeomsForObject函数来获取线段和顶点。这些是路径所有段的单独回调。结果是按我看到的顺序排列的-但是如何知道枚举何时完成?使用闭合的折线,可以确定最新分段的端点接近等于第一分段的起点。但这不适用于开放多边形...

1 个答案:

答案 0 :(得分:1)

根据我的经验,VertexBufferReader#enumGeomsForObject是一个同步函数,在实现VertexBufferReader时我看不到任何异步代码。因此,您可以将数据容器传递到enumGeomsForObject方法的第二个回调中,以存储所需的数据。

这是我的测试代码,最后一个枚举(GeometryCallback.data)的console.log( 'enuming node fragments', gc.data );console.log( 'enumed node fragments', gc.data );的结果数据相同

function GeometryCallback(viewer) {
    this.viewer = viewer;
    this.data = [];
}

GeometryCallback.prototype.onLineSegment = function(x1, y1, x2, y2, vpId) {
   console.log( 'On Line segment', this.data );
   this.data.push({
        type: 'Line segment',
        x1, y1, x2, y2, vpId
  });
}

GeometryCallback.prototype.onCircularArc = function(cx, cy, start, end, radius, vpId) {
  console.log( 'On Circular arc', this.data );
  this.data.push({
        type: 'CircularArc',
        cx, cy, start, end, radius, vpId
  });
};

GeometryCallback.prototype.onEllipticalArc = function(cx, cy, start, end, major, minor, tilt, vpId) {
 console.log( 'On Elliptical arc', this.data );
 this.data.push({
        type: 'EllipticalArc',
        cx, cy, start, end, major, minor, tilt, vpId
 });
};

var it = NOP_VIEWER.model.getData().instanceTree;
var gc = new GeometryCallback();
var dbId = NOP_VIEWER.getSelection()[0];
it.enumNodeFragments( dbId, function( fragId ) {
    var m = NOP_VIEWER.impl.getRenderProxy(NOP_VIEWER.model, fragId);
    var vbr = new Autodesk.Viewing.Private.VertexBufferReader(m.geometry, NOP_VIEWER.impl.use2dInstancing);
    vbr.enumGeomsForObject(dbId, gc);

    console.log( 'enuming node fragments', gc.data );
});

console.log( 'enumed node fragments', gc.data );