def configure_lighting(sim): light_setup = [ LightInfo( vector=[1.0, 1.0, 0.0, 1.0], color=[18.0, 18.0, 18.0], model=LightPositionModel.Global, ), LightInfo( vector=[0.0, -1.0, 0.0, 1.0], color=[5.0, 5.0, 5.0], model=LightPositionModel.Global, ), LightInfo( vector=[-1.0, 1.0, 1.0, 1.0], color=[18.0, 18.0, 18.0], model=LightPositionModel.Global, ), ] sim.set_light_setup(light_setup)
def test_set_custom_light_setup(sim): custom_setup_key = "custom_setup_key" light_setup = sim.get_light_setup(custom_setup_key) assert len(light_setup) == 0 light_setup.append(LightInfo(position=[1.0, 1.0, 1.0])) assert sim.get_light_setup() != light_setup sim.set_light_setup(light_setup, custom_setup_key) assert sim.get_light_setup(custom_setup_key) == light_setup
def test_set_custom_light_setup(make_cfg_settings): with habitat_sim.Simulator(make_cfg(make_cfg_settings)) as sim: custom_setup_key = "custom_setup_key" light_setup = sim.get_light_setup(custom_setup_key) assert len(light_setup) == 0 light_setup.append(LightInfo(position=[1.0, 1.0, 1.0])) assert sim.get_light_setup() != light_setup sim.set_light_setup(light_setup, custom_setup_key) assert sim.get_light_setup(custom_setup_key) == light_setup
def test_set_default_light_setup(sim): light_setup = [LightInfo(position=[1.0, 1.0, 1.0])] sim.set_light_setup(light_setup) assert sim.get_light_setup() == light_setup # ensure modifications to local light setup variable are not reflected in sim light_setup[0].model = LightPositionModel.CAMERA assert sim.get_light_setup() != light_setup sim.set_light_setup(light_setup, DEFAULT_LIGHTING_KEY) assert sim.get_light_setup() == light_setup
def test_set_default_light_setup(make_cfg_settings): with habitat_sim.Simulator(make_cfg(make_cfg_settings)) as sim: light_setup = [LightInfo(position=[1.0, 1.0, 1.0])] sim.set_light_setup(light_setup) assert sim.get_light_setup() == light_setup # ensure modifications to local light setup variable are not reflected in sim light_setup[0].model = LightPositionModel.CAMERA assert sim.get_light_setup() != light_setup sim.set_light_setup(light_setup, DEFAULT_LIGHTING_KEY) assert sim.get_light_setup() == light_setup
def test_set_custom_light_setup(make_cfg_settings): with habitat_sim.Simulator(make_cfg(make_cfg_settings)) as sim: custom_setup_key = "custom_setup_key" light_setup = sim.get_light_setup(custom_setup_key) assert len(light_setup) == 0 # define a point light (w == 1) light_setup.append(LightInfo(vector=[1.0, 1.0, 1.0, 1.0])) assert sim.get_light_setup() != light_setup sim.set_light_setup(light_setup, custom_setup_key) assert sim.get_light_setup(custom_setup_key) == light_setup
def load_light_setup_for_glb(json_filepath): with open(json_filepath) as json_file: data = json.load(json_file) lighting_setup = [] for light in data["lights"].values(): t = light["position"] light_w = 1.0 position = [float(t[0]), float(t[1]), float(t[2]), light_w] color_scale = float(light["intensity"]) color = [float(c * color_scale) for c in light["color"]] lighting_setup.append( LightInfo( vector=position, color=color, model=LightPositionModel.Global, )) return lighting_setup
def main(show_imgs=True, save_imgs=False): if save_imgs and not os.path.exists(output_path): os.mkdir(output_path) # [default scene lighting] # create the simulator and render flat shaded scene cfg = make_configuration() sim = habitat_sim.Simulator(cfg) agent_transform = place_agent(sim) get_obs(sim, show_imgs, save_imgs) # [scene swap shader] # close the simulator and re-initialize with DEFAULT_LIGHTING_KEY: sim.close() cfg = make_configuration() cfg.sim_cfg.scene_light_setup = habitat_sim.gfx.DEFAULT_LIGHTING_KEY sim = habitat_sim.Simulator(cfg) agent_transform = place_agent(sim) get_obs(sim, show_imgs, save_imgs) # create and register new light setup: my_scene_lighting_setup = [ LightInfo(vector=[0.0, 2.0, 0.6, 0.0], model=LightPositionModel.GLOBAL) ] sim.set_light_setup(my_scene_lighting_setup, "my_scene_lighting") # reconfigure with custom key: new_cfg = make_configuration() new_cfg.sim_cfg.scene_light_setup = "my_scene_lighting" sim.reconfigure(new_cfg) agent_transform = place_agent(sim) get_obs(sim, show_imgs, save_imgs) # [/scene] # reset to default scene shading sim.close() cfg = make_configuration() sim = habitat_sim.Simulator(cfg) agent_transform = place_agent(sim) # noqa: F841 # [example 2] # get the physics object attributes manager obj_templates_mgr = sim.get_object_template_manager() # load some object templates from configuration files sphere_template_id = obj_templates_mgr.load_configs( str(os.path.join(data_path, "test_assets/objects/sphere")))[0] chair_template_id = obj_templates_mgr.load_configs( str(os.path.join(data_path, "test_assets/objects/chair")))[0] id_1 = sim.add_object(sphere_template_id) sim.set_translation([3.2, 0.23, 0.03], id_1) get_obs(sim, show_imgs, save_imgs) # [/example 2] # [example 3] # create a custom light setup my_default_lighting = [ LightInfo(vector=[2.0, 2.0, 1.0, 0.0], model=LightPositionModel.CAMERA) ] # overwrite the default DEFAULT_LIGHTING_KEY light setup sim.set_light_setup(my_default_lighting) get_obs(sim, show_imgs, save_imgs) # [/example 3] # [example 4] id_2 = sim.add_object(chair_template_id) sim.set_rotation(mn.Quaternion.rotation(mn.Deg(-115), mn.Vector3.y_axis()), id_2) sim.set_translation([3.06, 0.47, 1.15], id_2) get_obs(sim, show_imgs, save_imgs) # [/example 4] # [example 5] light_setup_2 = [ LightInfo( vector=[2.0, 1.5, 5.0, 1.0], color=[0.0, 100.0, 100.0], model=LightPositionModel.GLOBAL, ) ] sim.set_light_setup(light_setup_2, "my_custom_lighting") # [/example 5] remove_all_objects(sim) # [example 6] id_1 = sim.add_object(chair_template_id, light_setup_key="my_custom_lighting") sim.set_rotation(mn.Quaternion.rotation(mn.Deg(-115), mn.Vector3.y_axis()), id_1) sim.set_translation([3.06, 0.47, 1.15], id_1) id_2 = sim.add_object(chair_template_id, light_setup_key="my_custom_lighting") sim.set_rotation(mn.Quaternion.rotation(mn.Deg(50), mn.Vector3.y_axis()), id_2) sim.set_translation([3.45927, 0.47, -0.624958], id_2) get_obs(sim, show_imgs, save_imgs) # [/example 6] # [example 7] existing_light_setup = sim.get_light_setup("my_custom_lighting") # create a new setup with an additional light new_light_setup = existing_light_setup + [ LightInfo( vector=[0.0, 0.0, 1.0, 0.0], color=[1.6, 1.6, 1.4], model=LightPositionModel.CAMERA, ) ] # register the old setup under a new name sim.set_light_setup(existing_light_setup, "my_old_custom_lighting") # [/example 7] # [example 8] # register the new setup overwriting the old one sim.set_light_setup(new_light_setup, "my_custom_lighting") get_obs(sim, show_imgs, save_imgs) # [/example 8] # [example 9] sim.set_object_light_setup(id_1, habitat_sim.gfx.DEFAULT_LIGHTING_KEY) get_obs(sim, show_imgs, save_imgs)
def main(show_imgs=True, save_imgs=False): if save_imgs and not os.path.exists(output_path): os.mkdir(output_path) # [default scene lighting] # create the simulator and render flat shaded scene cfg = make_configuration() sim = habitat_sim.Simulator(cfg) agent_transform = place_agent(sim) get_obs(sim, show_imgs, save_imgs) # [scene swap shader] # close the simulator and re-initialize with DEFAULT_LIGHTING_KEY: sim.close() cfg = make_configuration() cfg.sim_cfg.scene_light_setup = habitat_sim.gfx.DEFAULT_LIGHTING_KEY sim = habitat_sim.Simulator(cfg) agent_transform = place_agent(sim) get_obs(sim, show_imgs, save_imgs) # create and register new light setup: my_scene_lighting_setup = [ LightInfo(vector=[0.0, 2.0, 0.6, 0.0], model=LightPositionModel.Global) ] sim.set_light_setup(my_scene_lighting_setup, "my_scene_lighting") # reconfigure with custom key: new_cfg = make_configuration() new_cfg.sim_cfg.scene_light_setup = "my_scene_lighting" sim.reconfigure(new_cfg) agent_transform = place_agent(sim) get_obs(sim, show_imgs, save_imgs) # [/scene] # reset to default scene shading sim.close() cfg = make_configuration() sim = habitat_sim.Simulator(cfg) agent_transform = place_agent(sim) # noqa: F841 # [example 2] # get the rigid object attributes manager, which manages # templates used to create objects obj_template_mgr = sim.get_object_template_manager() # get the rigid object manager, which provides direct # access to objects rigid_obj_mgr = sim.get_rigid_object_manager() # load some object templates from configuration files sphere_template_id = obj_template_mgr.load_configs( str(os.path.join(data_path, "test_assets/objects/sphere")))[0] chair_template_id = obj_template_mgr.load_configs( str(os.path.join(data_path, "test_assets/objects/chair")))[0] # create a sphere and place it at a desired location obj_1 = rigid_obj_mgr.add_object_by_template_id(sphere_template_id) obj_1.translation = [3.2, 0.23, 0.03] get_obs(sim, show_imgs, save_imgs) # [/example 2] # [example 3] # create a custom light setup my_default_lighting = [ LightInfo(vector=[2.0, 2.0, 1.0, 0.0], model=LightPositionModel.Camera) ] # overwrite the default DEFAULT_LIGHTING_KEY light setup sim.set_light_setup(my_default_lighting) get_obs(sim, show_imgs, save_imgs) # [/example 3] # [example 4] # create a chair and place it at a location with a specified orientation obj_2 = rigid_obj_mgr.add_object_by_template_id(chair_template_id) obj_2.rotation = mn.Quaternion.rotation(mn.Deg(-115), mn.Vector3.y_axis()) obj_2.translation = [3.06, 0.47, 1.15] get_obs(sim, show_imgs, save_imgs) # [/example 4] # [example 5] light_setup_2 = [ LightInfo( vector=[2.0, 1.5, 5.0, 1.0], color=[0.0, 100.0, 100.0], model=LightPositionModel.Global, ) ] sim.set_light_setup(light_setup_2, "my_custom_lighting") # [/example 5] rigid_obj_mgr.remove_all_objects() # [example 6] # create and place 2 chairs with custom light setups chair_1 = rigid_obj_mgr.add_object_by_template_id( chair_template_id, light_setup_key="my_custom_lighting") chair_1.rotation = mn.Quaternion.rotation(mn.Deg(-115), mn.Vector3.y_axis()) chair_1.translation = [3.06, 0.47, 1.15] chair_2 = rigid_obj_mgr.add_object_by_template_id( chair_template_id, light_setup_key="my_custom_lighting") chair_2.rotation = mn.Quaternion.rotation(mn.Deg(50), mn.Vector3.y_axis()) chair_2.translation = [3.45927, 0.47, -0.624958] get_obs(sim, show_imgs, save_imgs) # [/example 6] # [example 7] existing_light_setup = sim.get_light_setup("my_custom_lighting") # create a new setup with an additional light new_light_setup = existing_light_setup + [ LightInfo( vector=[0.0, 0.0, 1.0, 0.0], color=[1.6, 1.6, 1.4], model=LightPositionModel.Camera, ) ] # register the old setup under a new name sim.set_light_setup(existing_light_setup, "my_old_custom_lighting") # [/example 7] # [example 8] # register the new setup overwriting the old one sim.set_light_setup(new_light_setup, "my_custom_lighting") get_obs(sim, show_imgs, save_imgs) # [/example 8] # [example 9] chair_1.set_light_setup(habitat_sim.gfx.DEFAULT_LIGHTING_KEY) get_obs(sim, show_imgs, save_imgs)