@@ -21,13 +21,13 @@ def draw_grid(self):
21
21
num_squares = 10 # Length of the grid in each direction (in units)
22
22
relative_cam = True # Whether the grid follows the camera rotation and movement
23
23
24
- the_grid = self .create_grid (relative_cam , num_squares )
24
+ the_grid = self .__create_grid (relative_cam , num_squares )
25
25
self .grid_object [0 ] = the_grid
26
26
27
27
# Update the labels instead of recreating them
28
28
create_grid_numbers (self .grid_object [1 ], relative_cam , num_squares )
29
29
30
- def create_grid (self , bool_camera_relative , num_squares ):
30
+ def __create_grid (self , bool_camera_relative , num_squares ):
31
31
"""
32
32
Draw a grid along each 3D plane, that is closest to the camera.
33
33
@@ -171,6 +171,30 @@ def set_visibility(self, is_visible):
171
171
# TODO this will need to be uncommented once grid_object reuse is done
172
172
#for number in self.grid_object[1]:
173
173
# number.visible = is_visible
174
+
175
+ def clear_scene (self ):
176
+ """
177
+ Clear the canvas of all objects (keeping the grid)
178
+
179
+ Due to how VPython operates, there is no 'deletion' of objects directly.
180
+ To 'delete' objects, first they must be rendered invisible.
181
+
182
+ Then: if a new object with the same variable name is used, the previous memory will be freed.
183
+ Or: del variable_name will free its memory.
184
+ If the object wasn't invisible, it would remain visible in the scene.
185
+
186
+ Since the scene doesnt track variable names, the best way to clear the scene is to render all objects invisible,
187
+ and have the user assume they are all deleted. However, all objects can be redisplayed by setting the visibility
188
+ """
189
+ # Save current grid visibility
190
+ grid_visibility = self .grid_object [0 ].visible
191
+
192
+ # Set all objects invisible
193
+ for scene_object in scene .objects :
194
+ scene_object .visible = False
195
+
196
+ # Set grid visibility to previous
197
+ self .set_visibility (grid_visibility )
174
198
175
199
176
200
def create_line (pos1 , pos2 ):
0 commit comments