Autodesk Forge - 浏览器标签问题
Posted
技术标签:
【中文标题】Autodesk Forge - 浏览器标签问题【英文标题】:Autodesk Forge - Browser labels problems 【发布时间】:2021-10-02 09:00:30 【问题描述】:我对使用 AggregatedView 的 Forge 浏览器有疑问。 如果我在查看器中加载 3 个模型,则在浏览器中显示标签“模型”3 次,而不是 revit 文件名(“1.rvt”、“2.rvt”和“3.rvt”),如附件中所述图片forge browser。 是否可以改变行为(使用某些选项)? 我尝试使用“accessControlProperties”选项 (https://forge.autodesk.com/en/docs/viewer/v2/reference/javascript/document/#load-documentid-onsuccesscallback-onerrorcallback-accesscontrolproperties),但没有任何变化。
TIA 桤木
function fetchForgeToken( callback )
callback( "eyJhbGciOiJSUzI1NiIsImtpZCI6IlU3c0dGRldUTzlBekNhSzBqZURRM2dQZXBURVdWN2VhIn0.eyJzY29wZSI6WyJkYXRhOnJlYWQiLCJkYXRhOmNyZWF0ZSIsImRhdGE6d3JpdGUiLCJ2aWV3YWJsZXM6cmVhZCJdLCJjbGllbnRfaWQiOiJpSGVHMlRrbW9ucmF6TjUyS1JoRUdHWnZFTVU3RWg3dCIsImF1ZCI6Imh0dHBzOi8vYXV0b2Rlc2suY29tL2F1ZC9hand0ZXhwNjAiLCJqdGkiOiJpVEVVZTdYdVRqam9MVzFnNzQyYWNrREtkd244Q3ZLRHZLcXI1NzBrVkk2ZUR6dzRlNDc3N1BkeFNhelRCWWo3IiwiZXhwIjoxNjI3MzAzNjQ0fQ.VNZZHhuo4fGLsy-StB_YLkEtFNphpuuTDCJt-NtAvzGOD8_dsRjj6szBm9-rXNqKIBUVeg3DkYHG3jfSFQeAN_ie76H2_fVs-zmHMelNi6jZBvyM6DGoE62068TvKpEK9_8po__YstQ1JygEuUyiqivXE0-RqYEjd15wNrb1PUqVJTA-Ug4lEEIGmFNyhQsW861MwcRklkcHzhC9gDijQKqcDAqC_udueWZ5Bh48SPtNNJe4bXFwWcWqEipom-apyArd1nLw9-fpmNd-qPgSQJwNo_0sk-wEIn1Zl6Uq8k67f1bBXBrg7XfUAS2-_M_YOTrHZFl6QVEQ-fvKr4PR9g", "2000" );
function launchViewer( models )
if( !models || models.length <= 0 )
return console.error( 'Empty model input' );
const options =
env: 'AutodeskProduction',
getAccessToken: fetchForgeToken
;
const options3d =
viewerConfig:
disableBimWalkInfoIcon: true
;
function loadManifest( documentId, documentName )
return new Promise(( resolve, reject ) =>
const onDocumentLoadSuccess = ( doc ) =>
//doc.downloadAecModelData();
doc.downloadAecModelData(() => resolve(doc));
;
console.log("doc.id = " + documentId);
//var accessControlProperties = name: documentName;
var accessControlProperties = modelNameOverride: documentName;
//https://forge.autodesk.com/en/docs/viewer/v2/reference/javascript/document/#load-documentid-onsuccesscallback-onerrorcallback-accesscontrolproperties
//oppure
//https://forge.autodesk.com/blog/customizing-model-browser-custom-label-behavior-styling-and-data-sources
Autodesk.Viewing.Document.load( documentId, onDocumentLoadSuccess, reject, accessControlProperties );
);
Autodesk.Viewing.Initializer( options, function()
//get the viewer div
const viewerDiv = document.getElementById( 'viewer' );
//initialize the viewer object
const view = new Autodesk.Viewing.AggregatedView();
view.init( viewerDiv, options3d );
const viewer = view.viewer;
const tasks = [];
models.forEach( md => tasks.push( loadManifest( md.urn, md.name ) ) );
Promise.all(tasks)
.then( docs => Promise.resolve( docs.map( doc =>
const bubbles = doc.getRoot().search(type:'geometry', role: '3d');
const bubble = bubbles[0];
if( !bubble ) return null;
return bubble;
)))
.then( bubbles => view.setNodes( bubbles ) );
);
const models = [
name: '1.rvt', urn: 'urn:dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLm5kLXcyZUNSU3ktdHhHTmZ6OWo4bFE/dmVyc2lvbj0x' , 名称:'2.rvt',瓮:'urn:dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLkxHVDFOSW1nUlgtZnN0cnhMZUU5aUE/dmVyc2lvbj0x', 名称:'3.rvt',骨灰盒:'urn:dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLjhTbE1zOGNWUllTenV1TGR6SXJiWHc/dmVyc2lvbj0x' ];
launchViewer( models.concat() );
【问题讨论】:
【参考方案1】:要分配modelNameOverride
,我们需要利用getCustomLoadOptions
。参见下面的代码 sn-p 示例:
const options3d =
viewerConfig:
disableBimWalkInfoIcon: true,
,
getCustomLoadOptions: (bubble) =>
const modelName = bubble.getDocument().getRoot().search( role: "viewable" )[0].data.name;
console.log(modelName);
let loadOptions = modelNameOverride: modelName ;
return loadOptions;
;
view.init( viewerDiv, options3d );
【讨论】:
以上是关于Autodesk Forge - 浏览器标签问题的主要内容,如果未能解决你的问题,请参考以下文章
Autodesk Forge - 查看器 getScreenShot - IOS 空白