Esempio n. 1
0
    def create_entities(self, scene):
        self.__mat_name = self.appleseed_name + "_mat" if not self.__preview else "preview_mat"
        as_mat_data = self.bl_mat.appleseed
        osl_params = {
            'surface_shader': "{0}_surface_shader".format(self.__mat_name)
        }
        shader_params = {
            'lighting_samples': as_mat_data.shader_lighting_samples
        } if hasattr(as_mat_data, "shader_lighting_samples") else {}

        self.__surface_name = "{0}_surface_shader".format(self.__mat_name)
        self.__as_shader = asr.SurfaceShader("physical_surface_shader",
                                             self.__surface_name,
                                             shader_params)
        if self.bl_node_tree:
            shadergroup_name = self.bl_node_tree.name if not self.__preview else "preview_mat_tree"
            osl_params['osl_surface'] = shadergroup_name

            if self.__shader_group is None:
                self.__shader_group = asr.ShaderGroup(shadergroup_name)

            self.__set_shader_group_parameters(scene)

        self.__as_mat = asr.Material('osl_material', self.__mat_name,
                                     osl_params)
Esempio n. 2
0
    def create_entities(self, depsgraph, engine=None):
        logger.debug(f"appleseed: Creating node tree entitiy for {self.__mat_name} node tree")

        tree_name = f"{self.__mat_name}_tree"

        self.__as_shader_group = asr.ShaderGroup(tree_name)

        self.__create_shadergroup(depsgraph.scene_eval, engine)
Esempio n. 3
0
    def create_entities(self, depsgraph, deforms_length):
        logger.debug(f"appleseed: Creating lamp entity for {self.orig_name}")
        as_lamp_data = self.bl_lamp.data.appleseed

        self.__lamp_model = self.__get_lamp_model()

        if self.bl_lamp.data.type != 'AREA':
            self.__radiance = self._convert_color(as_lamp_data.radiance)
            lamp_radiance_name = f"{self.orig_name}_radiance"

            self.__as_lamp_radiance = asr.ColorEntity(
                lamp_radiance_name, {'color_space': 'linear_rgb'},
                self.__radiance)

            if self.__lamp_model == 'point_light':
                self.__as_lamp_params = self.__get_point_lamp_params()
            if self.__lamp_model == 'spot_light':
                self.__as_lamp_params = self.__get_spot_lamp_params()
            if self.__lamp_model == 'directional_light':
                self.__as_lamp_params = self.__get_directional_lamp_params()
            if self.__lamp_model == 'sun_light':
                self.__as_lamp_params = self.__get_sun_lamp_params()

            self.__as_lamp = asr.Light(self.__lamp_model, self.orig_name,
                                       self.__as_lamp_params)

        else:
            shape_params = self._get_area_mesh_params()
            mesh_name = f"{self.orig_name}_mesh"

            self.__as_area_lamp_mesh = asr.create_primitive_mesh(
                mesh_name, shape_params)

            mat_name = f"{self.orig_name}_mat"

            shader_name = f"{self.orig_name}_tree"

            self.__instance_params = self._get_area_mesh_instance_params()

            if not self.bl_lamp.data.use_nodes:
                shader_name = f"{self.orig_name}_tree"

                self.__as_area_lamp_shadergroup = asr.ShaderGroup(shader_name)
                self._set_shadergroup()
            else:
                self.__node_tree = NodeTreeTranslator(
                    self.bl_lamp.data.node_tree, self._asset_handler,
                    self.orig_name)
                self.__node_tree.create_entities(depsgraph.scene_eval)

            self.__as_area_lamp_material = asr.Material(
                'osl_material', mat_name, {'osl_surface': shader_name})
