def __create_backdrop(self, preview_template_dir): # Define the background plane plane = asr.MeshObjectReader.read( [], "plane_obj", { 'filename': os.path.join(preview_template_dir, 'material_preview_ground.binarymesh') }) plane_inst = asr.ObjectInstance( "plane", {}, "plane_obj.part_0", asr.Transformd(asr.Matrix4d.identity()), {'default': "plane_mat"}) plane_mat = asr.Material("generic_material", "plane_mat", { 'bsdf': "plane_bsdf", 'surface_shader': "base_shader" }) plane_bsdf = asr.BSDF("lambertian_brdf", "plane_bsdf", {'reflectance': "plane_tex"}) plane_tex = asr.Texture( "disk_texture_2d", "plane_tex_tex", { 'filename': os.path.join(preview_template_dir, "checker_texture.png"), 'color_space': 'srgb' }, []) plane_tex_inst = asr.TextureInstance( "plane_tex", {}, "plane_tex_tex", asr.Transformf(asr.Matrix4f.identity())) return plane, plane_bsdf, plane_inst, plane_mat, plane_tex, plane_tex_inst
def __thin_lens_camera_params(self, scene, aspect_ratio, film_width, film_height): camera = self.bl_camera if camera.data.dof_object is not None: cam_target = bpy.data.objects[camera.data.dof_object.name] focal_distance = (cam_target.location - self.bl_camera.location).magnitude else: focal_distance = camera.data.dof_distance cam_params = self.__pinhole_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': focal_distance}) if camera.data.appleseed.enable_autofocus: x, y = find_auto_focus_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
def create_entities(self, bl_scene): logger.debug("Creating entity for %s", self.appleseed_name) tex_params = self.__get_tex_params() self.__as_tex = asr.Texture('disk_texture_2d', self.appleseed_name, tex_params, []) tex_inst_params = self.__get_tex_inst_params() self.__as_tex_inst = asr.TextureInstance( f"{self.appleseed_name}_inst", tex_inst_params, self.appleseed_name, asr.Transformf(asr.Matrix4f.identity()))
def create_entities(self, depsgraph): logger.debug( f"appleseed: Creating texture entity for {self.orig_name}") self.__as_tex_params = self.__get_tex_params() self.__as_tex = asr.Texture('disk_texture_2d', self.orig_name, self.__as_tex_params, []) self.__as_tex_inst_params = self.__get_tex_inst_params() self.__as_tex_inst = asr.TextureInstance( f"{self.orig_name}_inst", self.__as_tex_inst_params, self.obj_name, asr.Transformf(asr.Matrix4f.identity()))
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", { 'addressing_mode': 'wrap', 'filtering_mode': 'bilinear' }, lamp.name + "_radiance_mult_tex", asr.Transformf(asr.Matrix4f.identity()))
def create_entities(self, scene): logger.debug("Creating mesh entities for object %s", self.bl_obj.name) # Copy the transform. self._xform_seq.set_transform(0.0, self._convert_matrix(self.bl_obj.matrix_world)) # 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: mat_key = str(ObjectKey(m.material)) + "_mat" self.__front_materials["slot-%s" % i] = mat_key else: self.__front_materials["slot-%s" % i] = "__default_material" else: if len(material_slots) == 1: if material_slots[0].material.appleseed.osl_node_tree is not None: mat_key = str(ObjectKey(material_slots[0].material)) + "_mat" self.__front_materials["default"] = mat_key else: self.__front_materials["default"] = "__default_material" else: logger.debug("Mesh %s has no materials, assigning default material instead", mesh_name) self.__front_materials["default"] = "__default_material" double_sided_materials = False if self.bl_obj.appleseed.double_sided is False else True if double_sided_materials: self.__back_materials = self.__front_materials
def create_entities(self, scene): as_sky = self.bl_scene.world.appleseed_sky env_type = as_sky.env_type if env_type == 'sunsky': env_type = as_sky.sun_model if env_type == 'constant': self.__colors.append( asr.ColorEntity( 'horizon_radiance_color', {'color_space': 'linear_rgb'}, self._convert_color(self.bl_scene.world.horizon_color))) elif env_type in ('gradient', 'constant_hemisphere'): self.__colors.append( asr.ColorEntity( 'horizon_radiance_color', {'color_space': 'srgb'}, self._convert_color(self.bl_scene.world.horizon_color))) self.__colors.append( asr.ColorEntity( 'zenith_radiance_color', {'color_space': 'linear_rgb'}, self._convert_color(self.bl_scene.world.zenith_color))) if env_type in ('latlong_map', 'mirrorball_map'): try: filename = self.asset_handler.process_path( as_sky.env_tex.filepath, AssetType.TEXTURE_ASSET) except: logger.warning("No Texture Selected!") filename = "" tex_inst_params = { 'addressing_mode': 'wrap', 'filtering_mode': 'bilinear' } self.__env_tex = asr.Texture( 'disk_texture_2d', 'environment_tex', { 'filename': filename, 'color_space': as_sky.env_tex_colorspace }, []) self.__env_tex_inst = asr.TextureInstance( 'environment_tex_inst', tex_inst_params, 'environment_tex', asr.Transformf(asr.Matrix4f.identity())) if env_type == 'latlong_map': edf_params = { 'radiance': "environment_tex_inst", 'radiance_multiplier': as_sky.env_tex_mult, 'exposure': as_sky.env_exposure } elif env_type == 'mirrorball_map': edf_params = { 'radiance': "environment_tex_inst", 'exposure': as_sky.env_exposure, 'radiance_multiplier': as_sky.env_tex_mult } elif env_type == 'constant': edf_params = {'radiance': 'horizon_radiance_color'} elif env_type == 'gradient': edf_params = { 'horizon_radiance': "horizon_radiance_color", 'zenith_radiance': "zenith_radiance_color" } elif env_type == 'constant_hemisphere': edf_params = { 'lower_hemi_radiance': "horizon_radiance_color", 'upper_hemi_radiance': "zenith_radiance_color" } else: edf_params = { 'ground_albedo': as_sky.ground_albedo, 'sun_phi': as_sky.sun_phi, 'sun_theta': as_sky.sun_theta, 'turbidity': as_sky.turbidity, 'turbidity_multiplier': as_sky.turbidity_multiplier, 'luminance_multiplier': as_sky.luminance_multiplier, 'luminance_gamma': as_sky.luminance_gamma, 'saturation_multiplier': as_sky.saturation_multiplier, 'horizon_shift': as_sky.horizon_shift } self.__as_env_edf = asr.EnvironmentEDF(env_type + "_environment_edf", "sky_edf", edf_params) self.__as_env_shader = asr.EnvironmentShader( "edf_environment_shader", "sky_shader", { 'environment_edf': 'sky_edf', 'alpha_value': as_sky.env_alpha }) self.__as_env = asr.Environment("sky", { "environment_edf": "sky_edf", "environment_shader": "sky_shader" }) self.__as_env_edf.transform_sequence().set_transform( 0.0, asr.Transformd(self._convert_matrix(asr.Matrix4d.identity())))