Search code examples
autodesk-forgeautodeskautodesk-viewer

Wireframes extension unload lines on every update


I'm using this wireframe extension https://autodeskviewer.com/viewers/latest/extensions/Wireframes/Wireframes.js which I slightly modified its colors.

If I slightly move the camera, all the lines disappear and since our app constantly get input from the sensor, we end up with the lines always not showing.

enter image description here

I can't find what is making those lines disappear. How can I make those to always be visible?

It also happens in this example which you can reproduce:

enter image description here


Solution

  • Another way to avoid this issue after my research. Instead of using impl.scene and impl.sceneAfter, you can add those wireframe geometries into the viewer overlay. Here are the snippets of a workaround:

    //!-- 1. Add this two line in the `load` function.
    if( this.viewer.impl.overlayScenes[this.overlayName] === undefined )
        this.viewer.impl.createOverlayScene( this.overlayName );
    
    //!-- 2. Modified `addWireframes` with overlay functions
    function addWireframes(viewer, overlayName, groups) {
        var groupsCount = groups.length;
        for (var i = 0; i < groupsCount; ++i) {
            viewer.impl.addOverlay( overlayName, groups[i] );
        }
        viewer.impl.invalidate(false, true, true);
    }
    
    //!-- 3. Modified `revertWireframes` with overlay functions
    function revertWireframes(viewer, overlayName, groups) {
        var groupsCount = groups.length;
        for (var i = 0; i < groupsCount; ++i) {
            viewer.impl.removeOverlay( overlayName, groups[i] );
        }
        viewer.impl.invalidate(false, true, true);
    }
    
    //!-- 4 Update `impl.invalidate` function calls
    viewer.impl.invalidate(false, true, true);
    
    //!-- 5. Update function calls of both `addWireframes` and `revertWireframes`, for example:
    addWireframes(this.viewer, this.overlayName, this.groups);
    revertWireframes(this.viewer, this.overlayName, this.groups);
    

    P.S. Since this is just a workaround, not the formal solution. You would have to use it at your own risk.

    === Old Answer

    This might caused by the progressive rendering, you can turn it off via viewer.setProgressiveRendering( false ). But it will hurt the performance while viewing a large model in the Forge Viewer.

    Progressive rendering is the way how the viewer render large models. And it's no way to prevent and be fixed now unfortunately.

    Here is what it looks like on my side:

    https://i.sstatic.net/hDwNU.jpg