How to use the translators.assethandlers.AssetType.TEXTURE_ASSET function in translators

To help you get started, we’ve selected a few translators examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github appleseedhq / blenderseed / translators / assethandlers.py View on Github external
def process_path(self, filename, asset_type, sub_texture=False):
        archive_asset = bpy.path.abspath(filename)

        if '%' in archive_asset:
            archive_asset = self._convert_frame_number(archive_asset)

        if asset_type == AssetType.SHADER_ASSET:
            dir_name, file_name = os.path.split(archive_asset)
            self._searchpaths.append(dir_name)
            archive_asset = os.path.splitext(file_name)[0]

        if asset_type == AssetType.TEXTURE_ASSET and sub_texture:
            base_filename = os.path.splitext(archive_asset)[0]
            archive_asset = f"{base_filename}.tx"

        if asset_type == AssetType.ARCHIVE_ASSET:
            archive_dir, archive = os.path.split(archive_asset)
            self._searchpaths.append(archive_dir)
            archive_asset = archive

        return archive_asset
github appleseedhq / blenderseed / translators / materials.py View on Github external
def __parse_parameters(self, parameter_types, parameters, scene, shader, shader_keys):
        for key in parameter_types:
            if key in shader_keys:
                parameter_value = parameter_types[key]
                parameter = getattr(shader, key)
                if key in shader.filepaths:
                    sub_texture = scene.appleseed.sub_textures
                    parameter = self.asset_handler.process_path(parameter.filepath, AssetType.TEXTURE_ASSET, sub_texture)

                if parameter_value == "int checkbox":
                    parameter_value = "int"
                    parameter = int(parameter)
                if parameter_value in ('color', 'vector', 'normal', 'float[2]'):
                    parameter = " ".join(map(str, parameter))
                if parameter_value == 'float[2]':
                    parameter_value = 'float[]'
                parameters[key] = parameter_value + " " + str(parameter)
github appleseedhq / blenderseed / translators / camera.py View on Github external
camera = self.bl_camera

        cam_params = self.__basic_camera_params(scene, aspect_ratio, film_width, film_height)
        cam_params.update({'f_stop': camera.data.appleseed.f_number,
                           'autofocus_enabled': False,
                           'diaphragm_blades': camera.data.appleseed.diaphragm_blades,
                           'diaphragm_tilt_angle': camera.data.appleseed.diaphragm_angle,
                           'focal_distance': util.get_focal_distance(camera)})

        if camera.data.appleseed.enable_autofocus:
            x, y = util.find_autofocus_point(scene)
            cam_params['autofocus_target'] = asr.Vector2f(x, y)
            cam_params['autofocus_enabled'] = True

        if camera.data.appleseed.diaphragm_map != "":
            filename = self.asset_handler.process_path(camera.data.appleseed.diaphragm_map, AssetType.TEXTURE_ASSET)
            self.__cam_map = asr.Texture('disk_texture_2d', 'cam_map',
                                         {'filename': filename, 'color_space': camera.data.appleseed.diaphragm_map_colorspace}, [])
            self.__cam_map_inst = asr.TextureInstance("cam_map_inst", {'addressing_mode': 'wrap',
                                                                       'filtering_mode': 'bilinear'},
                                                      "cam_map", asr.Transformf(asr.Matrix4f.identity()))

            cam_params['diaphragm_map'] = 'cam_map_inst'
            del cam_params['diaphragm_blades']

        return cam_params
github appleseedhq / blenderseed / translators / textures.py View on Github external
def __get_tex_params(self):
        as_tex_params = self.bl_tex.appleseed
        filepath = self._asset_handler.process_path(self.bl_tex.filepath, AssetType.TEXTURE_ASSET)
        tex_params = {'filename': filepath, 'color_space': as_tex_params.as_color_space}

        return tex_params
github appleseedhq / blenderseed / translators / lamps.py View on Github external
light_params['tilt_angle'] = as_lamp_data.tilt_angle
        light_params['inner_angle'] = inner_angle
        light_params['outer_angle'] = outer_angle
        if as_lamp_data.radiance_use_tex and as_lamp_data.radiance_tex != "":
            tex_path = self.asset_handler.process_path(as_lamp_data.radiance_tex, AssetType.TEXTURE_ASSET)
            light_params['intensity'] = lamp.name + "_radiance_tex_inst"
            self.__radiance_tex = asr.Texture('disk_texture_2d', lamp.name + "_radiance_tex",
                                              {'filename': tex_path,
                                               'color_space': as_lamp_data.radiance_tex_color_space}, [])
            self.__radiance_tex_inst = asr.TextureInstance(lamp.name + "_radiance_tex_inst",
                                                           {'addressing_mode': 'wrap',
                                                            'filtering_mode': 'bilinear'},
                                                           lamp.name + "_radiance_tex",
                                                           asr.Transformf(asr.Matrix4f.identity()))
        if as_lamp_data.radiance_multiplier_use_tex and as_lamp_data.radiance_multiplier_tex != "":
            tex_path = self.asset_handler.process_path(as_lamp_data.radiance_multiplier_tex, AssetType.TEXTURE_ASSET)
            light_params['intensity_multiplier'] = lamp.name + "_radiance_mult_tex_inst"
            self.__radiance_mult_tex = asr.Texture('disk_texture_2d', lamp.name + "_radiance_mult_tex",
                                                   {'filename': tex_path,
                                                    'color_space': as_lamp_data.radiance_multiplier_tex_color_space}, [])
            self.__radiance_mult_tex_inst = asr.TextureInstance(lamp.name + "_radiance_mult_tex_inst",
                                                                {'addressing_mode': 'wrap',
                                                                 'filtering_mode': 'bilinear'},
                                                                lamp.name + "_radiance_mult_tex",
                                                                asr.Transformf(asr.Matrix4f.identity()))
