def test_minimal_project(self): from haps import Project, Scene, Assembly project = Project() scene = Scene() project.add(scene) assembly = Assembly('assembly') scene.add(assembly) self.assertEqual(self.splitXMLtoWords(str(project)), self.minimal_project, "These should be equal")
def test_setup_appleseed_object(self): from haps import Project, Scene, Assembly, Assembly_Instance, Transform, Matrix apple = APSobj.Appleseed() # apple is atm equal to this: project = Project() assembly = apple.Assembly() scene = Scene() project.add(scene) scene.add(Assembly('assembly')).add( Assembly_Instance('assembly_inst', assembly='assembly').add( Transform().add(Matrix()))) self.assertEqual(apple.assembly, Assembly('assembly')) self.assertEqual(apple.project, project)
def test_searching_and_removing(self): from haps import Scene, Camera, Transform, Look_At # Row camera: scene = Scene() scene.add(Camera("camera1", model="pinhole_camera").add( Transform(time=0).add( Look_At(origin=[0,0,0], target=[1,1,1], up=[0,1,0])) ) ) # Queries and deletion camera = scene.get_by_name('camera1') self.assertEqual(camera.find('transform').find('look_at').get('up') , [0, 1, 0]) look_at = camera.find('transform').find('look_at') camera.find('transform').remove(look_at) camera.find('transform').add(Look_At(origin=[1,1,1], target=[1,1,1], up=[0,1,0])) self.assertEqual(len(camera.find('transform').findall('look_at')) , 1)
def test_assembly_instance(self): from haps import Assembly, Assembly_Instance, Scene, Transform, Matrix scene = Scene() assembly = Assembly('assembly') # FIXME: This is bug, without name .find() doesn't work. asmb_inst1 = Assembly_Instance(name='asm1', assembly=assembly).add(Transform().add(Matrix())) scene.add(assembly) scene.add(asmb_inst1) self.assertIsNotNone(scene.find('assembly_instance'))
def test_empty_scene_cant_be_found(self): from haps import Scene, Project scene = Scene() project = Project().add(scene) # FIXME this is fixed # self.assertIsNotNone(project.find('scene')) # This works though self.assertIsNotNone(project.findall('scene')) self.assertEqual(len(project.findall('scene')), 1)
def test_free_standing_factory_method(self): from haps import Scene scene = Scene() scene.add( APSobj.Factory('Frame', 'beauty', parms=(('resolution', [1920, 1080]), ), camera='renderCam2')) scene.add( APSobj.Factory('Camera', 'renderCam2', parms=(('aspect_ratio', 1), ), model="pinhole_camera")) self.assertIsNotNone(scene.find("frame")) self.assertIsNotNone(scene.find("camera")) self.assertEqual(scene.find('camera').get('model'), 'pinhole_camera') self.assertEqual( scene.find('frame').get_by_name('resolution').get('value'), [1920, 1080])
def test_environment_and_edf(self): # Env + env_shader + Edf from haps import Environment_Shader, Environment, Edf, Scene scene = Scene() scene.add(Environment('env', environment_shader='env_shader')).add( Environment_Shader('env_shader', edf='edf')).add(Edf('edf', model='cone_edf')) self.assertIsNotNone(scene.find('environment')) self.assertIsNotNone(scene.find('edf'))
def test_spectral_color_creation(self): from haps import Color, Parameter, Values, Alpha, Scene scene = Scene() # Row Colours: spectral = Color('green') spectral.add(Parameter('color_space', 'spectral')) spectral.add(Parameter('wavelength_range', "400 700")) spectral.add(Values([0.092000, 0.097562, 0.095000, 0.096188, 0.097000])) spectral.add(Alpha([.5])) scene.add(spectral) self.assertEqual(scene.find('color').find('values').text, [0.092000, 0.097562, 0.095000, 0.096188, 0.097000]) self.assertEqual(scene.find('color').find('alpha').text, [0.5])
def test_materials_and_its_assigment(self): from haps import Bsdf, Scene, Surface_Shader, Material, Object_Instance from haps import Assign_Material, Environment, Environment_Shader, Edf # Materials + assigment: scene = Scene() obj_inst1 = Object_Instance('inst_obj') scene.add(obj_inst1) bsdf = Bsdf('sphere_brdf', model='disney_brdf') scene.add(bsdf) scene.add(Surface_Shader('sphere_shader', brdf=bsdf)) scene.add(Material('greenish', surface_shader='sphere_shader')) obj_inst1.add(Assign_Material(slot='Default', side='front', material='greenish')) self.assertIsNotNone(scene.find('bsdf')) self.assertEqual(scene.find('object_instance').find('assign_material').get('material'), 'greenish')