autodesk-forgeforge

Restore sectionBox in forge viewer


How to get bounding box info of intersection box in forge viewer? i want to restore section extension box bounding value to be restored.for that for below method i get box value. getSelectionbox

now i want to restore that to viewer/set that saved value to viewer for that is there any method is available?

i used setSectionBox(box) but it isn't worked for me.

Thank you

Here is code sample:

viewer.restoreState(currentState, null, false);

                viewer.hide(Object.values(val.hiddenNodes));
                if(Object.values(val.isolateNodes).length > 0){                     
                    viewer.isolate(Object.values(val.isolateNodes));
                }
                if(val.cutPlanes.length !== 0){
                    viewer.loadExtension("Autodesk.Section").then(function(sectionTool){
                        sectionTool.activate(val.sectionStyle);
                        
                        
                        var sectionTool = markupsExt.tool.getSectionBoxValues();

                        const sectionbboxmin = new THREE.Vector3(val.sectionBox[0], val.sectionBox[1], val.sectionBox[2]);      
                        const sectionbboxmax = new THREE.Vector3(val.sectionBox[3], val.sectionBox[4], val.sectionBox[5]);
                        const box = new THREE.Box3(sectionbboxmin,sectionbboxmax);
                        box.transform = val.sectionBoxTransform;
                        sectionTool.setSectionBox(box);
                    });
                }

Solution

  • I just tried applying a custom section box to a model in Forge Viewer using this code snippet:

    let box = new THREE.Box3(new THREE.Vector3(-100,-100,-100), new THREE.Vector3(100,100,100));
    let sectionExt = viewer.getExtension('Autodesk.Section');
    sectionExt.setSectionBox(box);
    

    And the result is this: enter image description here

    So this seems to be working ok. Could you provide more details about how you tried to set the section box?

    EDIT:

    Here's how you can restore the section box from a list of cutplanes (like the one you can obtain from viewer.getState()):

    function restoreSectionBox(viewer, cutplanes) {
        let box = new THREE.Box3();
        for (const cutplane of cutplanes) {
            const normal = new THREE.Vector3(cutplane[0], cutplane[1], cutplane[2]);
            const offset = cutplane[3];
            const pointOnPlane = normal.negate().multiplyScalar(offset);
            box.expandByPoint(pointOnPlane);
        }
        const sectionExt = viewer.getExtension('Autodesk.Section');
        sectionExt.setSectionBox(box);
    }
    
    // ...
    
    let cutplanes = [
        [1, 0, 0, 40],
        [0, 1, 0, 50],
        [0, 0, 1, 30],
        [-1, 0, 0, 60],
        [0, -1, 0, 20],
        [0, 0, -1, 70]
    ];
    restoreSectionBox(viewer, cutplanes);