added option "morph target" since many people complain that verts are re-ordered with some options enabled.

This commit is contained in:
2007-01-26 07:01:30 +00:00
parent 0decfd140b
commit 7239784b17
2 changed files with 39 additions and 14 deletions

View File

@@ -24,7 +24,7 @@ will be exported as mesh data.
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# OBJ Export v1.0 by Campbell Barton (AKA Ideasman) # OBJ Export v1.1 by Campbell Barton (AKA Ideasman)
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK ***** # ***** BEGIN GPL LICENSE BLOCK *****
# #
@@ -202,7 +202,7 @@ def write(filename, objects,\
EXPORT_TRI=False, EXPORT_EDGES=False, EXPORT_NORMALS=False, EXPORT_NORMALS_HQ=False,\ EXPORT_TRI=False, EXPORT_EDGES=False, EXPORT_NORMALS=False, EXPORT_NORMALS_HQ=False,\
EXPORT_UV=True, EXPORT_MTL=True, EXPORT_COPY_IMAGES=False,\ EXPORT_UV=True, EXPORT_MTL=True, EXPORT_COPY_IMAGES=False,\
EXPORT_APPLY_MODIFIERS=True, EXPORT_ROTX90=True, EXPORT_BLEN_OBS=True,\ EXPORT_APPLY_MODIFIERS=True, EXPORT_ROTX90=True, EXPORT_BLEN_OBS=True,\
EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False): EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False, EXPORT_MORPH_TARGET=False):
''' '''
Basic write function. The context and options must be alredy set Basic write function. The context and options must be alredy set
This can be accessed externaly This can be accessed externaly
@@ -223,6 +223,7 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False):
file.write('# www.blender3d.org\n') file.write('# www.blender3d.org\n')
# Tell the obj file what material file to use. # Tell the obj file what material file to use.
if EXPORT_MTL:
mtlfilename = '%s.mtl' % '.'.join(filename.split('.')[:-1]) mtlfilename = '%s.mtl' % '.'.join(filename.split('.')[:-1])
file.write('mtllib %s\n' % ( mtlfilename.split('\\')[-1].split('/')[-1] )) file.write('mtllib %s\n' % ( mtlfilename.split('\\')[-1].split('/')[-1] ))
@@ -321,7 +322,9 @@ EXPORT_GROUP_BY_OB=False, EXPORT_GROUP_BY_MAT=False):
# Sort by Material, then images # Sort by Material, then images
# so we dont over context switch in the obj file. # so we dont over context switch in the obj file.
if faceuv and EXPORT_UV: if EXPORT_MORPH_TARGET:
pass
elif faceuv and EXPORT_UV:
try: faces.sort(key = lambda a: (a.mat, a.image, a.smooth)) try: faces.sort(key = lambda a: (a.mat, a.image, a.smooth))
except: faces.sort(lambda a,b: cmp((a.mat, a.image, a.smooth), (b.mat, b.image, b.smooth))) except: faces.sort(lambda a,b: cmp((a.mat, a.image, a.smooth), (b.mat, b.image, b.smooth)))
elif len(materials) > 1: elif len(materials) > 1:
@@ -517,7 +520,7 @@ def write_ui(filename):
EXPORT_TRI = Draw.Create(0) EXPORT_TRI = Draw.Create(0)
EXPORT_EDGES = Draw.Create(1) EXPORT_EDGES = Draw.Create(1)
EXPORT_NORMALS = Draw.Create(0) EXPORT_NORMALS = Draw.Create(0)
EXPORT_NORMALS_HQ = Draw.Create(0) EXPORT_NORMALS_HQ = Draw.Create(1)
EXPORT_UV = Draw.Create(1) EXPORT_UV = Draw.Create(1)
EXPORT_MTL = Draw.Create(1) EXPORT_MTL = Draw.Create(1)
EXPORT_SEL_ONLY = Draw.Create(1) EXPORT_SEL_ONLY = Draw.Create(1)
@@ -527,6 +530,9 @@ def write_ui(filename):
EXPORT_BLEN_OBS = Draw.Create(1) EXPORT_BLEN_OBS = Draw.Create(1)
EXPORT_GROUP_BY_OB = Draw.Create(0) EXPORT_GROUP_BY_OB = Draw.Create(0)
EXPORT_GROUP_BY_MAT = Draw.Create(0) EXPORT_GROUP_BY_MAT = Draw.Create(0)
EXPORT_MORPH_TARGET = Draw.Create(0)
# removed too many options are bad!
# Get USER Options # Get USER Options
@@ -538,7 +544,7 @@ def write_ui(filename):
('Object Prefs...'),\ ('Object Prefs...'),\
('Apply Modifiers', EXPORT_APPLY_MODIFIERS, 'Use transformed mesh data from each object. May break vert order for morph targets.'),\ ('Apply Modifiers', EXPORT_APPLY_MODIFIERS, 'Use transformed mesh data from each object. May break vert order for morph targets.'),\
('Rotate X90', EXPORT_ROTX90 , 'Rotate on export so Blenders UP is translated into OBJs UP'),\ ('Rotate X90', EXPORT_ROTX90 , 'Rotate on export so Blenders UP is translated into OBJs UP'),\
(''),\ ('Morph Target', EXPORT_MORPH_TARGET, 'Keep vert and face order, disables some other options.'),\
('Extra Data...'),\ ('Extra Data...'),\
('Edges', EXPORT_EDGES, 'Edges not connected to faces.'),\ ('Edges', EXPORT_EDGES, 'Edges not connected to faces.'),\
('Normals', EXPORT_NORMALS, 'Export vertex normal data (Ignored on import).'),\ ('Normals', EXPORT_NORMALS, 'Export vertex normal data (Ignored on import).'),\
@@ -556,6 +562,13 @@ def write_ui(filename):
if not Draw.PupBlock('Export...', pup_block): if not Draw.PupBlock('Export...', pup_block):
return return
if EXPORT_MORPH_TARGET.val:
EXPORT_BLEN_OBS.val = False
EXPORT_GROUP_BY_OB.val = False
EXPORT_GROUP_BY_MAT.val = False
EXPORT_GROUP_BY_MAT.val = False
EXPORT_APPLY_MODIFIERS.val = False
Window.EditMode(0) Window.EditMode(0)
Window.WaitCursor(1) Window.WaitCursor(1)
@@ -574,6 +587,7 @@ def write_ui(filename):
EXPORT_BLEN_OBS = EXPORT_BLEN_OBS.val EXPORT_BLEN_OBS = EXPORT_BLEN_OBS.val
EXPORT_GROUP_BY_OB = EXPORT_GROUP_BY_OB.val EXPORT_GROUP_BY_OB = EXPORT_GROUP_BY_OB.val
EXPORT_GROUP_BY_MAT = EXPORT_GROUP_BY_MAT.val EXPORT_GROUP_BY_MAT = EXPORT_GROUP_BY_MAT.val
EXPORT_MORPH_TARGET = EXPORT_MORPH_TARGET.val
@@ -623,7 +637,7 @@ def write_ui(filename):
EXPORT_NORMALS_HQ, EXPORT_UV, EXPORT_MTL,\ EXPORT_NORMALS_HQ, EXPORT_UV, EXPORT_MTL,\
EXPORT_COPY_IMAGES, EXPORT_APPLY_MODIFIERS,\ EXPORT_COPY_IMAGES, EXPORT_APPLY_MODIFIERS,\
EXPORT_ROTX90, EXPORT_BLEN_OBS,\ EXPORT_ROTX90, EXPORT_BLEN_OBS,\
EXPORT_GROUP_BY_OB, EXPORT_GROUP_BY_MAT) EXPORT_GROUP_BY_OB, EXPORT_GROUP_BY_MAT, EXPORT_MORPH_TARGET)
Blender.Set('curframe', orig_frame) Blender.Set('curframe', orig_frame)

