Created
November 19, 2019 21:36
-
-
Save JoaoPedroRodrigues/9a8dc810795dfa599030f3ab024c3848 to your computer and use it in GitHub Desktop.
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
<head> | |
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=no" /> | |
<meta charset="utf-8"> | |
<link rel="stylesheet" href="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.min.css" type="text/css"> | |
<script src="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/viewer3D.min.js"></script> | |
<style> | |
body { | |
margin: 0; | |
} | |
#forgeViewer { | |
width: 100%; | |
height: 100%; | |
margin: 0; | |
background-color: #F0F8FF; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="forgeViewer"></div> | |
</body> | |
<script> | |
var viewer; | |
var options = { | |
env: 'AutodeskProduction', | |
api: 'derivativeV2', // for models uploaded to EMEA change this option to 'derivativeV2_EU' | |
getAccessToken: function(onTokenReady) { | |
var token = 'PUT-UR-TOKEN-HERE'; | |
var timeInSeconds = 3600; // Use value provided by Forge Authentication (OAuth) API | |
onTokenReady(token, timeInSeconds); | |
} | |
}; | |
Autodesk.Viewing.Initializer(options, function() { | |
var htmlDiv = document.getElementById('forgeViewer'); | |
viewer = new Autodesk.Viewing.GuiViewer3D(htmlDiv); | |
var startedCode = viewer.start(); | |
if (startedCode > 0) { | |
console.error('Failed to create a Viewer: WebGL not supported.'); | |
return; | |
} | |
console.log('Initialization complete, loading a model next...'); | |
}); | |
var documentId = 'urn:PUT-YOUR-URN-HERE'; | |
Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure); | |
function onDocumentLoadSuccess(viewerDocument) { | |
// viewerDocument is an instance of Autodesk.Viewing.Document | |
var defaultModel = viewerDocument.getRoot().getDefaultGeometry(); | |
viewer.loadDocumentNode(viewerDocument, defaultModel); | |
} | |
function onDocumentLoadFailure() { | |
console.error('Failed fetching Forge manifest'); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment