当我尝试显示
Navisworks 模型(.nwd/.nwc 文件)时,使用
viewer.start()
启动 Autodesk forge 查看器时,我在控制台中收到此错误。对于 .rvt、.fbx、.3ds 和 .max 文件,一切似乎都正常。
GuiViewer3D.js:244 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'getNamedViews')
at Object.addViews (GuiViewer3D.js:244:40)
at SvfLoader.js:256:31
这是我的代码:
const lunchViewer = (urn) => {
var options = {
env: 'AutodeskProduction',
getAccessToken: getForgeToken,
};
var documentId = 'urn:' + urn;
window.Autodesk.Viewing.Initializer(options, () => {
window.Autodesk.Viewing.Document.load(
documentId,
onDocumentLoadSuccess,
onDocumentLoadFailure
);
});
};
const onDocumentLoadSuccess = (doc) => {
const geometries = doc.getRoot().search({ type: 'geometry' });
if (geometries.length === 0) {
console.error('Document contains no geometries.');
return;
}
const viewerDiv = document.getElementById('viewer');
const config = {
extensions: [
'Autodesk.DocumentBrowser',
'Autodesk.Viewing.MarkupsCore',
],
};
const viewer = new window.Autodesk.Viewing.Private.GuiViewer3D(
viewerDiv,
config
);
const initGeom = geometries[0];
const svfUrl = doc.getViewablePath(initGeom);
const modelOptions = {
sharedPropertyDbPath: doc.getFullPath(
doc.getRoot().findPropertyDbPath()
),
};
viewer.start(
svfUrl,
modelOptions,
onLoadModelSuccess,
onLoadModelError
);
};
我使用上述方法能够在同一查看器中添加多个模型。还可以在查看器中同一加载模型的视图之间切换。
这是一个已知问题,已在查看器 v7.93 中修复。请尝试升级到v7.93看看是否有帮助。
对于旧版本,请考虑使用 GuiViewer3D#loadDocumentNode。
这是一个示例实用程序,演示如何使用 GuiViewer3D#loadDocumentNode 聚合多个模型: