Search code examples
reactjsautodesk-forgeautodesk-viewerautodesk

Implement APS (Forge) AggregatedView with React


I need some clarification on the Autodesk AggregatedView Viewer.

The documentation mentions the following: React compatibility: Just set an array of nodes from the React property and AggregatedView will take care of loading and hiding models as needed.

Does anyone have or know of a concrete example of how to set such an array of nodes (also what type of nodes?) and how this could potentially simplify viewer integration in a React environment?

I saw this post here: Autodesk forge viewer, aggregatedView,React & Ts unable to initialise. But to me this is not much different from a normal viewer implementation.

Thanks in advance!


Solution

  • I'm afraid this sentence in the documentation is a bit misleading. What it basically says is - instead of adding or removing models to/from the viewer, you can simply call the setNodes method with all the models you want, and the viewer will take care of the rest (adding models that are not loaded yet, removing models that are loaded but not in your list, etc.).

    Btw a "node" is basically an object representing a specific viewable that was generated by the Model Derivative service for your model. It's the object you would typically get from the doc.getRoot().search(...) or doc.getRoot().getDefaultGeometry() calls, like in the snippet below:

    function onDocumentLoadSuccess(doc) {
        viewer.loadDocumentNode(doc, doc.getRoot().getDefaultGeometry());
    }
    function onDocumentLoadFailure(code, message, errors) {
        console.error(code, message, errors);
    }
    Autodesk.Viewing.Document.load('urn:' + urn, onDocumentLoadSuccess, onDocumentLoadFailure);