117 | Forge Viewer Utils
118 | Collection of helpful tools for Autodesk Forge Viewer
119 | that are not (yet) part of its official API.
120 | Why?
121 | During Forge Accelerator events, there are often recurring themes
122 | of features that the attendees want to build, for example, finding a scene object under the mouse cursor,
123 | or being able to change the transform of an object. Unfortunately, many of these features cannot be built
124 | using the official APIs,
125 | sending developers into the dreaded, undocumented area of internal APIs, also known as viewer.impl.
126 | The goal of this wrapper library is to:
127 |
128 | - provide best practice examples of using the official APIs
129 | - show how commonly requested features can be implemented, for now, using
viewer.impl
130 | - provide more documentation to both the official and the
viewer.impl APIs
131 | - collect feedback for the Forge Viewer dev team
132 |
133 | Usage
134 | Drop the library in your webpage. You can either use the latest master version:
135 | <script src="https://petrbroz.github.io/forge-viewer-utils/master/Utilities.js"></script>
136 |
137 | Or a specific tagged version, for example v0.7.0:
138 | <script src="https://petrbroz.github.io/forge-viewer-utils/0.7.0/Utilities.js"></script>
139 |
140 |
141 | Similarly, the documentation is available both for the latest master
142 | version and for all tagged versions, for example, 0.7.0.
143 |
144 | Start using the Autodesk.Viewing.Utilities class, either by wrapping an existing instance
145 | of Viewer3D:
146 | const utils = new Autodesk.Viewing.Utilities(viewer3d);
147 | utils.load("your-urn");
148 |
149 | Or by initializing everything using the static method Autodesk.Viewing.Utilities.Initialize:
150 | <div id="viewer"></div>
151 | <script>
152 | async function getAccessToken(callback) {
153 | const resp = await fetch('/api/auth');
154 | const json = await resp.json();
155 | callback(json.access_token, json.expires_in);
156 | }
157 | async function run() {
158 | try {
159 | const utils = await Autodesk.Viewing.Utilities.Initialize(document.getElementById('viewer'), getAccessToken);
160 | const viewable = await utils.load("your-urn");
161 | console.log('Viewable loaded successfully', viewable);
162 | } catch(err) {
163 | console.error(err);
164 | }
165 | }
166 | run();
167 | </script>
168 |
169 | Development
170 |
171 | - install dependencies:
npm install
172 | - build code documentation:
npm run build:docs
173 | - running the examples
174 |
175 | - you need two things: Forge app credentials, and an urn of a model to view
176 |
177 | - you can create a free Forge app at https://forge.autodesk.com
178 | - to upload and translate a model for viewing, see the official tutorial
179 |
180 |
181 | - run the example server with your Forge credentials:
182 |
FORGE_CLIENT_ID=<client_id> FORGE_CLIENT_SECRET=<client_secret> node examples/server.js
183 | - open one of the example html files with an urn of your model as a url query,
184 | for example: http://localhost:3000/basic.html?dXyabcdefgh
185 |
186 |
187 |
188 |
189 |