Created
July 20, 2017 03:19
-
-
Save leefsmp/4b1a9f8cb4ef18f3df3a7f58a3856425 to your computer and use it in GitHub Desktop.
EJS Template viewer app demo
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
///////////////////////////////////////////////////////// | |
// Initialize viewer environment | |
// | |
///////////////////////////////////////////////////////// | |
function initialize (options) { | |
return new Promise(function(resolve, reject) { | |
Autodesk.Viewing.Initializer (options, | |
function () { | |
resolve () | |
}, function(error){ | |
reject (error) | |
}) | |
}) | |
} | |
///////////////////////////////////////////////////////// | |
// load document from URN | |
// | |
///////////////////////////////////////////////////////// | |
function loadDocument (urn) { | |
return new Promise(function(resolve, reject) { | |
var paramUrn = !urn.startsWith("urn:") | |
? "urn:" + urn | |
: urn | |
Autodesk.Viewing.Document.load(paramUrn, | |
function(doc) { | |
resolve (doc) | |
}, function (error) { | |
reject (error) | |
}) | |
}) | |
} | |
///////////////////////////////////////////////////////// | |
// Get viewable items from document | |
// | |
///////////////////////////////////////////////////////// | |
function getViewableItems (doc, roles) { | |
var rootItem = doc.getRootItem() | |
var items = [] | |
var roleArray = roles | |
? (Array.isArray(roles) ? roles : [roles]) | |
: [] | |
roleArray.forEach(function(role) { | |
var subItems = | |
Autodesk.Viewing.Document.getSubItemsWithProperties( | |
rootItem, { type: "geometry", role: role }, true) | |
items = items.concat(subItems) | |
}) | |
return items | |
} | |
///////////////////////////////////////////////////////// | |
// Initialize Environment | |
// | |
///////////////////////////////////////////////////////// | |
initialize({ | |
accessToken: "<%=accessToken%>", | |
env: "AutodeskProduction" | |
}).then(function() { | |
loadDocument ("<%=urn%>").then(function(doc) { | |
var items = getViewableItems (doc, ["3d", "2d"]) | |
var path = doc.getViewablePath(items[0]) | |
var viewerDiv = document.getElementById("viewer") | |
var viewer = new Autodesk.Viewing.Private.GuiViewer3D(viewerDiv) | |
viewer.start(path) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment