在 ViewingApplication 方法中使用 modelOptions
Using modelOptions in ViewingApplication approach
我目前无法加载具有 GlobalOffset 的模型。我已执行以下步骤:https://forge.autodesk.com/en/docs/viewer/v6/tutorials/basic-application/
这是他们对 DocumentLoaded 事件的实现:
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
(see doc). But this method hasn't a parameter modelOptions
like the loadModel
method of the Viewer3D (see doc)。
现在我的问题是:
我正在我的查看器实例中加载多个模型,并希望将每个模型的 GlobalOffset 设置为 globalOffset: {x: 0, y:0, z:0}
。但是我无法为 viewerApp.selectItem
加载的第一个模型设置 modelOptions
。有没有其他方法可以使用这种方法加载模型?
顺便说一句,这是我的实现(我使用的是 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 事件时,我首先检查查看器是否已被实例化,如果没有,则调用 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
见full sample and doc here
我找到了解决办法。不知道这是否正确,但对我有用:
我通过调用 var viewer = viewerApp.getViewer()
获得了一个新的 Viewer3D 实例。之后我通过调用 viewer.start(svfUrl, modelOptions, this.onItemLoadSuccess, this.onItemLoadFail)
手动启动查看器
var svfUrl = doc.getViewablePath(viewables[0].data);
var modelOptions = {
sharedPropertyDbPath: doc.getPropertyDbPath(),
globalOffset: { x: 0, y: 0, z: 0 }
};
if (!!this.viewerApp.getCurrentViewer()) {
this.viewerApp.getCurrentViewer().loadModel(svfUrl, modelOptions, this.onItemLoadSuccess, this.onItemLoadFail)
} else {
// Get a new Viewer3D instance by calling viewerApp.getViewer() with an empty object {}
var viewer = this.viewerApp.getViewer({})
// Start the viewer manually by passing the url of the svf model and the desired model options
viewer.start(svfUrl, modelOptions, this.onItemLoadSuccess, this.onItemLoadFail)
}
我目前无法加载具有 GlobalOffset 的模型。我已执行以下步骤:https://forge.autodesk.com/en/docs/viewer/v6/tutorials/basic-application/
这是他们对 DocumentLoaded 事件的实现:
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
(see doc). But this method hasn't a parameter modelOptions
like the loadModel
method of the Viewer3D (see doc)。
现在我的问题是:
我正在我的查看器实例中加载多个模型,并希望将每个模型的 GlobalOffset 设置为 globalOffset: {x: 0, y:0, z:0}
。但是我无法为 viewerApp.selectItem
加载的第一个模型设置 modelOptions
。有没有其他方法可以使用这种方法加载模型?
顺便说一句,这是我的实现(我使用的是 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 事件时,我首先检查查看器是否已被实例化,如果没有,则调用 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
见full sample and doc here
我找到了解决办法。不知道这是否正确,但对我有用:
我通过调用 var viewer = viewerApp.getViewer()
获得了一个新的 Viewer3D 实例。之后我通过调用 viewer.start(svfUrl, modelOptions, this.onItemLoadSuccess, this.onItemLoadFail)
var svfUrl = doc.getViewablePath(viewables[0].data);
var modelOptions = {
sharedPropertyDbPath: doc.getPropertyDbPath(),
globalOffset: { x: 0, y: 0, z: 0 }
};
if (!!this.viewerApp.getCurrentViewer()) {
this.viewerApp.getCurrentViewer().loadModel(svfUrl, modelOptions, this.onItemLoadSuccess, this.onItemLoadFail)
} else {
// Get a new Viewer3D instance by calling viewerApp.getViewer() with an empty object {}
var viewer = this.viewerApp.getViewer({})
// Start the viewer manually by passing the url of the svf model and the desired model options
viewer.start(svfUrl, modelOptions, this.onItemLoadSuccess, this.onItemLoadFail)
}