autodesk-forge - 将 VertexBufferReader 与 GeometryCallback 一起使用时 - 我如何知道枚举何时完成?
问题描述
我正在解析基于 2D dwg 的几何图形。线,折线,简单的东西。基于 https://stackoverflow.com/a/50693640/2337681我使用 VertexBufferReader 的 enumGeomsForObject 函数来获取线段和顶点。这些是路径所有段的单独回调。结果按我所见的顺序排列 - 但我怎么知道枚举何时完成?使用闭合的折线,可以确定最新段的端点接近等于第一段的起点。但这不适用于开放的多边形......
解决方案
以我的经验,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 );
推荐阅读
- objective-c - Objective C中的预处理器#if错误评估?
- c# - 是否可以在生成 Step 绑定时限制 specflow 搜索测试的项目?
- asterisk - 无法使用 Asterisk 发起呼叫
- mysql - 没有主键的 MySQL 更新
- python - Python CSV阅读器在列表中创建列表
- ios - 无法识别的选择器发送到实例 (UIPinchGestureRecognizer)
- macos - 左右两侧的 OSX High Sierra 码头
- python - 无法使用 cx_Freeze 编译
- ios - 如何使用 IOS 12 在 UITableViewCell 中正确添加 UICollectionView
- angular - Angular 6中的过滤方法返回空数组