github appleseedhq / blenderseed / translators / nodetree.py View on Github external
if isinstance(node, AppleseedOSLNode):  # appleseed nodes
                parameters = dict()
                parameter_types = node.parameter_types

                node_items = node.keys()

                for key in node_items:
                    if key in parameter_types:
                        parameter_value = getattr(node, key)
                        parameter_type = parameter_types[key]

                        if key in node.filepaths:
                            sub_texture = bl_scene.appleseed.sub_textures
                            parameter_value = self._asset_handler.process_path(
                                parameter_value.filepath,
                                AssetType.TEXTURE_ASSET, sub_texture)

                        if parameter_type == "int checkbox":
                            parameter_type = "int"
                            parameter_value = int(parameter_value)
                        elif parameter_type in ('color', 'vector', 'normal', 'point', 'float[2]'):
                            parameter_value = " ".join(map(str, parameter_value))
                            if parameter_type == 'float[2]':
                                parameter_type = 'float[]'

                        parameters[key] = parameter_type + " " + str(parameter_value)
                
                if node.node_type == 'osl':
                    shader_file_name = self._asset_handler.process_path(node.file_name, AssetType.SHADER_ASSET)
                    logger.debug(f"appleseed: Adding {node.name} shader to {self.__mat_name} node tree")
                    self.__as_shader_group.add_shader("shader", shader_file_name, node.name, parameters)
                elif node.node_type == 'osl_script':
github appleseedhq / blenderseed / translators / lamps.py View on Github external
def __create_spot_lamp(self, as_lamp_data, lamp, light_params):
        outer_angle = math.degrees(lamp.data.spot_size)
        inner_angle = (1.0 - lamp.data.spot_blend) * outer_angle
        light_params['exposure_multiplier'] = as_lamp_data.exposure_multiplier
        light_params['tilt_angle'] = as_lamp_data.tilt_angle
        light_params['inner_angle'] = inner_angle
        light_params['outer_angle'] = outer_angle
        if as_lamp_data.radiance_use_tex and as_lamp_data.radiance_tex != "":
            tex_path = self.asset_handler.process_path(as_lamp_data.radiance_tex, AssetType.TEXTURE_ASSET)
            light_params['intensity'] = lamp.name + "_radiance_tex_inst"
            self.__radiance_tex = asr.Texture('disk_texture_2d', lamp.name + "_radiance_tex",
                                              {'filename': tex_path,
                                               'color_space': as_lamp_data.radiance_tex_color_space}, [])
            self.__radiance_tex_inst = asr.TextureInstance(lamp.name + "_radiance_tex_inst",
                                                           {'addressing_mode': 'wrap',
                                                            'filtering_mode': 'bilinear'},
                                                           lamp.name + "_radiance_tex",
                                                           asr.Transformf(asr.Matrix4f.identity()))
        if as_lamp_data.radiance_multiplier_use_tex and as_lamp_data.radiance_multiplier_tex != "":
            tex_path = self.asset_handler.process_path(as_lamp_data.radiance_multiplier_tex, AssetType.TEXTURE_ASSET)
            light_params['intensity_multiplier'] = lamp.name + "_radiance_mult_tex_inst"
            self.__radiance_mult_tex = asr.Texture('disk_texture_2d', lamp.name + "_radiance_mult_tex",
                                                   {'filename': tex_path,
                                                    'color_space': as_lamp_data.radiance_multiplier_tex_color_space}, [])
            self.__radiance_mult_tex_inst = asr.TextureInstance(lamp.name + "_radiance_mult_tex_inst",
github appleseedhq / blenderseed / translators / mesh.py View on Github external
def create_entities(self, scene):
        logger.debug("Creating mesh entities for object %s", self.bl_obj.name)

        # Materials
        mesh_key = str(ObjectKey(self.bl_obj.data)) + "_obj"
        mesh_name = mesh_key

        asr_obj_props = self.bl_obj.appleseed

        self.__obj_params = {'alpha_map': asr_obj_props.object_alpha}
        if self.bl_obj.appleseed.object_alpha_texture is not None:
            filename = self.asset_handler.process_path(asr_obj_props.object_alpha_texture.filepath, AssetType.TEXTURE_ASSET)
            tex_inst_params = {'addressing_mode': asr_obj_props.object_alpha_texture_wrap_mode,
                               'filtering_mode': 'bilinear',
                               'alpha_mode': asr_obj_props.object_alpha_mode}
            self.__alpha_tex = asr.Texture('disk_texture_2d', mesh_name + "_tex",
                                           {'filename': filename,
                                            'color_space': asr_obj_props.object_alpha_texture_colorspace}, [])
            self.__alpha_tex_inst = asr.TextureInstance(mesh_name + "_tex_inst", tex_inst_params, mesh_name + "_tex",
                                                        asr.Transformf(asr.Matrix4f.identity()))

            self.__obj_params['alpha_map'] = mesh_name + "_tex_inst"

        material_slots = self.bl_obj.material_slots

        if len(material_slots) > 1:
            for i, m in enumerate(material_slots):
                if m.material.appleseed.osl_node_tree is not None: