def convert_sensor(project, scene, element):
    camera_params = {}
    camera_matrix = None
    frame_params = {
        "camera": "camera",
        "color_space": "srgb",
        "tile_size": "32 32"
    }

    for child in element:
        if child.tag == "float":
            if child.attrib["name"] == "fov":
                camera_params["horizontal_fov"] = child.attrib["value"]
        elif child.tag == "transform":
            camera_matrix = get_matrix(child.find("matrix"))
        elif child.tag == "sampler":
            convert_sampler(project, child)
        elif child.tag == "film":
            convert_film(camera_params, frame_params, child)

    camera = asr.Camera("pinhole_camera", "camera", camera_params)
    if camera_matrix is not None:
        roty = asr.Matrix4d.make_rotation(asr.Vector3d(0.0, 1.0, 0.0),
                                          math.radians(180.0))
        camera_matrix = camera_matrix * roty
        camera.transform_sequence().set_transform(
            0.0, asr.Transformd(camera_matrix))
    scene.cameras().insert(camera)

    project.set_frame(asr.Frame("beauty", frame_params))
Exemple #2
0
    def __update_frame_size(self, depsgraph):
        frame_params = self.__translate_frame(depsgraph)

        self.__frame = asr.Frame("beauty", frame_params, asr.AOVContainer())

        self.__project.set_frame(self.__frame)
        self.__frame = self.__project.get_frame()
Exemple #3
0
    def __set_frame(self, depsgraph):
        width, height = util.get_render_resolution(depsgraph.scene_eval)

        frame_params = {'resolution': asr.Vector2i(width, height),
                        'camera': "preview_camera"}

        frame = asr.Frame("beauty", frame_params)

        self.__project.set_frame(frame)
Exemple #4
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
Exemple #5
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 #6
0
    def __translate_frame(self, context):
        """
        Convert image related settings (resolution, crop windows, AOVs, ...) to appleseed.
        :param context:
        """

        logger.debug("Translating frame")

        asr_scene_props = self.bl_scene.appleseed
        scale = self.bl_scene.render.resolution_percentage / 100.0
        if context is not None:
            width = int(context.region.width)
            height = int(context.region.height)
            self.__viewport_resolution = [width, height]
        else:
            width = int(self.bl_scene.render.resolution_x * scale)
            height = int(self.bl_scene.render.resolution_y * scale)

        noise_seed = (asr_scene_props.noise_seed + self.bl_scene.frame_current) if asr_scene_props.per_frame_noise else asr_scene_props.noise_seed

        frame_params = {
            'resolution': asr.Vector2i(width, height),
            'camera': "Camera",
            'tile_size': asr.Vector2i(asr_scene_props.tile_size, asr_scene_props.tile_size),
            'filter': asr_scene_props.pixel_filter,
            'filter_size': asr_scene_props.pixel_filter_size,
            'denoiser': asr_scene_props.denoise_mode,
            'noise_seed': noise_seed,
            'skip_denoised': asr_scene_props.skip_denoised,
            'random_pixel_order': asr_scene_props.random_pixel_order,
            'prefilter_spikes': asr_scene_props.prefilter_spikes,
            'spike_threshold': asr_scene_props.spike_threshold,
            'patch_distance_threshold': asr_scene_props.patch_distance_threshold,
            'denoise_scales': asr_scene_props.denoise_scales,
            'mark_invalid_pixels': asr_scene_props.mark_invalid_pixels}

        aovs = asr.AOVContainer()
        if self.export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            aovs = self.__set_aovs(aovs)

        # Create and set the frame in the project.
        self.__frame = asr.Frame("beauty",
                                 frame_params,
                                 aovs)

        if self.bl_scene.render.use_border and self.export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            min_x = int(self.bl_scene.render.border_min_x * width)
            max_x = int(self.bl_scene.render.border_max_x * width) - 1
            min_y = height - int(self.bl_scene.render.border_max_y * height)
            max_y = height - int(self.bl_scene.render.border_min_y * height) - 1
            self.__frame.set_crop_window([min_x, min_y, max_x, max_y])

        elif self.export_mode == ProjectExportMode.INTERACTIVE_RENDER and context.space_data.use_render_border and context.region_data.view_perspective in ('ORTHO', 'PERSP'):
            min_x = int(context.space_data.render_border_min_x * width)
            max_x = int(context.space_data.render_border_max_x * width) - 1
            min_y = height - int(context.space_data.render_border_max_y * height)
            max_y = height - int(context.space_data.render_border_min_y * height) - 1
            self.__frame.set_crop_window([min_x, min_y, max_x, max_y])

        elif self.export_mode == ProjectExportMode.INTERACTIVE_RENDER and self.bl_scene.render.use_border and context.region_data.view_perspective == 'CAMERA':
            """
            I can't explain how the following code produces the correct render window.
            I basically threw every parameter combination I could think of together 
            until the result looked right.
            """

            zoom = 4 / ((math.sqrt(2) + context.region_data.view_camera_zoom / 50)** 2)
            frame_aspect_ratio = width / height
            camera_aspect_ratio = calc_film_aspect_ratio(self.bl_scene)
            if frame_aspect_ratio > 1:
                camera_width = width / zoom
                camera_height = camera_width / camera_aspect_ratio
            else:
                camera_height = height / (zoom * camera_aspect_ratio)
                camera_width = camera_height * camera_aspect_ratio

            view_offset_x, view_offset_y = context.region_data.view_camera_offset
            view_shift_x = ((view_offset_x * 2) / zoom) * width
            view_shift_y = ((view_offset_y * 2) / zoom) * height
            window_shift_x = (width - camera_width) / 2
            window_shift_y = (height - camera_height) / 2

            window_x_min = int(camera_width * self.bl_scene.render.border_min_x + window_shift_x - view_shift_x)
            window_x_max = int(camera_width * self.bl_scene.render.border_max_x + window_shift_x - view_shift_x)
            window_y_min = height - int(camera_height * self.bl_scene.render.border_max_y + window_shift_y - view_shift_y)
            window_y_max = height - int(camera_height * self.bl_scene.render.border_min_y + window_shift_y - view_shift_y)

            # Check for coordinates outside the render window.
            window_x_min = clamp_value(window_x_min, 0, width - 1)
            window_x_max = clamp_value(window_x_max, 0, width - 1)
            window_y_min = clamp_value(window_y_min, 0, height - 1)
            window_y_max = clamp_value(window_y_max, 0, height - 1)

            self.__frame.set_crop_window([window_x_min, window_y_min, window_x_max, window_y_max])

        self.__project.set_frame(self.__frame)
        self.__frame = self.as_project.get_frame()

        if len(asr_scene_props.post_processing_stages) > 0 and self.export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            self.__set_post_process()
