Пример #1
0
    def assign_materials_to_floor_wall_ceiling(self):
        """
        Assigns materials to the floor, wall and ceiling. These are randomly selected from the CCMaterials. This means
        it is required that the CCMaterialLoader has been executed before, this module is run.
        """

        # first create a uv mapping for each of the three objects
        for obj in [self.floor_obj, self.wall_obj, self.ceiling_obj]:
            if obj is not None:
                bpy.ops.object.select_all(action='DESELECT')
                obj.select_set(True)
                bpy.ops.object.mode_set(mode='EDIT')
                bpy.ops.mesh.select_all(action='SELECT')
                bpy.ops.uv.cube_project(cube_size=1.0)
                bpy.ops.object.mode_set(mode='OBJECT')

        # only select non see through materials
        config = {
            "conditions": {
                "cp_is_cc_texture": True,
                "cf_principled_bsdf_Alpha_eq": 1.0
            }
        }
        material_getter = Material(Config(config))
        all_cc_materials = material_getter.run()

        def assign_material(cur_obj: bpy.types.Object,
                            material: bpy.types.Material):
            """
            First all materials are removed and then the given material is assigned

            :param cur_obj: Current object
            :param material: Current material, which will be assigned
            """
            # first remove all existing
            if cur_obj.material_slots:
                for i in range(len(cur_obj.material_slots)):
                    bpy.ops.object.material_slot_remove({'object': cur_obj})
            # add the new one
            cur_obj.data.materials.append(material)

        if all_cc_materials:
            assign_material(self.floor_obj, random.choice(all_cc_materials))
            assign_material(self.wall_obj, random.choice(all_cc_materials))
            if self.ceiling_obj is not None and self.assign_material_to_ceiling:
                assign_material(self.ceiling_obj,
                                random.choice(all_cc_materials))
        else:
            warnings.warn(
                "There were no CCMaterials found, which means the CCMaterialLoader was not executed first!"
                "No materials have been assigned to the walls, floors and possible ceiling."
            )
Пример #2
0
    def run(self):
        # use a loader module to load objects
        bpy.ops.object.select_all(action='SELECT')
        previously_selected_objects = set(bpy.context.selected_objects)
        module_list_config = self.config.get_list("used_loader_config")
        modules = Utility.initialize_modules(module_list_config)
        for module in modules:
            print("Running module " + module.__class__.__name__)
            module.run()
        bpy.ops.object.select_all(action='SELECT')
        loaded_objects = list(
            set(bpy.context.selected_objects) - previously_selected_objects)

        # only select non see through materials
        config = {
            "conditions": {
                "cp_is_cc_texture": True,
                "cf_principled_bsdf_Alpha_eq": 1.0
            }
        }
        material_getter = MaterialProvider(Config(config))
        all_cc_materials = Material.convert_to_materials(material_getter.run())

        RandomRoomConstructor.construct(
            used_floor_area=self.used_floor_area,
            interior_objects=MeshObject.convert_to_meshes(loaded_objects),
            materials=all_cc_materials,
            amount_of_extrusions=self.amount_of_extrusions,
            fac_from_square_room=self.fac_from_square_room,
            corridor_width=self.corridor_width,
            wall_height=self.wall_height,
            amount_of_floor_cuts=self.amount_of_floor_cuts,
            only_use_big_edges=self.only_use_big_edges,
            create_ceiling=self.create_ceiling,
            assign_material_to_ceiling=self.assign_material_to_ceiling,
            placement_tries_per_face=self.tries_per_face,
            amount_of_objects_per_sq_meter=self.amount_of_objects_per_sq_meter)