Search code examples
autodeskautodesk-forgeautodesk-viewer

Cover cuts in cut planes


When I use the function viewer.setCutPlanes() the planes that are cut are not covered:

enter image description here enter image description here

But using the viewer's section analysis tool plane cut, they do get covered (and each cover is part of its own node which is nice):

enter image description here

How can I add those covers to the model when using viewer.setCutPlanes()?

PS: I found the section tool extension in the viewer, but it seems all of its relevant functions are private. Should I try to copy this extension and expose the necessary functions there? Is there a repo with the ES6 version of it?


Solution

  • Unfortunately, there is no ES6 module for the Forge Viewer. The Viewer3D.setCutPlanes() is an utility method for producing ThreeJS clipping planes only, and the cut-cover feature is archived by the Autodesk.Viewing.Extensions.Section.SectionTool now.

    Functions listed below must be copied from the SectionTool extension if you wanna perform this feature under self control:

    1. getDiffuseColor()
    2. init_three_triangulator()
    3. init_three_intersector()
    4. updateCapMeshes()

    Besides, the _viewer variable in those private functions above should be replaced by the Viewer3DImpl instance, i.e. the Viewer3D.impl. Or you can change function declaration of updateCapMeshes just like below:

    function updateCapMeshes( _viewer, plane ) {
    
      init_three_triangulator();
      init_three_intersector();
    
      // ... Original content of updateCapMeshes below ...
    }
    

    Call modified updateCapMeshes function to create cut-cover like this way:

    //-- Helper function to create your own cut planes.
    function createMyOwnPlane( _viewer, _sectionPlanes ) {
      if (_sectionPlanes.length === 1) {
         updateCapMeshes(_viewer, new THREE.Plane().setComponents(_sectionPlanes[0].x, _sectionPlanes[0].y, _sectionPlanes[0].z, _sectionPlanes[0].w));
      }
      _viewer.setCutPlanes(_sectionPlanes);
    }
    
    
    //-- Call functions here.
    var viewer = viewerApp.getCurrentViewer();
    createMyOwnPlane( viewer.impl, [ new THREE.Vector4(0, 0, 1, 0) ] );
    

    And you will get results like this picture without the TransformControl: Result of createMyOwnPlane

    BTW, cut-cover can be removed by this way~

    var oldsection = viewer.impl.sceneAfter.getObjectByName("section");
    if (oldsection)
      viewer.impl.sceneAfter.remove(oldsection);
    
    viewer.setCutPlanes();