加载 Forge Viewer 更改模型后的扩展

huangapple go评论59阅读模式
英文:

Loading back extensions after changing models for Forge Viewer

问题

目前,我正在实现一个查看器应用程序,它利用了来自 https://github.com/theNBS/ng2-adsk-forge-viewer 的 Angular 封装。

我成功地设置了查看器,并从 DataVisualisation SDK 中创建并加载了几个扩展。

然而,每当我在模型之间切换时,扩展就会被卸载,并且我会收到这个错误。

加载 Forge Viewer 更改模型后的扩展

// 更新要在查看器中显示的模型
public triggerDocumentChange() {
    this.modelService.selectedModelUrn = this.selectedModel.urn;
    this.viewerComponent.DocumentId = this.urnify(this.selectedModel.urn);
}

我尝试过的步骤:

  1. 每当加载文档时重新加载和注册扩展
this.viewer.addEventListener(
    Autodesk.Viewing.GEOMETRY_LOADED_EVENT,
    async () => {
        // 使用 modelService 初始化我们的数据视图,以帮助更改传感器值
        const dataView = new MyDataView(this.modelService, this.viewer);
        await dataView.init({
            start: new Date("2022-01-01"),
            end: new Date("2022-01-30"),
        });
        this.reRegisterAndLoadExtensions();

        // 获取从查看器注册的扩展的实例
        const extensions = this.getExtensionsInstance();
        for (const ext of extensions) { // 这是出错的地方!
            console.log("Loaded extension: " + ext);
            ext.dataView = dataView;
            ext.activate();
        }
    }
);

任何帮助将不胜感激!

英文:

Currently, I am implementing a Viewer Application that makes use of the angular wrapper from https://github.com/theNBS/ng2-adsk-forge-viewer

I managed to get the viewer set up, created and loaded several extensions from the DataVisualisation SDK.

However, whenever I change between models, the extensions get unloaded and I get this error.

加载 Forge Viewer 更改模型后的扩展

// Updates the model to be displayed in the viewer 
public triggerDocumentChange() { 
    this.modelService.selectedModelUrn = this.selectedModel.urn; 
    this.viewerComponent.DocumentId = this.urnify(this.selectedModel.urn); 
}

Steps I've tried:

  1. Reloading and registering the extensions whenever a document is loaded
this.viewer.addEventListener( 
  Autodesk.Viewing.GEOMETRY_LOADED_EVENT, 
    async () => { 
    // Initialize our data view with the modelService to help change the sensor values 
    const dataView = new MyDataView(this.modelService, 
       this.viewer); 
    await dataView.init({ 
    start: new Date("2022-01-01"), 
    end: new Date("2022-01-30"), 
}); 
this.reRegisterAndLoadExtensions(); 
 
// Get the instance of the registered extensions from the viewer
const extensions = this.getExtensionsInstance(); 
for (const ext of extensions) { // This is where the error is!
    console.log("Loaded extension: " + ext); 
    ext.dataView = dataView; 
    ext.activate(); 
} 

Any help would be greatly appreciated!

答案1

得分: 0

已解决!主要问题是由于在将扩展加载到查看器上时采用了异步方式导致的。

因此,每当模型发生更改时,扩展没有足够的时间在被查看器使用之前重新加载。导致了空指针异常!

英文:

Resolved! The main issue was due to asynchronous nature of loading extensions onto the viewer.

So whenever the model changed, the extensions did not have sufficient time to load back up before being used by the viewer. Causing the NullPointerException!

huangapple
  • 本文由 发表于 2023年6月12日 15:02:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76454263.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定