Search code examples
autodesk-forgeautodesk-viewer

How to move the section plane with a mouse wheel event


One of our users has this request to mimic the user experience of a different software.

Currently we create a section plane and move the yellow arrow with the mouse. Is it possible to move the created section plane in the direction of the arrow, with a key combination (shift + mouse scroll event).

If so, can someone point me in the right direction?


Solution

  • You can control the current section plane programatically, like so:

    function moveSectionPlaneByDelta(viewer, delta) {
        // Assuming that section tool is active
        const sectionTool = viewer.toolController.getActiveTool();
        const sectionPlanes = sectionTool.getSectionPlanes();
        if (sectionPlanes.length === 1) {
            const normal = new THREE.Vector3(sectionPlanes[0].x, sectionPlanes[0].y, sectionPlanes[0].z);
            const position = normal.clone().multiplyScalar(-sectionPlanes[0].w + delta);
            sectionTool.setSectionPlane(normal, position);
        }
    }
    
    // ...
    
    moveSectionPlaneByDelta(viewer, 5.0); // move in the direction of the plane normal
    moveSectionPlaneByDelta(viewer, -5.0); // move against the direction of the plane normal