View File

@@ -723,42 +723,54 @@ def load_obj_ui(filepath, BATCH_LOAD= False):
if BPyMessages.Error_NoFile(filepath): if BPyMessages.Error_NoFile(filepath):
return return
CREATE_SMOOTH_GROUPS= Draw.Create(0) CREATE_SMOOTH_GROUPS= Draw.Create(0)
CREATE_FGONS= Draw.Create(1) CREATE_FGONS= Draw.Create(1)
CREATE_EDGES= Draw.Create(1) CREATE_EDGES= Draw.Create(1)
SPLIT_OBJECTS= Draw.Create(1) SPLIT_OBJECTS= Draw.Create(1)
SPLIT_GROUPS= Draw.Create(1) SPLIT_GROUPS= Draw.Create(1)
SPLIT_MATERIALS= Draw.Create(1) SPLIT_MATERIALS= Draw.Create(1)
MORPH_TARGET= Draw.Create(0)
CLAMP_SIZE= Draw.Create(10.0) CLAMP_SIZE= Draw.Create(10.0)
IMAGE_SEARCH= Draw.Create(1) IMAGE_SEARCH= Draw.Create(1)
# Get USER Options # Get USER Options
pup_block= [\ pup_block= [\
'Import...',\
('Smooth Groups', CREATE_SMOOTH_GROUPS, 'Surround smooth groups by sharp edges'),\ ('Smooth Groups', CREATE_SMOOTH_GROUPS, 'Surround smooth groups by sharp edges'),\
('Create FGons', CREATE_FGONS, 'Import faces with more then 4 verts as fgons.'),\ ('Create FGons', CREATE_FGONS, 'Import faces with more then 4 verts as fgons.'),\
('Lines', CREATE_EDGES, 'Import lines and faces with 2 verts as edges'),\ ('Lines', CREATE_EDGES, 'Import lines and faces with 2 verts as edges'),\
('Split by Object', SPLIT_OBJECTS, 'Import OBJ Objects into Blender Objects'),\ 'Seperate objects from obj...',\
('Split by Groups', SPLIT_GROUPS, 'Import OBJ Groups into Blender Objects'),\ ('Object', SPLIT_OBJECTS, 'Import OBJ Objects into Blender Objects'),\
('Split by Material', SPLIT_MATERIALS, 'Import each material into a seperate mesh (Avoids > 16 per mesh error)'),\ ('Group', SPLIT_GROUPS, 'Import OBJ Groups into Blender Objects'),\
('Material', SPLIT_MATERIALS, 'Import each material into a seperate mesh (Avoids > 16 per mesh error)'),\
'Options...',\
('Morph Target', MORPH_TARGET, 'Keep vert and face order, disables some other options.'),\
('Clamp Scale:', CLAMP_SIZE, 0.0, 1000.0, 'Clamp the size to this maximum (Zero to Disable)'),\ ('Clamp Scale:', CLAMP_SIZE, 0.0, 1000.0, 'Clamp the size to this maximum (Zero to Disable)'),\
('Image Search', IMAGE_SEARCH, 'Search subdirs for any assosiated images (Warning, may be slow)'),\ ('Image Search', IMAGE_SEARCH, 'Search subdirs for any assosiated images (Warning, may be slow)'),\
] ]
if not Draw.PupBlock('Import OBJ...', pup_block): if not Draw.PupBlock('Import OBJ...', pup_block):
return return
if MORPH_TARGET.val:
SPLIT_OBJECTS.val = False
SPLIT_GROUPS.val = False
SPLIT_MATERIALS.val = False
Window.WaitCursor(1) Window.WaitCursor(1)
if BATCH_LOAD: # load the dir if BATCH_LOAD: # load the dir
try: try:
files= [ f for f in os.listdir(filepath) if f.lower().endswith('.obj') ] files= [ f for f in os.listdir(filepath) if f.lower().endswith('.obj') ]
except: except:
Window.WaitCursor(0)
Draw.PupMenu('Error%t|Could not open path ' + filepath) Draw.PupMenu('Error%t|Could not open path ' + filepath)
return return
if not files: if not files:
Window.WaitCursor(0)
Draw.PupMenu('Error%t|No files at path ' + filepath) Draw.PupMenu('Error%t|No files at path ' + filepath)
return return
@@ -824,7 +836,7 @@ else:
return False return False
for i, _obj in enumerate(lines): for i, _obj in enumerate(lines):
if between(i, 440,600): if between(i, 0,20):
_obj= _obj[:-1] _obj= _obj[:-1]
print 'Importing', _obj, '\nNUMBER', i, 'of', len(lines) print 'Importing', _obj, '\nNUMBER', i, 'of', len(lines)
_obj_file= _obj.split('/')[-1].split('\\')[-1] _obj_file= _obj.split('/')[-1].split('\\')[-1]
@@ -834,6 +846,5 @@ else:
print 'TOTAL TIME: %.6f' % (sys.time() - TIME) print 'TOTAL TIME: %.6f' % (sys.time() - TIME)
''' '''
#load_obj('/test.obj') #load_obj('/test.obj')
#load_obj('/fe/obj/mba1.obj') #load_obj('/fe/obj/mba1.obj')