Exemplo n.º 1
0
    def test_detect_faces(self):
        test_utils.new_scene()
        self._head_and_cameras()
        fb = FBLoader.get_builder()
        self.assertTrue(fb.is_face_detector_available())
        settings = get_main_settings()
        headnum = settings.get_last_headnum()
        head = settings.get_head(headnum)
        camnum = head.get_last_camnum()

        test_utils.select_camera(headnum, camnum - 1)
        reset_detected_faces()
        test_utils.pickmode_start(headnum=headnum, camnum=camnum - 1)
        faces = get_detected_faces()
        self.assertEqual(1, len(faces))

        test_utils.select_camera(headnum, camnum)
        reset_detected_faces()
        test_utils.pickmode_start(headnum=headnum, camnum=camnum)
        faces = get_detected_faces()
        self.assertEqual(TestConfig.faces_on_test_render, len(faces))
        for i in range(len(faces)):
            test_utils.pickmode_select(headnum=headnum,
                                       camnum=camnum,
                                       selected=i)
        test_utils.out_pinmode()
Exemplo n.º 2
0
    def test_duplicate_and_reconstruct(self):
        test_utils.new_scene()
        self._head_and_cameras()
        settings = get_main_settings()
        headnum = settings.get_last_headnum()
        test_utils.deselect_all()
        test_utils.select_camera(headnum, 0)
        test_utils.out_pinmode()

        headobj = test_utils.select_by_headnum(headnum)
        bpy.ops.object.duplicate_move(
            OBJECT_OT_duplicate={
                "linked": False,
                "mode": 'TRANSLATION'
            },
            TRANSFORM_OT_translate={"value": (-4.0, 0, 0)})
        test_utils.save_scene(filename='before.blend')

        op = get_operator(Config.fb_reconstruct_head_idname)
        op('EXEC_DEFAULT')
        headnum2 = settings.get_last_headnum()
        head_new = settings.get_head(headnum2)
        # Two heads in scene
        self.assertEqual(1, settings.get_last_headnum())
        # Three cameras created
        self.assertEqual(2, head_new.get_last_camnum())
Exemplo n.º 3
0
    def test_load_images_and_bake_texture(self):
        test_utils.new_scene()
        self._head_cams_and_pins()
        settings = get_main_settings()

        dir = os.path.dirname(os.path.abspath(__file__))
        filename = os.path.join(dir, 'images/ale_white_24x16.jpg')
        headnum = 0
        camnum = 1
        res = test_utils.create_camera_from_image(headnum=headnum,
                                                  camnum=camnum,
                                                  filename=filename)
        self.assertEqual(res, {'FINISHED'})
        head = settings.get_head(headnum)
        camera = head.get_camera(camnum)
        # Test EXIF read
        self.assertEqual(camera.exif.focal, 50.0)
        self.assertEqual(camera.exif.focal35mm, 75.0)

        camnum = 2
        filename = os.path.join(dir, 'images/ana_blue_24x16.tif')
        res = test_utils.create_camera_from_image(headnum=headnum,
                                                  camnum=camnum,
                                                  filename=filename)
        self.assertEqual(res, {'FINISHED'})

        tex_name = materials.bake_tex(headnum=0, tex_name='bake_texture_name')
        self.assertTrue(tex_name is not None)
Exemplo n.º 4
0
    def test_uv_switch(self):
        if TestConfig.skip_this_test('test_uv_switch'):
            return

        def _get_uv_names():
            return [x[0] for x in uv_items_callback(None, None)]

        def _get_uvs_in_np_array(obj):
            uv_map = obj.data.uv_layers.active
            uv_count = len(uv_map.data)
            np_uvs = np.empty((uv_count, 2), dtype=np.float32)
            uv_map.data.foreach_get('uv', np.reshape(np_uvs, uv_count * 2))
            return np_uvs

        test_utils.new_scene()
        self._head_cams_and_pins()
        settings = get_main_settings()
        headnum = settings.get_last_headnum()
        head = settings.get_head(headnum)
        headobj = head.headobj

        for level_of_detail in _get_models():
            head.model_type = level_of_detail

            previous = []
            for uv_name in _get_uv_names():
                head.tex_uv_shape = uv_name
                np_uvs = _get_uvs_in_np_array(headobj)
                for member in previous:
                    self.assertFalse(np.array_equal(np_uvs, member))
                previous.append(np_uvs)
Exemplo n.º 5
0
 def test_delete_cameras(self):
     test_utils.new_scene()
     self._head_and_cameras()
     settings = get_main_settings()
     headnum = settings.get_last_headnum()
     test_utils.create_empty_camera(headnum)
     self.assertEqual(4, len(settings.get_head(headnum).cameras))
     test_utils.delete_camera(headnum, 2)
     self.assertEqual(3, len(settings.get_head(headnum).cameras))
     test_utils.delete_camera(headnum, 2)
     self.assertEqual(2, len(settings.get_head(headnum).cameras))
