2023-01-02 18:42:55 +08:00
|
|
|
|
|
|
|
|
|
var viewer;
|
|
|
|
|
|
|
|
|
|
function launchViewer(urn) {
|
|
|
|
|
var options = {
|
|
|
|
|
env: 'AutodeskProduction',
|
|
|
|
|
getAccessToken: getForgeToken
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Autodesk.Viewing.Initializer(options, () => {
|
|
|
|
|
viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('forgeViewer'));
|
|
|
|
|
viewer.start();
|
|
|
|
|
var documentId = 'urn:' + urn;
|
|
|
|
|
Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onDocumentLoadSuccess(doc) {
|
|
|
|
|
var viewables = doc.getRoot().getDefaultGeometry();
|
|
|
|
|
viewer.loadDocumentNode(doc, viewables).then(i => {
|
|
|
|
|
// documented loaded, any action?
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onDocumentLoadFailure(viewerErrorCode) {
|
|
|
|
|
console.error('onDocumentLoadFailure() - errorCode:' + viewerErrorCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getForgeToken(callback) {
|
|
|
|
|
fetch('/api/forge/oauth/token').then(res => {
|
|
|
|
|
res.json().then(data => {
|
2024-03-19 15:35:39 +08:00
|
|
|
|
callback(data.dictionary.access_token, data.dictionary.expires_in);
|
2023-01-02 18:42:55 +08:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|