Esempio n. 4
0
    def create_entities(self, scene):
        mat_name = self.appleseed_name + "_mat" if not self.__preview else "preview_mat"
        as_mat_data = self.bl_mat.appleseed

        shader_params = {'lighting_samples': as_mat_data.shader_lighting_samples} if hasattr(as_mat_data, "shader_lighting_samples") else {}
        surface_name = "{0}_surface_shader".format(mat_name)
        self.__as_shader = asr.SurfaceShader("physical_surface_shader",
                                             surface_name, shader_params)

        if as_mat_data.mode == 'surface':
            mat_params = {'surface_shader': "{0}_surface_shader".format(mat_name)}
            if self.bl_node_tree:
                shadergroup_name = self.bl_node_tree.name if not self.__preview else "preview_mat_tree"
                mat_params['osl_surface'] = shadergroup_name

                if self.__shader_group is None:
                    self.__shader_group = asr.ShaderGroup(shadergroup_name)

                self.__set_shader_group_parameters(scene)

            self.__as_mat = asr.Material('osl_material', mat_name, mat_params)

        else:
            vol_name = mat_name + "_volume"

            self.__colors.append(asr.ColorEntity(vol_name + "_absorption_color", {'color_space': 'linear_rgb'},
                                                 self._convert_color(as_mat_data.volume_absorption)))
            self.__colors.append(asr.ColorEntity(vol_name + "_scattering_color", {'color_space': 'linear_rgb'},
                                                 self._convert_color(as_mat_data.volume_scattering)))

            vol_params = {'absorption': vol_name + "_absorption_color",
                          'scattering': vol_name + "_scattering_color",
                          'absorption_multiplier': as_mat_data.volume_absorption_multiplier,
                          'scattering_multiplier': as_mat_data.volume_scattering_multiplier,
                          'phase_function_model': as_mat_data.volume_phase_function_model,
                          'average_cosine': as_mat_data.volume_average_cosine}

            self.__volume = asr.Volume('generic_volume', vol_name, vol_params)

            mat_params = {'surface_shader': "{0}_surface_shader".format(mat_name),
                          'volume': vol_name}

            self.__as_mat = asr.Material('generic_material', mat_name, mat_params)
Esempio n. 5
0
    def __create_material(self, as_lamp_data, lamp_data):
        shader_name = self.bl_lamp.name + "_tree"
        if self.__lamp_shader_group is None:
            self.__lamp_shader_group = asr.ShaderGroup(shader_name)
        lamp_params = {'in_color': "color {0}".format(" ".join(map(str, as_lamp_data.area_color))),
                       'in_intensity': "float {0}".format(as_lamp_data.area_intensity),
                       'in_intensity_scale': "float {0}".format(as_lamp_data.area_intensity_scale),
                       'in_exposure': "float {0}".format(as_lamp_data.area_exposure),
                       'in_normalize': "int {0}".format(as_lamp_data.area_normalize)}
        self.__lamp_shader_group.clear()

        shader_dir_path = self.__find_shader_dir()
        shader_path = self.asset_handler.process_path(os.path.join(shader_dir_path, "as_blender_areaLight.oso"), AssetType.SHADER_ASSET)
        surface_path = self.asset_handler.process_path(os.path.join(shader_dir_path, "as_closure2surface.oso"), AssetType.SHADER_ASSET)

        self.__lamp_shader_group.add_shader("shader", shader_path, "asAreaLight", lamp_params)
        self.__lamp_shader_group.add_shader("surface", surface_path, "asClosure2Surface", {})
        self.__lamp_shader_group.add_connection("asAreaLight", "out_output", "asClosure2Surface", "in_input")
        # Emit are lamp material and surface shader.
        self.__edf_mat = asr.Material('osl_material', lamp_data.name + "_mat", {'osl_surface': shader_name})
