Revision: 20842 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20842 Author: campbellbarton Date: 2009-06-13 05:05:20 +0200 (Sat, 13 Jun 2009)
Log Message: ----------- X90 Rotate option so you can export without rotation and import, keeping the same orientation. Modified Paths: -------------- trunk/blender/release/scripts/import_obj.py Modified: trunk/blender/release/scripts/import_obj.py =================================================================== --- trunk/blender/release/scripts/import_obj.py 2009-06-13 01:30:47 UTC (rev 20841) +++ trunk/blender/release/scripts/import_obj.py 2009-06-13 03:05:20 UTC (rev 20842) @@ -2,7 +2,7 @@ """ Name: 'Wavefront (.obj)...' -Blender: 248 +Blender: 249 Group: 'Import' Tooltip: 'Load a Wavefront OBJ File, Shift: batch import all dir.' """ @@ -40,7 +40,7 @@ # ***** END GPL LICENCE BLOCK ***** # -------------------------------------------------------------------------- -from Blender import * +from Blender import Mesh, Draw, Window, Texture, Material, sys, Mathutils import bpy import BPyMesh import BPyImage @@ -614,7 +614,15 @@ ob = scn.objects.new(cu) new_objects.append(ob) +def transform_tuples(verts_loc, matrix): + vec = Mathutils.Vector(0.0,0.0,0.0) + def rotvec(v): + vec[:] = v + return tuple(vec * matrix) + + verts_loc[:] = [rotvec(v) for v in verts_loc] + def strip_slash(line_split): if line_split[-1][-1]== '\\': if len(line_split[-1])==1: @@ -651,6 +659,7 @@ SPLIT_OBJECTS= True, SPLIT_GROUPS= True, SPLIT_MATERIALS= True, + ROTATE_X90= True, IMAGE_SEARCH=True, POLYGROUPS=False): ''' @@ -921,6 +930,8 @@ print '%.4f sec' % (time_new-time_sub) time_sub= time_new + if not ROTATE_X90: + transform_tuples(verts_loc, Mathutils.RotationMatrix(-90, 3, 'x')) # deselect all scn = bpy.data.scenes.active @@ -962,6 +973,11 @@ for ob in new_objects: ob.setSize(scale, scale, scale) + # Better rotate the vert locations + #if not ROTATE_X90: + # for ob in new_objects: + # ob.RotX = -1.570796326794896558 + time_new= sys.time() print '%.4f sec' % (time_new-time_sub) @@ -975,7 +991,7 @@ if BPyMessages.Error_NoFile(filepath): return - global CREATE_SMOOTH_GROUPS, CREATE_FGONS, CREATE_EDGES, SPLIT_OBJECTS, SPLIT_GROUPS, SPLIT_MATERIALS, CLAMP_SIZE, IMAGE_SEARCH, POLYGROUPS, KEEP_VERT_ORDER + global CREATE_SMOOTH_GROUPS, CREATE_FGONS, CREATE_EDGES, SPLIT_OBJECTS, SPLIT_GROUPS, SPLIT_MATERIALS, CLAMP_SIZE, IMAGE_SEARCH, POLYGROUPS, KEEP_VERT_ORDER, ROTATE_X90 CREATE_SMOOTH_GROUPS= Draw.Create(0) CREATE_FGONS= Draw.Create(1) @@ -987,6 +1003,7 @@ IMAGE_SEARCH= Draw.Create(1) POLYGROUPS= Draw.Create(0) KEEP_VERT_ORDER= Draw.Create(1) + ROTATE_X90= Draw.Create(1) # Get USER Options @@ -1073,7 +1090,7 @@ ui_x -= 165 ui_y -= 90 - global CREATE_SMOOTH_GROUPS, CREATE_FGONS, CREATE_EDGES, SPLIT_OBJECTS, SPLIT_GROUPS, SPLIT_MATERIALS, CLAMP_SIZE, IMAGE_SEARCH, POLYGROUPS, KEEP_VERT_ORDER + global CREATE_SMOOTH_GROUPS, CREATE_FGONS, CREATE_EDGES, SPLIT_OBJECTS, SPLIT_GROUPS, SPLIT_MATERIALS, CLAMP_SIZE, IMAGE_SEARCH, POLYGROUPS, KEEP_VERT_ORDER, ROTATE_X90 Draw.Label('Import...', ui_x+9, ui_y+159, 220, 21) Draw.BeginAlign() @@ -1084,14 +1101,16 @@ Draw.Label('Separate objects by OBJ...', ui_x+9, ui_y+110, 220, 20) Draw.BeginAlign() - SPLIT_OBJECTS = Draw.Toggle('Object', EVENT_REDRAW, ui_x+9, ui_y+89, 70, 21, SPLIT_OBJECTS.val, 'Import OBJ Objects into Blender Objects', do_split) - SPLIT_GROUPS = Draw.Toggle('Group', EVENT_REDRAW, ui_x+79, ui_y+89, 70, 21, SPLIT_GROUPS.val, 'Import OBJ Groups into Blender Objects', do_split) - SPLIT_MATERIALS = Draw.Toggle('Material', EVENT_REDRAW, ui_x+149, ui_y+89, 70, 21, SPLIT_MATERIALS.val, 'Import each material into a seperate mesh (Avoids > 16 per mesh error)', do_split) + SPLIT_OBJECTS = Draw.Toggle('Object', EVENT_REDRAW, ui_x+9, ui_y+89, 55, 21, SPLIT_OBJECTS.val, 'Import OBJ Objects into Blender Objects', do_split) + SPLIT_GROUPS = Draw.Toggle('Group', EVENT_REDRAW, ui_x+64, ui_y+89, 55, 21, SPLIT_GROUPS.val, 'Import OBJ Groups into Blender Objects', do_split) + SPLIT_MATERIALS = Draw.Toggle('Material', EVENT_REDRAW, ui_x+119, ui_y+89, 60, 21, SPLIT_MATERIALS.val, 'Import each material into a seperate mesh (Avoids > 16 per mesh error)', do_split) Draw.EndAlign() # Only used for user feedback - KEEP_VERT_ORDER = Draw.Toggle('Keep Vert Order', EVENT_REDRAW, ui_x+229, ui_y+89, 110, 21, KEEP_VERT_ORDER.val, 'Keep vert and face order, disables split options, enable for morph targets', do_vertorder) + KEEP_VERT_ORDER = Draw.Toggle('Keep Vert Order', EVENT_REDRAW, ui_x+184, ui_y+89, 113, 21, KEEP_VERT_ORDER.val, 'Keep vert and face order, disables split options, enable for morph targets', do_vertorder) + ROTATE_X90 = Draw.Toggle('-X90', EVENT_REDRAW, ui_x+302, ui_y+89, 38, 21, ROTATE_X90.val, 'Rotate X 90.') + Draw.Label('Options...', ui_x+9, ui_y+60, 211, 20) CLAMP_SIZE = Draw.Number('Clamp Scale: ', EVENT_NONE, ui_x+9, ui_y+39, 130, 21, CLAMP_SIZE.val, 0.0, 1000.0, 'Clamp the size to this maximum (Zero to Disable)') POLYGROUPS = Draw.Toggle('Poly Groups', EVENT_REDRAW, ui_x+144, ui_y+39, 90, 21, POLYGROUPS.val, 'Import OBJ groups as vertex groups.', do_polygroups) @@ -1145,6 +1164,7 @@ SPLIT_OBJECTS.val,\ SPLIT_GROUPS.val,\ SPLIT_MATERIALS.val,\ + ROTATE_X90.val,\ IMAGE_SEARCH.val,\ POLYGROUPS.val ) @@ -1158,6 +1178,7 @@ SPLIT_OBJECTS.val,\ SPLIT_GROUPS.val,\ SPLIT_MATERIALS.val,\ + ROTATE_X90.val,\ IMAGE_SEARCH.val,\ POLYGROUPS.val ) @@ -1176,7 +1197,7 @@ else: Window.FileSelector(load_obj_ui, 'Import a Wavefront OBJ', '*.obj') -# For testing compatibility + # For testing compatibility ''' else: # DEBUG ONLY @@ -1197,7 +1218,7 @@ print 'Importing', obj_file, '\nNUMBER', i, 'of', len(files) newScn= bpy.data.scenes.new(os.path.basename(obj_file)) newScn.makeCurrent() - load_obj(obj_file, False) + load_obj(obj_file, False, IMAGE_SEARCH=0) print 'TOTAL TIME: %.6f' % (sys.time() - TIME) ''' _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs