Subbu S
Subbu S

Reputation: 31

AutoDesk Forge Viewer : Load Model Using the URN of SVF

Is it possible or there is any way to load Model through URN instead of URL.

we can load the model through URL :

this.viewer.loadModel(url, options) -> Here i know the url of the SVF

Is there any possibility to load the model using the URN, But in my case I know only URN of the svf.

In regular way,

We are loading the document using the URN of the uploaded file, on Document load success then we are loading the viewables.

var documentId = 'urn:dXJuOmFkc2sub2JqZ3Q6cGxuLW1vZGVN0L0NhZGFjR3JvdXBIUSUyMDIwMTkucnZ0';
        Autodesk.Viewing.Initializer(options, function onInitialized(){
            viewerApp = new Autodesk.Viewing.ViewingApplication('MyViewerDiv');
            viewerApp.registerViewer(viewerApp.k3D, Autodesk.Viewing.Private.GuiViewer3D);
            viewerApp.loadDocument(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
        });

    function onDocumentLoadSuccess(doc) {
        var viewables = viewerApp.bubble.search({type:'geometry', role:'3d',name:'blahblah'});
        if (viewables.length === 0) {
            console.error('Document contains no viewables.');
            return;
        }

        // Choose any of the avialble viewables
        console.log(viewables[0].data);
        console.log(doc.getViewablePath(viewables[0].data));
        viewerApp.selectItem(viewables[0].data, onItemLoadSuccess, onItemLoadFail);
    }

From above code, based on the URN of the uploaded OBJ, it is getting the manifest and loading the viewable, But In our scenario, we are doing that part at server side and getting the URN of the SVF.

But in our scenario, We have the URN of the SVF file. Is there any way to load the Model Using SVF URN.

I saw one possiblity is that appending

"https://developer.api.autodesk.com/derivativeservice/v2/derivatives/"

to my urn and calling the

viewer.loadModel(url)

Is loading the Model, But it is again a maintenance work, When there is a change in that URL from forge side we need to update it again.

Is there anyway from javascript to get the path of the model based on the URN?

Upvotes: 0

Views: 1758

Answers (1)

Bryan Huang
Bryan Huang

Reputation: 5342

To load by URN of the SVF simply pass in its, with the rest of your Viewer's environment kept the same as you would for URN of the document:

// get the URN of the SVF from the manifest, e.g. `urn%3Aadsk.viewing%3Afs.file%3AdXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6c2JzYjIzMzMzL3NiYmJiYmIuZHdn%2Foutput%2F3a65ae5a-804e-b91b-11d1-5bc44f41866f_f2d%2F3d.svf`

 Autodesk.Viewing.Initializer({ 
    'env' : 'AutodeskProduction', getAccessToken: onGetAccessToken
 }, function onInitialized(){
        //...
            viewer.start();
            viewer.loadModel('https://developer.api.autodesk.com/derivativeservice/v2/derivatives/urn%3Aadsk.viewing%3Afs.file%3AdXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6c2JzYjIzMzMzL3NiYmJiYmIuZHdn%2Foutput%2F3a65ae5a-804e-b91b-11d1-5bc44f41866f_f2d%2F3d.svf')
        });

BTW the viewerApplication API has been deprecated as of v7 so I'd recommend to follow this migration guide here to upgrade to v7 in order to get all those new features and fixes ...

Upvotes: 1

Related Questions