Skip to content

Commit

Permalink
Merge pull request #2383 from brisvag/fix/clipping-planes2
Browse files Browse the repository at this point in the history
  • Loading branch information
brisvag committed Oct 5, 2022
2 parents b678ce0 + c8c130e commit 859fcae
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions vispy/visuals/filters/clipping_planes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def __init__(self, clipping_planes: Optional[np.ndarray] = None, coord_system: s
fcode=Function(self.FRAG_CODE), fhook='pre', fpos=1,
)

# initialize clipping planes
self._clipping_planes = np.empty((0, 2, 3), dtype=np.float32)
self._clipping_planes_func = Function(self._build_clipping_planes_glsl(0))
self.fshader['clip_with_planes'] = self._clipping_planes_func

v_position = Varying('v_position', 'vec4')
self.vshader['v_position'] = v_position
self.fshader['v_position'] = v_position
Expand Down Expand Up @@ -103,12 +108,15 @@ def clipping_planes(self) -> np.ndarray:
@clipping_planes.setter
def clipping_planes(self, value: Optional[np.ndarray]):
if value is None:
value = np.empty([0, 2, 3])
self._clipping_planes = value
value = np.empty((0, 2, 3), dtype=np.float32)

clip_func = Function(self._build_clipping_planes_glsl(len(value)))
self.fshader['clip_with_planes'] = clip_func
# only recreate function if amount of clipping planes changes
if len(value) != len(self._clipping_planes):
self._clipping_planes_func = Function(self._build_clipping_planes_glsl(len(value)))
self.fshader['clip_with_planes'] = self._clipping_planes_func

self._clipping_planes = value

for idx, plane in enumerate(value):
clip_func[f'clipping_plane_pos{idx}'] = tuple(plane[0])
clip_func[f'clipping_plane_norm{idx}'] = tuple(plane[1])
self._clipping_planes_func[f'clipping_plane_pos{idx}'] = tuple(plane[0])
self._clipping_planes_func[f'clipping_plane_norm{idx}'] = tuple(plane[1])

0 comments on commit 859fcae

Please sign in to comment.