def _draw_points_callback(
        self, draw_manager, object_anchor, positions, colors
    ):
        """A callback function to draw a point cloud in Blender's 3D view."""
        handle_is_valid = True
        try:
            # Check if object still exists
            object_anchor_name = object_anchor.name
        except:
            handle_is_valid = False

        if handle_is_valid:
            if object_anchor_name in bpy.data.objects:
                # Use the visibility of the object to enable /
                # disable the drawing of the point cloud
                if bpy.data.objects[object_anchor_name].visible_get():
                    # Update the batch depending on the anchor pose (only if
                    # necessary)
                    object_anchor_has_changed = not np.array_equal(
                        self._object_anchor_pose_previous,
                        object_anchor.matrix_world,
                    )
                    if self._batch_cached is None or object_anchor_has_changed:
                        self._object_anchor_pose_previous = np.copy(
                            object_anchor.matrix_world
                        )
                        transf_pos_list = _compute_transformed_coords(
                            object_anchor.matrix_world, positions
                        )

                        self._batch_cached = batch_for_shader(
                            self._shader,
                            "POINTS",
                            {"pos": transf_pos_list, "color": colors},
                        )

                    self._shader.bind()
                    gpu.state.point_size_set(self._point_size)

                    previous_depth_mask_value = gpu.state.depth_mask_get()
                    previous_depth_test_value = gpu.state.depth_test_get()
                    gpu.state.depth_mask_set(True)
                    gpu.state.depth_test_set("LESS_EQUAL")

                    self._batch_cached.draw(self._shader)

                    gpu.state.depth_mask_set(previous_depth_mask_value)
                    gpu.state.depth_test_set(previous_depth_test_value)

        else:
            if self._draw_handler_handle is not None:
                log_report(
                    "INFO",
                    "Removing draw handler of deleted point cloud handle",
                )
                bpy.types.SpaceView3D.draw_handler_remove(
                    self._draw_handler_handle, "WINDOW"
                )
                self._draw_handler_handle = None
                self._batch_cached = None
                draw_manager.delete_anchor(object_anchor)
A callback function to draw a point cloud in Blender's 3D view.
photogrammetry_importer/opengl/draw_manager.py