Esempio n. 6
0
    def update_lamp(self, depsgraph, as_main_assembly, as_scene, as_project):
        logger.debug(f"appleseed: Updating lamp entity for {self.orig_name}")
        as_lamp_data = self.bl_lamp.data.appleseed

        current_model = self.__lamp_model

        self.__lamp_model = self.__get_lamp_model()

        if current_model == self.__lamp_model:
            if self.__lamp_model != 'area_lamp':
                # Check if the radiance has changed.
                current_radiance = self.__radiance
                self.__radiance = self._convert_color(as_lamp_data.radiance)

                if current_radiance != self.__radiance:
                    as_main_assembly.colors().remove(self.__as_lamp_radiance)

                    lamp_radiance_name = f"{self.orig_name}_radiance"

                    self.__as_lamp_radiance = asr.ColorEntity(
                        lamp_radiance_name, {'color_space': 'linear_rgb'},
                        self.__radiance)

                    as_main_assembly.colors().insert(self.__as_lamp_radiance)
                    self.__as_lamp_radiance = as_main_assembly.colors(
                    ).get_by_name(lamp_radiance_name)

                # Update lamp parameters.
                if self.__lamp_model == 'point_light':
                    self.__as_lamp_params = self.__get_point_lamp_params()
                if self.__lamp_model == 'spot_light':
                    self.__as_lamp_params = self.__get_spot_lamp_params()
                if self.__lamp_model == 'directional_light':
                    self.__as_lamp_params = self.__get_directional_lamp_params(
                    )
                if self.__lamp_model == 'sun_light':
                    self.__as_lamp_params = self.__get_sun_lamp_params()

                self.__as_lamp.set_parameters(self.__as_lamp_params)
            else:
                self.__ass.object_instances().remove(self.__as_area_lamp_inst)
                self.__ass.objects().remove(self.__as_area_lamp_mesh)

                shape_params = self._get_area_mesh_params()
                mesh_name = f"{self.orig_name}_mesh"
                mat_name = f"{self.orig_name}_mat"

                self.__as_area_lamp_mesh = asr.create_primitive_mesh(
                    mesh_name, shape_params)

                self.__instance_params = self._get_area_mesh_instance_params()

                self.__as_area_lamp_inst = asr.ObjectInstance(
                    self.__as_area_lamp_inst_name, self.__instance_params,
                    mesh_name, asr.Transformd(asr.Matrix4d().identity()),
                    {"default": mat_name}, {"default": "__null_material"})

                self.__ass.objects().insert(self.__as_area_lamp_mesh)
                self.__as_area_lamp_mesh = self.__ass.objects().get_by_name(
                    mesh_name)

                self.__ass.object_instances().insert(self.__as_area_lamp_inst)
                self.__as_area_lamp_inst = self.__ass.object_instances(
                ).get_by_name(self.__as_area_lamp_inst_name)

                if self.bl_lamp.data.use_nodes:
                    if self.__as_area_lamp_shadergroup is not None:
                        as_main_assembly.shader_groups().remove(
                            self.__as_area_lamp_shadergroup)
                        self.__as_area_lamp_shadergroup = None
                        self.__node_tree = NodeTreeTranslator(
                            self.bl_lamp.data.node_tree, self._asset_handler,
                            self.orig_name)
                        self.__node_tree.create_entities(depsgraph.scene_eval)
                    else:
                        self.__node_tree.update_nodetree(depsgraph.scene_eval)
                else:
                    if self.__node_tree is not None:
                        self.__node_tree.delete_nodetree(as_main_assembly)
                        self.__node_tree = None

                        shader_name = f"{self.orig_name}_tree"

                        self.__as_area_lamp_shadergroup = asr.ShaderGroup(
                            shader_name)
                        self._set_shadergroup()
                    else:
                        self._set_shadergroup()

        else:
            # Delete current light.
            if current_model != 'area_lamp':
                self.__ass.lights().remove(self.__as_lamp)

                as_main_assembly.colors().remove(self.__as_lamp_radiance)
            else:
                self.__ass.objects().remove(self.__as_area_lamp_mesh)
                self.__ass.object_instances().remove(self.__as_area_lamp_inst)
                as_main_assembly.materials().remove(
                    self.__as_area_lamp_material)

                if self.__as_area_lamp_shadergroup is not None:
                    as_main_assembly.shader_groups().remove(
                        self.__as_area_lamp_shadergroup)
                    self.__as_area_lamp_shadergroup = None
                else:
                    self.__node_tree.delete_nodetree(as_main_assembly)

            # Create new light.
            self.create_entities(depsgraph, 0)

            if self.__lamp_model != 'area_lamp':
                radiance_name = self.__as_lamp_radiance.get_name()
                as_main_assembly.colors().insert(self.__as_lamp_radiance)
                self.__as_lamp_radiance = as_main_assembly.colors(
                ).get_by_name(radiance_name)

                self.__ass.lights().insert(self.__as_lamp)
                self.__as_lamp = self.__ass.lights().get_by_name(
                    self.orig_name)
            else:
                mat_name = f"{self.orig_name}_mat"

                mesh_name = f"{self.orig_name}_mesh"

                self.__as_area_lamp_inst_name = f"{self.orig_name}_inst"

                as_main_assembly.materials().insert(
                    self.__as_area_lamp_material)
                self.__as_area_lamp_material = as_main_assembly.materials(
                ).get_by_name(mat_name)

                if self.__as_area_lamp_shadergroup is not None:
                    shadergroup_name = self.__as_area_lamp_shadergroup.get_name(
                    )
                    as_main_assembly.shader_groups().insert(
                        self.__as_area_lamp_shadergroup)
                    self.__as_area_lamp_shadergroup = as_main_assembly.shader_groups(
                    ).get_by_name(shadergroup_name)
                else:
                    self.__node_tree.flush_entities(as_scene, as_main_assembly,
                                                    as_project)

                self.__as_area_lamp_inst = asr.ObjectInstance(
                    self.__as_area_lamp_inst_name, self.__instance_params,
                    mesh_name, asr.Transformd(asr.Matrix4d().identity()),
                    {"default": mat_name}, {"default": "__null_material"})

                self.__ass.objects().insert(self.__as_area_lamp_mesh)
                self.__as_area_lamp_mesh = self.__ass.objects().get_by_name(
                    mesh_name)

                self.__ass.object_instances().insert(self.__as_area_lamp_inst)
                self.__as_area_lamp_inst = self.__ass.object_instances(
                ).get_by_name(self.__as_area_lamp_inst_name)
Esempio n. 7
0
    def create_entities(self, bl_scene):
        tree_name = f"{self.__mat_name}_tree"

        self.__as_shader_group = asr.ShaderGroup(tree_name)

        self.__create_shadergroup(bl_scene)