Want to render your own CAD model in Autodesk Forge Viewer? Read on!
Want to render your own CAD model in Autodesk Forge Viewer? Read on!
Autodesk’s Forge Viewer is a WebGL-based, JavaScript library for 3D and 2D model rendering. These 3D and 2D data may come from a wide variety of applications such as AutoCAD, Fusion 360, Revit or any other CAD application. Many industries use this viewer to render model data in the browser but that needs the model data to be converted into SVF format (a generic format used by forge viewer to render the model data).
Fig. 1: Flowchart describing the flow of conversion
Get started with these quick steps to convert any CAD model Forge viewer compatible
- Create an App in Forge (Use this link to SignIn/Register https://forge.autodesk.com)
Fig. 2: List of API selections used by the app
Once your app is created successfully it will look like this, note down the client-id and client secret for the next step
Fig. 3: App information available after successful app creation
- Generate access-token from client-id and client-secret
To generate an access token you will need to use the Authentication API of Forge
Fig. 4: Successful access token generation for client_id and client_secret
This access token will be used by all the operations related to bucket creation, reading bucket, reading bucket’s object data and writing bucket’s object data.
Set this access token in the Authorization attribute of the header
Fig. 5: Setting up access token in Authorization attribute of header
An access token is set as an environment variable in Postman.
- Create a bucket in the forge server
Fig. 6: Successful bucket creation using access-token
- Upload the model in the Forge bucket
Here .rvt file is used to upload in Forge Bucket but you can use any.
Programmatically you can convert the .rvt file content into a byte array and send it in the request body. (You need to set Content-Type as application/octet-stream)
Fig. 7: Successful upload of an object(a .rvt file) in the forge bucket
After the successful upload of the object in the Forge bucket, you need to get the objectId from its response
This objectId needs to be encoded into the Base-64 string.
You can refer to this link https://www.base64encode.org/
- Translate the model into SVF format (forge viewer renderable format)
This process uses model-derivative API of the forge
Fig. 8: Successful creation of translation of object into SVF
After the conversion process is started it continues to run on the Forge server. You can track the progress of the conversion below
Fig. 9: Successful translated CAD model data into SVF
For visualizing the CAD model in Forge Viewer, Forge Extension has been integrated into Visual Studio Code.
You can refer to this link https://forge.autodesk.com/blog/forge-visual-studio-code
Fig. 10: Visualising the CAD model data in forge viewer
So we see how simple it is to convert any 3D CAD model Forge viewer renderable. You can integrate Forge Viewer in your application and can use language-specific SDK as well for your application.
Follow ProtoTech Solutions for software technology industry trends and Global CAD news and updates.
For more queries regarding any of the above-mentioned topics, feel free to connect with us on our website https://prototechsolutions.com, or email us at info@prototechsolutions.com