コード例 #1
0
    def test_test_occlusion(self):
        # test of ray tracing occlusion test
        scene = bpy.context.scene
        layer = scene.view_layers['View Layer']

        # test visibile object
        self.assertFalse(geometry.test_occlusion(scene, layer, self._cam, self._obj1, self._w, self._h, False),
                         'Visible object appears occluded')
        self.assertFalse(geometry.test_occlusion(scene, layer, self._cam, self._obj1, self._w, self._h, True),
                         'Visible object appears occluded')

        # test non visible object
        self.assertTrue(geometry.test_occlusion(scene, layer, self._cam, self._obj_non_visible, self._w, self._h),
                        'Non visible object appears visible')
コード例 #2
0
    def test_visibility(self, camera_name: str, locations: np.array):
        """Test whether given camera sees all target objects
        and store visibility level/label for each target object
        
        Args:
            camera(str): selected camera name
            locations(list): list of locations to check. If None, check current camera location
        """

        # grep camera object from name
        camera = bpy.context.scene.objects[camera_name]

        # make sure to work with multi-dim array
        if locations.shape == (3, ):
            locations = np.reshape(locations, (1, 3))

        # loop over locations
        for i_loc, location in enumerate(locations):
            camera.location = location

            any_not_visible_or_occluded = False
            for obj in self.objs:
                not_visible_or_occluded = abr_geom.test_occlusion(
                    bpy.context.scene,
                    bpy.context.scene.view_layers['View Layer'],
                    camera,
                    obj['bpy'],
                    bpy.context.scene.render.resolution_x,
                    bpy.context.scene.render.resolution_y,
                    require_all=False,
                    origin_offset=0.01)
                # store object visibility info
                obj['visible'] = not not_visible_or_occluded
                if not_visible_or_occluded:
                    self.logger.warn(f"object {obj} not visible or occluded")

                # keep trace if any obj was not visible or occluded
                any_not_visible_or_occluded = any_not_visible_or_occluded or not_visible_or_occluded

            # if any_not_visibile_or_occluded --> at least one object is not visible from one location: return False
            if any_not_visible_or_occluded:
                return False

        # --> all objects are visible (from all locations): return True
        return True