Exemple #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)
Exemple #2
0
    def __create_null_material(self):
        logger.debug("Creating null material")

        material = asr.Material('generic_material',
                                "__null_material",
                                {})
        self.__main_assembly.materials().insert(material)
Exemple #3
0
def process_shape_material(scene, assembly, instance_name, element):
    material = None

    # Material reference.
    ref_element = element.find("ref")
    if ref_element is not None:
        material_name = ref_element.attrib["id"]
        material = assembly.materials().get_by_name(material_name)

    # Embedded material (has priority over the referenced material).
    bsdf_element = element.find("bsdf")
    if bsdf_element is not None:
        material_name = "{0}_material".format(instance_name)
        convert_material(assembly, material_name, {}, bsdf_element)
        material = assembly.materials().get_by_name(material_name)

    # Embedded emitter (we suppose it's an area emitter).
    emitter_element = element.find("emitter")
    if emitter_element is not None:
        edf_name = "{0}_edf".format(instance_name)
        convert_emitter(scene, assembly, edf_name, emitter_element)

        material_params = material.get_parameters()
        material_params["edf"] = edf_name

        # Hack: force light-emitting materials to be single-sided.
        set_private_param(material_params, "two_sided", False)

        material_name = make_unique_name(instance_name + "_material", assembly.materials())
        material = asr.Material("generic_material", material_name, material_params)
        assembly.materials().insert(material)
        material = assembly.materials().get_by_name(material_name)

    return material.get_name() if material is not None else None
Exemple #4
0
 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
Exemple #5
0
    def __create_default_material(self):
        logger.debug("Creating default material")

        surface_shader = asr.SurfaceShader("diagnostic_surface_shader", "__default_surface_shader", {'mode': 'facing_ratio'})
        material = asr.Material('generic_material', "__default_material", {'surface_shader': '__default_surface_shader'})

        self.__main_assembly.surface_shaders().insert(surface_shader)
        self.__main_assembly.materials().insert(material)
    def create_entities(self, bl_scene):
        logger.debug("Creating entity for %s", self.appleseed_name)
        as_mat_data = self.bl_mat.appleseed

        if self.bl_mat.node_tree is not None:
            self.__as_nodetree = NodeTreeTranslator(self.bl_mat.node_tree,
                                                    self.asset_handler,
                                                    self.appleseed_name)
            self.__as_nodetree.create_entities(bl_scene)

        mat_name = f"{self.appleseed_name}_mat"
        surface_name = f"{self.appleseed_name}_surface"

        self.__as_shader_params = self.__get_shader_params()

        self.__as_shader = asr.SurfaceShader("physical_surface_shader",
                                             surface_name, {})

        self.__as_mat_params = self.__get_mat_params()

        if as_mat_data.mode == 'surface':
            self.__as_mat = asr.Material('osl_material', mat_name, {})
        else:
            vol_name = f"{self.appleseed_name}_volume"

            self.__as_volume_params = self.__get_vol_params()

            self.__as_colors.append(
                asr.ColorEntity(
                    f"{vol_name}_absorption_color",
                    {'color_space': 'linear_rgb'},
                    self._convert_color(as_mat_data.volume_absorption)))

            self.__as_colors.append(
                asr.ColorEntity(
                    f"{vol_name}_scattering_color",
                    {'color_space': 'linear_rgb'},
                    self._convert_color(as_mat_data.volume_scattering)))

            self.__as_mat = asr.Material('generic_material', mat_name, {})
            self.__as_volume = asr.Volume('generic_volume', vol_name, {})
            self.__as_volume.set_parameters(self.__as_volume_params)

        self.__as_mat.set_parameters(self.__as_mat_params)
        self.__as_shader.set_parameters(self.__as_shader_params)
Exemple #7
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)
Exemple #8
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})
Exemple #9
0
 def __create_lamp(self, preview_template_dir):
     # Define the single area lamp used for illumination
     lamp = asr.MeshObjectReader.read(self.__project.get_search_paths(), "lamp_obj",
                                      {'filename': os.path.join(preview_template_dir, 'material_preview_lamp.binarymesh')})
     lamp_matrix = asr.Matrix4d([0.8611875772476196, 0.508287250995636, 0.0, 0.0,
                                 -0.508287250995636, 0.8611875772476196, 0.0, 0.0,
                                 0.0, 0.0, 1.0, 0.0,
                                 0.0, 0.0, 0.0, 1.0])
     lamp_inst = asr.ObjectInstance("lamp", {}, "lamp_obj.part_0", asr.Transformd(lamp_matrix),
                                    {'default': "lamp_mat"}, {'default': "lamp_mat"})
     lamp_mat = asr.Material("generic_material", "lamp_mat", {'edf': "lamp_edf", 'surface_shader': "base_shader"})
     lamp_edf = asr.EDF("diffuse_edf", "lamp_edf", {'radiance': 7})
     return lamp, lamp_edf, lamp_inst, lamp_mat
