Example #1
0
    def __view_camera_params(self, aspect_ratio):
        film_width, film_height = calc_film_dimensions(aspect_ratio,
                                                       self.bl_camera.data,
                                                       self.__zoom)

        self._matrix = self.bl_camera.matrix_world
        cam_mapping = {
            'PERSP': 'pinhole_camera',
            'ORTHO': 'orthographic_camera',
            'PANO': 'spherical_camera'
        }
        model = cam_mapping[self.bl_camera.data.type]

        if model == 'pinhole_camera' and self.bl_camera.data.appleseed.enable_dof:
            model = 'thinlens_camera'

        if model == 'orthographic_camera':
            sensor_width = self.bl_camera.data.ortho_scale * self.__zoom
            params = {'film_width': sensor_width, 'aspect_ratio': aspect_ratio}

            if self.bl_camera.data.sensor_fit == 'VERTICAL' or (
                    self.bl_camera.data.sensor_fit == 'AUTO'
                    and aspect_ratio < 1):
                params['film_height'] = params.pop('film_width')

        elif model == 'spherical_camera':
            raise NotImplementedError(
                "Spherical camera not supported for interactive rendering")

        elif model == 'thinlens_camera':
            if self.bl_camera.data.dof_object is not None:
                cam_target = bpy.data.objects[
                    self.bl_camera.data.dof_object.name]
                focal_distance = (cam_target.location -
                                  self.bl_camera.location).magnitude
            else:
                focal_distance = self.bl_camera.data.dof_distance
            params = {
                'film_dimensions': asr.Vector2f(film_width, film_height),
                'focal_length': self.bl_camera.data.lens / 1000,
                'aspect_ratio': aspect_ratio,
                'f_stop': self.bl_camera.data.appleseed.f_number,
                'autofocus_enabled': False,
                'diaphragm_blades':
                self.bl_camera.data.appleseed.diaphragm_blades,
                'diaphragm_tilt_angle':
                self.bl_camera.data.appleseed.diaphragm_angle,
                'focal_distance': focal_distance
            }

        else:
            params = {
                'focal_length': self.bl_camera.data.lens / 1000,
                'aspect_ratio': aspect_ratio,
                'film_dimensions': asr.Vector2f(film_width, film_height)
            }

        return model, params
Example #2
0
    def __create_thin_lens_camera(self, scene, aspect_ratio, film_width,
                                  film_height):
        camera = self.bl_camera
        if camera.data.dof_object is not None:
            cam_target = bpy.data.objects[camera.data.dof_object.name]
            focal_distance = (cam_target.location -
                              self.bl_camera.location).magnitude
        else:
            focal_distance = camera.data.dof_distance
        cam_params = {
            'aspect_ratio': aspect_ratio,
            'focal_length': camera.data.lens / 1000,
            'film_dimensions': asr.Vector2f(film_width, film_height),
            'near_z': camera.data.appleseed.near_z,
            'f_stop': camera.data.appleseed.f_number,
            'autofocus_enabled': False,
            'diaphragm_blades': camera.data.appleseed.diaphragm_blades,
            'diaphragm_tilt_angle': camera.data.appleseed.diaphragm_angle,
            'focal_distance': focal_distance,
            'shutter_open_end_time': scene.appleseed.shutter_open_end_time,
            'shutter_open_begin_time': scene.appleseed.shutter_open,
            'shutter_close_begin_time':
            scene.appleseed.shutter_close_begin_time,
            'shutter_close_end_time': scene.appleseed.shutter_close
        }
        if camera.data.appleseed.enable_autofocus:
            x, y = find_auto_focus_point(scene)
            cam_params['autofocus_target'] = asr.Vector2f(x, y)
            cam_params['autofocus_enabled'] = True
        if camera.data.appleseed.diaphragm_map != "":
            filename = self.asset_handler.process_path(
                camera.data.appleseed.diaphragm_map, AssetType.TEXTURE_ASSET)
            self.__cam_map = asr.Texture(
                'disk_texture_2d', 'cam_map', {
                    'filename': filename,
                    'color_space':
                    camera.data.appleseed.diaphragm_map_colorspace
                }, [])
            self.__cam_map_inst = asr.TextureInstance(
                "cam_map_inst", {
                    'addressing_mode': 'wrap',
                    'filtering_mode': 'bilinear'
                }, "cam_map", asr.Transformf(asr.Matrix4f.identity()))

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

        return cam_params
