我正在使用以下 JavaScript 代码在 Autodesk Forge Viewer 中显示模型:
var options = {
'document': 'urn:' + urn,
'env': 'AutodeskProduction',
'getAccessToken': getToken,
'refreshToken': getToken
};
Autodesk.Viewing.Initializer(options, function () {
Autodesk.Viewing.Document.load(options.document,
function (doc) { // onSuccessCallback
// load the viewer
},
function (errorCode) { // onErrorCallback
interval = setInterval(function () {
$.ajax({
url: 'https://developer.api.autodesk.com' + '/viewingservice/v1/' + urn,
type: 'GET',
headers: { Authorization: 'Bearer ' + getToken() },
success: function (i) {
switch (i.status) {
case 'success':
// load the viewer
break;
case 'failed':
case 'timeout':
// report error
break;
case 'inprogress':
break;
default:
break;
}
},
error: function (b, d, e) {
// report error
}
});
}, 3000); // Repeatedly request the viewing service for each 3 seconds
}
);
});
onSuccessCallback:它将在查看器中显示模型。
onErrorCallback:它将继续发布查看服务,直到获得“成功”状态。如果状态为“失败”或“超时”,它将向用户报告他们无法查看此模型。
在 Autodesk.Viewing.Document.load(options.document) 之后,它会跳转到 errorCode==9('在获取的文档中没有可查看的内容')。然后我不断请求查看服务从中获取结果。这是错误代码列表:
var errorCodes = {
1: 'An unknown failure has occurred.',
2: 'Bad data (corrupted or malformed) was encountered.',
3: 'A network failure was encountered.',
4: 'Access was denied to a network resource (HTTP 403)',
5: 'A network resource could not be found (HTTP 404)',
6: 'A server error was returned when accessing a network resource (HTTP 5xx)',
7: 'An unhandled response code was returned when accessing a network resource (HTTP "everything else")',
8: 'Browser error: webGL is not supported by the current browser',
9: 'There is nothing viewable in the fetched document',
10: 'Browser error: webGL is supported, but not enabled',
11: 'There is no geomtry in loaded model',
12: 'Collaboration server error'
};
问题是有时它会返回 status=='failed'(在 Revit 中)或 status=='timeout'(在 Inventor 中)而没有更多详细信息。某些 Revit/Inventor 文件会发生这种情况,而不是所有情况。
我如何要求 Forge 查看服务重新翻译这些文件以显示回 Web 浏览器。他们总是从对查看服务的请求中失败。所以这些文件没有机会在 Forge 查看器中显示。