Collection of helpful tools for Autodesk Forge Viewer that are not (yet) part of its official API.
During Forge Accelerator events, there are often recurring themes
of features that the attendees want to build, for example, finding a scene object under the mouse cursor,
or being able to change the transform of an object. Unfortunately, many of these features cannot be built
using the official APIs,
sending developers into the dreaded, undocumented area of internal APIs, also known as viewer.impl
.
The goal of this wrapper library is to:
- provide best practice examples of using the official APIs
- show how commonly requested features can be implemented, for now, using
viewer.impl
- provide more documentation to both the official and the
viewer.impl
APIs - collect feedback for the Forge Viewer dev team
Drop the library in your webpage. You can either use the latest master
version:
<script src="https://petrbroz.github.io/forge-viewer-utils/master/Utilities.js"></script>
Or a specific tagged version, for example v0.7.0
:
<script src="https://petrbroz.github.io/forge-viewer-utils/0.7.0/Utilities.js"></script>
Similarly, the documentation is available both for the latest master version and for all tagged versions, for example, 0.7.0.
Start using the Autodesk.Viewing.Utilities
class, either by wrapping an existing instance
of Viewer3D:
const utils = new Autodesk.Viewing.Utilities(viewer3d);
utils.load("your-urn");
Or by initializing everything using the static method Autodesk.Viewing.Utilities.Initialize
:
<div id="viewer"></div>
<script>
async function getAccessToken(callback) {
const resp = await fetch('/api/auth');
const json = await resp.json();
callback(json.access_token, json.expires_in);
}
async function run() {
try {
const utils = await Autodesk.Viewing.Utilities.Initialize(document.getElementById('viewer'), getAccessToken);
const viewable = await utils.load("your-urn");
console.log('Viewable loaded successfully', viewable);
} catch(err) {
console.error(err);
}
}
run();
</script>
- install dependencies:
npm install
- build code documentation:
npm run build:docs
- running the examples
- you need two things: Forge app credentials, and an urn of a model to view
- you can create a free Forge app at https://forge.autodesk.com
- to upload and translate a model for viewing, see the official tutorial
- run the example server with your Forge credentials:
FORGE_CLIENT_ID=<client_id> FORGE_CLIENT_SECRET=<client_secret> node examples/server.js
- open one of the example html files with an urn of your model as a url query, for example: http://localhost:3000/basic.html?dXyabcdefgh
- you need two things: Forge app credentials, and an urn of a model to view