def translate_to_phyre()

in src/python/phyre/virtual_tools.py [0:0]


def translate_to_phyre(C, world_description):
    d = world_description
    pgw = C

    ## d is assumed to be a dictionary in Virtual Tools level format
    ## please
    gcond = d['gcond']
    all_ids = {}
    for nm, o in d['objects'].items():
        if nm[0] != '_':
            density = o['density']
            dynamic = density == 1.0
            if dynamic:
                add_str = "dynamic "
            else:
                add_str = "static "

            if o['type'] == 'Poly':
                vertices = o['vertices']
                vertices.reverse()
                bid = pgw.add_convex_polygon(
                    convert_phyre_tools_vertices(vertices), dynamic)

            elif o['type'] == 'Ball':
                add_str = add_str + 'ball '
                center_x = o['position'][0] * PHYRE_SCALE / VT_SCALE
                center_y = o['position'][1] * PHYRE_SCALE / VT_SCALE
                bid = pgw.add(add_str,
                              scale=o['radius'] * 2 / VT_SCALE,
                              center_x=center_x,
                              center_y=center_y)

            elif o['type'] == 'Container':
                bid, bbid = add_container(pgw,
                                          o['points'],
                                          o['width'],
                                          dynamic,
                                          goal_container=gcond['goal'] == nm)

            elif o['type'] == 'Compound':
                polys = o['polys']

                for p in polys:
                    p.reverse()

                converted_polylist = [
                    convert_phyre_tools_vertices(poly) for poly in polys
                ]
                bid = pgw.add_multipolygons(polygons=converted_polylist,
                                            dynamic=dynamic)

            elif o['type'] == 'Goal':
                vertices = o['vertices']
                vertices.reverse()
                bid = pgw.add_convex_polygon(
                    convert_phyre_tools_vertices(vertices), dynamic)
            else:
                raise Exception("Invalid object type for PHYRE given: ",
                                o['type'])
            all_ids[nm] = bid

    if gcond['type'] == 'SpecificInGoal' and gcond['goal'] != 'Floor' and gcond[
            'goal'] != 'Ground':
        container_id = all_ids[gcond['goal']]
        pgw.update_task(body1=all_ids[gcond['obj']],
                        body2=container_id,
                        relationships=[pgw.SpatialRelationship.TOUCHING])

    elif gcond['type'] == 'SpecificTouch' or (
            gcond['type'] == 'SpecificInGoal' and
        (gcond['goal'] == 'Floor' or gcond['goal'] == 'Ground')):
        pgw.update_task(body1=all_ids[gcond['obj']],
                        body2=all_ids[gcond['goal']],
                        relationships=[pgw.SpatialRelationship.TOUCHING])
    else:
        raise Exception("Invalid goal type for PHYRE given: ", gcond['type'])
    return pgw