def convert_sphere_shape(scene, assembly, element): # Radius. radius_element = element.find("float[@name='radius']") radius = float(radius_element.attrib["value"]) if radius_element is not None else 1.0 # Center. center_element = element.find("point[@name='center']") center = asr.Vector3d(get_vector(center_element)) if center_element is not None else asr.Vector3d(0.0) # Object. object_name = make_new_object_name(assembly) object = asr.create_primitive_mesh(object_name, { "primitive": "sphere", "resolution_u": 32, "resolution_v": 16, "radius": radius }) # Instance transform. matrix = asr.Matrix4d.make_translation(center) matrix_element = element.find("transform[@name='toWorld']/matrix") if matrix_element is not None: # todo: no idea what is the right multiplication order, untested. matrix = matrix * get_matrix(matrix_element) transform = asr.Transformd(matrix) # Instance material. material_name = process_shape_material(scene, assembly, object_name, element) instance = make_object_instance(assembly, object, material_name, transform) assembly.object_instances().insert(instance) assembly.objects().insert(object)
def convert_disk_shape(scene, assembly, element): # Radius. radius_element = element.find("float[@name='radius']") radius = float( radius_element.attrib["value"]) if radius_element is not None else 1.0 # Object. object_name = make_new_object_name(assembly) object = asr.create_primitive_mesh( object_name, { "primitive": "disk", "resolution_u": 1, "resolution_v": 32, "radius": radius }) # Instance transform. matrix = get_matrix(element.find("transform[@name='toWorld']/matrix")) rotx = asr.Matrix4d.make_rotation(asr.Vector3d(1.0, 0.0, 0.0), math.radians(90.0)) matrix = matrix * rotx transform = asr.Transformd(matrix) # Instance material. material_name = process_shape_material(scene, assembly, object_name, element) instance = make_object_instance(assembly, object, material_name, transform) assembly.object_instances().insert(instance) assembly.objects().insert(object)
def convert_sun_emitter(scene, assembly, emitter_name, element): sun_params = {} turbidity = element.find("float[@name='turbidity']") if turbidity is not None: sun_params["turbidity"] = float(turbidity.attrib["value"]) - 2.0 else: sun_params["turbidity"] = 1.0 scale = element.find("float[@name='scale']") if scale is not None: sun_params["radiance_multiplier"] = float(scale.attrib["value"]) sun = asr.Light("sun_light", "sun_light", sun_params) sun_direction = element.find("vector[@name='sunDirection']") if sun_direction is not None: from_direction = asr.Vector3d(0.0, 0.0, 1.0) to_direction = asr.Vector3d(get_vector(sun_direction)) sun.set_transform( asr.Transformd( asr.Matrix4d.make_rotation( asr.Quaterniond.make_rotation(from_direction, to_direction)))) assembly.lights().insert(sun)
def convert_rectangle_shape(scene, assembly, element): # Object. object_name = make_new_object_name(assembly) object = asr.create_primitive_mesh( object_name, { "primitive": "grid", "resolution_u": 1, "resolution_v": 1, "width": 2.0, "height": 2.0 }) # Instance transform. matrix = get_matrix(element.find("transform[@name='toWorld']/matrix")) rotx = asr.Matrix4d.make_rotation(asr.Vector3d(1.0, 0.0, 0.0), math.radians(90.0)) matrix = matrix * rotx transform = asr.Transformd(matrix) # Instance material. material_name = process_shape_material(scene, assembly, object_name, element) instance = make_object_instance(assembly, object, material_name, transform) assembly.object_instances().insert(instance) assembly.objects().insert(object)
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))
def convert_envmap_emitter(scene, emitter_name, element): filepath = element.find("string[@name='filename']").attrib["value"] texture_instance_name = create_texture(scene, "environment_map", filepath) env_edf = asr.EnvironmentEDF("latlong_map_environment_edf", "environment_edf", {"radiance": texture_instance_name}) matrix_element = element.find("transform[@name='toWorld']/matrix") if matrix_element is not None: matrix = get_matrix(matrix_element) roty = asr.Matrix4d.make_rotation(asr.Vector3d(0.0, 1.0, 0.0), math.radians(-90.0)) matrix = matrix * roty env_edf.transform_sequence().set_transform(0.0, asr.Transformd(matrix)) scene.environment_edfs().insert(env_edf) scene.environment_shaders().insert( asr.EnvironmentShader("edf_environment_shader", "environment_shader", {"environment_edf": 'environment_edf'})) scene.set_environment( asr.Environment( "environment", { "environment_edf": "environment_edf", "environment_shader": "environment_shader" }))
def __create_backdrop(self, preview_template_dir): # Define the background plane plane = asr.MeshObjectReader.read( [], "plane_obj", { 'filename': os.path.join(preview_template_dir, 'material_preview_ground.binarymesh') }) plane_inst = asr.ObjectInstance( "plane", {}, "plane_obj.part_0", asr.Transformd(asr.Matrix4d.identity()), {'default': "plane_mat"}) plane_mat = asr.Material("generic_material", "plane_mat", { 'bsdf': "plane_bsdf", 'surface_shader': "base_shader" }) plane_bsdf = asr.BSDF("lambertian_brdf", "plane_bsdf", {'reflectance': "plane_tex"}) plane_tex = asr.Texture( "disk_texture_2d", "plane_tex_tex", { 'filename': os.path.join(preview_template_dir, "checker_texture.png"), 'color_space': 'srgb' }, []) plane_tex_inst = asr.TextureInstance( "plane_tex", {}, "plane_tex_tex", asr.Transformf(asr.Matrix4f.identity())) return plane, plane_bsdf, plane_inst, plane_mat, plane_tex, plane_tex_inst
def __create_sphere(self, preview_template_dir): # Define the sphere preview object. sphere = asr.MeshObjectReader.read(self.__project.get_search_paths(), "sphere_obj", {'filename': os.path.join(preview_template_dir, 'material_preview_sphere.binarymesh')}) sphere_inst = asr.ObjectInstance("sphere", {}, "sphere_obj.part_0", asr.Transformd(asr.Matrix4d.identity()), {'default': "preview_mat"}, {'default': "preview_mat"}) return sphere, sphere_inst
def __create_project(self): """ Creates the base project. """ logger.debug("Creating appleseed project") self.__project = asr.Project(self.bl_scene.name) # Render settings. self.__project.add_default_configurations() # Create the scene. self.__project.set_scene(asr.Scene()) # Create the environment. self.__project.get_scene().set_environment(asr.Environment("environment", {})) # Create the main assembly. self.__project.get_scene().assemblies().insert(asr.Assembly("assembly", {})) self.__main_assembly = self.__project.get_scene().assemblies()["assembly"] # Instance the main assembly. assembly_inst = asr.AssemblyInstance("assembly_inst", {}, "assembly") assembly_inst.transform_sequence().set_transform(0.0, asr.Transformd(asr.Matrix4d.identity())) self.__project.get_scene().assembly_instances().insert(assembly_inst) # Create default materials. self.__create_default_material() self.__create_null_material()
def _convert_matrix(m): """ Converts a Blender matrix to an appleseed matrix We have the following conventions: Both Blender and appleseed use right-hand coordinate systems. Both Blender and appleseed use column-major matrices. Both Blender and appleseed use pre-multiplication. In Blender, given a matrix m, m[i][j] is the element at the i'th row, j'th column. The only difference between the coordinate systems of Blender and appleseed is the up vector: in Blender, up is Z+; in appleseed, up is Y+. So we need to add a -90 degree rotation along the x axis to translate. :param m: Input Blender object matrix :return: appleseed transform of the modified matrix """ matrix = asr.Matrix4d([ m[0][0], m[0][1], m[0][2], m[0][3], m[1][0], m[1][1], m[1][2], m[1][3], m[2][0], m[2][1], m[2][2], m[2][3], m[3][0], m[3][1], m[3][2], m[3][3] ]) rotation_modify = asr.Matrix4d.make_rotation( asr.Vector3d(1.0, 0.0, 0.0), math.radians(-90.0)) matrix = rotation_modify * matrix return asr.Transformd(matrix)
def __create_camera(self, scene): # Define the render camera camera = asr.Camera('pinhole_camera', "preview_camera", {"film_width": 0.032, "focal_length": 0.035, "aspect_ratio": util.get_frame_aspect_ratio(scene)}) camera_matrix = asr.Matrix4d([1.0, 0.0, 0.0, -0.03582507744431496, 0.0, -4.371138828673793e-08, -1.0, -2.135615587234497, 0.0, 1.0, -4.371138828673793e-08, 0.5015512704849243, 0.0, 0.0, 0.0, 1.0]) camera.transform_sequence().set_transform(0.0, asr.Transformd(camera_matrix)) self.__project.get_scene().cameras().insert(camera)
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
def __create_project(self): # Create the environment. self.__project.get_scene().set_environment(asr.Environment("environment", {})) # Create the main assembly. self.__project.get_scene().assemblies().insert(asr.Assembly("assembly", {})) self.__main_assembly = self.__project.get_scene().assemblies()["assembly"] # Instance the main assembly. assembly_inst = asr.AssemblyInstance("assembly_inst", {}, "assembly") assembly_inst.transform_sequence().set_transform(0.0, asr.Transformd(asr.Matrix4d.identity())) self.__project.get_scene().assembly_instances().insert(assembly_inst) # Path to the .binarymesh models needed for the preview render preview_template_dir = os.path.join(os.path.dirname(os.path.dirname(util.realpath(__file__))), "mat_preview") return preview_template_dir
def convert_cube_shape(scene, assembly, element): # Object. object_name = make_new_object_name(assembly) object = asr.create_primitive_mesh(object_name, {"primitive": "cube"}) # Instance transform. matrix_element = element.find("transform[@name='toWorld']/matrix") matrix = get_matrix(matrix_element) if matrix_element is not None else asr.Matrix4d.identity() transform = asr.Transformd(matrix) # Instance material. material_name = process_shape_material(scene, assembly, object_name, element) instance = make_object_instance(assembly, object, material_name, transform) assembly.object_instances().insert(instance) assembly.objects().insert(object)
def convert_obj_shape(project, scene, assembly, element): # Read OBJ file from disk and create objects. object_name = make_new_object_name(assembly) filepath = element.find("string[@name='filename']").attrib["value"] objects = asr.MeshObjectReader.read(project.get_search_paths(), object_name, {"filename": filepath}) # Instance transform. matrix = get_matrix(element.find("transform[@name='toWorld']/matrix")) transform = asr.Transformd(matrix) # Instance material. material_name = process_shape_material(scene, assembly, object_name, element) for object in objects: instance = make_object_instance(assembly, object, material_name, transform) assembly.object_instances().insert(instance) assembly.objects().insert(object)
def update_obj_instance(self): self.__ass.object_instances().remove(self.__as_mesh_inst) self.__as_mesh_inst_params = self.__get_mesh_inst_params() self.__front_materials, self.__back_materials = self.__get_material_mappings( ) mesh_name = self.__object_instance_mesh_name(self.orig_name) self.__as_mesh_inst = asr.ObjectInstance( self.__obj_inst_name, self.__as_mesh_inst_params, mesh_name, asr.Transformd(asr.Matrix4d().identity()), self.__front_materials, self.__back_materials) self.__ass.object_instances().insert(self.__as_mesh_inst) self.__as_mesh_inst = self.__ass.object_instances().get_by_name( self.__obj_inst_name)
def convert(tree): project = asr.Project("project") # Search paths. paths = project.get_search_paths() paths.append("models") paths.append("textures") project.set_search_paths(paths) # Add default configurations to the project. project.add_default_configurations() # Enable caustics. project.configurations().get_by_name("final").insert_path( "pt.enable_caustics", True) project.configurations().get_by_name("interactive").insert_path( "pt.enable_caustics", True) # Create a scene. scene = asr.Scene() # Create an assembly. assembly = asr.Assembly("assembly") assembly.surface_shaders().insert( asr.SurfaceShader("physical_surface_shader", "physical_surface_shader")) # Convert the Mitsuba scene. convert_scene(project, scene, assembly, tree.getroot()) # Create an instance of the assembly. 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) # Bind the scene to the project. project.set_scene(scene) return project
def update_object(self, context, depsgraph, as_assembly, textures_to_add, as_texture_translators): logger.debug("Updating translator for %s", self.appleseed_name) mesh_name = self.__object_instance_mesh_name( f"{self.appleseed_name}_obj") self.__as_mesh_inst_params = self.__get_mesh_inst_params() self.__front_materials, self.__back_materials = self.__get_material_mappings( ) self.__ass.object_instances().remove(self.__as_mesh_inst) self.__as_mesh_inst = asr.ObjectInstance( self.appleseed_name, self.__as_mesh_inst_params, mesh_name, asr.Transformd(asr.Matrix4d().identity()), self.__front_materials, self.__back_materials) self.__ass.object_instances().insert(self.__as_mesh_inst) self.__as_mesh_inst = self.__ass.object_instances().get_by_name( self.appleseed_name)
def _convert_matrix(m): """ Converts a Blender matrix to an appleseed matrix We have the following conventions: Both Blender and appleseed use right-hand coordinate systems. Both Blender and appleseed use column-major matrices. Both Blender and appleseed use pre-multiplication. In Blender, given a matrix m, m[i][j] is the element at the i'th row, j'th column. The only difference between the coordinate systems of Blender and appleseed is the up vector: in Blender, up is Z+; in appleseed, up is Y+. """ matrix = asr.Matrix4d([m[0][0], m[0][1], m[0][2], m[0][3], m[1][0], m[1][1], m[1][2], m[1][3], m[2][0], m[2][1], m[2][2], m[2][3], m[3][0], m[3][1], m[3][2], m[3][3]]) return asr.Transformd(matrix)
def flush_entities(self, as_scene, as_assembly, as_project): logger.debug("appleseed: Flushing world entity to project") if self.__as_env_type != 'none': self.__as_env_edf.transform_sequence().set_transform( 0.0, asr.Transformd(self._convert_matrix(asr.Matrix4d.identity()))) for index, color in enumerate(self.__as_colors): color_name = color.get_name() as_scene.colors().insert(color) self.__as_colors[index] = as_scene.colors().get_by_name( color_name) as_env_edf_name = self.__as_env_edf.get_name() as_scene.environment_edfs().insert(self.__as_env_edf) self.__as_env_edf = as_scene.environment_edfs().get_by_name( as_env_edf_name) as_env_shader_name = self.__as_env_shader.get_name() as_scene.environment_shaders().insert(self.__as_env_shader) self.__as_env_shader = as_scene.environment_shaders().get_by_name( as_env_shader_name) as_scene.set_environment(self.__as_env)
def create_entities(self, scene): as_sky = self.bl_scene.world.appleseed_sky env_type = as_sky.env_type if env_type == 'sunsky': env_type = as_sky.sun_model if env_type == 'constant': self.__colors.append( asr.ColorEntity( 'horizon_radiance_color', {'color_space': 'linear_rgb'}, self._convert_color(self.bl_scene.world.horizon_color))) elif env_type in ('gradient', 'constant_hemisphere'): self.__colors.append( asr.ColorEntity( 'horizon_radiance_color', {'color_space': 'srgb'}, self._convert_color(self.bl_scene.world.horizon_color))) self.__colors.append( asr.ColorEntity( 'zenith_radiance_color', {'color_space': 'linear_rgb'}, self._convert_color(self.bl_scene.world.zenith_color))) if env_type in ('latlong_map', 'mirrorball_map'): try: filename = self.asset_handler.process_path( as_sky.env_tex.filepath, AssetType.TEXTURE_ASSET) except: logger.warning("No Texture Selected!") filename = "" tex_inst_params = { 'addressing_mode': 'wrap', 'filtering_mode': 'bilinear' } self.__env_tex = asr.Texture( 'disk_texture_2d', 'environment_tex', { 'filename': filename, 'color_space': as_sky.env_tex_colorspace }, []) self.__env_tex_inst = asr.TextureInstance( 'environment_tex_inst', tex_inst_params, 'environment_tex', asr.Transformf(asr.Matrix4f.identity())) if env_type == 'latlong_map': edf_params = { 'radiance': "environment_tex_inst", 'radiance_multiplier': as_sky.env_tex_mult, 'exposure': as_sky.env_exposure } elif env_type == 'mirrorball_map': edf_params = { 'radiance': "environment_tex_inst", 'exposure': as_sky.env_exposure, 'radiance_multiplier': as_sky.env_tex_mult } elif env_type == 'constant': edf_params = {'radiance': 'horizon_radiance_color'} elif env_type == 'gradient': edf_params = { 'horizon_radiance': "horizon_radiance_color", 'zenith_radiance': "zenith_radiance_color" } elif env_type == 'constant_hemisphere': edf_params = { 'lower_hemi_radiance': "horizon_radiance_color", 'upper_hemi_radiance': "zenith_radiance_color" } else: edf_params = { 'ground_albedo': as_sky.ground_albedo, 'sun_phi': as_sky.sun_phi, 'sun_theta': as_sky.sun_theta, 'turbidity': as_sky.turbidity, 'turbidity_multiplier': as_sky.turbidity_multiplier, 'luminance_multiplier': as_sky.luminance_multiplier, 'luminance_gamma': as_sky.luminance_gamma, 'saturation_multiplier': as_sky.saturation_multiplier, 'horizon_shift': as_sky.horizon_shift } self.__as_env_edf = asr.EnvironmentEDF(env_type + "_environment_edf", "sky_edf", edf_params) self.__as_env_shader = asr.EnvironmentShader( "edf_environment_shader", "sky_shader", { 'environment_edf': 'sky_edf', 'alpha_value': as_sky.env_alpha }) self.__as_env = asr.Environment("sky", { "environment_edf": "sky_edf", "environment_shader": "sky_shader" }) self.__as_env_edf.transform_sequence().set_transform( 0.0, asr.Transformd(self._convert_matrix(asr.Matrix4d.identity())))
def flush_entities(self, assembly): # Compute tangents if needed. if self.__export_mode != ProjectExportMode.PROJECT_EXPORT: if self.bl_obj.data.appleseed.smooth_tangents and self.bl_obj.data.appleseed.export_uvs: asr.compute_smooth_vertex_tangents(self.__mesh_object) asr_obj_props = self.bl_obj.appleseed mesh_name = self.__mesh_object.get_name() object_instance_params = {'visibility': {'camera': asr_obj_props.camera_visible, 'light': asr_obj_props.light_visible, 'shadow': asr_obj_props.shadow_visible, 'diffuse': asr_obj_props.diffuse_visible, 'glossy': asr_obj_props.glossy_visible, 'specular': asr_obj_props.specular_visible, 'transparency': asr_obj_props.transparency_visible}, 'medium_priority': asr_obj_props.medium_priority, 'ray_bias_method': asr_obj_props.object_ray_bias_method, 'ray_bias_distance': asr_obj_props.object_ray_bias_distance} if asr_obj_props.object_sss_set != "": object_instance_params['sss_set_id'] = asr_obj_props.object_sss_set if self.__export_mode == ProjectExportMode.PROJECT_EXPORT: # Replace the MeshObject by an empty one referencing # the binarymesh files we saved before. params = {} if len(self.__mesh_filenames) == 1: # No motion blur. Write a single filename. params['filename'] = "_geometry/" + self.__mesh_filenames[0] else: # Motion blur. Write one filename per motion pose. params['filename'] = {} for i, f in enumerate(self.__mesh_filenames): params['filename'][str(i)] = "_geometry/" + f self.__mesh_object = asr.MeshObject(mesh_name, params) self._xform_seq.optimize() logger.debug( "Flushing object %s, num instances = %s, num xform keys = %s", self.appleseed_name, self._num_instances, self._xform_seq.size()) if self.__export_mode == ProjectExportMode.INTERACTIVE_RENDER: # We always create assemblies when doing IPR to allow quick xform edits. needs_assembly = True else: # Only create an assembly if the object is instanced or has xform motion blur. needs_assembly = self._num_instances > 1 or self._xform_seq.size() > 1 if needs_assembly: logger.debug("Creating assembly for object %s, name: %s", mesh_name, self.assembly_name) ass = asr.Assembly(self.assembly_name) logger.debug("Creating object instance for object %s, name: %s", mesh_name, self.appleseed_name) obj_inst = asr.ObjectInstance( self.appleseed_name, object_instance_params, self.__object_instance_mesh_name(mesh_name), asr.Transformd(asr.Matrix4d().identity()), self.__front_materials, self.__back_materials) ass.objects().insert(self.__mesh_object) self.__mesh_object = ass.objects().get_by_name(mesh_name) obj_inst_name = obj_inst.get_name() ass.object_instances().insert(obj_inst) self.__obj_inst = ass.object_instances().get_by_name(obj_inst_name) assembly_instance_name = self.assembly_name + "_inst" logger.debug("Creating assembly instance for object %s, name: %s", mesh_name, assembly_instance_name) ass_name = self._insert_entity_with_unique_name(assembly.assemblies(), ass, ass.get_name()) self.__ass = assembly.assemblies().get_by_name(ass_name) ass_inst = asr.AssemblyInstance( assembly_instance_name, {}, ass_name) ass_inst.set_transform_sequence(self._xform_seq) ass_inst_name = self._insert_entity_with_unique_name(assembly.assembly_instances(), ass_inst, ass_inst.get_name()) self.__ass_inst = assembly.assembly_instances().get_by_name(ass_inst_name) if self.__alpha_tex is not None: self.__ass.textures().insert(self.__alpha_tex) if self.__alpha_tex_inst is not None: self.__ass.texture_instances().insert(self.__alpha_tex_inst) else: logger.debug("Creating object instance for object %s, name: %s", mesh_name, self.appleseed_name) mesh_name = self._insert_entity_with_unique_name(assembly.objects(), self.__mesh_object, mesh_name) self.__mesh_object = assembly.objects().get_by_name(mesh_name) obj_inst = asr.ObjectInstance( self.appleseed_name, object_instance_params, self.__object_instance_mesh_name(mesh_name), self._xform_seq.get_earliest_transform(), self.__front_materials, self.__back_materials) obj_inst_name = self._insert_entity_with_unique_name(assembly.object_instances(), obj_inst, obj_inst.get_name()) self.__obj_inst = assembly.object_instances().get_by_name(obj_inst_name) if self.__alpha_tex is not None: assembly.textures().insert(self.__alpha_tex) if self.__alpha_tex_inst is not None: assembly.texture_instances().insert(self.__alpha_tex_inst)
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 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
def flush_entities(self, as_assembly, as_project): logger.debug("Flushing entity for %s", self.appleseed_name) for instance in self.__instances.values(): instance.optimize() mesh_name = f"{self.appleseed_name}_obj" if self.__export_mode == ProjectExportMode.PROJECT_EXPORT: # Replace the MeshObject by an empty one referencing # the binarymesh files we saved before. params = {} if len(self.__mesh_filenames) == 1: # No motion blur. Write a single filename. params['filename'] = "_geometry/" + self.__mesh_filenames[0] else: # Motion blur. Write one filename per motion pose. params['filename'] = {} for i, f in enumerate(self.__mesh_filenames): params['filename'][str(i)] = "_geometry/" + f self.__as_mesh = asr.MeshObject(mesh_name, params) mesh_name = self.__object_instance_mesh_name( f"{self.appleseed_name}_obj") if self.__export_mode == ProjectExportMode.INTERACTIVE_RENDER or len( self.__instances) > 1: self.__has_assembly = True else: for instance in self.__instances.values(): xform_seq = instance if xform_seq.size() > 1: self.__has_assembly = True if self.__has_assembly: self.__as_mesh_inst = asr.ObjectInstance( self.appleseed_name, self.__as_mesh_inst_params, mesh_name, asr.Transformd(asr.Matrix4d().identity()), self.__front_materials, self.__back_materials) ass_name = f"{self.appleseed_name}_ass" self.__ass = asr.Assembly(ass_name) self.__ass.objects().insert(self.__as_mesh) self.__as_mesh = self.__ass.objects().get_by_name(mesh_name) self.__ass.object_instances().insert(self.__as_mesh_inst) self.__as_mesh_inst = self.__ass.object_instances().get_by_name( self.appleseed_name) as_assembly.assemblies().insert(self.__ass) self.__ass = as_assembly.assemblies().get_by_name(ass_name) for key, transform_matrix in self.__instances.items(): ass_inst_name = f"{key}_ass_inst" ass_inst = asr.AssemblyInstance(ass_inst_name, {}, ass_name) ass_inst.set_transform_sequence(transform_matrix) as_assembly.assembly_instances().insert(ass_inst) self.__instances[key] = as_assembly.assembly_instances( ).get_by_name(ass_inst_name) else: self.__as_mesh_inst = asr.ObjectInstance( self.appleseed_name, self.__as_mesh_inst_params, mesh_name, xform_seq.get_earliest_transform(), self.__front_materials, self.__back_materials) as_assembly.objects().insert(self.__as_mesh) self.__as_mesh = as_assembly.objects().get_by_name(mesh_name) as_assembly.object_instances().insert(self.__as_mesh_inst) self.__as_mesh_inst = as_assembly.object_instances().get_by_name( self.appleseed_name)
def update_lamp(self, depsgraph, as_main_assembly, as_scene, as_project): logger.debug(f"appleseed: Updating lamp entity for {self.orig_name}") as_lamp_data = self.bl_lamp.data.appleseed current_model = self.__lamp_model self.__lamp_model = self.__get_lamp_model() if current_model == self.__lamp_model: if self.__lamp_model != 'area_lamp': # Check if the radiance has changed. current_radiance = self.__radiance self.__radiance = self._convert_color(as_lamp_data.radiance) if current_radiance != self.__radiance: as_main_assembly.colors().remove(self.__as_lamp_radiance) lamp_radiance_name = f"{self.orig_name}_radiance" self.__as_lamp_radiance = asr.ColorEntity( lamp_radiance_name, {'color_space': 'linear_rgb'}, self.__radiance) as_main_assembly.colors().insert(self.__as_lamp_radiance) self.__as_lamp_radiance = as_main_assembly.colors( ).get_by_name(lamp_radiance_name) # Update lamp parameters. if self.__lamp_model == 'point_light': self.__as_lamp_params = self.__get_point_lamp_params() if self.__lamp_model == 'spot_light': self.__as_lamp_params = self.__get_spot_lamp_params() if self.__lamp_model == 'directional_light': self.__as_lamp_params = self.__get_directional_lamp_params( ) if self.__lamp_model == 'sun_light': self.__as_lamp_params = self.__get_sun_lamp_params() self.__as_lamp.set_parameters(self.__as_lamp_params) else: self.__ass.object_instances().remove(self.__as_area_lamp_inst) self.__ass.objects().remove(self.__as_area_lamp_mesh) shape_params = self._get_area_mesh_params() mesh_name = f"{self.orig_name}_mesh" mat_name = f"{self.orig_name}_mat" self.__as_area_lamp_mesh = asr.create_primitive_mesh( mesh_name, shape_params) self.__instance_params = self._get_area_mesh_instance_params() self.__as_area_lamp_inst = asr.ObjectInstance( self.__as_area_lamp_inst_name, self.__instance_params, mesh_name, asr.Transformd(asr.Matrix4d().identity()), {"default": mat_name}, {"default": "__null_material"}) self.__ass.objects().insert(self.__as_area_lamp_mesh) self.__as_area_lamp_mesh = self.__ass.objects().get_by_name( mesh_name) self.__ass.object_instances().insert(self.__as_area_lamp_inst) self.__as_area_lamp_inst = self.__ass.object_instances( ).get_by_name(self.__as_area_lamp_inst_name) if self.bl_lamp.data.use_nodes: if self.__as_area_lamp_shadergroup is not None: as_main_assembly.shader_groups().remove( self.__as_area_lamp_shadergroup) self.__as_area_lamp_shadergroup = None self.__node_tree = NodeTreeTranslator( self.bl_lamp.data.node_tree, self._asset_handler, self.orig_name) self.__node_tree.create_entities(depsgraph.scene_eval) else: self.__node_tree.update_nodetree(depsgraph.scene_eval) else: if self.__node_tree is not None: self.__node_tree.delete_nodetree(as_main_assembly) self.__node_tree = None shader_name = f"{self.orig_name}_tree" self.__as_area_lamp_shadergroup = asr.ShaderGroup( shader_name) self._set_shadergroup() else: self._set_shadergroup() else: # Delete current light. if current_model != 'area_lamp': self.__ass.lights().remove(self.__as_lamp) as_main_assembly.colors().remove(self.__as_lamp_radiance) else: self.__ass.objects().remove(self.__as_area_lamp_mesh) self.__ass.object_instances().remove(self.__as_area_lamp_inst) as_main_assembly.materials().remove( self.__as_area_lamp_material) if self.__as_area_lamp_shadergroup is not None: as_main_assembly.shader_groups().remove( self.__as_area_lamp_shadergroup) self.__as_area_lamp_shadergroup = None else: self.__node_tree.delete_nodetree(as_main_assembly) # Create new light. self.create_entities(depsgraph, 0) if self.__lamp_model != 'area_lamp': radiance_name = self.__as_lamp_radiance.get_name() as_main_assembly.colors().insert(self.__as_lamp_radiance) self.__as_lamp_radiance = as_main_assembly.colors( ).get_by_name(radiance_name) self.__ass.lights().insert(self.__as_lamp) self.__as_lamp = self.__ass.lights().get_by_name( self.orig_name) else: mat_name = f"{self.orig_name}_mat" mesh_name = f"{self.orig_name}_mesh" self.__as_area_lamp_inst_name = f"{self.orig_name}_inst" as_main_assembly.materials().insert( self.__as_area_lamp_material) self.__as_area_lamp_material = as_main_assembly.materials( ).get_by_name(mat_name) if self.__as_area_lamp_shadergroup is not None: shadergroup_name = self.__as_area_lamp_shadergroup.get_name( ) as_main_assembly.shader_groups().insert( self.__as_area_lamp_shadergroup) self.__as_area_lamp_shadergroup = as_main_assembly.shader_groups( ).get_by_name(shadergroup_name) else: self.__node_tree.flush_entities(as_scene, as_main_assembly, as_project) self.__as_area_lamp_inst = asr.ObjectInstance( self.__as_area_lamp_inst_name, self.__instance_params, mesh_name, asr.Transformd(asr.Matrix4d().identity()), {"default": mat_name}, {"default": "__null_material"}) self.__ass.objects().insert(self.__as_area_lamp_mesh) self.__as_area_lamp_mesh = self.__ass.objects().get_by_name( mesh_name) self.__ass.object_instances().insert(self.__as_area_lamp_inst) self.__as_area_lamp_inst = self.__ass.object_instances( ).get_by_name(self.__as_area_lamp_inst_name)
def flush_entities(self, as_scene, as_main_assembly, as_project): logger.debug( f"appleseed: Flushing lamp entity for {self.orig_name} to project") self.__instance_lib.optimize_xforms() needs_assembly = self.__export_mode == ProjectExportMode.INTERACTIVE_RENDER or self.__instance_lib.needs_assembly( ) if self.__lamp_model != 'area_lamp': radiance_name = self.__as_lamp_radiance.get_name() as_main_assembly.colors().insert(self.__as_lamp_radiance) self.__as_lamp_radiance = as_main_assembly.colors().get_by_name( radiance_name) if needs_assembly: self.__ass_name = f"{self.orig_name}_ass" self.__ass = asr.Assembly(self.__ass_name) self.__ass.lights().insert(self.__as_lamp) self.__as_lamp = self.__ass.lights().get_by_name( self.orig_name) as_main_assembly.assemblies().insert(self.__ass) self.__ass = as_main_assembly.assemblies().get_by_name( self.__ass_name) self.flush_instances(as_main_assembly) else: self.__as_lamp.set_transform( self.__instance_lib.get_single_transform()) as_main_assembly.lights().insert(self.__as_lamp) self.__as_lamp = as_main_assembly.lights().get_by_name( self.obj_name) else: mat_name = f"{self.orig_name}_mat" mesh_name = f"{self.orig_name}_mesh" self.__as_area_lamp_inst_name = f"{self.orig_name}_inst" as_main_assembly.materials().insert(self.__as_area_lamp_material) self.__as_area_lamp_material = as_main_assembly.materials( ).get_by_name(mat_name) if self.__as_area_lamp_shadergroup is not None: shadergroup_name = self.__as_area_lamp_shadergroup.get_name() as_main_assembly.shader_groups().insert( self.__as_area_lamp_shadergroup) self.__as_area_lamp_shadergroup = as_main_assembly.shader_groups( ).get_by_name(shadergroup_name) else: self.__node_tree.flush_entities(as_scene, as_main_assembly, as_project) if needs_assembly: self.__as_area_lamp_inst = asr.ObjectInstance( self.__as_area_lamp_inst_name, self.__instance_params, mesh_name, asr.Transformd(asr.Matrix4d().identity()), {"default": mat_name}, {"default": "__null_material"}) self.__ass_name = f"{self.orig_name}_ass" self.__ass = asr.Assembly(self.__ass_name) self.__ass.objects().insert(self.__as_area_lamp_mesh) self.__as_area_lamp_mesh = self.__ass.objects().get_by_name( mesh_name) self.__ass.object_instances().insert(self.__as_area_lamp_inst) self.__as_area_lamp_inst = self.__ass.object_instances( ).get_by_name(self.__as_area_lamp_inst_name) as_main_assembly.assemblies().insert(self.__ass) self.__ass = as_main_assembly.assemblies().get_by_name( self.__ass_name) self.flush_instances(as_main_assembly) else: self.__as_area_lamp_inst = asr.ObjectInstance( self.__as_area_lamp_inst_name, self.__instance_params, mesh_name, self.__instance_lib.get_single_transform(), {"default": mat_name}, {"default": "__null_material"}) as_main_assembly.objects().insert(self.__as_area_lamp_mesh) self.__as_area_lamp_mesh = as_main_assembly.objects( ).get_by_name(mesh_name) as_main_assembly.object_instances().insert( self.__as_area_lamp_inst) self.__as_mesh_inst = as_main_assembly.object_instances( ).get_by_name(self.__as_area_lamp_inst_name)
def _convert_matrix(self, m): matrix = asr.Matrix4d(super()._convert_matrix(m)) return asr.Transformd(matrix)
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 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