diff --git a/release/scripts/import_obj.py b/release/scripts/import_obj.py index 8f9d724f44c..bd27b77ff8b 100644 --- a/release/scripts/import_obj.py +++ b/release/scripts/import_obj.py @@ -207,16 +207,30 @@ def create_materials(filepath, material_libs, unique_materials, unique_material_ mtl.close() -def split_mesh(verts_loc, faces, unique_materials, SPLIT_OBJECTS, SPLIT_MATERIALS): + + +def split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OBJECTS, SPLIT_MATERIALS): ''' Takes vert_loc and faces, and seperates into multiple sets of - (verts_loc, faces, unique_materials) + (verts_loc, faces, unique_materials, dataname) This is done so objects do not overload the 16 material limit. ''' - if not SPLIT_OBJECTS and not SPLIT_MATERIALS: - return [(verts_loc, faces, unique_materials)] + filename = stripExt(stripPath(filepath)) + if not SPLIT_OBJECTS and not SPLIT_MATERIALS: + # use the filename for the object name since we arnt chopping up the mesh. + return [(verts_loc, faces, unique_materials, filename)] + + + def key_to_name(key): + # if the key is a tuple, join it to make a string + if type(key) == tuple: + return '%s_%s' % key + elif not key: + return filename # assume its a string. make sure this is true if the splitting code is changed + else: + return key # Return a key that makes the faces unique. if SPLIT_OBJECTS and not SPLIT_MATERIALS: @@ -229,7 +243,7 @@ def split_mesh(verts_loc, faces, unique_materials, SPLIT_OBJECTS, SPLIT_MATERIAL else: # Both def face_key(face): - return face[2], face[4] # material + return face[4], face[2] # object,material face_split_dict= {} @@ -243,14 +257,14 @@ def split_mesh(verts_loc, faces, unique_materials, SPLIT_OBJECTS, SPLIT_MATERIAL if oldkey != key: # Check the key has changed. try: - faces_split, verts_split, unique_materials_split, vert_remap= face_split_dict[key] + verts_split, faces_split, unique_materials_split, vert_remap= face_split_dict[key] except KeyError: faces_split= [] verts_split= [] unique_materials_split= {} vert_remap= [-1]*len(verts_loc) - face_split_dict[key]= (faces_split, verts_split, unique_materials_split, vert_remap) + face_split_dict[key]= (verts_split, faces_split, unique_materials_split, vert_remap) oldkey= key @@ -275,10 +289,10 @@ def split_mesh(verts_loc, faces, unique_materials, SPLIT_OBJECTS, SPLIT_MATERIAL # remove one of the itemas and reorder - return [(verts_split, faces_split, unique_materials_split) for faces_split, verts_split, unique_materials_split, vert_remap in face_split_dict.itervalues()] + return [(value[0], value[1], value[2], key_to_name(key)) for key, value in face_split_dict.iteritems()] -def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, verts_tex, faces, unique_materials, unique_material_images, unique_smooth_groups): +def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, verts_tex, faces, unique_materials, unique_material_images, unique_smooth_groups, dataname): ''' Takes all the data gathered and generates a mesh, adding the new object to new_objects deals with fgons, sharp edges and assigning materials @@ -391,10 +405,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v for name, index in material_mapping.iteritems(): materials[index]= unique_materials[name] - try: - me= Mesh.New(faces[0][5]) # object name from first face - except: - me= Mesh.New() + me= Mesh.New(dataname) me.materials= materials[0:16] # make sure the list isnt too big. #me.verts.extend([(0,0,0)]) # dummy vert @@ -672,9 +683,9 @@ def load_obj(filepath, CLAMP_SIZE= 0.0, CREATE_FGONS= True, CREATE_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) ), # Split the mesh by objects/materials, may - for verts_loc_split, faces_split, unique_materials_split in split_mesh(verts_loc, faces, unique_materials, SPLIT_OBJECTS, SPLIT_MATERIALS): + for verts_loc_split, faces_split, unique_materials_split, dataname in split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OBJECTS, SPLIT_MATERIALS): # Create meshes from the data - create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc_split, verts_tex, faces_split, unique_materials_split, unique_material_images, unique_smooth_groups) + create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc_split, verts_tex, faces_split, unique_materials_split, unique_material_images, unique_smooth_groups, dataname) axis_min= [ 1000000000]*3 axis_max= [-1000000000]*3 diff --git a/release/scripts/save_theme.py b/release/scripts/save_theme.py index 981477cdd09..7b21b5c74f7 100644 --- a/release/scripts/save_theme.py +++ b/release/scripts/save_theme.py @@ -75,7 +75,6 @@ theme = Theme.Get()[0] # get current theme default_fname = Blender.Get("scriptsdir") default_fname = Blender.sys.join(default_fname, theme.name + '_theme.py') default_fname = default_fname.replace(' ','_') -type_str = type('') def write_theme(filename): "Write the current theme as a bpython script" @@ -125,7 +124,7 @@ theme = Theme.New('%s') for var in vars: v = "%s.%s" % (tsp, var) exec("value = %s" % v) - if type(value) == type_str: + if type(value) == str: fout.write("%s = '%s'\n" % (v, value)) else: fout.write("%s = %s\n" % (v, value)) diff --git a/release/scripts/weightpaint_clean.py b/release/scripts/weightpaint_clean.py index f6e42507f26..038c5e18c1a 100644 --- a/release/scripts/weightpaint_clean.py +++ b/release/scripts/weightpaint_clean.py @@ -38,7 +38,7 @@ It removes very low weighted verts from the current group with a weight option. # ***** END GPL LICENCE BLOCK ***** # -------------------------------------------------------------------------- -from Blender import Scene, Draw +from Blender import Scene, Draw, Object import BPyMesh SMALL_NUM= 0.000001 def weightClean(me, PREF_THRESH, PREF_KEEP_SINGLE, PREF_OTHER_GROUPS): @@ -46,6 +46,8 @@ def weightClean(me, PREF_THRESH, PREF_KEEP_SINGLE, PREF_OTHER_GROUPS): groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me) act_group= me.activeGroup + rem_count = 0 + if PREF_OTHER_GROUPS: for wd in vWeightDict: l = len(wd) @@ -55,6 +57,7 @@ def weightClean(me, PREF_THRESH, PREF_KEEP_SINGLE, PREF_OTHER_GROUPS): if w <= PREF_THRESH: # small weight, remove. del wd[group] + rem_count +=1 l-=1 if PREF_KEEP_SINGLE and l == 1: @@ -68,11 +71,13 @@ def weightClean(me, PREF_THRESH, PREF_KEEP_SINGLE, PREF_OTHER_GROUPS): if w <= PREF_THRESH: # small weight, remove. del wd[act_group] + rem_count +=1 except: pass # Copy weights back to the mesh. BPyMesh.dict2MeshWeight(me, groupNames, vWeightDict) + return rem_count def main(): @@ -98,7 +103,19 @@ def main(): if not Draw.PupBlock('Clean Selected Meshes...', pup_block): return - weightClean(me, PREF_PEAKWEIGHT.val, PREF_KEEP_SINGLE.val, PREF_OTHER_GROUPS.val) + rem_count = weightClean(me, PREF_PEAKWEIGHT.val, PREF_KEEP_SINGLE.val, PREF_OTHER_GROUPS.val) + + # Run on entire blend file. usefull sometimes but dont let users do it. + ''' + rem_count = 0 + for ob in Object.Get(): + if ob.type != 'Mesh': + continue + me= ob.getData(mesh=1) + + rem_count += weightClean(me, PREF_PEAKWEIGHT.val, PREF_KEEP_SINGLE.val, PREF_OTHER_GROUPS.val) + ''' + Draw.PupMenu('Removed %i verts from groups' % rem_count) if __name__=='__main__': main() \ No newline at end of file