【问题标题】:Issue while loading BIM files in viewer在查看器中加载 BIM 文件时出现问题
【发布时间】:2019-08-15 10:22:40
【问题描述】:

在 Autodesk forge 查看器中查看文件时,出现一些错误,例如 • “无法读取未定义的属性‘setEndpoint’” • “doc.getRootItem 不是函数” 并且将能够在硬重新加载(Ctrl + Shift + R)后查看页面。有时,即使在硬重新加载并清除浏览器缓存后,同样的错误也会再次出现。

var options = {
    env: 'AutodeskProduction',
    accessToken: getAccessToken() //Method to get access token- no errors here
};
var documentId = 'urn:' + urn;
Autodesk.Viewing.Initializer(options, function onInitialized() {
    Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
});

//Autodesk.Viewing.Document.load - success function.
function onDocumentLoadSuccess(doc) {
    setTimeout(function() {
        debugger;
    }, 5000);

//Error is thrown in the line below.                
    var viewables = Autodesk.Viewing.Document.getSubItemsWithProperties(doc.getRootItem(), {
        'type': 'geometry'
    }, true); //throws error on calling doc.getRootItem()

    if (viewables.length === 0) {
        console.error('Document contains no viewables.');
        return;
    }
    // Choose any of the avialble viewables
    var initialViewable = viewables[0];
    var svfUrl = doc.getViewablePath(initialViewable);
    var modelOptions = {
        sharedPropertyDbPath: doc.getPropertyDbPath()
    };

    var viewerDiv = document.getElementById('divViewer');
    viewer = new Autodesk.Viewing.Private.GuiViewer3D(viewerDiv);
    viewer.start(svfUrl, modelOptions, onLoadModelSuccess, onLoadModelError);
}

【问题讨论】:

    标签: autodesk-forge


    【解决方案1】:

    升级到 Viewer v7 后,请使用 doc.getRoot() - doc.getRootItem() 已被弃用:

     NOP_VIEWER.loadDocumentNode(doc, doc.getRoot().getDefaultGeometry());
    

    查看实时示例 here 和迁移指南到 v7 here

    【讨论】:

      猜你喜欢
      • 2011-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-25
      • 2020-08-23
      • 1970-01-01
      • 2021-06-06
      相关资源
      最近更新 更多