Example #3
0
    def __thin_lens_camera_params(self, bl_scene, engine, aspect_ratio,
                                  film_width, film_height):
        camera = self.bl_camera

        cam_params = self.__base_camera_params(bl_scene, engine, aspect_ratio,
                                               film_width, film_height)

        cam_params.update({
            'f_stop': camera.data.appleseed.f_number,
            'autofocus_enabled': False,
            'diaphragm_blades': camera.data.appleseed.diaphragm_blades,
            'diaphragm_tilt_angle': camera.data.appleseed.diaphragm_angle,
            'focal_distance': util.get_focal_distance(camera)
        })

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

        if camera.data.appleseed.diaphragm_map is not None:
            tex_name = f"{camera.data.appleseed.diaphragm_map.name_full}_inst"
            cam_params['diaphragm_map'] = tex_name
            del cam_params['diaphragm_blades']

        return cam_params
Example #4
0
    def __base_camera_params(self, bl_scene, engine, aspect_ratio, film_width,
                             film_height):
        camera = self.bl_camera
        x_aspect_comp = 1 if aspect_ratio > 1 else 1 / aspect_ratio
        y_aspect_comp = aspect_ratio if aspect_ratio > 1 else 1
        cam_params = {
            'aspect_ratio':
            aspect_ratio,
            'focal_length':
            camera.data.lens / 1000,  # mm to meters.
            'film_dimensions':
            asr.Vector2f(film_width, film_height),
            'near_z':
            camera.data.appleseed.near_z,
            'shift_x': (engine.camera_shift_x(camera) + camera.data.shift_x) *
            x_aspect_comp * film_width,
            'shift_y':
            camera.data.shift_y * y_aspect_comp * film_height,
            'shutter_open_end_time':
            bl_scene.appleseed.shutter_open_end_time,
            'shutter_open_begin_time':
            bl_scene.appleseed.shutter_open,
            'shutter_close_begin_time':
            bl_scene.appleseed.shutter_close_begin_time,
            'shutter_close_end_time':
            bl_scene.appleseed.shutter_close
        }

        return cam_params
Example #5
0
    def __pinhole_camera_params(self, scene, aspect_ratio, film_width, film_height):
        camera = self.bl_camera
        cam_params = {'aspect_ratio': aspect_ratio,
                      'focal_length': camera.data.lens / 1000, # mm to meters.
                      'film_dimensions': asr.Vector2f(film_width, film_height),
                      'near_z': camera.data.appleseed.near_z,
                      'shift_x': camera.data.shift_x * film_width,
                      'shift_y': camera.data.shift_y * film_height,
                      'shutter_open_end_time': scene.appleseed.shutter_open_end_time,
                      'shutter_open_begin_time': scene.appleseed.shutter_open,
                      'shutter_close_begin_time': scene.appleseed.shutter_close_begin_time,
                      'shutter_close_end_time': scene.appleseed.shutter_close}

        return cam_params
Example #6
0
    def __thin_lens_camera_params(self, scene, aspect_ratio, film_width,
                                  film_height):
        camera = self.bl_camera

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

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

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

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

        return cam_params
Example #7
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
Example #8
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
    def __set_view_camera_params(self, aspect_ratio, textures_to_add,
                                 as_texture_translators):
        film_width, film_height = util.calc_film_dimensions(
            aspect_ratio, self.bl_camera.data, self.__zoom)

        offset = tuple(self.__context.region_data.view_camera_offset)

        x_aspect_comp = 1 if aspect_ratio > 1 else 1 / aspect_ratio
        y_aspect_comp = aspect_ratio if aspect_ratio > 1 else 1

        self.__shift_x = ((offset[0] * 2 +
                           (self.bl_camera.data.shift_x * x_aspect_comp)) /
                          self.__zoom) * film_width
        self.__shift_y = ((offset[1] * 2 +
                           (self.bl_camera.data.shift_y * y_aspect_comp)) /
                          self.__zoom) * film_height

        self.__matrix = self.bl_camera.matrix_world

        if self.__model == 'orthographic_camera':
            sensor_width = self.bl_camera.data.ortho_scale * self.__zoom
            params = {'film_width': sensor_width, 'aspect_ratio': aspect_ratio}

            if self.bl_camera.data.sensor_fit == 'VERTICAL' or (
                    self.bl_camera.data.sensor_fit == 'AUTO'
                    and aspect_ratio < 1):
                params['film_height'] = params.pop('film_width')

        else:
            aspect_ratio = util.calc_film_aspect_ratio(self.__context.scene)
            params = {
                'focal_length': self.bl_camera.data.lens / 1000,
                'aspect_ratio': aspect_ratio,
                'shift_x': self.__shift_x,
                'shift_y': self.__shift_y,
                'film_dimensions': asr.Vector2f(film_width, film_height)
            }

        if self.__model == 'fisheyelens_camera':
            if self.bl_camera.data.appleseed.fisheye_projection_type is not 'none':
                params[
                    'projection_type'] = self.bl_camera.data.appleseed.fisheye_projection_type
            else:
                self.__engine.report(
                    {'ERROR'},
                    "Panoramic camera not supported in interactive mode")

        if self.__model == 'thinlens_camera':
            params.update({
                'f_stop':
                self.bl_camera.data.appleseed.f_number,
                'autofocus_enabled':
                False,
                'diaphragm_blades':
                self.bl_camera.data.appleseed.diaphragm_blades,
                'diaphragm_tilt_angle':
                self.bl_camera.data.appleseed.diaphragm_angle,
                'focal_distance':
                util.get_focal_distance(self.bl_camera)
            })

            if textures_to_add is not None and as_texture_translators is not None:
                if self.bl_camera.data.appleseed.diaphragm_map is not None:
                    tex_id = self.bl_camera.data.appleseed.diaphragm_map.name_full
                    if tex_id not in as_texture_translators:
                        textures_to_add[tex_id] = TextureTranslator(
                            self.bl_camera.data.appleseed.diaphragm_map,
                            self.asset_handler)
                    tex_name = f"{self.bl_camera.data.appleseed.diaphragm_map.name_full}_inst"
                    params.update({'diaphragm_map': tex_name})
                    del params['diaphragm_blades']

        self.__params = params