Exemplo n.º 6
0
    def test_delete_cameras(self):
        test_utils.new_scene()
        self._head_and_cameras()
        settings = get_main_settings()
        headnum = settings.get_last_headnum()

        filenames = DataHolder.get_image_file_names()
        self.assertEqual(len(filenames),
                         len(settings.get_head(headnum).cameras))
        test_utils.delete_camera(headnum, 2)
        self.assertEqual(
            len(filenames) - 1, len(settings.get_head(headnum).cameras))
        test_utils.delete_camera(headnum, 2)
        self.assertEqual(
            len(filenames) - 2, len(settings.get_head(headnum).cameras))
Exemplo n.º 7
0
    def test_models_and_parts(self):
        if TestConfig.skip_this_test('test_models_and_parts'):
            return

        def _check_models(head):
            previous_polycount = 1.0e+6
            for level_of_detail in _get_models():
                head.model_type = level_of_detail
                poly_count = len(head.headobj.data.polygons)
                logger.debug('Model_count mask {}: {}'.format(
                    level_of_detail, poly_count))
                self.assertTrue(previous_polycount > poly_count)
                previous_polycount = poly_count

        def _check_masks(head, fb_masks_count):
            max_poly_count = len(head.headobj.data.polygons)
            logger.debug('Max_poly_count: {}'.format(max_poly_count))

            for i in range(len(head.masks)):
                head.masks[i] = False
                poly_count = len(head.headobj.data.polygons)
                logger.debug('Poly_count mask {}: {}'.format(i, poly_count))
                if i < TestConfig.fb_mask_count:
                    self.assertTrue(max_poly_count > poly_count)
                else:
                    self.assertTrue(max_poly_count == poly_count)
                head.masks[i] = True
                poly_count = len(head.headobj.data.polygons)
                self.assertTrue(max_poly_count == poly_count)

        logger = logging.getLogger(__name__)
        test_utils.new_scene()
        self._head_cams_and_pins()
        settings = get_main_settings()
        headnum = settings.get_last_headnum()
        head = settings.get_head(headnum)

        _check_models(head)

        for level_of_detail in _get_models():
            head.model_type = level_of_detail
            _check_masks(head, TestConfig.fb_mask_count)
Exemplo n.º 8
0
    def test_create_blendshapes_and_animation(self):
        test_utils.new_scene()
        self._head_cams_and_pins()
        settings = get_main_settings()
        headnum = settings.get_last_headnum()
        head = settings.get_head(headnum)
        headobj = head.headobj

        test_utils.create_blendshapes()
        self.assertTrue(headobj.data.shape_keys is not None)
        blendshapes = headobj.data.shape_keys.key_blocks
        self.assertEqual(len(blendshapes),
                         TestConfig.facs_blendshapes_count + 1)  # FACS + Basic

        test_utils.create_example_animation()
        self.assertTrue(headobj.data.shape_keys and
                        headobj.data.shape_keys.animation_data and \
                        headobj.data.shape_keys.animation_data.action)

        test_utils.delete_blendshapes()
        self.assertTrue(headobj.data.shape_keys is None)
Exemplo n.º 9
0
    def test_change_camera_params(self):
        test_utils.new_scene()
        self._head_cams_and_pins()
        settings = get_main_settings()
        headnum = settings.get_last_headnum()
        head = settings.get_head(headnum)
        camnum = head.get_last_camnum()
        camobj = head.get_camera(camnum).camobj

        new_focal = 35.0
        head.focal = new_focal
        self.assertEqual(new_focal, camobj.data.lens)
        new_focal = 18.0
        head.focal = new_focal
        self.assertEqual(new_focal, camobj.data.lens)
        new_sensor_width = 15
        head.sensor_width = new_sensor_width
        # Config.default_sensor_width instead cutom new_sensor_width!
        self.assertEqual(Config.default_sensor_width, camobj.data.sensor_width)
        new_sensor_width = 20
        head.sensor_width = new_sensor_width
        self.assertEqual(Config.default_sensor_width, camobj.data.sensor_width)
Exemplo n.º 10
0
 def test_wireframe_coloring(self):
     test_utils.new_scene()
     self._head_and_cameras()
     op = get_operator(Config.fb_wireframe_color_idname)
     op('EXEC_DEFAULT', action='wireframe_green')
Exemplo n.º 11
0
 def test_move_pins(self):
     test_utils.new_scene()
     self._head_cams_and_pins()
Exemplo n.º 12
0
 def test_create_head_and_cameras(self):
     test_utils.new_scene()
     self._head_and_cameras()
Exemplo n.º 13
0
 def test_addon_on(self):
     test_utils.new_scene()
     settings = get_main_settings()
     self.assertEqual(0, len(settings.heads))