Exemple #10
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})
Exemple #11
0
    def create_entities(self, depsgraph, engine):
        logger.debug(
            f"appleseed: Creating material entity for {self.orig_name}")

        surface_name = f"{self.orig_name}_surface"

        if self.bl_mat.node_tree is not None:
            self.__as_nodetree = NodeTreeTranslator(self.bl_node_tree,
                                                    self._asset_handler,
                                                    self.orig_name)
            self.__as_nodetree.create_entities(depsgraph, engine)

        self.__as_shader_params = self.__get_shader_params()
        self.__as_mat_params = self.__get_mat_params()

        self.__as_shader = asr.SurfaceShader("physical_surface_shader",
                                             surface_name, {})

        self.__as_mat = asr.Material('osl_material', self.orig_name, {})

        self.__as_mat.set_parameters(self.__as_mat_params)
        self.__as_shader.set_parameters(self.__as_shader_params)
Exemple #12
0
def build_project():
    # Create an empty project.
    project = asr.Project("4-point-lights")

    paths = project.get_search_paths()
    paths.append("data")
    project.set_search_paths(paths)

    # Add default configurations to the project.
    project.add_default_configurations()

    # Set the number of samples. This is basically the quality parameter: the higher the number
    # of samples, the smoother the image but the longer the rendering time.
    # todo: fix.
    conf = project.configurations()["final"]
    conf.insert_path("uniform_pixel_renderer.samples", 1)

    # Create a scene.
    scene = asr.Scene()

    # Create an assembly.
    assembly = asr.Assembly("assembly")

    # Prepare the orientation of all the objects in the scene.
    orientation = asr.Matrix4d.make_rotation(asr.Vector3d(1.0, 0.0, 0.0),
                                             math.radians(-90.0))

    #------------------------------------------------------------------------
    # Materials
    #------------------------------------------------------------------------
    # Create a material called "01 - Default_mat" and insert it into the assembly.
    assembly.materials().insert(
        asr.Material(
            "disney_material", "01 - Default_mat", {
                "alpha_map": "1",
                "layer1": {
                    "anisotropic": "0",
                    "base_color": "[1, 1, 1]",
                    "clearcoat": "0",
                    "clearcoat_gloss": "0",
                    "layer_name": "layer1",
                    "layer_number": "0",
                    "mask": "1.0",
                    "metallic": "0",
                    "roughness": "1",
                    "sheen": "0",
                    "sheen_tint": "0",
                    "specular": "0",
                    "specular_tint": "0",
                    "subsurface": "0.0"
                }
            }))

    #------------------------------------------------------------------------
    # Geometry
    #------------------------------------------------------------------------

    # Load the scene geometry from disk.
    objects = asr.MeshObjectReader.read(project.get_search_paths(), "plane",
                                        {"filename": "Plane001.binarymesh"})

    # Insert all the objects into the assembly.
    for object in objects:
        # Create an instance of this object and insert it into the assembly.
        instance_name = object.get_name() + "_inst"
        material_name = {"material_slot_0": "01 - Default_mat"}
        mat = orientation * asr.Matrix4d.make_translation(
            asr.Vector3d(0.0, 0.0, 0.0))
        instance = asr.ObjectInstance(
            instance_name, {
                "visibility": {
                    "camera": "true",
                    "diffuse": "true",
                    "glossy": "true",
                    "light": "true",
                    "probe": "true",
                    "shadow": "true",
                    "specular": "true",
                    "subsurface": "true",
                    "transparency": "true"
                }
            }, object.get_name(), asr.Transformd(mat), material_name,
            material_name)

        assembly.object_instances().insert(instance)

        # Insert this object into the scene.
        assembly.objects().insert(object)

    #------------------------------------------------------------------------
    # Lights
    #------------------------------------------------------------------------

    # Create a list of colors and for each of them create a light.
    light_colors = {
        "white": [1.0, 1.0, 1.0],
        "red": [1.0, 0.0, 0.0],
        "green": [0.0, 1.0, 0.0],
        "blue": [0.0, 0.0, 1.0]
    }

    light_positions = [
        asr.Vector3d(25.0, -25.0, 5.0),
        asr.Vector3d(-25.0, -25.0, 5.0),
        asr.Vector3d(25.0, 25.0, 5.0),
        asr.Vector3d(-25.0, 25.0, 5.0)
    ]

    for key in light_colors:
        color_name = "color_" + key
        # Add colors to the project.
        assembly.colors().insert(
            asr.ColorEntity(color_name, {
                "color_space": "linear_rgb",
                "multiplier": 1.0
            }, light_colors[key]))
        idx = light_colors.keys().index(key)
        light_name = "light_" + key
        # Create the light.
        light = asr.Light(
            "max_omni_light", light_name, {
                "decay_exponent": "0",
                "decay_start": "40",
                "intensity": color_name,
                "intensity_multiplier": "3.14159"
            })
        mat = orientation * asr.Matrix4d.make_translation(light_positions[idx])
        light.set_transform(asr.Transformd(mat))
        assembly.lights().insert(light)

    #------------------------------------------------------------------------
    # Assembly instance
    #------------------------------------------------------------------------

    # Create an instance of the assembly and insert it into the scene.
    assembly_inst = asr.AssemblyInstance("assembly_inst", {},
                                         assembly.get_name())
    assembly_inst.transform_sequence().set_transform(
        0.0, asr.Transformd(asr.Matrix4d.identity()))
    scene.assembly_instances().insert(assembly_inst)

    # Insert the assembly into the scene.
    scene.assemblies().insert(assembly)

    #------------------------------------------------------------------------
    # Environment
    #------------------------------------------------------------------------

    # Create an environment called "env" and bind it to the scene.
    scene.set_environment(asr.Environment("env", {}))

    #------------------------------------------------------------------------
    # Camera
    #------------------------------------------------------------------------

    # Create an orthographic camera with film dimensions 128 x 128 in.
    params = {
        "controller_target": "0 0 0",
        "film_dimensions": "128 128",
        "near_z": "-0.1",
        "shutter_close_time": "1.0",
        "shutter_open_time": "0.0"
    }

    camera = asr.Camera("orthographic_camera", "camera", params)

    # Place and orient the camera. By default cameras are located in (0.0, 0.0, 0.0)
    # and are looking toward Z- (0.0, 0.0, -1.0).
    mat = orientation * asr.Matrix4d.make_translation(
        asr.Vector3d(0.0, 0.0, 0.0))
    camera.transform_sequence().set_transform(0.0, asr.Transformd(mat))

    # Bind the camera to the scene.
    scene.cameras().insert(camera)

    #------------------------------------------------------------------------
    # Frame
    #------------------------------------------------------------------------

    # Create a frame and bind it to the project.
    params = {
        "camera": "camera",
        "clamping": "false",
        "color_space": "srgb",
        "filter": "box",
        "filter_size": "0.5",
        "gamma_correction": "1.0",
        "pixel_format": "float",
        "premultiplied_alpha": "true",
        "resolution": "512 512",
        "tile_size": "64 64"
    }
    project.set_frame(asr.Frame("beauty", params))

    # Bind the scene to the project.
    project.set_scene(scene)

    return project