Exemple #7
0
    def __translate_frame(self):
        """
        Convert image related settings (resolution, crop windows, AOVs, ...) to appleseed.
        """

        logger.debug("Translating frame")

        asr_scene_props = self.bl_scene.appleseed
        scale = self.bl_scene.render.resolution_percentage / 100.0
        if self.__context:
            width = int(self.__context.region.width)
            height = int(self.__context.region.height)
            self.__viewport_resolution = [width, height]
        else:
            width = int(self.bl_scene.render.resolution_x * scale)
            height = int(self.bl_scene.render.resolution_y * scale)

        frame_params = {
            'resolution':
            asr.Vector2i(width, height),
            'camera':
            self.bl_scene.camera.name,
            'tile_size':
            asr.Vector2i(asr_scene_props.tile_size, asr_scene_props.tile_size),
            'filter':
            asr_scene_props.pixel_filter,
            'filter_size':
            asr_scene_props.pixel_filter_size,
            'denoiser':
            asr_scene_props.denoise_mode,
            'skip_denoised':
            asr_scene_props.skip_denoised,
            'random_pixel_order':
            asr_scene_props.random_pixel_order,
            'prefilter_spikes':
            asr_scene_props.prefilter_spikes,
            'spike_threshold':
            asr_scene_props.spike_threshold,
            'patch_distance_threshold':
            asr_scene_props.patch_distance_threshold,
            'denoise_scales':
            asr_scene_props.denoise_scales,
            'mark_invalid_pixels':
            asr_scene_props.mark_invalid_pixels
        }

        # AOVs
        aovs = asr.AOVContainer()
        if self.export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            if asr_scene_props.diffuse_aov:
                aovs.insert(asr.AOV('diffuse_aov', {}))
            if asr_scene_props.direct_diffuse_aov:
                aovs.insert(asr.AOV('direct_diffuse_aov', {}))
            if asr_scene_props.indirect_diffuse_aov:
                aovs.insert(asr.AOV('indirect_diffuse_aov', {}))
            if asr_scene_props.glossy_aov:
                aovs.insert(asr.AOV('glossy_aov', {}))
            if asr_scene_props.direct_glossy_aov:
                aovs.insert(asr.AOV('direct_glossy_aov', {}))
            if asr_scene_props.indirect_glossy_aov:
                aovs.insert(asr.AOV('indirect_glossy_aov', {}))
            if asr_scene_props.normal_aov:
                aovs.insert(asr.AOV('normal_aov', {}))
            if asr_scene_props.position_aov:
                aovs.insert(asr.AOV('position_aov', {}))
            if asr_scene_props.uv_aov:
                aovs.insert(asr.AOV('uv_aov', {}))
            if asr_scene_props.depth_aov:
                aovs.insert(asr.AOV('depth_aov', {}))
            if asr_scene_props.pixel_time_aov:
                aovs.insert(asr.AOV('pixel_time_aov', {}))
            if asr_scene_props.invalid_samples_aov:
                aovs.insert(asr.AOV('invalid_samples_aov', {}))
            if asr_scene_props.pixel_sample_count_aov:
                aovs.insert(asr.AOV('pixel_sample_count_aov', {}))
            if asr_scene_props.pixel_variation_aov:
                aovs.insert(asr.AOV('pixel_variation_aov', {}))
            if asr_scene_props.albedo_aov:
                aovs.insert(asr.AOV('albedo_aov', {}))
            if asr_scene_props.emission_aov:
                aovs.insert(asr.AOV('emission_aov', {}))
            if asr_scene_props.npr_shading_aov:
                aovs.insert(asr.AOV('npr_shading_aov', {}))
            if asr_scene_props.npr_contour_aov:
                aovs.insert(asr.AOV('npr_contour_aov', {}))

        # Create and set the frame in the project.
        frame = asr.Frame("beauty", frame_params, aovs)

        if len(
                asr_scene_props.post_processing_stages
        ) > 0 and self.export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            for index, stage in enumerate(
                    asr_scene_props.post_processing_stages):
                if stage.model == 'render_stamp_post_processing_stage':
                    params = {
                        'order': index,
                        'format_string': stage.render_stamp
                    }
                else:
                    params = {
                        'order': index,
                        'color_map': stage.color_map,
                        'auto_range': stage.auto_range,
                        'range_min': stage.range_min,
                        'range_max': stage.range_max,
                        'add_legend_bar': stage.add_legend_bar,
                        'legend_bar_ticks': stage.legend_bar_ticks,
                        'render_isolines': stage.render_isolines,
                        'line_thickness': stage.line_thickness
                    }

                    if stage.color_map == 'custom':
                        params[
                            'color_map_file_path'] = stage.color_map_file_path

                post_process = asr.PostProcessingStage(stage.model, stage.name,
                                                       params)

                frame.post_processing_stages().insert(post_process)

        if self.bl_scene.render.use_border and self.export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            min_x = int(self.bl_scene.render.border_min_x * width)
            max_x = int(self.bl_scene.render.border_max_x * width) - 1
            min_y = height - int(self.bl_scene.render.border_max_y * height)
            max_y = height - int(
                self.bl_scene.render.border_min_y * height) - 1
            frame.set_crop_window([min_x, min_y, max_x, max_y])

        elif self.export_mode == ProjectExportMode.INTERACTIVE_RENDER and self.__context.space_data.use_render_border \
                and self.__context.region_data.view_perspective in ('ORTHO', 'PERSP'):
            min_x = int(self.__context.space_data.render_border_min_x * width)
            max_x = int(
                self.__context.space_data.render_border_max_x * width) - 1
            min_y = height - int(
                self.__context.space_data.render_border_max_y * height)
            max_y = height - int(
                self.__context.space_data.render_border_min_y * height) - 1
            frame.set_crop_window([min_x, min_y, max_x, max_y])

        self.__project.set_frame(frame)
