Search code examples
autodesk-forgeautodesk-viewer

How to get Autodesk Forge Viewer to support .rcp files


I have a web project (React) using the Autodesk Forge Viewer to display 3D (& 2D) models from our Enterprise BIM360 account. Since last year, the same viewer running within BIM360 is now supporting .rcp files, we would like to allow it as well. But I couldnt make it to work so far, and I have not found any documentation specific to .rcp support.

My current viewer initialization is as follow. It's mostly standard code from documentation and it works fine with 3D models.

const options: Autodesk.Viewing.InitializerOptions = {
   getAccessToken: (callback) => callback(token.accessToken, token.expiresIn),
   loaderExtensions: { svf: "Autodesk.MemoryLimited" }
};
 
Autodesk.Viewing.Initializer(options, () => {
   const viewer = new Autodesk.Viewing.GuiViewer3D(ref.current);

   var startedCode = viewerObject.start();
   if (startedCode > 0) {
      onError('Error - Failed to create a Viewer: WebGL not supported.');
      return;
   }

   //urn is Base64
   Autodesk.Viewing.Document.load(urn, onDocumentLoadSuccess, onDocumentLoadError);
});

I naively tried to give it the Base34 urn of an .rcp file without success. Looking at the network, I can see a 400 Bad Request on a manifest request (https://cdn.derivative.autodesk.com/derivativeservice/v2/manifest/{urn}?domain=http%3A%2F%2Flocalhost%3A6006). it feels like Document.load() code only works for .svf format which has a manifest but .rcp don't?

Going through https://lmv.ninja.autodesk.com samples, I realized the .rcp files can be loaded using the following code:

viewer.loadModel(url, {}, onModalLoadSuccess,onModelLoadError);
viewer.loadExtension('Autodesk.ReCap')

which I got to work with the sample file: https://s3.amazonaws.com/lmv.models/recap_models/AutodeskReCapSampleProject.rcp

However, it does not work with a private link from our BIM360 account. Looking at the network, I can see the requests returning with a 401 Unauthorized. Sadly my access token is not added to the headers. A bug? Or am I missing something?

POST https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/{guid}.rcp
401 Unauthorized
{ 
   "developerMessage":"Token is not provided in the request.", 
   "moreInfo": "https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/error_handling/", 
   "errorCode": "AUTH-010"
}

I tried to see how lmv.ninja would do it from a BIM360 model but I can't go through the login step. It keep redirect me to the default page without logging me in. Clearly looks like another bug to me.

Note: I have updated the viewer library to latest

https://autodeskviewer.com/viewers/latest/viewer3D.min.js
https://autodeskviewer.com/viewers/latest/extensions/ReCap/ReCap.min.js
https://autodeskviewer.com/viewers/latest/lmvworker.min.js

Thanks for the help

Clement


Solution

  • Here is an update... Try using the iframe version of the Forge Viewer, like this...

    STEPS:

    1. Take the raw BIM 360 / ACC URL Address, and extract out the ITEMS, PROJECTS & FOLDERS variables (see coloring used in the screenshot)
    2. in each of the variables, replace ':' character with '%3A'
    3. remove the 'b.' from the project variable
    4. Grab the ACCESSTOKEN from the tileset.json file Bearer Header (or use your own 3-legged system)
    5. Put the variables into this URL:
    https://cdn.recap.autodesk.com/viewer/latest/index.html?file={$ITEMS}&pid=${PROJECTS}&fid=${FOLDERS}&env=prd&src=bim360&accessToken=${ACCESSTOKEN}
    

    here's an example, with the variables populated:

    BIM 360 URL:
    https://docs.b360.autodesk.com/projects/37cf25af-1304-4c2b-b54f-0c98ed8a42e0/folders/urn:adsk.wipprod:fs.folder:co.AtLas5d8T_eWl2SzFB5pSg/detail/viewer/items/urn:adsk.wipprod:dm.lineage:tYiwN_yMTDmj5jroyTCwBQ
    
    IFRAME URL:
    https://cdn.recap.autodesk.com/viewer/latest/index.html?file=urn%3Aadsk.wipprod%3Adm.lineage%3AtYiwN_yMTDmj5jroyTCwBQ&pid=37cf25af-1304-4c2b-b54f-0c98ed8a42e0&fid=urn%3Aadsk.wipprod%3Afs.folder%3Aco.AtLas5d8T_eWl2SzFB5pSg&env=prd&src=bim360&accessToken=eyJhbGciO...etc 
    

    Then put this iFrame URL into a browser, and the Recap viewer will load with your point cloud, like this screenshot...

    enter image description here

    This is a workaround, until URN support is added (bubble decoder coming soon).