Clipping Planes - Line by line comments

Hi All

I found the clipping planes example in three.js webgl - clipping planes website and I wanted to get some comments on the following code lines as I’m not sure I totally understand it.

Here is the code :

const globalPlane = new THREE.Plane(new THREE.Vector3(0, 0, 1), -5);

// ***** Clipping setup (renderer): *****

// This is the part I’m not sure about. What is it exactly Empty (an array ?). I’m confused about the
// Empty variable here…
const globalPlanes = [globalPlane], Empty = Object.freeze([]);

renderer.clippingPlanes = Empty; // GUI sets it to globalPlanes

//renderer.localClippingEnabled = 5;

const gui = new GUI(),



    folderGlobal = gui.addFolder('Global Clipping'),

    propsGlobal = {

        get 'Enabled'() {

// What does this line do exactly ?
return renderer.clippingPlanes !== Empty;

        },

        set 'Enabled'(v) {

// if the checkbox is checked (true), then renderer.clippingPlanes get the value of globalPlanes ??
// What does the v value represent here ? why do we include it here ?

         renderer.clippingPlanes = v ? globalPlanes : Empty;

        },

        get 'Plane'() {

            return globalPlane.constant;

        },

        set 'Plane'(v) {

// Does globalPlane.constant represent the distance from the origin to the clipping plane
globalPlane.constant = v;

        }

    };

folderGlobal.add(propsGlobal, 'Enabled');

folderGlobal.add(propsGlobal, 'Plane', -20, +20);
1 Like

Curious. Following

It seems your questions are primarily related to basic javascript functionality and less three.js. I’d take a look at the docs for Object.freeze (which just makes it so an object cannot be modified) and setters and getters (which let you provide custom functionality when reading and writing members).

// Does globalPlane.constant represent the distance from the origin to the clipping plane
globalPlane.constant = v;

This is also answered in the three.js docs for Plane:

constant - (optional) the signed distance from the origin to the plane. Default is 0 .

Thanks gkjohnson, for providing some response elements !