Exemple #13
0
def build_project():
    # Create an empty project.
    project = asr.Project("grid-point-lights-generator")

    paths = project.get_search_paths()
    paths.append("data")
    project.set_search_paths(paths)

    # Add default configurations to the project.
    project.add_default_configurations()

    # Set the number of samples. This is basically the quality parameter: the higher the number
    # of samples, the smoother the image but the longer the rendering time.
    # todo: fix.
    conf = project.configurations()["final"]
    conf.insert_path("uniform_pixel_renderer.samples", 1)

    # Create a scene.
    scene = asr.Scene()

    # Create an assembly.
    assembly = asr.Assembly("assembly")

    # Prepare the orientation of all the objects in the scene.
    orientation = asr.Matrix4d.make_rotation(asr.Vector3d(1.0, 0.0, 0.0), math.radians(-90.0))

    #------------------------------------------------------------------------
    # COLOR
    #------------------------------------------------------------------------

    assembly.colors().insert(asr.ColorEntity("light_color",
                                             {
                                                 "color_space": "linear_rgb",
                                                 "multiplier": 1.0,
                                                 "wavelength_range": "400.0 700.0"
                                             },
                                             [1.000000, 0.830634, 0.378440]))

    #------------------------------------------------------------------------
    # EDF
    #------------------------------------------------------------------------

    # Create light edfs.
    assembly.edfs().insert(asr.EDF(
        "diffuse_edf",
        "light_material_edf",
        {
            "cast_indirect_light": "true",
            "importance_multiplier": "1.0",
            "light_near_start": "0.0",
            "radiance": "light_color",
            "radiance_multiplier": "9"
        }))

    #------------------------------------------------------------------------
    # Materials
    #------------------------------------------------------------------------
    # Create a material called "01 - Default_mat" and insert it into the assembly.
    assembly.materials().insert(asr.Material(
        "disney_material",
        "01 - Default_mat",
        {
            "alpha_map": "1",
            "layer1": {
                "anisotropic": "0",
                "base_color": "[1, 1, 1]",
                "clearcoat": "0",
                "clearcoat_gloss": "0",
                "layer_name": "layer1",
                "layer_number": "0",
                "mask": "1.0",
                "metallic": "0",
                "roughness": "1",
                "sheen": "0",
                "sheen_tint": "0",
                "specular": "0",
                "specular_tint": "0",
                "subsurface": "0.0"
            }
        }))

    # Create light material.
    assembly.materials().insert(asr.Material(
        "generic_material",
        "light_material",
        {
            "bump_amplitude": "1.0",
            "displacement_method": "bump",
            "edf": "light_material_edf",
            "normal_map_up": "z",
            "shade_alpha_cutouts": "false"
        }))

    #------------------------------------------------------------------------
    # Geometry
    #------------------------------------------------------------------------

    # Load the scene geometry from disk.
    objects = asr.MeshObjectReader.read(project.get_search_paths(), "plane", {"filename": "Plane001.binarymesh"})

    # Insert all the objects into the assembly.
    for object in objects:
        # Create an instance of this object and insert it into the assembly.
        instance_name = object.get_name() + "_inst"
        material_name = {"material_slot_0": "01 - Default_mat"}
        mat = orientation * asr.Matrix4d.make_translation(asr.Vector3d(0.0, 0.0, 0.0))
        instance = asr.ObjectInstance(
            instance_name,
            {"visibility": {}},
            object.get_name(),
            asr.Transformd(mat),
            material_name,
            material_name)

        assembly.object_instances().insert(instance)

        # Insert this object into the scene.
        assembly.objects().insert(object)

    #------------------------------------------------------------------------
    # Lights
    #------------------------------------------------------------------------
    light_z_distance = 1.0

    lights = asr.MeshObjectReader.read(project.get_search_paths(), "rectangle", {"filename": "rectangle.obj"})

    for light in lights:

        if Color == "white":
            step = float(PlaneSize) / GridLightsCount
            light_count = 0
            grid_range = np.linspace((-PlaneSize + step) / 2, (PlaneSize - step) / 2, GridLightsCount)
            for j in grid_range:
                for i in grid_range:
                    # Create an instance of this light and insert it into the assembly.
                    instance_name = light.get_name() + "_inst_" + str(light_count)
                    light_count = light_count + 1
                    material_front = {"material_slot_0": "01 - Default_mat"}
                    material_back = {"material_slot_0": "light_material"}
                    light_position = asr.Vector3d(i, j, light_z_distance)
                    mat = orientation * asr.Matrix4d.make_translation(light_position)
                    instance = asr.ObjectInstance(
                        instance_name,
                        {"visibility":
                         {
                             "camera": "false",
                             "diffuse": "true",
                             "glossy": "true",
                             "light": "true",
                             "probe": "true",
                             "shadow": "true",
                             "specular": "true",
                             "subsurface": "true",
                             "transparency": "true"
                         }},
                        light.get_name(),
                        asr.Transformd(mat),
                        material_front,
                        material_back)

                    assembly.object_instances().insert(instance)
        else:
            print("Unknown Color: {0}".format(Color))
            return

        # Insert this light into the scene.
        assembly.objects().insert(light)

    #------------------------------------------------------------------------
    # Assembly instance
    #------------------------------------------------------------------------

    # Create an instance of the assembly and insert it into the scene.
    assembly_inst = asr.AssemblyInstance("assembly_inst", {}, assembly.get_name())
    assembly_inst.transform_sequence().set_transform(0.0, asr.Transformd(asr.Matrix4d.identity()))
    scene.assembly_instances().insert(assembly_inst)

    # Insert the assembly into the scene.
    scene.assemblies().insert(assembly)

    #------------------------------------------------------------------------
    # Environment
    #------------------------------------------------------------------------

    # Create an environment called "env" and bind it to the scene.
    scene.set_environment(asr.Environment("env", {}))

    #------------------------------------------------------------------------
    # Camera
    #------------------------------------------------------------------------

    # Create an orthographic camera.
    params = {
        "controller_target": "0 0 0",
        "film_dimensions": "128 128",
        "near_z": "-0.1",
        "shutter_close_time": "1.0",
        "shutter_open_time": "0.0"
    }

    camera = asr.Camera("orthographic_camera", "camera", params)

    # Place and orient the camera.
    mat = orientation * asr.Matrix4d.make_translation(asr.Vector3d(0.0, 0.0, 0.0))
    camera.transform_sequence().set_transform(0.0, asr.Transformd(mat))

    # Bind the camera to the scene.
    scene.cameras().insert(camera)

    #------------------------------------------------------------------------
    # Frame
    #------------------------------------------------------------------------

    # Create a frame and bind it to the project.
    params = {
        "camera": "camera",
        "clamping": "false",
        "color_space": "srgb",
        "filter": "box",
        "filter_size": "0.5",
        "gamma_correction": "1.0",
        "pixel_format": "float",
        "premultiplied_alpha": "true",
        "resolution": "512 512",
        "tile_size": "64 64"}
    project.set_frame(asr.Frame("beauty", params))

    # Bind the scene to the project.
    project.set_scene(scene)

    return project