Example #10
0
    def __convert_mesh(self, me):
        # Material slots.
        material_slots = self.bl_obj.material_slots

        self.__mesh_object.reserve_material_slots(len(material_slots))

        if len(material_slots) > 1:
            for i, m in enumerate(material_slots):
                self.__mesh_object.push_material_slot("slot-%s" % i)
        else:
            self.__mesh_object.push_material_slot("default")

        # Vertices
        self.__mesh_object.reserve_vertices(len(me.vertices))

        for v in me.vertices:
            self.__mesh_object.push_vertex(asr.Vector3f(v.co[0], v.co[1], v.co[2]))

        # Faces.
        self.__mesh_object.reserve_triangles(len(me.polygons))

        for f in me.polygons:
            assert (len(f.vertices) == 3)
            tri = asr.Triangle(
                f.vertices[0],
                f.vertices[1],
                f.vertices[2],
                f.material_index)

            self.__mesh_object.push_triangle(tri)

        loops = me.loops

        # UVs.
        if self.bl_obj.data.appleseed.export_uvs and len(me.uv_textures) > 0:
            uv_texture = me.uv_textures.active.data[:]
            uv_layer = me.uv_layers.active.data[:]

            self.__mesh_object.reserve_tex_coords(len(me.polygons) * 3)

            uv_index = 0

            for i, f in enumerate(me.polygons):
                loop = f.loop_indices
                tri = self.__mesh_object.get_triangle(i)

                uv = uv_layer[f.loop_indices[0]].uv
                self.__mesh_object.push_tex_coords(asr.Vector2f(uv[0], uv[1]))
                tri.m_a0 = uv_index
                uv_index += 1

                uv = uv_layer[f.loop_indices[1]].uv
                self.__mesh_object.push_tex_coords(asr.Vector2f(uv[0], uv[1]))
                tri.m_a1 = uv_index
                uv_index += 1

                uv = uv_layer[f.loop_indices[2]].uv
                self.__mesh_object.push_tex_coords(asr.Vector2f(uv[0], uv[1]))
                tri.m_a2 = uv_index
                uv_index += 1

        # Normals.
        if self.bl_obj.data.appleseed.export_normals:
            me.calc_normals_split()

            self.__mesh_object.reserve_vertex_normals(len(me.polygons) * 3)

            normal_index = 0

            for i, f in enumerate(me.polygons):
                loop = f.loop_indices
                tri = self.__mesh_object.get_triangle(i)

                n = loops[f.loop_indices[0]].normal
                self.__mesh_object.push_vertex_normal(asr.Vector3f(n[0], n[1], n[2]))
                tri.m_n0 = normal_index
                normal_index += 1

                n = loops[f.loop_indices[1]].normal
                self.__mesh_object.push_vertex_normal(asr.Vector3f(n[0], n[1], n[2]))
                tri.m_n1 = normal_index
                normal_index += 1

                n = loops[f.loop_indices[2]].normal
                self.__mesh_object.push_vertex_normal(asr.Vector3f(n[0], n[1], n[2]))
                tri.m_n2 = normal_index
                normal_index += 1
