07-24-2010, 06:01 PM,
|
|
NaN
Posting Freak
|
Posts: 2,024
Threads: 120
Joined: Jan 2010
|
|
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.
|
|
08-08-2010, 02:35 AM,
|
|
alex25
Senior Member
|
Posts: 531
Threads: 42
Joined: Jun 2006
|
|
NaN Wrote:It is actually ready since July 25th. I just haven't uploaded it. I would like to rewrite the scene description format completely, evaluating the options at the moment. having just used the import script i have to say that i found it extremely useful. great job. let me make a suggestion, if i may (based on the experience with hungaroring06). joe file names look something like this: bridge_ad_lights_02.dof-00.joe, bridge_ad_lights_02.dof-01.joe. when importing, it will be nice to strip the .dof-??.joe part and combine them into a single blender object. then when i export them back i would get a single dof object bridge_ad_lights_02.dof so it would be easier to see what changed (and ultimately the names of the joe object files would stay the same). hopefully i was clear enough and that this is something simple enough to implement (this would also save 10 characters for the file names which considering the blender name length limitation will also help).
thanks for the great work.
--alex--
|
|
08-16-2010, 05:42 PM,
|
|
alex25
Senior Member
|
Posts: 531
Threads: 42
Joined: Jun 2006
|
|
NaN Wrote:I've hit a serious issue not sure how to deal with. For some strange reason Blender limits the length of the texture/model name to 21 characters. This means some texture/joe names will be truncated/incorrect after export, sigh.
Any suggestions are welcomed. i suggest mapping the names to something blender will accept (take the first 18 characters and add a three digit prefix, for example. this is what i think blender does). write the mapping to a file. have the export file read the mapping file and rename the object back to its original name when saving it. i'm using blender and the import/export scripts to fix the tracks and trying to figure out the mapping between the blender names and the original names is a real pain in the ass. i don't think it would be that hard to implement (maybe not elegant, but such is life). thanks.
--alex--
|
|
08-18-2010, 11:50 AM,
|
|
NaN
Posting Freak
|
Posts: 2,024
Threads: 120
Joined: Jan 2010
|
|
Haven't made much progress towards a new track description format, sigh.
I've uploaded the most recent vdrift.py. The script will apply materials named surface-xx with distinct colors to track objects depending on their surface. To change the surface select one of the available surface-xx materials or create a new one called surface-xx(xx number of the surface).
http://svn.vdrift.net/repos/vdrift-art/trunk/tools/
|
|
08-18-2010, 12:06 PM,
|
|
alex25
Senior Member
|
Posts: 531
Threads: 42
Joined: Jun 2006
|
|
hmm, this broke the import scripts:
Code: max: 0
Traceback (most recent call last):
File "import-jpk.py", line 25, in load_jpk
jpk = joe_pack().load(filename)
File "./vdrift.py", line 352, in load
self.load_list(filename)
File "./vdrift.py", line 479, in load_list
delta = scale / maxid
ZeroDivisionError: integer division or modulo by zero
as for the long names. apparently you can store the long names in IDProperties and then use that on export. trying to figure out how to actually do it.
--alex--
|
|
|