def build_project():
    # Create an empty project.
    project = asr.Project("grid-point-lights-generator")

    paths = project.get_search_paths()
    paths.append("data")
    project.set_search_paths(paths)

    # Add default configurations to the project.
    project.add_default_configurations()

    # Set the number of samples. This is basically the quality parameter: the higher the number
    # of samples, the smoother the image but the longer the rendering time.
    # todo: fix.
    conf = project.configurations()["final"]
    conf.insert_path("uniform_pixel_renderer.samples", 1)

    # Create a scene.
    scene = asr.Scene()

    # Create an assembly.
    assembly = asr.Assembly("assembly")

    # Prepare the orientation of all the objects in the scene.
    orientation = asr.Matrix4d.make_rotation(asr.Vector3d(1.0, 0.0, 0.0),
                                             math.radians(-90.0))

    #------------------------------------------------------------------------
    # Materials
    #------------------------------------------------------------------------
    # Create a material called "01 - Default_mat" and insert it into the assembly.
    assembly.materials().insert(
        asr.Material(
            "disney_material", "01 - Default_mat", {
                "alpha_map": "1",
                "layer1": {
                    "anisotropic": "0",
                    "base_color": "[1, 1, 1]",
                    "clearcoat": "0",
                    "clearcoat_gloss": "0",
                    "layer_name": "layer1",
                    "layer_number": "0",
                    "mask": "1.0",
                    "metallic": "0",
                    "roughness": "1",
                    "sheen": "0",
                    "sheen_tint": "0",
                    "specular": "0",
                    "specular_tint": "0",
                    "subsurface": "0.0"
                }
            }))

    #------------------------------------------------------------------------
    # Geometry
    #------------------------------------------------------------------------

    # Load the scene geometry from disk.
    objects = asr.MeshObjectReader.read(project.get_search_paths(), "plane",
                                        {"filename": "Plane001.binarymesh"})

    # Insert all the objects into the assembly.
    for object in objects:
        # Create an instance of this object and insert it into the assembly.
        instance_name = object.get_name() + "_inst"
        material_name = {"material_slot_0": "01 - Default_mat"}
        mat = orientation * asr.Matrix4d.make_translation(
            asr.Vector3d(0.0, 0.0, 0.0))
        instance = asr.ObjectInstance(
            instance_name, {
                "visibility": {
                    "camera": "true",
                    "diffuse": "true",
                    "glossy": "true",
                    "light": "true",
                    "probe": "true",
                    "shadow": "true",
                    "specular": "true",
                    "subsurface": "true",
                    "transparency": "true"
                }
            }, object.get_name(), asr.Transformd(mat), material_name,
            material_name)

        assembly.object_instances().insert(instance)

        # Insert this object into the scene.
        assembly.objects().insert(object)

    #------------------------------------------------------------------------
    # Lights
    #------------------------------------------------------------------------
    light_z_distance = 1.0

    if color == "white":
        assembly.colors().insert(
            asr.ColorEntity("white", {
                "color_space": "linear_rgb",
                "multiplier": 1.0
            }, [1.0, 1.0, 1.0]))

        step = float(plane_size) / grid_lights_count
        light_count = 0
        grid_range = np.linspace(-plane_size / 2 + step, plane_size / 2 - step,
                                 grid_lights_count)

        for j in grid_range:
            for i in grid_range:
                # Create a point light called "light" and insert it into the assembly.
                light_name = "light_" + str(light_count)
                light_count = light_count + 1
                light = asr.Light("point_light", light_name, {
                    "intensity": "white",
                    "intensity_multiplier": "3"
                })
                light_position = asr.Vector3d(i, j, light_z_distance)
                mat = orientation * asr.Matrix4d.make_translation(
                    light_position)
                light.set_transform(asr.Transformd(mat))
                assembly.lights().insert(light)

    elif color == "mix":
        for i in xrange(0, grid_lights_count * grid_lights_count):
            s = random.uniform(0, 1)
            if s < 0.65:
                ran = random.gauss(1, 0.01)
            elif s < 0.9:
                ran = random.gauss(0.3, 0.1)
            else:
                ran = random.gauss(0.7, 0.01)
            random_color = list(colorsys.hls_to_rgb(ran, 0.5, 1.0))
            assembly.colors().insert(
                asr.ColorEntity("color_" + str(i), {
                    "color_space": "linear_rgb",
                    "multiplier": 1.0
                }, random_color))

        step = float(plane_size) / grid_lights_count
        light_count = 0
        grid_range = np.linspace(-plane_size / 2 + step, plane_size / 2 - step,
                                 grid_lights_count)

        for j in grid_range:
            for i in grid_range:
                # Create a point light called "light" and insert it into the assembly.
                light_name = "light_" + str(light_count)
                color_name = "color_" + str(light_count)
                light_count = light_count + 1
                light = asr.Light("point_light", light_name, {
                    "intensity": color_name,
                    "intensity_multiplier": "3"
                })
                light_position = asr.Vector3d(i, j, light_z_distance)
                mat = orientation * asr.Matrix4d.make_translation(
                    light_position)
                light.set_transform(asr.Transformd(mat))
                assembly.lights().insert(light)
    else:
        print("Unknown color: {0}".format(color))
        return

    #------------------------------------------------------------------------
    # Assembly instance
    #------------------------------------------------------------------------

    # Create an instance of the assembly and insert it into the scene.
    assembly_inst = asr.AssemblyInstance("assembly_inst", {},
                                         assembly.get_name())
    assembly_inst.transform_sequence().set_transform(
        0.0, asr.Transformd(asr.Matrix4d.identity()))
    scene.assembly_instances().insert(assembly_inst)

    # Insert the assembly into the scene.
    scene.assemblies().insert(assembly)

    #------------------------------------------------------------------------
    # Environment
    #------------------------------------------------------------------------

    # Create an environment called "env" and bind it to the scene.
    scene.set_environment(asr.Environment("env", {}))

    #------------------------------------------------------------------------
    # Camera
    #------------------------------------------------------------------------

    # Create an orthographic camera.
    params = {
        "controller_target": "0 0 0",
        "film_dimensions": "128 128",
        "near_z": "-0.1",
        "shutter_close_time": "1.0",
        "shutter_open_time": "0.0"
    }

    camera = asr.Camera("orthographic_camera", "camera", params)

    # Place and orient the camera.
    mat = orientation * asr.Matrix4d.make_translation(
        asr.Vector3d(0.0, 0.0, 0.0))
    camera.transform_sequence().set_transform(0.0, asr.Transformd(mat))

    # Bind the camera to the scene.
    scene.cameras().insert(camera)

    #------------------------------------------------------------------------
    # Frame
    #------------------------------------------------------------------------

    # Create a frame and bind it to the project.
    params = {
        "camera": "camera",
        "clamping": "false",
        "color_space": "srgb",
        "filter": "box",
        "filter_size": "0.5",
        "gamma_correction": "1.0",
        "pixel_format": "float",
        "premultiplied_alpha": "true",
        "resolution": "512 512",
        "tile_size": "64 64"
    }
    project.set_frame(asr.Frame("beauty", params))

    # Bind the scene to the project.
    project.set_scene(scene)

    return project