Example #11
0
    def __view_camera_params(self, aspect_ratio):
        film_width, film_height = util.calc_film_dimensions(
            aspect_ratio, self.bl_camera.data, self.__zoom)

        offset = tuple(self.context.region_data.view_camera_offset)

        x_aspect_comp = 1 if aspect_ratio > 1 else 1 / aspect_ratio
        y_aspect_comp = aspect_ratio if aspect_ratio > 1 else 1

        self.__shift_x = ((offset[0] * 2 +
                           (self.bl_camera.data.shift_x * x_aspect_comp)) /
                          self.__zoom) * film_width
        self.__shift_y = ((offset[1] * 2 +
                           (self.bl_camera.data.shift_y * y_aspect_comp)) /
                          self.__zoom) * film_height

        self.__matrix = self.bl_camera.matrix_world
        cam_mapping = {
            'PERSP': 'pinhole_camera',
            'ORTHO': 'orthographic_camera',
            'PANO': 'fisheyelens_camera'
        }

        model = cam_mapping[self.bl_camera.data.type]

        if model == 'pinhole_camera' and self.bl_camera.data.appleseed.enable_dof and self.bl_camera.data.type != 'PANO':
            model = 'thinlens_camera'

        if model == 'orthographic_camera':
            sensor_width = self.bl_camera.data.ortho_scale * self.__zoom
            params = {'film_width': sensor_width, 'aspect_ratio': aspect_ratio}

            if self.bl_camera.data.sensor_fit == 'VERTICAL' or (
                    self.bl_camera.data.sensor_fit == 'AUTO'
                    and aspect_ratio < 1):
                params['film_height'] = params.pop('film_width')

        else:
            aspect_ratio = util.get_frame_aspect_ratio(self.context.scene)
            params = {
                'focal_length': self.bl_camera.data.lens / 1000,
                'aspect_ratio': aspect_ratio,
                'shift_x': self.__shift_x,
                'shift_y': self.__shift_y,
                'film_dimensions': asr.Vector2f(film_width, film_height)
            }

        if model == 'fisheyelens_camera':
            if self.bl_camera.data.appleseed.fisheye_projection_type is not 'none':
                params[
                    'projection_type'] = self.bl_camera.data.appleseed.fisheye_projection_type
            else:
                print(
                    "Spherical camera not supported for interactive rendering")

        if model == 'thinlens_camera':
            params.update({
                'f_stop':
                self.bl_camera.data.appleseed.f_number,
                'autofocus_enabled':
                False,
                'diaphragm_blades':
                self.bl_camera.data.appleseed.diaphragm_blades,
                'diaphragm_tilt_angle':
                self.bl_camera.data.appleseed.diaphragm_angle,
                'focal_distance':
                util.get_focal_distance(self.bl_camera)
            })

        return model, params
Example #12
0
    def __set_view_camera_params(self, context, aspect_ratio):
        film_width, film_height = util.calc_film_dimensions(
            aspect_ratio, self.bl_camera.data, self.__zoom)

        offset = tuple(context.region_data.view_camera_offset)

        x_aspect_comp = 1 if aspect_ratio > 1 else 1 / aspect_ratio
        y_aspect_comp = aspect_ratio if aspect_ratio > 1 else 1

        self.__shift_x = ((offset[0] * 2 +
                           (self.bl_camera.data.shift_x * x_aspect_comp)) /
                          self.__zoom) * film_width
        self.__shift_y = ((offset[1] * 2 +
                           (self.bl_camera.data.shift_y * y_aspect_comp)) /
                          self.__zoom) * film_height

        self.__set_matrix(context)

        if self.__model == 'orthographic_camera':
            sensor_width = self.bl_camera.data.ortho_scale * self.__zoom
            params = {'film_width': sensor_width, 'aspect_ratio': aspect_ratio}

            if self.bl_camera.data.sensor_fit == 'VERTICAL' or (
                    self.bl_camera.data.sensor_fit == 'AUTO'
                    and aspect_ratio < 1):
                params['film_height'] = params.pop('film_width')

        else:
            aspect_ratio = util.calc_film_aspect_ratio(context.scene)
            params = {
                'focal_length': self.bl_camera.data.lens / 1000,
                'aspect_ratio': aspect_ratio,
                'shift_x': self.__shift_x,
                'shift_y': self.__shift_y,
                'film_dimensions': asr.Vector2f(film_width, film_height)
            }

        if self.__model == 'fisheyelens_camera':
            if self.bl_camera.data.appleseed.fisheye_projection_type is not 'none':
                params[
                    'projection_type'] = self.bl_camera.data.appleseed.fisheye_projection_type

        if self.__model == 'thinlens_camera':
            params.update({
                'f_stop':
                self.bl_camera.data.appleseed.f_number,
                'autofocus_enabled':
                False,
                'diaphragm_blades':
                self.bl_camera.data.appleseed.diaphragm_blades,
                'diaphragm_tilt_angle':
                self.bl_camera.data.appleseed.diaphragm_angle,
                'focal_distance':
                util.get_focal_distance(self.bl_camera)
            })

            if self.bl_camera.data.appleseed.diaphragm_map is not None:
                tex_name = f"{self.bl_camera.data.appleseed.diaphragm_map.name_full}_inst"
                params.update({'diaphragm_map': tex_name})
                del params['diaphragm_blades']

        return params