Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
surfaces.txt
07-24-2010, 06:01 PM,
#5
 
The script looks for list.txt files in root, creates surfaces.txt and updates list.txt.

Code:
import os

def locate(pattern, root=os.getcwd()):
    for path, dirs, files in os.walk(root):
        for filename in [os.path.abspath(os.path.join(path, filename)) for filename in files if filename.endswith(pattern)]:
            yield filename

root = 'E:/vdrift/vdrift-data/tracks'
pattern = 'list.txt'

for filename in locate(pattern, root):
    print filename
    objects = []
    object = []
    file = open(filename)
    line = file.readline().rstrip()
    while line != '':
        if '.joe' in line:
            if len(object): objects.append(object)
            object = []
            object.append(line)
        elif len(object) > 0 and line != '\n' and line != '' and not line.startswith('#'):
            object.append(line)
        line = file.readline()
    objects.append(object)
    file.close()
    #print 'objects: ' + str(len(objects))
    surfaces = []
    for object in objects:
        surface = [object[6], object[7], object[10], object[11], object[12], object[13]]
        i = 0
        while i < len(surfaces):
            if surface == surfaces[i]: break
            i = i + 1
        if i == len(surfaces):
            surfaces.append(surface)
        if len(object) == 14:
            object.extend(['0\n', '0\n', str(i)+'\n'])
        elif len(object) == 16:
            object.append(str(i)+'\n')
        else:
            object[16] = str(i)+'\n'
    #print 'surfaces: ' + str(len(surfaces))
    dir = os.path.dirname(filename)
    sfile = open(dir + '/surfaces.txt', 'w')
    id = 0
    for surface in surfaces:
        #print surface
        sfile.write('[surface-'+ str(id).zfill(2) + ']\n')
        #sfile.write('ID = ' + str(id) + '\n')
        sfile.write('Type = asphalt\n')
        sfile.write('BumpWaveLength = ' + str(surface[0]))
        sfile.write('BumpAmplitude = ' + str(surface[1]))
        sfile.write('FrictionNonTread = ' + str(surface[2]))
        sfile.write('FrictionTread = ' + str(surface[3]))
        sfile.write('RollResistanceCoefficient = ' + str(surface[4]))
        sfile.write('RollingDrag = ' + str(surface[5]))
        sfile.write('\n')
        id = id + 1
    sfile.close()
    #print 'write objects'
    file = open(filename, 'w')
    file.write('17\n')
    i = 0
    for object in objects:
        file.write('\n#entry ' + str(i) + '\n')
        i = i + 1
        for entry in object:
            file.write(str(entry))
    file.close()

By the way, I am currently updating the import_jpk/export_jpk scripts to support object parameters.
[Image: Unbenannto5oj0.jpg]
Reply


Messages In This Thread
surfaces.txt - by alex25 - 07-19-2010, 03:06 PM
[No subject] - by NaN - 07-20-2010, 01:05 PM
[No subject] - by alex25 - 07-21-2010, 03:15 PM
[No subject] - by alex25 - 07-24-2010, 05:37 PM
[No subject] - by NaN - 07-24-2010, 06:01 PM
[No subject] - by alex25 - 07-25-2010, 01:54 PM
[No subject] - by NaN - 07-25-2010, 04:37 PM
[No subject] - by thelusiv - 08-05-2010, 03:44 AM
[No subject] - by NaN - 08-05-2010, 03:17 PM
[No subject] - by alex25 - 08-08-2010, 02:35 AM
[No subject] - by alex25 - 08-16-2010, 05:42 PM
[No subject] - by NaN - 08-18-2010, 11:50 AM
[No subject] - by alex25 - 08-18-2010, 12:06 PM
[No subject] - by NaN - 08-18-2010, 12:24 PM
[No subject] - by NaN - 08-18-2010, 12:32 PM
[No subject] - by alex25 - 08-18-2010, 12:48 PM
[No subject] - by alex25 - 08-18-2010, 01:24 PM
[No subject] - by NaN - 08-18-2010, 02:31 PM
[No subject] - by alex25 - 08-18-2010, 03:10 PM
[No subject] - by alex25 - 08-19-2010, 12:46 PM
[No subject] - by NaN - 08-20-2010, 06:52 AM
[No subject] - by thelusiv - 08-22-2010, 04:43 AM
[No subject] - by NaN - 08-22-2010, 02:33 PM
[No subject] - by alex25 - 08-22-2010, 08:20 PM
[No subject] - by thelusiv - 08-23-2010, 05:15 AM
[No subject] - by portets - 08-23-2010, 09:48 PM
[No subject] - by NaN - 08-24-2010, 08:19 AM
[No subject] - by thelusiv - 08-24-2010, 09:50 PM
[No subject] - by NaN - 08-25-2010, 12:53 PM
[No subject] - by NaN - 08-25-2010, 04:06 PM
[No subject] - by thelusiv - 08-25-2010, 09:42 PM
[No subject] - by NaN - 08-26-2010, 03:53 AM
[No subject] - by thelusiv - 08-26-2010, 09:45 PM
[No subject] - by thelusiv - 08-27-2010, 07:42 AM
[No subject] - by NaN - 08-27-2010, 01:10 PM
[No subject] - by thelusiv - 08-29-2010, 06:34 PM
[No subject] - by NaN - 08-29-2010, 07:45 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)