Exemple #15
0
def build_project():
    # Create an empty project.
    project = asr.Project('test project')

    # Add default configurations to the project.
    project.add_default_configurations()

    # Set the number of samples. This is basically the quality parameter: the higher the number
    # of samples, the smoother the image but the longer the rendering time.
    # todo: fix.
    conf = project.configurations()['final']
    conf.insert_path('uniform_pixel_renderer.samples', 16)

    # Create a scene.
    scene = asr.Scene()

    # Create an assembly.
    assembly = asr.Assembly("assembly")

    #------------------------------------------------------------------------
    # Materials
    #------------------------------------------------------------------------

    for i in range(0, 10):
        assembly.bsdfs().insert(
            asr.BSDF(
                "glossy_brdf", "glossy" + str(i), {
                    "mdf": "ggx",
                    "reflectance": 1.0,
                    "roughness": i / 9.0,
                    "energy_compensation": 0.0
                }))

        assembly.bsdfs().insert(
            asr.BSDF(
                "glossy_brdf", "glossy_ec" + str(i), {
                    "mdf": "ggx",
                    "reflectance": 1.0,
                    "roughness": i / 9.0,
                    "energy_compensation": 1.0
                }))

    for i in range(0, 10):
        assembly.materials().insert(
            asr.Material("generic_material", "mat" + str(i),
                         {"bsdf": "glossy" + str(i)}))

        assembly.materials().insert(
            asr.Material("generic_material", "mat_ec" + str(i),
                         {"bsdf": "glossy_ec" + str(i)}))

    #------------------------------------------------------------------------
    # Geometry
    #------------------------------------------------------------------------

    object_name = "sphere"
    object = asr.MeshObject(object_name, {
        "primitive": "sphere",
        "radius": 0.4
    })
    assembly.objects().insert(object)

    obj_instance_params = {'visibility': {"glossy": False, "shadow": False}}

    for i in range(0, 10):
        instance_name = object_name + "_inst" + str(i)
        material_names = {"default": "mat" + str(i)}

        mat = asr.Matrix4d.make_translation(asr.Vector3d(-5.0 + i, -0.5, 0.0))

        instance = asr.ObjectInstance(instance_name,
                                      obj_instance_params, object_name,
                                      asr.Transformd(mat), material_names)
        assembly.object_instances().insert(instance)

    for i in range(0, 10):
        instance_name = object_name + "_ec_inst" + str(i)
        material_names = {"default": "mat_ec" + str(i)}

        mat = asr.Matrix4d.make_translation(asr.Vector3d(-5.0 + i, 0.5, 0.0))

        instance = asr.ObjectInstance(instance_name,
                                      obj_instance_params, object_name,
                                      asr.Transformd(mat), material_names)
        assembly.object_instances().insert(instance)

    #------------------------------------------------------------------------
    # Assembly instance
    #------------------------------------------------------------------------

    # Create an instance of the assembly and insert it into the scene.
    assembly_inst = asr.AssemblyInstance("assembly_inst", {},
                                         assembly.get_name())
    assembly_inst.transform_sequence().set_transform(
        0.0, asr.Transformd(asr.Matrix4d.identity()))
    scene.assembly_instances().insert(assembly_inst)

    # Insert the assembly into the scene.
    scene.assemblies().insert(assembly)

    #------------------------------------------------------------------------
    # Environment
    #------------------------------------------------------------------------

    # Create a color called "gray" and insert it into the scene.
    Gray = [0.5, 0.5, 0.5]
    scene.colors().insert(
        asr.ColorEntity("gray", {
            'color_space': 'linear_rgb',
            'multiplier': 1.0
        }, Gray))

    # Create an environment EDF called "gray_edf" and insert it into the scene.
    scene.environment_edfs().insert(
        asr.EnvironmentEDF("constant_environment_edf", "gray_edf",
                           {'radiance': 'gray'}))

    # Create an environment shader called "gray_shader" and insert it into the scene.
    scene.environment_shaders().insert(
        asr.EnvironmentShader("edf_environment_shader", "gray_shader",
                              {'environment_edf': 'gray_edf'}))

    # Create an environment called "sky" and bind it to the scene.
    scene.set_environment(
        asr.Environment("sky", {
            "environment_edf": "gray_edf",
            "environment_shader": "gray_shader"
        }))

    #------------------------------------------------------------------------
    # Camera
    #------------------------------------------------------------------------

    params = {
        'film_dimensions': asr.Vector2f(0.0640, 0.0200),
        'focal_length': 0.035
    }
    camera = asr.Camera("pinhole_camera", "camera", params)

    mat = asr.Matrix4d.make_translation(
        asr.Vector3d(-0.444315058060864, -0.071277492791890,
                     5.674764299781837))
    camera.transform_sequence().set_transform(0.0, asr.Transformd(mat))

    # Bind the camera to the scene.
    scene.cameras().insert(camera)

    #------------------------------------------------------------------------
    # Frame
    #------------------------------------------------------------------------

    # Create a frame and bind it to the project.
    params = {'camera': 'camera', 'resolution': asr.Vector2i(640, 200)}
    project.set_frame(asr.Frame("beauty", params))

    # Bind the scene to the project.
    project.set_scene(scene)

    return project
