def convert_area_emitter(assembly, emitter_name, element): if emitter_name is None: fatal("Area emitters must have a name") edf_params = {} radiance = element.find("*[@name='radiance']") edf_params["radiance"] = convert_colormap(assembly, emitter_name, radiance) assembly.edfs().insert(asr.EDF("diffuse_edf", emitter_name, edf_params))
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 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