Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, sys
- import re
- import string
- import time
- #This script takes the UV coordinates from a 3d OBJ model, and traces the faces of the model onto the UV plane with paths
- #So you can get vector masks for your UVs!
- #set the name of your file here, and the size your gonna want the texture
- #then launch the script!
- #note: when in fireworks, dont forget to combine paths to a union!
- filename= 'storm6.obj'
- xsize= 1024
- ysize = 1024
- f= open(filename)
- vertexes=[]
- uvs=range(1,100000)
- uvs[1]=3
- faces=[]
- uvcnt=0
- lines=f.readlines()
- outfilename=filename + '.ai'
- outfile=open(outfilename,'w')
- for line in lines:
- if line.find('vt')==0:
- uvcnt+=1 #cause vertexes are numbered from 1 in OBJ files
- lsplit= line.split(' ')
- try:
- u=float(lsplit[1])
- v=float(lsplit[2])
- except ValueError:
- print "error parsing line %s"% line
- uvs[uvcnt]=[u,v];
- outfile.write("%!PS-Adobe-3.0\n%%Creator: Adobe Fireworks\n%%DocumentNeededResources: procset Adobe_level2_AI5 1.0 0\n%%+ procset Adobe_packedarray 2.0 0\n%%+ procset Adobe_cmykcolor 1.1 0\n%%+ procset Adobe_cshow 1.1 0\n%%+ procset Adobe_customcolor 1.0 0\n%%+ procset Adobe_typography_AI5 1.0 0 \n%%+ procset Adobe_Illustrator_AI5 1.0 0 \n")
- outfile.write("%%%%BoundingBox:0 0 %i %i\n"%(xsize,ysize))
- outfile.write("%%AI3_TemplateBox: 0 0 %i %i\n"%(xsize,ysize))
- outfile.write("%%PageOrigin:0 0\n%AI5_FileFormat 3\n%AI3_ColorUsage: Color\n%%DocumentProcessColors: Cyan Magenta Yellow Black\n%%EndComments\n%%BeginProlog\n%%EndProlog\n%%BeginSetup\nAdobe_packedarray /initialize get exec\nAdobe_cmykcolor /initialize get exec\nAdobe_cshow /initialize get exec\nAdobe_customcolor /initialize get exec\nAdobe_typography_AI5 /initialize get exec\nAdobe_Illustrator_AI5 /initialize get exec\n%%EndSetup\n1 1 1 1 0 0 0 79 128 255 Lb \n(Layer 1) Ln \n")
- for line in lines:
- if line.find('f')==0:
- fsplit=line.split(' ')
- outfile.write("0.600 0.600 0.400 Xa\n1 XR\n")
- first=-1
- for vert in fsplit:
- if vert != 'f':
- nums=vert.split('/');
- try:
- index= int(nums[1])
- except ValueError:
- print "error parsing %s" %line
- index=1
- if first==-1:
- outfile.write("%f %f m\n"%(uvs[index][0]*xsize,uvs[index][1]*ysize))
- first=index
- else:
- outfile.write("%f %f l\n"%(uvs[index][0]*xsize,uvs[index][1]*ysize))
- outfile.write("%f %f l\n"%(uvs[first][0]*xsize,uvs[first][1]*ysize))
- outfile.write("f\n")
- outfile.write("LB\n%%PageTrailer\ngsave annotatepage grestore showpage\n%%Trailer\nAdobe_Illustrator_AI5 /terminate get exec\nAdobe_typography_AI5 /terminate get exec\nAdobe_customcolor /terminate get exec\nAdobe_cshow /terminate get exec\nAdobe_cmykcolor /terminate get exec\nAdobe_packedarray /terminate get exec\n%%EOF\n")
- outfile.close()
- print "done"
- s = raw_input('Done, press ENTER to exit')
Advertisement
Add Comment
Please, Sign In to add comment