Exemple #16
0
def build_project():
    # Create an empty project.
    project = asr.Project('test project')
    paths = project.get_search_paths()
    paths.append('data')
    project.set_search_paths(paths)

    # Add default configurations to the project.
    project.add_default_configurations()

    # Set the number of samples. This is basically the quality parameter: the higher the number
    # of samples, the smoother the image but the longer the rendering time.
    # todo: fix.
    conf = project.configurations()['final']
    conf.insert_path('uniform_pixel_renderer.samples', 25)

    # Create a scene.
    scene = asr.Scene()

    # Create an assembly.
    assembly = asr.Assembly("assembly")

    #------------------------------------------------------------------------
    # Materials
    #------------------------------------------------------------------------

    # Create a color called "gray" and insert it into the assembly.
    GrayReflectance = [0.5, 0.5, 0.5]
    assembly.colors().insert(
        asr.ColorEntity("gray", {'color_space': 'srgb'}, GrayReflectance))

    # Create a BRDF called "diffuse_gray_brdf" and insert it into the assembly.
    assembly.bsdfs().insert(
        asr.BSDF("lambertian_brdf", "diffuse_gray_brdf",
                 {'reflectance': 'gray'}))

    # Create a physical surface shader and insert it into the assembly.
    assembly.surface_shaders().insert(
        asr.SurfaceShader("physical_surface_shader",
                          "physical_surface_shader"))

    # Create a material called "gray_material" and insert it into the assembly.
    assembly.materials().insert(
        asr.Material(
            "gray_material", {
                "surface_shader": "physical_surface_shader",
                "bsdf": "diffuse_gray_brdf"
            }))

    #------------------------------------------------------------------------
    # Geometry
    #------------------------------------------------------------------------

    # Load the scene geometry from disk.
    objects = asr.MeshObjectReader.read(project.get_search_paths(), "cube",
                                        {'filename': 'scene.obj'})

    # Insert all the objects into the assembly.
    for object in objects:
        # Create an instance of this object and insert it into the assembly.
        instance_name = object.get_name() + "_inst"
        material_names = {
            "default": "gray_material",
            "default2": "gray_material"
        }
        instance = asr.ObjectInstance(instance_name, {}, object.get_name(),
                                      asr.Transformd(asr.Matrix4d.identity()),
                                      material_names)
        assembly.object_instances().insert(instance)

        # Insert this object into the scene.
        assembly.objects().insert(object)

    #------------------------------------------------------------------------
    # Light
    #------------------------------------------------------------------------

    # Create a color called "light_intensity" and insert it into the assembly.
    LightRadiance = [1.0, 1.0, 1.0]
    assembly.colors().insert(
        asr.ColorEntity("light_intensity", {
            'color_space': 'srgb',
            'multiplier': 30.0
        }, LightRadiance))

    # Create a point light called "light" and insert it into the assembly.
    light = asr.Light("point_light", "light", {'intensity': 'light_intensity'})
    light.set_transform(
        asr.Transformd(asr.Matrix4d.translation(asr.Vector3d(0.6, 2.0, 1.0))))
    assembly.lights().insert(light)

    # Create an instance of the assembly and insert it into the scene.
    assembly_inst = asr.AssemblyInstance("assembly_inst", {},
                                         assembly.get_name())
    assembly_inst.transform_sequence().set_transform(
        0.0, asr.Transformd(asr.Matrix4d.identity()))
    scene.assembly_instances().insert(assembly_inst)

    # Insert the assembly into the scene.
    scene.assemblies().insert(assembly)

    #------------------------------------------------------------------------
    # Environment
    #------------------------------------------------------------------------

    # Create a color called "sky_radiance" and insert it into the scene.
    SkyRadiance = [0.75, 0.80, 1.0]
    scene.colors().insert(
        asr.ColorEntity("sky_radiance", {
            'color_space': 'srgb',
            'multiplier': 0.5
        }, SkyRadiance))

    # Create an environment EDF called "sky_edf" and insert it into the scene.
    scene.environment_edfs().insert(
        asr.EnvironmentEDF("constant_environment_edf", "sky_edf",
                           {'radiance': 'sky_radiance'}))

    # Create an environment shader called "sky_shader" and insert it into the scene.
    scene.environment_shaders().insert(
        asr.EnvironmentShader("edf_environment_shader", "sky_shader",
                              {'environment_edf': 'sky_edf'}))

    # Create an environment called "sky" and bind it to the scene.
    scene.set_environment(
        asr.Environment("sky", {
            "environment_edf": "sky_edf",
            "environment_shader": "sky_shader"
        }))

    #------------------------------------------------------------------------
    # Camera
    #------------------------------------------------------------------------

    # Create a pinhole camera with film dimensions 0.980 x 0.735 in (24.892 x 18.669 mm).
    params = {
        'film_dimensions': asr.Vector2f(0.024892, 0.018669),
        'focal_length': 0.035
    }
    camera = asr.Camera("pinhole_camera", "camera", params)

    # Place and orient the camera. By default cameras are located in (0.0, 0.0, 0.0)
    # and are looking toward Z- (0.0, 0.0, -1.0).
    mat = asr.Matrix4d.rotation(asr.Vector3d(1.0, 0.0, 0.0),
                                math.radians(-20.0))
    mat = mat * asr.Matrix4d.translation(asr.Vector3d(0.0, 0.8, 11.0))
    camera.transform_sequence().set_transform(0.0, asr.Transformd(mat))

    # Bind the camera to the scene.
    scene.set_camera(camera)

    #------------------------------------------------------------------------
    # Frame
    #------------------------------------------------------------------------

    # Create a frame and bind it to the project.
    params = {
        'camera': scene.get_camera().get_name(),
        'resolution': asr.Vector2i(640, 480),
        'color_space': 'srgb'
    }
    project.set_frame(asr.Frame("beauty", params))

    # Bind the scene to the project.
    project.set_scene(scene)

    return project
