diff --git a/release/scripts/obj_import.py b/release/scripts/obj_import.py index 9ab2f1aa26c..d59762df377 100644 --- a/release/scripts/obj_import.py +++ b/release/scripts/obj_import.py @@ -206,23 +206,23 @@ def load_mtl(dir, IMPORT_USE_EXISTING_MTL, mtl_file, meshDict, materialDict): print '\tERROR: Unable to parse MTL file: "%s"' % mtl_file return print '\tUsing MTL: "%s"' % mtl_file -#===========================================================================# -# Returns unique name of object/mesh (preserve overwriting existing meshes) # -#===========================================================================# -def getUniqueName(name): - newName= name[:19] # 19 chars is the longest name. - uniqueInt= 0 - while newName in getUniqueName.uniqueNames: - newName= '%s.%.3i' % (name[:15], uniqueInt) - uniqueInt +=1 - getUniqueName.uniqueNames.append(newName) - return newName -getUniqueName.uniqueNames= [] #==================================================================================# # This loads data from .obj file # #==================================================================================# -def load_obj(file, IMPORT_MTL=1, IMPORT_USE_EXISTING_MTL=0, IMPORT_CONSTRAIN_BOUNDS=0.0, IMPORT_ROTATE_X90=0, IMPORT_EDGES=1, IMPORT_SMOOTH_ALL=0, IMPORT_FGON=1, IMPORT_SMOOTH_GROUPS=0, IMPORT_MTL_SPLIT=0): +def load_obj(\ + file,\ + IMPORT_MTL=1,\ + IMPORT_USE_EXISTING_MTL=0,\ + IMPORT_CONSTRAIN_BOUNDS=0.0,\ + IMPORT_ROTATE_X90=0,\ + IMPORT_EDGES=1,\ + IMPORT_SMOOTH_ALL=0,\ + IMPORT_FGON=1,\ + IMPORT_SMOOTH_GROUPS=0,\ + IMPORT_MTL_SPLIT=0,\ + IMPORT_AS_INSTANCE=0): + global currentMesh,\ currentUsedVertList,\ currentUsedVertListSmoothGroup,\ @@ -234,9 +234,6 @@ def load_obj(file, IMPORT_MTL=1, IMPORT_USE_EXISTING_MTL=0, IMPORT_CONSTRAIN_BOU time1= sys.time() - getUniqueName.uniqueNames.extend( [ob.name for ob in Object.Get()] ) - getUniqueName.uniqueNames.extend( NMesh.GetNames() ) - # Deselect all objects in the scene. # do this first so we dont have to bother, with objects we import for ob in Scene.GetCurrent().getChildren(): @@ -297,7 +294,6 @@ def load_obj(file, IMPORT_MTL=1, IMPORT_USE_EXISTING_MTL=0, IMPORT_CONSTRAIN_BOU fileLines= [lsplit for l in fileLines if not l.startswith('vn') if not l.startswith('#') for lsplit in (l.split(),) if lsplit] - if IMPORT_CONSTRAIN_BOUNDS == 0.0: if IMPORT_ROTATE_X90: def Vert(x,y,z): @@ -818,23 +814,52 @@ def load_obj(file, IMPORT_MTL=1, IMPORT_USE_EXISTING_MTL=0, IMPORT_CONSTRAIN_BOU SCALE/=10 importedObjects= [] + + scn= Scene.GetCurrent() + + # DeSelect all + for ob in scn.getChildren(): + ob.sel=0 + + # Create objects for each mesh. for mk, me in meshDict.iteritems(): nme= me[0] # Ignore no vert meshes. if not nme.verts: # == [] continue - name= getUniqueName(mk) - ob= NMesh.PutRaw(nme, name) - ob.name= name - importedObjects.append(ob) + ob= Object.New('Mesh', fileName) + nme.name= mk + ob.link(nme) ob.setSize(SCALE, SCALE, SCALE) - + importedObjects.append(ob) + + Layers= scn.Layers + if IMPORT_AS_INSTANCE: + # Create a group for this import. + group_scn= Scene.New(fileName) + for ob in importedObjects: + group_scn.link(ob) # dont worry about the layers + + grp= Group.New(fileName) + grp.objects= importedObjects + + grp_ob= Object.New('Empty', fileName) + grp_ob.enableDupGroup= True + grp_ob.DupGroup= grp + scn.link(grp_ob) + grp_ob.Layers= Layers + grp_ob.sel= 1 + + else: + # Select all imported objects. + for ob in importedObjects: + scn.link(ob) + ob.Layers= Layers + ob.sel= 1 + - # Select all imported objects. - for ob in importedObjects: - ob.sel= 1 if badObjUvs > 0: print '\tERROR: found %d faces with badly formatted UV coords. everything else went okay.' % badObjUvs @@ -861,11 +886,13 @@ def load_obj_ui(file): IMPORT_FGON= Draw.Create(1) IMPORT_SMOOTH_GROUPS= Draw.Create(0) IMPORT_MTL_SPLIT= Draw.Create(0) + IMPORT_AS_INSTANCE= Draw.Create(0) # Get USER Options pup_block= [\ ('All *.obj\'s in dir', IMPORT_DIR, 'Import all obj files in this dir (avoid overlapping data with "Create scene")'),\ ('Create Scene', IMPORT_NEW_SCENE, 'Imports each obj into its own scene, named from the file'),\ + ('Group Instance', IMPORT_AS_INSTANCE, 'Import objects into a new scene and group, creating an instance in the current scene.'),\ 'Materials...',\ ('Import (*.mtl)', IMPORT_MTL, 'Imports material settings and images from the obj\'s .mtl file'),\ ('Re-Use Existing', IMPORT_USE_EXISTING_MTL, 'Use materials from the current blend where names match.'),\ @@ -901,6 +928,7 @@ def load_obj_ui(file): IMPORT_FGON= IMPORT_FGON.val IMPORT_SMOOTH_GROUPS= IMPORT_SMOOTH_GROUPS.val IMPORT_MTL_SPLIT= IMPORT_MTL_SPLIT.val + IMPORT_AS_INSTANCE= IMPORT_AS_INSTANCE.val orig_scene= Scene.GetCurrent() # Dont do material split if we dont import material @@ -926,7 +954,7 @@ def load_obj_ui(file): scn.makeCurrent() Window.DrawProgressBar((float(count)/obj_len) - 0.01, '%s: %i of %i' % (f, count, obj_len)) - load_obj(d+f, IMPORT_MTL, IMPORT_USE_EXISTING_MTL, IMPORT_CONSTRAIN_BOUNDS, IMPORT_ROTATE_X90, IMPORT_EDGES, IMPORT_SMOOTH_ALL, IMPORT_FGON, IMPORT_SMOOTH_GROUPS, IMPORT_MTL_SPLIT) + load_obj(d+f, IMPORT_MTL, IMPORT_USE_EXISTING_MTL, IMPORT_CONSTRAIN_BOUNDS, IMPORT_ROTATE_X90, IMPORT_EDGES, IMPORT_SMOOTH_ALL, IMPORT_FGON, IMPORT_SMOOTH_GROUPS, IMPORT_MTL_SPLIT, IMPORT_AS_INSTANCE) orig_scene.makeCurrent() # We can leave them in there new scene. diff --git a/source/blender/python/api2_2x/doc/Group.py b/source/blender/python/api2_2x/doc/Group.py index 2a2e1974f8b..6fd39232bb2 100644 --- a/source/blender/python/api2_2x/doc/Group.py +++ b/source/blender/python/api2_2x/doc/Group.py @@ -92,6 +92,9 @@ class Group: This object gives access to Groups in Blender. @ivar name: The name of this Group object. @ivar users: Number of users this group has (read only) - @ivar objects: Objects that this group uses. This is an iterator with list like access so use list(gp.objects) if you need to use a list). where gp is a group object. + @ivar objects: Objects that this group uses. + This is an iterator with list like access so use list(gp.objects) if you need to use a list. (where gp is a group object). + The groups objects can be set by assigning a list or iterator of objects to the groups objects. + objects.append() and objects.remove() also work with the the objects iterator just like with lists. """ diff --git a/source/blender/python/api2_2x/doc/Object.py b/source/blender/python/api2_2x/doc/Object.py index 1dbfb06d182..be391176ece 100644 --- a/source/blender/python/api2_2x/doc/Object.py +++ b/source/blender/python/api2_2x/doc/Object.py @@ -302,10 +302,11 @@ class Object: True/False - does not indicate that this object has any dupliFrames, (as returned by DupObjects) just that dupliFrames are enabled. @type enableDupFrames: bool (True/False) - @ivar enableDupGroup: The DupliFroup status of the object. + @ivar enableDupGroup: The DupliGroup status of the object. True/False - Set DupGroup to a group for this to take effect, Use DupObjects to get the object data from this instance. (Use with L{DupObjects}) @type enableDupGroup: bool (True/False) + Set True to make this object an instance of the objects DupGroup. @ivar enableDupRot: The DupliRot status of the object. True/False - Use with enableDupVerts to rotate each instance by the vertex normal. (Use with L{enableDupVerts})