0

I am creating a site with a forge-viewer and want to view multiple loaded models in a single window. How can I enable the function of loading and viewing several models in one place?

This is for a new site. I have already tried all the methods and recommendations available on the Internet,but none of them helped me solve my problem.

My code is fully consistent with the code from this source https://github.com/Autodesk-Forge/learn.forge.viewmodels/tree/nodejs

I expect that I can finally add the function of loading and viewing several models in one window, but so far I did not manage to do it.

2 Answers2

1

Read up on this and this series of blogs for a pretty thorough walkthrough on model aggregation with Viewer.

In a nutshell you will need to load different models using viewer.start for the first model and then viewer.loadModel for the others:

this.viewer.start(svfUrl, loadOptions, onLoadModelSuccess, onLoadModelError);
this.viewer.loadModel(svfUrl, loadOptions, onLoadModelSuccess, onLoadModelError); 

See doc for this method here.

Bryan Huang
  • 5,247
  • 2
  • 15
  • 20
  • Thank you for your answer, but can I ask you something else? My viewer is completely identical to this example. https://github.com/Autodesk-Forge/learn.forge.viewmodels/tree/nodejs Could you tell me where I should add this code? There is a second option, I tried to implement your advice on the code that provides the documentation, but I still fail. https://forge.autodesk.com/en/docs/viewer/v6/tutorials/basic-application/ – Alisa Bondarchuk Feb 11 '19 at 09:16
  • You can keep the node backend the same and replace the frontend following this sample which is more straightforward: https://forge.autodesk.com/blog/aggregate-multi-models-sequence-forge-viewer – Bryan Huang Feb 11 '19 at 10:46
  • Bryan Huang, I am very grateful for your help, I partially managed to solve the problem, but I still did not achieve the desired result. I managed to load several models using the code of the article you gave me last, but this solution can only be temporary. At the moment I can upload several models as it is said in the last article, but this is a mechanical work, and I need to automate it. What do I want to do? I want that when loading documents into a bouquet, they are loaded into one area, and not into different ones, but so far I have not been able to achieve this. Thank you very much. – Alisa Bondarchuk Feb 14 '19 at 05:47
  • Check out this sample [here](https://github.com/Autodesk-Forge/learn.forge.viewmodels/tree/nodejs?files=1) which allows the user to upload a model for translation and take the relevant bits and integrate them into your workflow to automate the model upload and translation. – Bryan Huang Feb 18 '19 at 12:01
  • Unfortunately, my code almost completely corresponds to the code from this article (at the top I gave a link to it). I have one question and I think that this way I will be able to solve my problem. I need to get an array of all loaded objects / files. I read this decision https://stackoverflow.com/questions/52267698/how-to-get-the-urn-of-the-bucket-file, but I don't know how to transfer the data to the array. I would be very grateful if you help me. – Alisa Bondarchuk Feb 18 '19 at 12:14
  • The data returned from that endpoint from the answer of you link is already a JSON array and ready to be consumed by both your front and back ends - once parsed simply treat them as plain old objects. Can see [here](https://www.lennu.net/jquery-ajax-example-with-json-response/)(jQuery is optional and feel free to use your own library/framework of choice) and [here](https://stackoverflow.com/questions/17811827/get-a-json-via-http-request-in-nodejs) for how to parse them and take the object IDs to form your model array. – Bryan Huang Feb 22 '19 at 05:04
  • I looked at these articles, but I could not get an array, can you help me give some kind of code? Thank you. – Alisa Bondarchuk Feb 26 '19 at 13:06
1

For loading multiple models in a viewer version 7, make sure you add the viewer option keepCurrentModels: true, like this:

function loadModels(urns) {

    const viewerOptions = {
        env: 'AutodeskProduction',
        accessToken: token.access_token,
        extensions:[ ]
    };

    Autodesk.Viewing.Initializer(viewerOptions, () => {

        const div = document.getElementById('forgeViewer');
        viewer = new Autodesk.Viewing.Private.GuiViewer3D(div);
        viewer.start();
        urns.map((m)=>{
            Autodesk.Viewing.Document.load(`urn:${m.urn}`, (doc) => {
                var viewables = doc.getRoot().getDefaultGeometry();
                viewer.loadDocumentNode(doc, viewables,{
                    keepCurrentModels: true,
                })
                .then( onLoadFinished );
            });

        })
    });

    function onLoadFinished(doc) {
        console.log('loaded');
    }
}

https://forge.autodesk.com/blog/loading-multiple-models-forge-viewer-v7 https://github.com/wallabyway/federatedmodels-v7

Georg Kastenhofer
  • 1,387
  • 12
  • 32