def test_cc_material_loader(self): """ Tests if the default cc materials are loaded. """ bproc.init() materials = bproc.loader.load_ccmaterials(used_assets=["metal", "wood", "fabric"]) list_of_some_textures = ["Metal001", "Fabric006", "Wood050"] for material in materials: if material.get_name() in list_of_some_textures: list_of_some_textures.remove(material.get_name()) # If the list is not empty, not all object have been loaded self.assertEqual(list_of_some_textures, [])
def test_object_loader(self): """ Tests if the object loader is loading all objects from a given .obj file. """ bproc.init() objs = bproc.loader.load_obj(os.path.join(resource_folder, "scene.obj")) # List of objects in the loaded "../examples/resources.obj" list_of_objects = ["Cube", "Cube.001", "Icosphere", "Icosphere.001", "Icosphere.002", "Suzanne", "Cylinder", "Cylinder.001", "Cylinder.002"] for obj in objs: list_of_objects.remove(obj.get_name()) # If the list is not empty, not all object have been loaded self.assertEqual(list_of_objects, [])
def test_blender_reference_after_undo(self): """ Test if the blender_data objects are still valid after an undo execution is done. """ with SilentMode(): bproc.init() objs = bproc.loader.load_obj( os.path.join(test_path_manager.example_resources, "scene.obj")) for obj in objs: obj.set_cp("test", 0) with Utility.UndoAfterExecution(): for obj in objs: obj.set_cp("test", 1) for obj in objs: self.assertEqual(obj.get_cp("test"), 0)
def test_camera_add_camera_pose(self): """ Tests if the camera to world matrix is set right. """ bproc.init() poi = np.array([0, 0, 0]) #location = np.array([1, 2, 3]) #rotation_matrix = np.array([[-0.5285266 -0.8057487 0.26726118] # [ 0.7770431 -0.33239999 0.53452241] # [-0.34185314 0.49018279 0.8017838 ]]) cam2world_matrix = np.array([[-0.5285266, -0.8057487, 0.26726118, 1.0], [0.7770431, -0.33239999, 0.53452241, 2.0], [-0.34185314, 0.49018279, 0.8017838, 3.0], [0.0, 0.0, 0.0, 1.0]]) bproc.camera.add_camera_pose(cam2world_matrix) cam_ob = bpy.context.scene.camera cam2world_matrix_calc = np.array(cam_ob.matrix_world) for x, y in zip(np.reshape(cam2world_matrix, -1).tolist(), np.reshape(cam2world_matrix_calc, -1).tolist()): self.assertAlmostEqual(x, y)
import argparse import numpy as np parser = argparse.ArgumentParser() parser.add_argument( 'object', nargs='?', default="examples/basics/camera_object_pose/obj_000004.ply", help="Path to the model file") parser.add_argument('output_dir', nargs='?', default="examples/basics/camera_object_pose/output", help="Path to where the final files will be saved") args = parser.parse_args() bproc.init() # load the objects into the scene obj = bproc.loader.load_obj(args.object)[0] # Use vertex color for texturing for mat in obj.get_materials(): mat.map_vertex_color() # Set pose of object via local-to-world transformation matrix obj.set_local2world_mat( [[0.331458, -0.9415833, 0.05963787, -0.04474526765165741], [-0.6064861, -0.2610635, -0.7510136, 0.08970402424862098], [0.7227108, 0.2127592, -0.6575879, 0.6823395750305427], [0, 0, 0, 1.0]]) # Scale 3D model from mm to m obj.set_scale([0.001, 0.001, 0.001]) # Set category id which will be used in the BopWriter obj.set_cp("category_id", 1)