示例#1
0
def adhesion(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 = 12

    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)

    slider_vec = gp_Dir(1, 1, 0)

    for i, xxx in enumerate(_dyn_shapes):
        dyn_shape, table_shape = xxx
        bj = DynamicSliderJoint(dyn_context)
        bj.set_axis(slider_vec)
        center = center_boundingbox(table_shape)
        if i == 0:
            bj.attach_shapes(prev, ode.environment)
            first_joint = bj
        else:
            bj.attach_shapes(prev, dyn_shape)
        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 middle block in motion
    vec1 = (160, 66, 0)
    #vec1 = (1.20, 0.66, 0)
    middle, topods = dyn_shapes[N / 2]

    middle.setLinearVel(vec1)
    #middle.setForce(vec1)

    # change the color of the bottom element a little...
    ais = middle.get_ais_shape().GetObject()
    from OCC.Graphic3d import Graphic3d_NOM_SILVER
    ais.SetMaterial(Graphic3d_NOM_SILVER)

    bj.attach_shapes(dyn_shape, ode.environment)
    first_joint.attach_shapes(first, ode.environment)

    floor = ode.GeomPlane(dyn_context._space, (0, 0, 1), zmin)

    dyn_context.mu = 0  # icey!!!
    dyn_context.setERP(0.1)  # 0.2 default
    dyn_context.setCFM(1e-12)  # 1e-10 default
    dyn_context.set_simulation_duration(1200)
    dyn_context.set_animation_frame_rate(40)
    dyn_context.set_time_step(0.01)
    dyn_context.start_open_loop(True)
示例#2
0
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)
示例#3
0
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)
示例#4
0
def adhesion(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 = 12

    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)

    slider_vec = gp_Dir(1,1,0)

    for i,xxx in enumerate(_dyn_shapes):
        dyn_shape, table_shape = xxx
        bj = DynamicSliderJoint(dyn_context)
        bj.set_axis(slider_vec)
        center = center_boundingbox(table_shape)
        if i == 0:
            bj.attach_shapes(prev, ode.environment)
            first_joint = bj
        else:
            bj.attach_shapes(prev, dyn_shape)
        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 middle block in motion
    vec1 = (160, 66, 0)
    #vec1 = (1.20, 0.66, 0)
    middle, topods = dyn_shapes[N/2]

    middle.setLinearVel(vec1)
    #middle.setForce(vec1)

    # change the color of the bottom element a little...
    ais = middle.get_ais_shape().GetObject()
    from OCC.Graphic3d import Graphic3d_NOM_SILVER
    ais.SetMaterial(Graphic3d_NOM_SILVER)

    bj.attach_shapes( dyn_shape, ode.environment )
    first_joint.attach_shapes( first, ode.environment )

    floor = ode.GeomPlane(dyn_context._space, (0,0,1), zmin)

    dyn_context.mu = 0 # icey!!!
    dyn_context.setERP(0.1) # 0.2 default
    dyn_context.setCFM(1e-12) # 1e-10 default
    dyn_context.set_simulation_duration(1200)
    dyn_context.set_animation_frame_rate(40)
    dyn_context.set_time_step(0.01)
    dyn_context.start_open_loop(True)