[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21858] branches/soc-2009-kazanbas: - added operator for OBJ importer plus some python 3 conversions
Arystanbek Dyussenov
arystan.d at gmail.com
Fri Jul 24 16:26:48 CEST 2009
Revision: 21858
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21858
Author: kazanbas
Date: 2009-07-24 16:26:47 +0200 (Fri, 24 Jul 2009)
Log Message:
-----------
- added operator for OBJ importer plus some python 3 conversions
Modified Paths:
--------------
branches/soc-2009-kazanbas/release/io/export_obj.py
branches/soc-2009-kazanbas/release/io/import_obj.py
branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_pose.c
Modified: branches/soc-2009-kazanbas/release/io/export_obj.py
===================================================================
--- branches/soc-2009-kazanbas/release/io/export_obj.py 2009-07-24 13:41:57 UTC (rev 21857)
+++ branches/soc-2009-kazanbas/release/io/export_obj.py 2009-07-24 14:26:47 UTC (rev 21858)
@@ -200,19 +200,16 @@
# XXX not converted
def test_nurbs_compat(ob):
- if ob.type != 'CURVE':
+ if ob.type != 'Curve':
return False
- for nu in ob.data.curves:
+ for nu in ob.data:
if (not nu.knotsV) and nu.type != 1: # not a surface and not bezier
return True
-
-# for nu in ob.data:
-# if (not nu.knotsV) and nu.type != 1: # not a surface and not bezier
-# return True
return False
+
# XXX not converted
def write_nurb(file, ob, ob_mat):
tot_verts = 0
Modified: branches/soc-2009-kazanbas/release/io/import_obj.py
===================================================================
--- branches/soc-2009-kazanbas/release/io/import_obj.py 2009-07-24 13:41:57 UTC (rev 21857)
+++ branches/soc-2009-kazanbas/release/io/import_obj.py 2009-07-24 14:26:47 UTC (rev 21858)
@@ -57,7 +57,8 @@
lastSlash= max(path.rfind('\\'), path.rfind('/'))
if lastSlash != -1:
path= path[:lastSlash]
- return '%s%s' % (path, sys.sep)
+ return '%s%s' % (path, os.sep)
+# return '%s%s' % (path, sys.sep)
def stripPath(path):
'''Strips the slashes from the back of a string'''
@@ -219,8 +220,9 @@
# Add an MTL with the same name as the obj if no MTLs are spesified.
temp_mtl= stripExt(stripPath(filepath))+ '.mtl'
-
- if sys.exists(DIR + temp_mtl) and temp_mtl not in material_libs:
+
+ if os.path.exists(DIR + temp_mtl) and temp_mtl not in material_libs:
+# if sys.exists(DIR + temp_mtl) and temp_mtl not in material_libs:
material_libs.append( temp_mtl )
del temp_mtl
@@ -236,7 +238,7 @@
for libname in material_libs:
mtlpath= DIR + libname
- if not bpy.sys.exists(mtlpath):
+ if not os.path.exists(mtlpath):
# if not sys.exists(mtlpath):
#print '\tError Missing MTL: "%s"' % mtlpath
pass
@@ -247,7 +249,7 @@
for line in mtl: #.xreadlines():
if line.startswith('newmtl'):
context_material_name= line_value(line.split())
- if unique_materials.has_key(context_material_name):
+ if context_material_name in unique_materials:
context_material = unique_materials[ context_material_name ]
else:
context_material = None
@@ -377,14 +379,14 @@
face_vert_loc_indicies[enum] = vert_remap[i] # remap to the local index
matname= face[2]
- if matname and not unique_materials_split.has_key(matname):
+ if matname and matname not in unique_materials_split:
unique_materials_split[matname] = unique_materials[matname]
faces_split.append(face)
# remove one of the itemas and reorder
- return [(value[0], value[1], value[2], key_to_name(key)) for key, value in face_split_dict.iteritems()]
+ return [(value[0], value[1], value[2], key_to_name(key)) for key, value in face_split_dict.items()]
def create_mesh(scn, new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, verts_tex, faces, unique_materials, unique_material_images, unique_smooth_groups, vertex_groups, dataname):
@@ -397,7 +399,7 @@
if unique_smooth_groups:
sharp_edges= {}
- smooth_group_users= dict([ (context_smooth_group, {}) for context_smooth_group in unique_smooth_groups.iterkeys() ])
+ smooth_group_users= dict([ (context_smooth_group, {}) for context_smooth_group in unique_smooth_groups.keys() ])
context_smooth_group_old= -1
# Split fgons into tri's
@@ -408,7 +410,7 @@
context_object= None
# reverse loop through face indicies
- for f_idx in xrange(len(faces)-1, -1, -1):
+ for f_idx in range(len(faces)-1, -1, -1):
face_vert_loc_indicies,\
face_vert_tex_indicies,\
@@ -425,7 +427,7 @@
if CREATE_EDGES:
# generators are better in python 2.4+ but can't be used in 2.3
# edges.extend( (face_vert_loc_indicies[i], face_vert_loc_indicies[i+1]) for i in xrange(len_face_vert_loc_indicies-1) )
- edges.extend( [(face_vert_loc_indicies[i], face_vert_loc_indicies[i+1]) for i in xrange(len_face_vert_loc_indicies-1)] )
+ edges.extend( [(face_vert_loc_indicies[i], face_vert_loc_indicies[i+1]) for i in range(len_face_vert_loc_indicies-1)] )
faces.pop(f_idx)
else:
@@ -437,7 +439,7 @@
edge_dict= smooth_group_users[context_smooth_group]
context_smooth_group_old= context_smooth_group
- for i in xrange(len_face_vert_loc_indicies):
+ for i in range(len_face_vert_loc_indicies):
i1= face_vert_loc_indicies[i]
i2= face_vert_loc_indicies[i-1]
if i1>i2: i1,i2= i2,i1
@@ -485,8 +487,8 @@
# Build sharp edges
if unique_smooth_groups:
- for edge_dict in smooth_group_users.itervalues():
- for key, users in edge_dict.iteritems():
+ for edge_dict in smooth_group_users.values():
+ for key, users in edge_dict.items():
if users==1: # This edge is on the boundry of a group
sharp_edges[key]= None
@@ -496,7 +498,7 @@
materials= [None] * len(unique_materials)
- for name, index in material_mapping.iteritems():
+ for name, index in material_mapping.items():
materials[index]= unique_materials[name]
me= bpy.data.add_mesh(dataname)
@@ -639,7 +641,7 @@
# Create the vertex groups. No need to have the flag passed here since we test for the
# content of the vertex_groups. If the user selects to NOT have vertex groups saved then
# the following test will never run
- for group_name, group_indicies in vertex_groups.iteritems():
+ for group_name, group_indicies in vertex_groups.items():
group= ob.add_vertex_group(group_name)
# me.addVertGroup(group_name)
for vertex_index in group_indicies:
@@ -660,16 +662,16 @@
cstype = context_nurbs.get('cstype', None)
if cstype == None:
- print '\tWarning, cstype not found'
+ print('\tWarning, cstype not found')
return
if cstype != 'bspline':
- print '\tWarning, cstype is not supported (only bspline)'
+ print('\tWarning, cstype is not supported (only bspline)')
return
if not curv_idx:
- print '\tWarning, curv argument empty or not set'
+ print('\tWarning, curv argument empty or not set')
return
if len(deg) > 1 or parm_v:
- print '\tWarning, surfaces not supported'
+ print('\tWarning, surfaces not supported')
return
cu = bpy.data.curves.new(name, 'Curve')
@@ -691,7 +693,7 @@
# get for endpoint flag from the weighting
if curv_range and len(parm_u) > deg[0]+1:
do_endpoints = True
- for i in xrange(deg[0]+1):
+ for i in range(deg[0]+1):
if abs(parm_u[i]-curv_range[0]) > 0.0001:
do_endpoints = False
@@ -773,7 +775,7 @@
This function passes the file and sends the data off
to be split into objects and then converted into mesh objects
'''
- print '\nimporting obj "%s"' % filepath
+ print('\nimporting obj "%s"' % filepath)
if SPLIT_OBJECTS or SPLIT_GROUPS or SPLIT_MATERIALS:
POLYGROUPS = False
@@ -816,7 +818,7 @@
# so we need to know weather
context_multi_line= ''
- print '\tparsing obj file "%s"...' % filepath,
+ print('\tparsing obj file "%s"...' % filepath, end=' ')
time_sub= bpy.sys.time()
# time_sub= sys.time()
@@ -1028,31 +1030,31 @@
file.close()
time_new= bpy.sys.time()
# time_new= sys.time()
- print '%.4f sec' % (time_new-time_sub)
+ print('%.4f sec' % (time_new-time_sub))
time_sub= time_new
- print '\tloading materials and images...',
+ print('\tloading materials and images...', end=' ')
create_materials(filepath, material_libs, unique_materials, unique_material_images, IMAGE_SEARCH)
time_new= bpy.sys.time()
# time_new= sys.time()
- print '%.4f sec' % (time_new-time_sub)
+ print('%.4f sec' % (time_new-time_sub))
time_sub= time_new
if not ROTATE_X90:
verts_loc[:] = [(v[0], v[2], -v[1]) for v in verts_loc]
# deselect all
- if context.selected_objects:
- bpy.ops.OBJECT_OT_select_all_toggle()
+# if context.selected_objects:
+# bpy.ops.OBJECT_OT_select_all_toggle()
scene = context.scene
# scn = bpy.data.scenes.active
# scn.objects.selected = []
new_objects= [] # put new objects here
- print '\tbuilding geometry...\n\tverts:%i faces:%i materials: %i smoothgroups:%i ...' % ( len(verts_loc), len(faces), len(unique_materials), len(unique_smooth_groups) ),
+ print('\tbuilding geometry...\n\tverts:%i faces:%i materials: %i smoothgroups:%i ...' % ( len(verts_loc), len(faces), len(unique_materials), len(unique_smooth_groups) ), end=' ')
# Split the mesh by objects/materials, may
if SPLIT_OBJECTS or SPLIT_GROUPS: SPLIT_OB_OR_GROUP = True
else: SPLIT_OB_OR_GROUP = False
@@ -1095,8 +1097,8 @@
time_new= bpy.sys.time()
# time_new= sys.time()
- print '%.4f sec' % (time_new-time_sub)
- print 'finished importing: "%s" in %.4f sec.' % (filepath, (time_new-time_main))
+ print('%.4f sec' % (time_new-time_sub))
+ print('finished importing: "%s" in %.4f sec.' % (filepath, (time_new-time_main)))
DEBUG= True
@@ -1189,14 +1191,14 @@
def do_help(e,v):
url = __url__[0]
- print 'Trying to open web browser with documentation at this address...'
- print '\t' + url
+ print('Trying to open web browser with documentation at this address...')
+ print('\t' + url)
try:
import webbrowser
webbrowser.open(url)
except:
- print '...could not open a browser window.'
+ print('...could not open a browser window.')
def obj_ui():
ui_x, ui_y = GLOBALS['MOUSE']
@@ -1306,11 +1308,11 @@
DEBUG= False
-if __name__=='__main__' and not DEBUG:
- if os and Window.GetKeyQualifiers() & Window.Qual.SHIFT:
- Window.FileSelector(load_obj_ui_batch, 'Import OBJ Dir', '')
- else:
- Window.FileSelector(load_obj_ui, 'Import a Wavefront OBJ', '*.obj')
+# if __name__=='__main__' and not DEBUG:
+# if os and Window.GetKeyQualifiers() & Window.Qual.SHIFT:
+# Window.FileSelector(load_obj_ui_batch, 'Import OBJ Dir', '')
+# else:
+# Window.FileSelector(load_obj_ui, 'Import a Wavefront OBJ', '*.obj')
# For testing compatibility
'''
@@ -1340,6 +1342,70 @@
#load_obj('/test.obj')
#load_obj('/fe/obj/mba1.obj')
+
+
+class IMPORT_OT_obj(bpy.types.Operator):
+ '''
+ Operator documentation text, will be used for the operator tooltip and python docs.
+ '''
+ __idname__ = "import.obj"
+ __label__ = "Import OBJ"
+
+ # List of operator properties, the attributes will be assigned
+ # to the class instance from the operator settings before calling.
+
+ __props__ = [
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list