コード例 #1
0
    def run(self):
        """ Returns the result of processing of the list of values. """
        transform_by = self.config.get_string("transform_by")
        elements = self.config.get_list("elements")

        raw_result = []
        for element in elements:
            element_conf = Config({"element": element})
            if isinstance(element, list):
                raw_result.append(element_conf.get_vector3d("element"))
            else:
                raw_result.append(element_conf.get_raw_value("element"))

        if len(raw_result) > 0:
            if self._check_compatibility(raw_result):
                if transform_by == "sum":
                    ref_result = self._sum(raw_result)
                elif transform_by == "avg":
                    ref_result = self._avg(raw_result)
                else:
                    raise RuntimeError("Unknown 'transform_by' operation: " +
                                       transform_by)
            else:
                raise RuntimeError(
                    "Provider output types don't match. All must either int, float, or mathutils.Vector."
                )
        else:
            raise RuntimeError(
                "List of resulting values of `elements` is empty. Please, check Provider configuration."
            )

        return ref_result
コード例 #2
0
    def _get_the_set_params(self, params_conf: Config) -> dict:
        """ Extracts actual values to set from a Config object.

        :param params_conf: Object with all user-defined data.
        :return: Parameters to set as {name of the parameter: it's value} pairs.
        """
        params = {}
        for key in params_conf.data.keys():
            result = None
            if key == "cf_color_link_to_displacement":
                result = params_conf.get_float(key)
            elif key == "cf_change_to_vertex_color":
                result = params_conf.get_string(key)
            elif key == "cf_textures":
                result = {}
                paths_conf = Config(params_conf.get_raw_dict(key))
                for text_key in paths_conf.data.keys():
                    text_path = paths_conf.get_string(text_key)
                    result.update({text_key: text_path})
            elif key == "cf_switch_to_emission_shader":
                result = {}
                emission_conf = Config(params_conf.get_raw_dict(key))
                for emission_key in emission_conf.data.keys():
                    if emission_key == "color":
                        attr_val = emission_conf.get_list(
                            "color", [1, 1, 1, 1])
                    elif emission_key == "strength":
                        attr_val = emission_conf.get_float("strength", 1.0)
                    result.update({emission_key: attr_val})
            elif key == "cf_infuse_texture":
                result = Config(params_conf.get_raw_dict(key))
            elif key == "cf_infuse_material":
                result = Config(params_conf.get_raw_dict(key))
            elif key == "cf_add_dust":
                result = params_conf.get_raw_dict(key)
            elif "cf_set_" in key or "cf_add_" in key:
                result = params_conf.get_raw_value(key)
            else:
                result = params_conf.get_raw_value(key)

            params.update({key: result})

        return params
コード例 #3
0
    def _get_the_set_params(self, params_conf: Config):
        """ Extracts actual values to set from a Config object.

        :param params_conf: Object with all user-defined data. Type: Config.
        :return: Parameters to set as {name of the parameter: it's value} pairs. Type: dict.
        """
        params = {}
        for key in params_conf.data.keys():
            if key == "cf_add_modifier":
                modifier_config = Config(params_conf.get_raw_dict(key))
                # instruction about unpacking the data: key, corresponding Config method to extract the value,
                # it's default value and a postproc function
                instructions = {
                    "name": (Config.get_string, None, str.upper),
                    "thickness": (Config.get_float, None, None)
                }
                # unpack
                result = self._unpack_params(modifier_config, instructions)
            elif key == "cf_set_shading":
                result = {
                    "shading_mode":
                    params_conf.get_string("cf_set_shading"),
                    "angle_value":
                    params_conf.get_float(
                        "cf_shading_auto_smooth_angle_in_deg", 30)
                }
            elif key == "cf_add_displace_modifier_with_texture":
                displace_config = Config(params_conf.get_raw_dict(key))
                # instruction about unpacking the data: key, corresponding Config method to extract the value,
                # it's default value and a postproc function
                instructions = {
                    "texture": (Config.get_raw_value, [], None),
                    "mid_level": (Config.get_float, 0.5, None),
                    "subdiv_level": (Config.get_int, 2, None),
                    "strength": (Config.get_float, 0.1, None),
                    "min_vertices_for_subdiv": (Config.get_int, 10000, None)
                }
                # unpack
                result = self._unpack_params(displace_config, instructions)
            elif key == "cf_add_uv_mapping":
                uv_config = Config(params_conf.get_raw_dict(key))
                # instruction about unpacking the data: key, corresponding Config method to extract the value,
                # it's default value and a postproc function
                instructions = {
                    "projection": (Config.get_string, None, str.lower),
                    "forced_recalc_of_uv_maps": (Config.get_bool, False, None)
                }
                # unpack
                result = self._unpack_params(uv_config, instructions)
            elif key == "cf_randomize_materials":
                rand_config = Config(params_conf.get_raw_dict(key))
                # instruction about unpacking the data: key, corresponding Config method to extract the value,
                # it's default value and a postproc function
                instructions = {
                    "randomization_level": (Config.get_float, 0.2, None),
                    "add_to_objects_without_material":
                    (Config.get_bool, False, None),
                    "materials_to_replace_with":
                    (Config.get_list, BlenderUtility.get_all_materials(),
                     None),
                    "obj_materials_cond_to_be_replaced":
                    (Config.get_raw_dict, {}, None)
                }
                result = self._unpack_params(rand_config, instructions)
                result["material_to_replace_with"] = choice(
                    result["materials_to_replace_with"])
            else:
                result = params_conf.get_raw_value(key)

            params.update({key: result})

        return params