Exemplo n.º 1
0
def convert_to_enu(filename):
    world = WebotsParser()
    world.load(filename)

    for node in world.content['root']:
        if node['name'] == 'WorldInfo':
            for field in node['fields']:
                if field['name'] == 'coordinateSystem':
                    # remove the 'coordinateSystem ENU'
                    del node['fields'][node['fields'].index(field)]
        elif node['name'] not in [
                'Viewpoint', 'TexturedBackground', 'TexturedBackgroundLight'
        ]:
            print('Rotating', node['name'])
            rotation_found = False
            for field in node['fields']:
                if field['name'] in ['rotation']:
                    rotation_found = True
                    field['value'] = rotation(field['value'],
                                              [1, 0, 0, 0.5 * math.pi])
                elif field['name'] in ['translation']:
                    field['value'] = [
                        field['value'][0],
                        str(-float(field['value'][2])), field['value'][1]
                    ]
            if not rotation_found:
                node['fields'].append({
                    'name':
                    'rotation',
                    'value': ['1', '0', '0', str(0.5 * math.pi)],
                    'type':
                    'SFRotation'
                })
    world.save(filename)
Exemplo n.º 2
0
def convert_to_nue(filename):
    world = WebotsParser()
    world.load(filename)

    for node in world.content['root']:
        if node['name'] == 'WorldInfo':
            is_nue = False
            for field in node['fields']:
                if field['name'] == 'northDirection':
                    assert field['value'] == ['0', '0', '1']
                    # remove the 'northDirection 0 0 1'
                    del node['fields'][node['fields'].index(field)]
                if field['name'] == 'coordinateSystem':
                    field['value'] = 'NUE'
                    is_nue = True
            if not is_nue:
                node['fields'].append({
                    'name': 'coordinateSystem',
                    'value': 'NUE',
                    'type': 'SFString'
                })
        elif node['name'] not in [
                'Viewpoint', 'TexturedBackground', 'TexturedBackgroundLight'
        ]:
            print('Rotating', node['name'])
            rotation_found = False
            for field in node['fields']:
                if field['name'] in ['rotation']:
                    rotation_found = True
                    field['value'] = rotation(field['value'],
                                              [0, 1, 0, 0.5 * math.pi])
                elif field['name'] in ['translation']:
                    field['value'] = [
                        field['value'][2], field['value'][1],
                        str(-float(field['value'][0]))
                    ]
            if not rotation_found:
                node['fields'].append({
                    'name':
                    'rotation',
                    'value': ['0', '1', '0', str(0.5 * math.pi)],
                    'type':
                    'SFRotation'
                })
    world.save(filename)
Exemplo n.º 3
0
def convert_to_nue(filename):
    world = WebotsParser()
    world.load(filename)

    for node in world.content['root']:
        if node['name'] == 'WorldInfo':
            for field in node['fields']:
                if field['name'] == 'gravity':
                    gravity = float(field['value'][1])
                    if gravity != 0:
                        gravity = -gravity
                    field['value'] = WebotsParser.str(gravity)
                    field['type'] = 'SFFloat'
                if field[
                        'name'] == 'coordinateSystem':  # world file already updated
                    return
            node['fields'].append({
                'name': 'coordinateSystem',
                'value': 'NUE',
                'type': 'SFString'
            })
        elif node['name'] in converted_protos:
            print('Rotating', node['name'])
            rotation_found = False
            for field in node['fields']:
                if field['name'] in ['rotation']:
                    rotation_found = True
                    field['value'] = rotation(field['value'],
                                              converted_protos[node['name']])
            if not rotation_found:
                node['fields'].append({
                    'name':
                    'rotation',
                    'value':
                    rotation(['0', '1', '0', '0'],
                             converted_protos[node['name']]),
                    'type':
                    'SFRotation'
                })
    world.save(filename)