首页 > 解决方案 > Autodesk Forge 设计自动化/模型衍生 API - 查看器缓存 svf 文件

问题描述

我正在使用设计自动化 API 来生成模型,然后我不想将可视化加载到查看器中,我使用的是 v6。当我第一次这样做时它工作正常,但查看器将继续加载相同的 .svf 文件,我尝试删除清单,我将 true 传递给 x-ads-force 参数并且我在初始化查看器时包含 If-Modified-Since 标头...

我使用.net SDK

DerivativesAPI.Translate(Job, True)

伪造 Javascript....

var viewer;

function showModel(AccessToken, urn) {
var options = {
    env: 'AutodeskProduction',
    accessToken: AccessToken,
    api: 'derivativeV2'    // for models uploaded to EMEA change this option to 'derivativeV2_EU'
};
var documentId = 'urn:' + urn;
Autodesk.Viewing.endpoint.HTTP_REQUEST_HEADERS['If-Modified-Since'] = 'Sat, 29 Oct 1994 19:43:31 GMT';
Autodesk.Viewing.Initializer(options, function onInitialized() {
    Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
});
}

function onDocumentLoadSuccess(doc) {

// A document contains references to 3D and 2D geometries.
var geometries = doc.getRoot().search({ 'type': 'geometry' });
if (geometries.length === 0) {
    console.error('Document contains no geometries.');
    return;
 }

// Choose any of the avialable geometries
var initGeom = geometries[0];

// Create Viewer instance
var viewerDiv = document.getElementById('MyViewerDiv');
var config = {
    extensions: initGeom.extensions() || []
};
viewer = new Autodesk.Viewing.Private.GuiViewer3D(viewerDiv, config);

// Load the chosen geometry
  var svfUrl = doc.getViewablePath(initGeom);
   var modelOptions = {
    sharedPropertyDbPath: doc.getPropertyDbPath()
   };
   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);
 }

标签: javascript.netautodesk-forgeautodesk-viewerautodesk-model-derivative

解决方案


请更改此行以加载其他 SVF:

// Choose any of the avialable geometries
var initGeom = geometries[0];

要开启运行时,您可以使用Autodesk.DocumentBrowser

var config = {
    extensions: ['Autodesk.DocumentBrowser'].concat( initGeom.extensions() )
};
viewer = new Autodesk.Viewing.Private.GuiViewer3D(viewerDiv, config);

在此处输入图像描述

最后,请注意 RVT 模型的发布设置,模型衍生 API 将仅导出在发布设置中选择的视图集。如果Publish Settings没有预定义的视图集,它将默认使用默认的 3D 视图导出。


推荐阅读