typescript - 在 ViewingApplication 方法中使用 modelOptions
问题描述
我目前正忙于使用 GlobalOffset 加载模型。我已按照以下步骤操作:https ://forge.autodesk.com/en/docs/viewer/v6/tutorials/basic-application/
这是他们对 DocumentLoaded-event 的实现:
function onDocumentLoadSuccess(doc) {
// We could still make use of Document.getSubItemsWithProperties()
// However, when using a ViewingApplication, we have access to the **bubble** attribute,
// which references the root node of a graph that wraps each object from the Manifest JSON.
var viewables = viewerApp.bubble.search({'type':'geometry'});
if (viewables.length === 0) {
console.error('Document contains no viewables.');
return;
}
// Choose any of the avialble viewables
viewerApp.selectItem(viewables[0].data, onItemLoadSuccess, onItemLoadFail);
}
此事件处理程序的最后一步是调用viewerApp.selectItem
(请参阅 doc)。但是这个方法没有modelOptions
像loadModel
Viewer3D 的方法那样的参数(参见文档)。
所以现在我的问题是:我在查看器实例中加载多个模型,并希望将每个模型的 GlobalOffset 设置为globalOffset: {x: 0, y:0, z:0}
. 但我无法modelOptions
为第一个加载的模型设置viewerApp.selectItem
. 有没有其他方法可以使用这种方法加载模型?
顺便说一句,这是我的实现(我正在使用 TypeScript):
private onDocumentLoaded(doc: Autodesk.Viewing.Document) {
if (!this.viewerApp.bubble) return;
var viewables = this.viewerApp.bubble.search(Autodesk.Viewing.BubbleNode.MODEL_NODE);
if (viewables.length === 0) {
console.error('Document contains no viewables.');
return;
}
if (!!this.viewerApp.getCurrentViewer()) {
var svfUrl = doc.getViewablePath(viewables[0].data);
var modelOptions = {
sharedPropertyDbPath: doc.getPropertyDbPath(),
globalOffset: { x: 0, y: 0, z: 0 }
};
this.viewerApp.getCurrentViewer().loadModel(svfUrl, modelOptions, this.onItemLoadSuccess, this.onItemLoadFail);
} else {
this.viewerApp.setCurrentViewer(this.viewerApp.getViewer({}));
this.viewerApp.selectItem(viewables[0].data, this.onItemLoadSuccess.bind(this), this.onItemLoadFail.bind(this));
}
}
当我的 DocumentLoaded-event 被调用时,我首先检查一个查看器是否已经被实例化,如果没有调用该selectItem
方法并加载第一个模型。这就是我卡住的地方。
解决方案
另一种方法是使用 Viewer3D 而不是 ViewerApplication:
Autodesk.Viewing.Initializer(options, function onInitialized(){
Autodesk.Viewing.Document.load(urn, function(doc){
...
var svfUrl = doc.getViewablePath(initGeom);
var modelOptions={
globalOffsets: ...
}
viewer.start(svfUrl, modelOptions); // load your first model
});
});
...
viewer.loadModel(svfUrl, modelOpts) //second model
推荐阅读
- android - Android TalkBack EditText - 提示与 contentDescription
- php - ORDER BY 子句在实时服务器中无法正常工作
- c++ - 用 stl 矩阵初始化 boost 矩阵
- objective-c - 多页文件可可打印
- java - 从给定的数组构造一棵树
- xml - 使用 xslt 从 XML 中删除 xmlns=""
- java - Paypal SDK 将计费计划设置为有效
- metadata - 尤里卡提供者如何将自定义元数据携带到尤里卡中心
- python - Dataframe 中的值以区分行(如果它是列表)
- sql - 在一个表中显示来自不同临时表的值