Prepare a File for the Viewer
To prepare a file for the online viewer, first get an access token
with the data:read
and data:write
scopes.
<- getToken(id = Sys.getenv("client_id"), secret = Sys.getenv("client_secret"),
resp = "data:read data:write")
scope <- resp$content$access_token myToken
Nex, encode the urn using the jsonlite::base64_enc()
function.
<- jsonlite::base64_enc(myUrn) myEncodedUrn
Then, translate the file into SVF format:
<- translateSvf(urn = myEncodedUrn, token = myToken) resp
To check the status of the translation process:
<- checkFile(urn = myEncodedUrn, token = myToken)
resp resp
Finally, embed the urn of the file in the viewer, which is described in the Viewer section.
Extract Data from a File
To extract data from a file, follow the steps in the previous section
for getting a token with the data:read
and
data:write
scopes, encoding the urn
of the
file using the jsonlite::base64_enc()
function, and
translating the file into SVF format using the
translateSvf()
function. Next, retrieve metadata for a file
using the getMetadata()
function, which returns an object
with the type
, name
, and guid
of
the file. Note the guid
and store it in
.Renviron
.
<- getMetadata(urn = myEncodedUrn, token = myToken)
resp <- resp$content$data$metadata[[1]]$guid myGuid
To get the object tree of a model, use the
getObjectTree()
function.
<- getObjectTree(guid = myGuid, urn = myEncodedUrn, token = myToken)
resp resp
To extract data from the model, use the getData()
function.
<- getData(guid = myGuid, urn = myEncodedUrn, token = myToken) resp
Viewer
AutoDesk provides a WebGL-based viewer for rendering 2D and 3D
models. To use the viewer, make sure to first follow the instructions in
Prepare a File for the Viewer above. Then simply pass
the urn
of the file and the token
to the
viewer3D()
function:
(urn = myEncodedUrn, token = myToken) viewer3D
The viewer can also be embedded in Shiny applications, interactive R
markdown documents, and other web pages thanks to the Shiny Modules
framework. Here is a simple example of a Shiny app and the
viewerUI()
function:
<- function(request) {
ui ::fluidPage(
shiny("pg", myEncodedUrn, myToken)
viewerUI)
}
<- function(input, output, session) {
server }
::shinyApp(ui, server) shiny