Guest User

obj 2 Illustrator

a guest
May 3rd, 2010
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.84 KB | None | 0 0
  1. import os, sys
  2. import re
  3. import string
  4. import time
  5. #This script takes the UV coordinates from a 3d OBJ model, and traces the faces of the model onto the UV plane with paths
  6. #So you can get vector masks for your UVs!
  7.  
  8. #set the name of your file here, and the size your gonna want the texture
  9. #then launch the script!
  10. #note: when in fireworks, dont forget to combine paths to a union!
  11. # by Beherith ([email protected]) Licence: CC
  12. filename= 'storm6.obj'
  13. xsize= 1024
  14. ysize = 1024
  15.  
  16.  
  17. f= open(filename)
  18.  
  19. vertexes=[]
  20. uvs=range(1,100000)
  21. uvs[1]=3
  22. faces=[]
  23. uvcnt=0
  24. lines=f.readlines()
  25. outfilename=filename + '.ai'
  26. outfile=open(outfilename,'w')
  27. for line in lines:
  28.     if line.find('vt')==0:
  29.         uvcnt+=1 #cause vertexes are numbered from 1 in OBJ files
  30.         lsplit= line.split(' ')
  31.         try:
  32.             u=float(lsplit[1])
  33.             v=float(lsplit[2])
  34.            
  35.         except ValueError:
  36.             print "error parsing line %s"% line
  37.            
  38.         uvs[uvcnt]=[u,v];
  39.        
  40. 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")
  41. outfile.write("%%%%BoundingBox:0 0 %i %i\n"%(xsize,ysize))
  42. outfile.write("%%AI3_TemplateBox: 0 0 %i %i\n"%(xsize,ysize))
  43. 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")
  44.  
  45. for line in lines:
  46.     if line.find('f')==0:
  47.         fsplit=line.split(' ')
  48.         outfile.write("0.600 0.600 0.400 Xa\n1 XR\n")
  49.         first=-1
  50.         for vert in fsplit:
  51.             if vert != 'f':
  52.                 nums=vert.split('/');
  53.                 try:
  54.                     index= int(nums[1])
  55.                 except ValueError:
  56.                     print "error parsing %s" %line
  57.                     index=1
  58.                 if first==-1:
  59.                     outfile.write("%f %f m\n"%(uvs[index][0]*xsize,uvs[index][1]*ysize))
  60.                     first=index
  61.                 else:
  62.                     outfile.write("%f %f l\n"%(uvs[index][0]*xsize,uvs[index][1]*ysize))
  63.         outfile.write("%f %f l\n"%(uvs[first][0]*xsize,uvs[first][1]*ysize))
  64.         outfile.write("f\n")
  65.        
  66. 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")
  67. outfile.close()
  68. print "done"
  69. s = raw_input('Done, press ENTER to exit')
Advertisement
Add Comment
Please, Sign In to add comment