Last active
November 2, 2016 03:24
-
-
Save leefsmp/81a7243fd407a6f099fd4cb4261a0527 to your computer and use it in GitHub Desktop.
Forge Viewing Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var options = { | |
env: 'AutodeskProduction', | |
getAccessToken: function (onGetAccessToken) { | |
// Asynchronous request from your app to request | |
// access token from your server ... | |
yourAppGetAccessTokenAsync(function (tokenResponse) { | |
onGetAccessToken ( | |
tokenResponse.access_token, | |
tokenResponse.expires_in) | |
}) | |
} | |
} | |
var documentId = 'urn:<YOUR_DESIGN_URN_HERE>'; | |
var viewerApp = null | |
Autodesk.Viewing.Initializer(options, function onInitialized(){ | |
viewerApp = new Autodesk.Viewing.ViewingApplication( | |
'MyViewerDiv') | |
viewerApp.registerViewer( | |
viewerApp.k3D, | |
Autodesk.Viewing.Private.GuiViewer3D) | |
viewerApp.loadDocument(documentId, | |
onDocumentLoadSuccess, | |
onDocumentLoadFailure) | |
}) | |
function onDocumentLoadSuccess(doc) { | |
// We could still make use of Document.getSubItemsWithProperties() | |
// However, when using a ViewingApplication | |
// we have access to the **bubble** attribute, | |
// which references the root node of a graph | |
// that wraps each object from the Manifest JSON | |
var viewables = viewerApp.bubble.search({'type':'geometry'}) | |
if (viewables.length === 0) { | |
console.error('Document contains no viewables.') | |
return | |
} | |
// Choose first viewable by default | |
viewerApp.selectItem( | |
viewables[0].data, | |
onItemLoadSuccess, | |
onItemLoadFail) | |
} | |
function onDocumentLoadFailure(errorCode) { | |
console.error('onDocumentLoadFailure() - errorCode:' + | |
errorCode) | |
} | |
function onItemLoadSuccess(viewer, item) { | |
console.log('onItemLoadSuccess()!') | |
console.log(viewer) | |
console.log(item) | |
// ... access viewer API ... | |
} | |
function onItemLoadFail(errorCode) { | |
console.error('onItemLoadFail() - errorCode:' + | |
errorCode) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment