19 Jul 2017

Viewer setCutPlanes

Default blog image

The Viewer has a setCutPlanes method that, according to documentation, requires a "list of Vector4 plane representation: {x:a, y:b, z:c, w:d} Plane general equation: ax + by + cz + d = 0 where a, b, and c are not all zero Passing an empty list or null is equivalent to setting zero cut planes", but how to use it?

One way to quickly try it is by using .getState method to have some valid cut planes:

// get the current state
var state = viewer.getState();

// and the cut planes on this state
var cutplanes = state.cutplanes;

Now we have a cut plane, either created or copied from state, we can use these cut plane method:

// now prepare a list of planes for cut
var planes = [];

// the getState returns a list of cut planes, 
// so let's iterate through it
for (var p = 0; p<cutplanes.length; p++)
{
  var cutplane = cutplanes[p];

  // create a THREE.Vector4
  var vector4 = new THREE.Vector4(
    cutplane[0], cutplane[1],
    cutplane[2], cutplane[3]);

  planes.push(vector4);
}

// restore to original state
viewer.restoreState(null);

// apply the new cut planes
viewer.setCutPlanes(planes);

 

Related Article