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_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 rotating_box(event=None): display.EraseAll() dyn_context = DynamicSimulationContext() dyn_context.set_display(display, safe_yield) # Create s shape and add it to the dynamic context s1 = BRepPrimAPI_MakeBox(10, 20, 30).Shape() d = dyn_context.register_shape(s1) #d.enable_view_cog() d.setAngularVel([-1, 0, 0]) dyn_context.register_post_step_callback(safe_yield) dyn_context.start_open_loop() dyn_context.clear()
def rotating_box(event=None): display.EraseAll() dyn_context = DynamicSimulationContext() dyn_context.set_display(display, safe_yield) # Create s shape and add it to the dynamic context s1 = BRepPrimAPI_MakeBox(10,20,30).Shape() d = dyn_context.register_shape(s1) #d.enable_view_cog() d.setAngularVel([-1,0,0]) dyn_context.register_post_step_callback(safe_yield) dyn_context.start_open_loop() dyn_context.clear()
def hinge(event=None): ''' hinge joint example adapted from pyode http://pyode.sourceforge.net/tutorials/tutorial2.html ''' from OCC.Utils.Common import center_boundingbox display.EraseAll() # 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 table block1 = BRepPrimAPI_MakeBox(4, 1, 1).Shape() N = 36 * 3 dyn_shapes = [] for i in range(1, N): table_shape = translate_topods_from_vector(block1, gp_Vec(0, 0, 2 * (i * 0.5)), copy=True) dyn_shape = dyn_context.register_shape(table_shape, enable_collision_detection=True, use_boundingbox=True) dyn_shapes.append((dyn_shape, table_shape)) dyn_shapes = iter(dyn_shapes) prev, table_shape = dyn_shapes.next() # safe for future reference first, cube = prev, table_shape prev_center = center_boundingbox(table_shape) for i, xxx in enumerate(dyn_shapes): dyn_shape, table_shape = xxx bj = DynamicBallJoint(dyn_context) center = center_boundingbox(table_shape) bj.attach_shapes(prev, dyn_shape) if i % 2 == 0: bj.set_anchor((prev_center.as_vec() - gp_Vec(2, 0, 0.5)).as_pnt()) else: bj.set_anchor((prev_center.as_vec() - gp_Vec(-2, 0, 0.5)).as_pnt()) dyn_context.register_joint(bj) prev = dyn_shape prev_center = center # get the 1st block, the one one the ground... xmin, ymin, zmin, xmax, ymax, zmax = get_boundingbox(cube) # set the lower block in motion vec1 = (12, 88, 0) first.setLinearVel(vec1) # change the color of the bottom element a little... ais = first.get_ais_shape().GetObject() from OCC.Graphic3d import Graphic3d_NOM_SILVER ais.SetMaterial(Graphic3d_NOM_SILVER) # lock the upper block #bj.attach_shapes(dyn_shape, ode.environment) vec2 = (-12, -88, 0) dyn_shape.setLinearVel(vec2) ais = dyn_shape.get_ais_shape().GetObject() ais.SetMaterial(Graphic3d_NOM_SILVER) # create a floor... floor = ode.GeomPlane(dyn_context._space, (0, 0, 1), zmin) def f(): XXX = 0.15 * N first.setLinearVel((0, XXX, 0)) dyn_shape.setLinearVel((0, -XXX, 0)) dyn_context.mu = 500 dyn_context.setERP(0.8) # 0.2 default dyn_context.setCFM(1e-12) # 1e-10 default dyn_context.set_simulation_duration(1200.) dyn_context.set_animation_frame_rate(60) dyn_context.set_time_step(0.01) dyn_context.register_post_step_callback(f) dyn_context.start_open_loop(True)
def hinge(event=None): ''' hinge joint example adapted from pyode http://pyode.sourceforge.net/tutorials/tutorial2.html ''' from OCC.Utils.Common import center_boundingbox display.EraseAll() # 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 table block1 = BRepPrimAPI_MakeBox(4,1,1).Shape() N = 36*3 dyn_shapes = [] for i in range(1,N): table_shape = translate_topods_from_vector(block1, gp_Vec(0,0,2*(i*0.5)), copy=True) dyn_shape = dyn_context.register_shape(table_shape, enable_collision_detection=True, use_boundingbox=True) dyn_shapes.append((dyn_shape,table_shape)) dyn_shapes = iter(dyn_shapes) prev, table_shape = dyn_shapes.next() # safe for future reference first, cube = prev, table_shape prev_center = center_boundingbox(table_shape) for i,xxx in enumerate(dyn_shapes): dyn_shape, table_shape = xxx bj = DynamicBallJoint(dyn_context) center = center_boundingbox(table_shape) bj.attach_shapes(prev, dyn_shape) if i%2 == 0: bj.set_anchor( (prev_center.as_vec() - gp_Vec(2,0,0.5)).as_pnt() ) else: bj.set_anchor( (prev_center.as_vec() - gp_Vec(-2,0,0.5)).as_pnt() ) dyn_context.register_joint(bj) prev=dyn_shape prev_center = center # get the 1st block, the one one the ground... xmin, ymin, zmin, xmax, ymax, zmax = get_boundingbox(cube).Get() # set the lower block in motion vec1 = (12, 88, 0) first.setLinearVel(vec1) # change the color of the bottom element a little... ais = first.get_ais_shape().GetObject() from OCC.Graphic3d import Graphic3d_NOM_SILVER ais.SetMaterial(Graphic3d_NOM_SILVER) # lock the upper block #bj.attach_shapes(dyn_shape, ode.environment) vec2 = (-12, -88, 0) dyn_shape.setLinearVel(vec2) ais = dyn_shape.get_ais_shape().GetObject() ais.SetMaterial(Graphic3d_NOM_SILVER) # create a floor... floor = ode.GeomPlane(dyn_context._space, (0,0,1), zmin) def f(): print 'first:',first.getPosition() print 'velo:', first.getLinearVel() XXX = 0.15 * N first.setLinearVel((0, XXX,0)) dyn_shape.setLinearVel((0,-XXX,0)) dyn_context.mu = 500 dyn_context.setERP(0.8) # 0.2 default dyn_context.setCFM(1e-12) # 1e-10 default dyn_context.set_simulation_duration(1200.) dyn_context.set_animation_frame_rate(60) dyn_context.set_time_step(0.01) dyn_context.register_post_step_callback(f) dyn_context.start_open_loop(True)