我一直在尝试通过autodesk-forge api生成查看器。我已经看过nodejs演示,甚至尝试使用与autodesk-forge nodejs相关的示例代码。由于我正在按照文档以某种方式得到错误的请求上传* .rvt文件后出错我知道我们需要将上传的响应转换为base64并将其传递给urn:**** ...按照程序后我仍然在生成视图时出错我无法找到任何帮助,所以任何人都可以详细说明如何通过示例代码实现。
以下是我使用的示例代码: -
var viewer;
var options = {
env: 'AutodeskProduction',
getAccessToken: getForgeToken
}
var documentId = 'urn:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cmVhY3QtbGF5b3V0LXNhbXBsZS12aWV3ZXIzN2lleGRiZG5xY2Franplc2JocWNlcTVhc2htNzh2My9VcmJhbkhvdXNlLTIwMTUucnZ0=';
Autodesk.Viewing.Initializer(options, function onInitialized() {
Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
});
/**
* Autodesk.Viewing.Document.load() success callback.
* Proceeds with model initialization.
*/
function onDocumentLoadSuccess(doc) {
// A document contains references to 3D and 2D viewables.
var viewable = Autodesk.Viewing.Document.getSubItemsWithProperties(doc.getRootItem(), {
'type': 'geometry',
'role': '3d'
}, true);
if (viewable.length === 0) {
console.error('Document contains no viewables.');
return;
}
// Choose any of the available viewable
var initialViewable = viewable[0]; // You can check for other available views in your model,
var svfUrl = doc.getViewablePath(initialViewable);
var modelOptions = {
sharedPropertyDbPath: doc.getPropertyDbPath()
};
var viewerDiv = document.getElementById('viewerDiv');
viewer = new Autodesk.Viewing.Viewer3D(viewerDiv);
viewer = new Autodesk.Viewing.Private.GuiViewer3D(viewerDiv);
viewer.start(svfUrl, modelOptions, onLoadModelSuccess, onLoadModelError);
}
function onDocumentLoadFailure(viewerErrorCode) {
console.error('onDocumentLoadFailure() - errorCode:' + viewerErrorCode);
}
function onLoadModelSuccess(model) {
console.log('onLoadModelSuccess()!');
console.log('Validate model loaded: ' + (viewer.model === model));
console.log(model);
}
function onLoadModelError(viewerErrorCode) {
console.error('onLoadModelError() - errorCode:' + viewerErrorCode);
}
function changeBackground (){
viewer.setBackgroundColor(0, 59, 111, 255,255, 255);
}
function resetBackground (){
viewer.setBackgroundColor(169,169,169, 255,255, 255);
}
function loadMarkup3D (){
viewer.loadExtension('Viewing.Extension.Markup3D');
}
function loadTransform (){
viewer.loadExtension('Viewing.Extension.Transform');
}
function loadControlSelector(){
viewer.loadExtension('_Viewing.Extension.ControlSelector');
}
任何帮助将不胜感激,我很惊讶它需要找到方法......提前预订