Exemple #8
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 #9
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
Exemple #10
0
    def translate_scene(self, engine, depsgraph, context=None):
        logger.debug("appleseed: Translating scene %s", depsgraph.scene_eval.name)

        prof_timer = Timer()
        prof_timer.start()

        self.__create_project(depsgraph)

        if self.__export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            self.__calc_shutter_times(depsgraph)

        self.__translate_render_settings(depsgraph)

        self.__calc_viewport_resolution(depsgraph, context)

        aovs = self.__set_aovs(depsgraph)
        frame_params = self.__translate_frame(depsgraph)

        self.__frame = asr.Frame("beauty", frame_params, aovs)

        self.__calc_crop_window(depsgraph, context)

        if self.__crop_window is not None:
            self.__frame.set_crop_window(self.__crop_window)

        if len(depsgraph.scene_eval.appleseed.post_processing_stages) > 0 and self.__export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            self.__set_post_process(depsgraph)

        self.__project.set_frame(self.__frame)
        self.__frame = self.__project.get_frame()

        # Create camera
        if depsgraph.scene_eval.camera is not None:
            # Create interactive or final render camera
            if self.__export_mode == ProjectExportMode.INTERACTIVE_RENDER:
                self.__as_camera_translator = InteractiveCameraTranslator(depsgraph.scene_eval.camera, self.__asset_handler)
            else:
                self.__as_camera_translator = RenderCameraTranslator(depsgraph.scene_eval.camera, self.__asset_handler)
        else:
            engine.error_set("appleseed: No camera in scene!")

        # Create world
        if depsgraph.scene_eval.world is not None:
            self.__as_world_translator = WorldTranslator(depsgraph.scene_eval.world, self.__asset_handler)

        # Blender scene processing
        objects_to_add = dict()
        materials_to_add = dict()
        textures_to_add = dict()

        for obj in bpy.data.objects:
            if obj.type == 'LIGHT':
                objects_to_add[obj] = LampTranslator(obj, self.__export_mode, self.__asset_handler)
            elif obj.type == 'MESH' and len(obj.data.loops) > 0:
                objects_to_add[obj] = MeshTranslator(obj, self.__export_mode, self.__asset_handler)
            elif obj.type == 'EMPTY' and obj.appleseed.object_export == "archive_assembly":
                objects_to_add[obj] = ArchiveAssemblyTranslator(obj, self.__asset_handler)

        for mat in bpy.data.materials:
            materials_to_add[mat] = MaterialTranslator(mat, self.__asset_handler)

        for tex in bpy.data.images:
            if tex.users > 0 and tex.name not in ("Render Result", "Viewer Node"):
                textures_to_add[tex] = TextureTranslator(tex, self.__asset_handler)

        # Create camera, world, material and texture entities
        self.__as_camera_translator.create_entities(depsgraph, context, engine)

        if self.__as_world_translator is not None:
            self.__as_world_translator.create_entities(depsgraph)

        for obj, trans in materials_to_add.items():
            trans.create_entities(depsgraph, engine)
        for obj, trans in textures_to_add.items():
            trans.create_entities(depsgraph)

        # Set initial position of all objects and lamps
        self.__calc_initial_positions(depsgraph, engine, objects_to_add)

        # Remove unused translators
        for translator in list(objects_to_add.keys()):
            if objects_to_add[translator].instances_size == 0:
                del objects_to_add[translator]

        # Create 3D entities
        for obj, trans in objects_to_add.items():
            trans.create_entities(depsgraph, len(self.__deform_times))

        # Calculate additional steps for motion blur
        if self.__export_mode != ProjectExportMode.INTERACTIVE_RENDER:
            self.__calc_motion_steps(depsgraph, engine, objects_to_add)

        self.__as_camera_translator.flush_entities(self.as_scene, self.as_main_assembly, self.as_project)
        if self.__as_world_translator is not None:
            self.__as_world_translator.flush_entities(self.as_scene, self.as_main_assembly, self.as_project)

        for obj, trans in objects_to_add.items():
            trans.flush_entities(self.as_scene, self.as_main_assembly, self.as_project)
        for obj, trans in materials_to_add.items():
            trans.flush_entities(self.as_scene, self.as_main_assembly, self.as_project)
        for obj, trans in textures_to_add.items():
            trans.flush_entities(self.as_scene, self.as_main_assembly, self.as_project)

        # Transfer temp translators to main list
        for bl_obj, translator in objects_to_add.items():
            self.__as_object_translators[bl_obj] = translator
        for bl_obj, translator in materials_to_add.items():
            self.__as_material_translators[bl_obj] = translator
        for bl_obj, translator in textures_to_add.items():
            self.__as_texture_translators[bl_obj] = translator

        self.__load_searchpaths()

        prof_timer.stop()
        logger.debug("Scene translated in %f seconds.", prof_timer.elapsed())
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