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);