def convert_material(assembly, material_name, material_params, element):
    if material_name is None and "id" in element.attrib:
        material_name = element.attrib["id"]

    type = element.attrib["type"]

    # Two-sided adapter.
    if type == "twosided":
        set_private_param(material_params, "two_sided", True)
        return convert_material(assembly, material_name, material_params,
                                element.find("bsdf"))

    # Bump mapping adapter.
    # todo: add bump mapping support.
    if type == "bumpmap":
        return convert_material(assembly, material_name, material_params,
                                element.find("bsdf"))

    # Opacity adapter.
    if type == "mask":
        opacity_element = element.find("*[@name='opacity']")
        opacity = 0.5
        if opacity_element is not None:
            if opacity_element.tag == "rgb":
                opacity_rgb = get_rgb(opacity_element)
                if opacity_rgb[0] == opacity_rgb[1] and opacity_rgb[
                        0] == opacity_rgb[2]:
                    opacity = opacity_rgb[0]
                else:
                    warning(
                        "Colored opacity not supported, using average opacity")
                    opacity = (opacity_rgb[0] + opacity_rgb[1] +
                               opacity_rgb[2]) / 3
            else:
                warning("Textured opacity not supported")
        material_params["alpha_map"] = opacity
        return convert_material(assembly, material_name, material_params,
                                element.find("bsdf"))

    # BSDF.
    bsdf_name = "{0}_bsdf".format(material_name)
    if type == "diffuse":
        convert_diffuse_bsdf(assembly, bsdf_name, element)
    elif type == "roughdiffuse":
        convert_roughdiffuse_bsdf(assembly, bsdf_name, element)
    elif type == "plastic":
        convert_plastic_bsdf(assembly, bsdf_name, element)
    elif type == "roughplastic":
        convert_roughplastic_bsdf(assembly, bsdf_name, element)
    elif type == "conductor":
        convert_conductor_bsdf(assembly, bsdf_name, element)
    elif type == "roughconductor":
        convert_roughconductor_bsdf(assembly, bsdf_name, element)
    elif type == "dielectric":
        set_private_param(material_params, "two_sided", True)
        convert_dielectric_bsdf(assembly, bsdf_name, element)
    elif type == "roughdielectric":
        set_private_param(material_params, "two_sided", True)
        convert_roughdielectric_bsdf(assembly, bsdf_name, element)
    elif type == "thindielectric":
        set_private_param(material_params, "two_sided", True)
        set_private_param(material_params, "thin_dielectric", True)
        convert_dielectric_bsdf(assembly, bsdf_name, element)
    else:
        warning("Don't know how to convert BSDF of type {0}".format(type))
        return

    # Hack: force light-emitting materials to be single-sided.
    if "edf" in material_params:
        set_private_param(material_params, "two_sided", False)

    # Material.
    material_params["bsdf"] = bsdf_name
    material_params["surface_shader"] = "physical_surface_shader"
    assembly.materials().insert(
        asr.Material("generic_material", material_name, material_params))