请确保您已完全下载所有提取的 DWG 可视气泡,并且您要加载的模型的路径正确,因为错误代码 5 代表NETWORK_FILE_NOT_FOUND
.
我刚刚使用下面的代码片段从AutoCAD 示例文件中测试了这个blocks_and_tables_-_metric.dwg ,它工作正常。
var options = {
env: 'Local',
};
var doc = { 'rootFolder': 'Model', 'path': '29c9e407-f76f-a1c0-0972-dcb5b496fff9_f2d/primaryGraphics.f2d', 'name': '2D view' };
var viewerDiv = document.getElementById( 'MyViewerDiv' );
var viewer = new Autodesk.Viewing.Private.GuiViewer3D( viewerDiv );
Autodesk.Viewing.Initializer(options, function() {
if( viewer.initialize() != 0 ) return console.error( 'Failed to initialize viewer' );
var basePath = getCurrentBaseURL();
var modelFolderPath = basePath + doc.rootFolder + '/';
var modelFilePath = modelFolderPath + doc.path;
var modelOptions = {
sharedPropertyDbPath: modelFolderPath
};
viewer.loadModel( modelFilePath, modelOptions, onLoadModelSuccess, onLoadModelError );
});
function getCurrentBaseURL() {
var basePath = '';
var lastSlash = document.location.href.lastIndexOf( '/' );
if( lastSlash != -1 )
basePath = document.location.href.substr( 0, lastSlash + 1 );
return basePath;
}
/**
* viewer.loadModel() success callback.
* Invoked after the model's SVF has been initially loaded.
* It may trigger before any geometry has been downloaded and displayed on-screen.
*/
function onLoadModelSuccess( model ) {
console.log( 'onLoadModelSuccess()!' );
console.log( 'Validate model loaded: ' + ( viewer.model === model ) );
console.log( model );
}
/**
* viewer.loadModel() failure callback.
* Invoked when there's an error fetching the SVF file.
*/
function onLoadModelError( viewerErrorCode ) {
console.error( 'onLoadModelError() - errorCode:' + viewerErrorCode );
}
blocks_and_tables__-_metric.dwg提取模型的文件结构如下图所示:
我使用的 2D 模型的文件结构是: