def falling_pump(event=None): def load_brep(filename): # Load the shape from a file aShape = TopoDS_Shape() builder = BRep_Builder() BRepTools_Read(aShape,str(filename),builder) return aShape # Just a copy/paste of the torus code display.EraseAll() dyn_context = DynamicSimulationContext() dyn_context.set_display(display, safe_yield) dyn_context.enable_collision_detection() dyn_context.enable_gravity() s1 = load_brep('../../data/BREP/40_pump_body.brep') d = dyn_context.register_shape(s1,enable_collision_detection=True,use_trimesh=True) # The plane (note: this plane is not a dynamic shape, it's just displayed) P1 = gp_Pnt(0,0,-1000) V1 = gp_Vec(0,0,1) face = make_plane(P1,V1, -1000., 1000., -600., 600.) # Then create a geom for this plane # Create a plane geom which prevent the objects from falling forever floor = ode.GeomPlane(dyn_context._space, (0,0,1), -1000) display.DisplayColoredShape(face,'RED') display.FitAll() #Starts the simulation dyn_context.set_simulation_duration(30) #1s forthe simulation dyn_context.set_time_step(0.001) dyn_context.start_open_loop() del dyn_context
def two_boxes_sphere_plane_collision(event=None): display.EraseAll() dyn_context = DynamicSimulationContext() dyn_context.set_display(display, safe_yield) dyn_context.enable_collision_detection() dyn_context.enable_gravity() # The first box s1 = BRepPrimAPI_MakeBox(10,20,30).Shape() d = dyn_context.register_shape(s1,enable_collision_detection=True,use_boundingbox=True) d.setAngularVel([-1,-0.5,0.3]) # the box is rotating # The second box box2 = BRepPrimAPI_MakeBox(10,20,30).Shape() box2 = translate_topods_from_vector(box2, gp_Vec(5, 5, 100)) d2 = dyn_context.register_shape(box2,enable_collision_detection=True,use_boundingbox=True) # The sphere sphere = BRepPrimAPI_MakeSphere(10).Shape() sphere = translate_topods_from_vector(sphere, gp_Vec(0,0,250)) d3 = dyn_context.register_shape(sphere,enable_collision_detection=True,use_sphere=True) # Draw a plane (note: this plane is not a dynamic shape, it's just displayed) face = make_plane( gp_Pnt(0,0,-100), gp_Vec(0,0,1), -100., 100., -100., 100.) display.DisplayColoredShape(face,'RED') display.FitAll() # Then create a geom for this plane # Create a plane geom which prevent the objects from falling forever floor = ode.GeomPlane(dyn_context._space, (0,0,1), -100) #Starts the simulation #raw_input('Hit a key when ready to start simulation') dyn_context.set_simulation_duration(10.) dyn_context.set_animation_frame_rate(60) dyn_context.start_open_loop()
def falling_torus_torus(event=None): display.EraseAll() dyn_context = DynamicSimulationContext() dyn_context.set_display(display, safe_yield) dyn_context.enable_collision_detection() dyn_context.enable_gravity() # The torus s1 = BRepPrimAPI_MakeTorus(15,5).Shape() d = dyn_context.register_shape(s1, enable_collision_detection=True,use_trimesh=True) # The box s2 = BRepPrimAPI_MakeTorus(10,6).Shape() transformed_shape_2 = translate_topods_from_vector(s2, gp_Vec(0,0,100)) d2 = dyn_context.register_shape(transformed_shape_2,enable_collision_detection=True,use_trimesh=True) d2.setAngularVel([-3,3,3]) # The plane (note: this plane is not a dynamic shape, it's just displayed) P1 = gp_Pnt(0,0,-100) V1 = gp_Vec(0,0,1) face = make_plane(P1,V1,-100., 100., -60., 60.) # Then create a geom for this plane # Create a plane geom which prevent the objects from falling forever floor = ode.GeomPlane(dyn_context._space, (0,0,1), -100) display.DisplayColoredShape(face,'RED') display.FitAll() #Starts the simulation dyn_context.set_simulation_duration(20) #1s forthe simulation dyn_context.set_time_step(0.01) dyn_context.start_open_loop()
def falling_torus(event=None): display.EraseAll() dyn_context = DynamicSimulationContext() dyn_context.set_display(display, safe_yield) dyn_context.enable_collision_detection() dyn_context.enable_gravity() # test the post_register_callback feature def f(): print 'Wooooooooooo' dyn_context.register_post_step_callback(f) # The torus s1 = BRepPrimAPI_MakeTorus(15,5).Shape() d = dyn_context.register_shape(s1,enable_collision_detection=True,use_trimesh=True) d.setAngularVel([-1,-0.5,0.3]) # the box is rotating # The plane (note: this plane is not a dynamic shape, it's just displayed) P1 = gp_Pnt(0,0,-100) V1 = gp_Vec(0,0,1) face = make_plane(P1,V1, -100., 100., -60., 60.) # Then create a geom for this plane # Create a plane geom which prevent the objects from falling forever floor = ode.GeomPlane(dyn_context._space, (0,0,1), -100) display.DisplayColoredShape(face,'RED') display.FitAll() #Starts the simulation dyn_context.set_simulation_duration(20) #1s forthe simulation dyn_context.set_time_step(0.01) dyn_context.start_open_loop()
def falling_pump(event=None): def load_brep(filename): # Load the shape from a file aShape = TopoDS_Shape() builder = BRep_Builder() BRepTools_Read(aShape, str(filename), builder) return aShape # Just a copy/paste of the torus code display.EraseAll() dyn_context = DynamicSimulationContext() dyn_context.set_display(display, safe_yield) dyn_context.enable_collision_detection() dyn_context.enable_gravity() s1 = load_brep('../../data/BREP/40_pump_body.brep') d = dyn_context.register_shape(s1, enable_collision_detection=True, use_trimesh=True) # The plane (note: this plane is not a dynamic shape, it's just displayed) P1 = gp_Pnt(0, 0, -1000) V1 = gp_Vec(0, 0, 1) face = make_plane(P1, V1, -1000., 1000., -600., 600.) # Then create a geom for this plane # Create a plane geom which prevent the objects from falling forever floor = ode.GeomPlane(dyn_context._space, (0, 0, 1), -1000) display.DisplayColoredShape(face, 'RED') display.FitAll() #Starts the simulation dyn_context.set_simulation_duration(30) #1s forthe simulation dyn_context.set_time_step(0.001) dyn_context.start_open_loop() del dyn_context
def dominos(event=None): ''' The well known domino demo. Dominos are placed on a marble table and start collapsing. ''' display.EraseAll() l_table = 180. w_table = 180. h_table = 15. # Create the dynamic context dyn_context = DynamicSimulationContext() dyn_context.set_display(display, safe_yield) dyn_context.enable_collision_detection() dyn_context.enable_gravity() # Create the floor The floor is not visible floor = ode.GeomPlane(dyn_context._space, (0,0,1), -h_table) # create the table table_shape = BRepPrimAPI_MakeBox(l_table,w_table,h_table).Shape() # move the table down # the table rests on the `floor` #table_shape = translate_topods_from_vector(table_shape, gp_Vec(-l_table/2, -l_table/2, -h_table)) table_shape = translate_topods_from_vector(table_shape, gp_Vec(-l_table/2, -l_table/2, -h_table)) dynamic_table = dyn_context.register_shape(table_shape,enable_collision_detection=True,use_boundingbox=True) dynamic_table.set_fixed() # Create a 'ground' P1 = gp_Pnt(0,0,-h_table) V1 = gp_Vec(0,0,1) face = make_plane(P1, V1,-150., 150., -100., 100.,) display.DisplayColoredShape(face,color='RED') # wrap a texture on the plane texture_filename = os.path.join(os.path.split(os.path.abspath(__file__))[0], 'ground.bmp') t = Texture(texture_filename) m = Graphic3d_MaterialAspect(Graphic3d_NOM_ALUMINIUM) #s = BRepPrimAPI_MakeCylinder(60, 200) display.DisplayShape(table_shape,material=m,texture=t) #display.FitAll() # Create the first domino domino_shape = BRepPrimAPI_MakeBox(5,20,40).Shape() v = gp_Vec(19, 0, 0) domino_shape = translate_topods_from_vector(domino_shape, v) dynamic_domino = dyn_context.register_shape(domino_shape,enable_collision_detection=True,use_boundingbox=True) # create a list of domino_boxes for _ in range(3): transformed_shape = translate_topods_from_vector(domino_shape, v, copy=True) dynamic_transformed = dyn_context.register_shape(transformed_shape,enable_collision_detection=True,use_boundingbox=True) # The last domino is rotating around the y-axis (he's falling) dynamic_transformed.setAngularVel([0,0,0]) # Finally, start simulation loop dyn_context.set_simulation_duration(5) dyn_context.set_time_step(0.001) dyn_context.set_animation_frame_rate(60) #dyn_context.set dyn_context.start_open_loop()
def box_plane_collision(event=None): display.EraseAll() dyn_context = DynamicSimulationContext() dyn_context.set_display(display, safe_yield) dyn_context.enable_collision_detection() dyn_context.enable_gravity() # The box s1 = BRepPrimAPI_MakeBox(10,20,30).Shape() d = dyn_context.register_shape(s1,enable_collision_detection=True,use_boundingbox=True) d.setAngularVel([-1,-0.5,0.3]) # the box is rotating # The plane (note: this plane is not a dynamic shape, it's just displayed) P1 = gp_Pnt(0,0,-100) V1 = gp_Vec(0,0,1) face = make_plane(P1, V1, -100., 100., -60., 60) # Then create a geom for this plane # Create a plane geom which prevent the objects from falling forever floor = ode.GeomPlane(dyn_context._space, (0,0,1), -100) display.DisplayColoredShape(face,'RED') display.FitAll() #Starts the simulation dyn_context.set_animation_frame_rate(60) dyn_context.start_open_loop()
def two_boxes_sphere_plane_collision(event=None): display.EraseAll() dyn_context = DynamicSimulationContext() dyn_context.set_display(display, safe_yield) dyn_context.enable_collision_detection() dyn_context.enable_gravity() # The first box s1 = BRepPrimAPI_MakeBox(10, 20, 30).Shape() d = dyn_context.register_shape(s1, enable_collision_detection=True, use_boundingbox=True) d.setAngularVel([-1, -0.5, 0.3]) # the box is rotating # The second box box2 = BRepPrimAPI_MakeBox(10, 20, 30).Shape() box2 = translate_topods_from_vector(box2, gp_Vec(5, 5, 100)) d2 = dyn_context.register_shape(box2, enable_collision_detection=True, use_boundingbox=True) # The sphere sphere = BRepPrimAPI_MakeSphere(10).Shape() sphere = translate_topods_from_vector(sphere, gp_Vec(0, 0, 250)) d3 = dyn_context.register_shape(sphere, enable_collision_detection=True, use_sphere=True) # Draw a plane (note: this plane is not a dynamic shape, it's just displayed) face = make_plane(gp_Pnt(0, 0, -100), gp_Vec(0, 0, 1), -100., 100., -100., 100.) display.DisplayColoredShape(face, 'RED') display.FitAll() # Then create a geom for this plane # Create a plane geom which prevent the objects from falling forever floor = ode.GeomPlane(dyn_context._space, (0, 0, 1), -100) #Starts the simulation #raw_input('Hit a key when ready to start simulation') dyn_context.set_simulation_duration(10.) dyn_context.set_animation_frame_rate(60) dyn_context.start_open_loop()
def box_plane_collision(event=None): display.EraseAll() dyn_context = DynamicSimulationContext() dyn_context.set_display(display, safe_yield) dyn_context.enable_collision_detection() dyn_context.enable_gravity() # The box s1 = BRepPrimAPI_MakeBox(10, 20, 30).Shape() d = dyn_context.register_shape(s1, enable_collision_detection=True, use_boundingbox=True) d.setAngularVel([-1, -0.5, 0.3]) # the box is rotating # The plane (note: this plane is not a dynamic shape, it's just displayed) P1 = gp_Pnt(0, 0, -100) V1 = gp_Vec(0, 0, 1) face = make_plane(P1, V1, -100., 100., -60., 60) # Then create a geom for this plane # Create a plane geom which prevent the objects from falling forever floor = ode.GeomPlane(dyn_context._space, (0, 0, 1), -100) display.DisplayColoredShape(face, 'RED') display.FitAll() #Starts the simulation dyn_context.set_animation_frame_rate(60) dyn_context.start_open_loop()
def dominos(event=None): ''' The well known domino demo. Dominos are placed on a marble table and start collapsing. ''' display.EraseAll() l_table = 180. w_table = 180. h_table = 15. # Create the dynamic context dyn_context = DynamicSimulationContext() dyn_context.set_display(display, safe_yield) dyn_context.enable_collision_detection() dyn_context.enable_gravity() # Create the floor The floor is not visible floor = ode.GeomPlane(dyn_context._space, (0, 0, 1), -h_table) # create the table table_shape = BRepPrimAPI_MakeBox(l_table, w_table, h_table).Shape() # move the table down # the table rests on the `floor` #table_shape = translate_topods_from_vector(table_shape, gp_Vec(-l_table/2, -l_table/2, -h_table)) table_shape = translate_topods_from_vector( table_shape, gp_Vec(-l_table / 2, -l_table / 2, -h_table)) dynamic_table = dyn_context.register_shape(table_shape, enable_collision_detection=True, use_boundingbox=True) dynamic_table.set_fixed() # Create a 'ground' P1 = gp_Pnt(0, 0, -h_table) V1 = gp_Vec(0, 0, 1) face = make_plane( P1, V1, -150., 150., -100., 100., ) display.DisplayColoredShape(face, color='RED') # wrap a texture on the plane texture_filename = os.path.join( os.path.split(os.path.abspath(__file__))[0], 'ground.bmp') t = Texture(texture_filename) m = Graphic3d_MaterialAspect(Graphic3d_NOM_ALUMINIUM) #s = BRepPrimAPI_MakeCylinder(60, 200) display.DisplayShape(table_shape, material=m, texture=t) #display.FitAll() # Create the first domino domino_shape = BRepPrimAPI_MakeBox(5, 20, 40).Shape() v = gp_Vec(19, 0, 0) domino_shape = translate_topods_from_vector(domino_shape, v) dynamic_domino = dyn_context.register_shape( domino_shape, enable_collision_detection=True, use_boundingbox=True) # create a list of domino_boxes for _ in range(3): transformed_shape = translate_topods_from_vector(domino_shape, v, copy=True) dynamic_transformed = dyn_context.register_shape( transformed_shape, enable_collision_detection=True, use_boundingbox=True) # The last domino is rotating around the y-axis (he's falling) dynamic_transformed.setAngularVel([0, 0, 0]) # Finally, start simulation loop dyn_context.set_simulation_duration(5) dyn_context.set_time_step(0.001) dyn_context.set_animation_frame_rate(60) #dyn_context.set dyn_context.start_open_loop()