How to close rgl X11 windows?

2.7k views Asked by At

I want to create a 3D animation with rgl package. My code is like this:

for (frame in 1:100) {
    open3d()
    ... # run some commands here for plotting, like points3d() or spheres3d()
     # Now, save the frame to a png file
    rgl.snapshot(paste0("Frame",sprintf("%04d",frame),".png"))     
}

It works fine and creates an snapshot in PNG file for each frame. But after that, there would be 100 open X11 windows. The other problem is that I guess with opening many windows the running time would be too high.

I tried using rgl.close() and clear3d(), none of them worked fine (they made the output png files to be black).

Is there anyway?

2

There are 2 answers

0
LBV On

# rgl.close() ... works fine and is self explanatory

3D visualization device system

Description
3D real-time rendering system.
Usage
# Low level rgl.* interface
rgl.open(useNULL = rgl.useNULL())     # open new device
rgl.close()    # close current device
1
DrPo On

I realized this is an old question, but this is the simple solution I came up with to close all rgl windows.

while (rgl.cur() > 0) { rgl.close() }