CadQuery / sphinxcadquery

An extension to visualize CadQuery 3D files in your Sphinx documentation
BSD 3-Clause "New" or "Revised" License
13 stars 4 forks source link

Could we skip off-screen scenes rendering? #18

Open Peque opened 3 years ago

Peque commented 3 years ago

We used to have this check in the loop:

    scenes.forEach( function ( scene ) {

        var rect = scene.userData.view.getBoundingClientRect();
        // check if it's offscreen. If so skip it
        if ( rect.bottom < 0 || rect.top > renderer.domElement.clientHeight ||
             rect.right < 0 || rect.left > renderer.domElement.clientWidth ) {

            return; // it's off screen

        }

        // set the viewport
        var width = rect.right - rect.left;
        var height = rect.bottom - rect.top;
        var left = rect.left;
        var bottom = renderer.domElement.clientHeight - rect.bottom;

        renderer.setViewport( left, bottom, width, height );
        renderer.setScissor( left, bottom, width, height );

        var camera = scene.userData.camera
        camera.aspect = width / height;
        camera.updateProjectionMatrix();

        renderer.render( scene, scene.userData.camera );

    } );

However, it resulted in scenes "sticking" when scrolling up/down.

How to reproduce: go to one scene and scroll fast up or down. The scene, or part of it, may get stuck to the view, as long as another scene does not appear with the scroll (i.e.: try to scroll away from any scenes).