Skip to content

Instantly share code, notes, and snippets.

@hdon
Created February 4, 2009 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdon/57966 to your computer and use it in GitHub Desktop.
Save hdon/57966 to your computer and use it in GitHub Desktop.
donny@teamspace:~/.blender/scripts$ diff obj_export.py obj_export2.py
4c4
< Name: 'Wavefront (.obj)...'
---
> Name: 'Wavefront (w/color) (.obj)...'
10c10
< __author__ = "Campbell Barton, Jiri Hnidek"
---
> __author__ = "Campbell Barton, Jiri Hnidek, Donny Viszneki"
12c12
< __version__ = "1.0"
---
> __version__ = "1.1"
49a50,57
> # Use itertools.izip_longest() if possible, otherwise use zip(None, ...)
> def zip_longest(*args):
> return map(None, *args)
> try:
> import itertools
> zip_longest = itertools.izip_longest
> except: pass
>
203c211,212
< EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False):
---
> EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False,\
> EXPORT_VERTEX_COLORS=True):
413a423,424
> # Begin writing a face record
> # An 'f' begins the record
415,455c426,449
< if m.faceUV and EXPORT_UV:
< if EXPORT_NORMALS:
< if f.smooth: # Smoothed, use vertex normals
< for vi, v in enumerate(f_v):
< file.write( ' %d/%d/%d' % (\
< v.index+totverts,\
< globalUVCoords[ veckey2d(f.uv[vi]) ],\
< globalNormals[ veckey3d(v.no) ])) # vert, uv, normal
< else: # No smoothing, face normals
< no = globalNormals[ veckey3d(f.no) ]
< for vi, v in enumerate(f_v):
< file.write( ' %d/%d/%d' % (\
< v.index+totverts,\
< globalUVCoords[ veckey2d(f.uv[vi]) ],\
< no)) # vert, uv, normal
<
< else: # No Normals
< for vi, v in enumerate(f_v):
< file.write( ' %d/%d' % (\
< v.index+totverts,\
< globalUVCoords[ veckey2d(f.uv[vi])])) # vert, uv
<
<
< else: # No UV's
< if EXPORT_NORMALS:
< if f.smooth: # Smoothed, use vertex normals
< for v in f_v:
< file.write( ' %d//%d' % (\
< v.index+totverts,\
< globalNormals[ veckey3d(v.no) ]))
< else: # No smoothing, face normals
< no = globalNormals[ veckey3d(f.no) ]
< for v in f_v:
< file.write( ' %d//%d' % (\
< v.index+totverts,\
< no))
< else: # No Normals
< for v in f_v:
< file.write( ' %d' % (\
< v.index+totverts))
<
---
> PER_VERT_NORMALS = EXPORT_NORMALS and f.smooth
> # Collect per-face normal
> if EXPORT_NORMALS:
> if not f.smooth:
> no = globalNormals[ veckey3d(f.no) ]
> else: no = ''
> # Write all face vertex records
> for i,(v,uv,col) in enumerate(zip_longest(f.v, m.faceUV and f.uv or [], f.col)):
> # Collect per-vertex normal
> if PER_VERT_NORMALS:
> no = globalNormals[veckey3d(v.no)]
> # Collect model vertex
> vt = v.index + totverts
> # Collect texture vertex
> if EXPORT_UV and uv: uv = globalUVCoords[veckey2d(uv)]
> else: uv = ''
> # Collect per-vertex color
> if EXPORT_VERTEX_COLORS:
> col = '#%02x%02x%02x' % (col.r, col.g, col.b)
> else: col = ''
> # Finally, output a face vertex record
> file.write(' %d/%s/%s%s' % (vt, uv, no, col))
>
> # End face record
516c510
<
---
> EXPORT_VERTEX_COLORS = Draw.Create(1)
536a531
> ('Vertex Colors', EXPORT_VERTEX_COLORS, 'Export vertex colors.'),\
557a553
> EXPORT_VERTEX_COLORS = EXPORT_VERTEX_COLORS.val
603c599,600
< EXPORT_BLEN_OBS, EXPORT_GROUP_BY_OB, EXPORT_GROUP_BY_MAT)
---
> EXPORT_BLEN_OBS, EXPORT_GROUP_BY_OB, EXPORT_GROUP_BY_MAT,\
> EXPORT_VERTEX_COLORS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment