Skip to content
Snippets Groups Projects
Commit 2f64f2f3 authored by Campbell Barton's avatar Campbell Barton
Browse files

rename obj import vars

parent 87e698f1
No related branches found
No related tags found
No related merge requests found
...@@ -56,18 +56,18 @@ class ImportOBJ(bpy.types.Operator, ImportHelper): ...@@ -56,18 +56,18 @@ class ImportOBJ(bpy.types.Operator, ImportHelper):
filename_ext = ".obj" filename_ext = ".obj"
filter_glob = StringProperty(default="*.obj;*.mtl", options={'HIDDEN'}) filter_glob = StringProperty(default="*.obj;*.mtl", options={'HIDDEN'})
CREATE_SMOOTH_GROUPS = BoolProperty(name="Smooth Groups", description="Surround smooth groups by sharp edges", default=True) use_smooth_groups = BoolProperty(name="Smooth Groups", description="Surround smooth groups by sharp edges", default=True)
CREATE_FGONS = BoolProperty(name="NGons as FGons", description="Import faces with more then 4 verts as fgons", default=True) use_ngons = BoolProperty(name="NGons as FGons", description="Import faces with more then 4 verts as fgons", default=True)
CREATE_EDGES = BoolProperty(name="Lines as Edges", description="Import lines and faces with 2 verts as edge", default=True) use_edges = BoolProperty(name="Lines as Edges", description="Import lines and faces with 2 verts as edge", default=True)
SPLIT_OBJECTS = BoolProperty(name="Object", description="Import OBJ Objects into Blender Objects", default=True) use_split_objects = BoolProperty(name="Object", description="Import OBJ Objects into Blender Objects", default=True)
SPLIT_GROUPS = BoolProperty(name="Group", description="Import OBJ Groups into Blender Objects", default=True) use_split_groups = BoolProperty(name="Group", description="Import OBJ Groups into Blender Objects", default=True)
# old comment: only used for user feedback # old comment: only used for user feedback
# disabled this option because in old code a handler for it disabled SPLIT* params, it's not passed to load_obj # disabled this option because in old code a handler for it disabled SPLIT* params, it's not passed to load_obj
# KEEP_VERT_ORDER = BoolProperty(name="Keep Vert Order", description="Keep vert and face order, disables split options, enable for morph targets", default= True) # KEEP_VERT_ORDER = BoolProperty(name="Keep Vert Order", description="Keep vert and face order, disables split options, enable for morph targets", default= True)
ROTATE_X90 = BoolProperty(name="-X90", description="Rotate X 90.", default=True) use_rotate_x90 = BoolProperty(name="-X90", description="Rotate X 90.", default=True)
CLAMP_SIZE = FloatProperty(name="Clamp Scale", description="Clamp the size to this maximum (Zero to Disable)", min=0.0, max=1000.0, soft_min=0.0, soft_max=1000.0, default=0.0) global_clamp_size = FloatProperty(name="Clamp Scale", description="Clamp the size to this maximum (Zero to Disable)", min=0.0, max=1000.0, soft_min=0.0, soft_max=1000.0, default=0.0)
POLYGROUPS = BoolProperty(name="Poly Groups", description="Import OBJ groups as vertex groups.", default=False) use_groups_as_vgroups = BoolProperty(name="Poly Groups", description="Import OBJ groups as vertex groups.", default=False)
IMAGE_SEARCH = BoolProperty(name="Image Search", description="Search subdirs for any assosiated images (Warning, may be slow)", default=True) use_image_search = BoolProperty(name="Image Search", description="Search subdirs for any assosiated images (Warning, may be slow)", default=True)
def execute(self, context): def execute(self, context):
# print("Selected: " + context.active_object.name) # print("Selected: " + context.active_object.name)
......
...@@ -239,7 +239,7 @@ def line_value(line_split): ...@@ -239,7 +239,7 @@ def line_value(line_split):
return b' '.join(line_split[1:]) return b' '.join(line_split[1:])
def obj_image_load(imagepath, DIR, IMAGE_SEARCH): def obj_image_load(imagepath, DIR, use_image_search):
if b'_' in imagepath: if b'_' in imagepath:
image = load_image(imagepath.replace(b'_', b' '), DIR) image = load_image(imagepath.replace(b'_', b' '), DIR)
if image: if image:
...@@ -252,25 +252,25 @@ def obj_image_load(imagepath, DIR, IMAGE_SEARCH): ...@@ -252,25 +252,25 @@ def obj_image_load(imagepath, DIR, IMAGE_SEARCH):
print("failed to load %r doesn't exist" % imagepath) print("failed to load %r doesn't exist" % imagepath)
return None return None
# def obj_image_load(imagepath, DIR, IMAGE_SEARCH): # def obj_image_load(imagepath, DIR, use_image_search):
# ''' # '''
# Mainly uses comprehensiveImageLoad # Mainly uses comprehensiveImageLoad
# but tries to replace '_' with ' ' for Max's exporter replaces spaces with underscores. # but tries to replace '_' with ' ' for Max's exporter replaces spaces with underscores.
# ''' # '''
# if '_' in imagepath: # if '_' in imagepath:
# image= BPyImage.comprehensiveImageLoad(imagepath, DIR, PLACE_HOLDER= False, RECURSIVE= IMAGE_SEARCH) # image= BPyImage.comprehensiveImageLoad(imagepath, DIR, PLACE_HOLDER= False, RECURSIVE= use_image_search)
# if image: return image # if image: return image
# # Did the exporter rename the image? # # Did the exporter rename the image?
# image= BPyImage.comprehensiveImageLoad(imagepath.replace('_', ' '), DIR, PLACE_HOLDER= False, RECURSIVE= IMAGE_SEARCH) # image= BPyImage.comprehensiveImageLoad(imagepath.replace('_', ' '), DIR, PLACE_HOLDER= False, RECURSIVE= use_image_search)
# if image: return image # if image: return image
# # Return an image, placeholder if it dosnt exist # # Return an image, placeholder if it dosnt exist
# image= BPyImage.comprehensiveImageLoad(imagepath, DIR, PLACE_HOLDER= True, RECURSIVE= IMAGE_SEARCH) # image= BPyImage.comprehensiveImageLoad(imagepath, DIR, PLACE_HOLDER= True, RECURSIVE= use_image_search)
# return image # return image
def create_materials(filepath, material_libs, unique_materials, unique_material_images, IMAGE_SEARCH): def create_materials(filepath, material_libs, unique_materials, unique_material_images, use_image_search):
''' '''
Create all the used materials in this obj, Create all the used materials in this obj,
assign colors and images to the materials from all referenced material libs assign colors and images to the materials from all referenced material libs
...@@ -285,7 +285,7 @@ def create_materials(filepath, material_libs, unique_materials, unique_material_ ...@@ -285,7 +285,7 @@ def create_materials(filepath, material_libs, unique_materials, unique_material_
texture = bpy.data.textures.new(name=type, type='IMAGE') texture = bpy.data.textures.new(name=type, type='IMAGE')
# Absolute path - c:\.. etc would work here # Absolute path - c:\.. etc would work here
image = obj_image_load(imagepath, DIR, IMAGE_SEARCH) image = obj_image_load(imagepath, DIR, use_image_search)
has_data = False has_data = False
if image: if image:
...@@ -604,13 +604,13 @@ def split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP): ...@@ -604,13 +604,13 @@ def split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP):
return [(value[0], value[1], value[2], key_to_name(key)) for key, value in list(face_split_dict.items())] return [(value[0], value[1], value[2], key_to_name(key)) for key, value in list(face_split_dict.items())]
def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, verts_tex, faces, unique_materials, unique_material_images, unique_smooth_groups, vertex_groups, dataname): def create_mesh(new_objects, has_ngons, use_ngons, use_edges, verts_loc, verts_tex, faces, unique_materials, unique_material_images, unique_smooth_groups, vertex_groups, dataname):
''' '''
Takes all the data gathered and generates a mesh, adding the new object to new_objects Takes all the data gathered and generates a mesh, adding the new object to new_objects
deals with fgons, sharp edges and assigning materials deals with fgons, sharp edges and assigning materials
''' '''
if not has_ngons: if not has_ngons:
CREATE_FGONS = False use_ngons = False
if unique_smooth_groups: if unique_smooth_groups:
sharp_edges = {} sharp_edges = {}
...@@ -619,7 +619,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v ...@@ -619,7 +619,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v
# Split fgons into tri's # Split fgons into tri's
fgon_edges = {} # Used for storing fgon keys fgon_edges = {} # Used for storing fgon keys
if CREATE_EDGES: if use_edges:
edges = [] edges = []
context_object = None context_object = None
...@@ -639,7 +639,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v ...@@ -639,7 +639,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v
faces.pop(f_idx) # cant add single vert faces faces.pop(f_idx) # cant add single vert faces
elif not face_vert_tex_indices or len_face_vert_loc_indices == 2: # faces that have no texture coords are lines elif not face_vert_tex_indices or len_face_vert_loc_indices == 2: # faces that have no texture coords are lines
if CREATE_EDGES: if use_edges:
# generators are better in python 2.4+ but can't be used in 2.3 # generators are better in python 2.4+ but can't be used in 2.3
# edges.extend( (face_vert_loc_indices[i], face_vert_loc_indices[i+1]) for i in xrange(len_face_vert_loc_indices-1) ) # edges.extend( (face_vert_loc_indices[i], face_vert_loc_indices[i+1]) for i in xrange(len_face_vert_loc_indices-1) )
edges.extend([(face_vert_loc_indices[i], face_vert_loc_indices[i + 1]) for i in range(len_face_vert_loc_indices - 1)]) edges.extend([(face_vert_loc_indices[i], face_vert_loc_indices[i + 1]) for i in range(len_face_vert_loc_indices - 1)])
...@@ -680,7 +680,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v ...@@ -680,7 +680,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v
) )
# edges to make fgons # edges to make fgons
if CREATE_FGONS: if use_ngons:
edge_users = {} edge_users = {}
for ngon in ngon_face_indices: for ngon in ngon_face_indices:
for i in (0, 1, 2): for i in (0, 1, 2):
...@@ -744,7 +744,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v ...@@ -744,7 +744,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v
if len(face[0]) < 2: if len(face[0]) < 2:
pass # raise "bad face" pass # raise "bad face"
elif len(face[0]) == 2: elif len(face[0]) == 2:
if CREATE_EDGES: if use_edges:
edges.append(face[0]) edges.append(face[0])
else: else:
...@@ -801,10 +801,10 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v ...@@ -801,10 +801,10 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v
del me_faces del me_faces
# del ALPHA # del ALPHA
if CREATE_EDGES and not edges: if use_edges and not edges:
CREATE_EDGES = False use_edges = False
if CREATE_EDGES: if use_edges:
me.edges.add(len(edges)) me.edges.add(len(edges))
# edges should be a list of (a, b) tuples # edges should be a list of (a, b) tuples
...@@ -820,13 +820,13 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v ...@@ -820,13 +820,13 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v
return (e1[0] == e2[0] and e1[1] == e2[1]) or (e1[0] == e2[1] and e1[1] == e2[0]) return (e1[0] == e2[0] and e1[1] == e2[1]) or (e1[0] == e2[1] and e1[1] == e2[0])
# XXX slow # XXX slow
# if CREATE_FGONS and fgon_edges: # if use_ngons and fgon_edges:
# for fgon_edge in fgon_edges.keys(): # for fgon_edge in fgon_edges.keys():
# for ed in me.edges: # for ed in me.edges:
# if edges_match(fgon_edge, ed.vertices): # if edges_match(fgon_edge, ed.vertices):
# ed.is_fgon = True # ed.is_fgon = True
# if CREATE_FGONS and fgon_edges: # if use_ngons and fgon_edges:
# FGON= Mesh.EdgeFlags.FGON # FGON= Mesh.EdgeFlags.FGON
# for ed in me.findEdges( fgon_edges.keys() ): # for ed in me.findEdges( fgon_edges.keys() ):
# if ed is not None: # if ed is not None:
...@@ -848,7 +848,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v ...@@ -848,7 +848,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v
# del SHARP # del SHARP
me.validate() me.validate()
me.update(calc_edges=CREATE_EDGES) me.update(calc_edges=use_edges)
ob = bpy.data.objects.new("Mesh", me) ob = bpy.data.objects.new("Mesh", me)
new_objects.append(ob) new_objects.append(ob)
...@@ -963,15 +963,15 @@ def get_float_func(filepath): ...@@ -963,15 +963,15 @@ def get_float_func(filepath):
def load(operator, context, filepath, def load(operator, context, filepath,
CLAMP_SIZE=0.0, global_clamp_size=0.0,
CREATE_FGONS=True, use_ngons=True,
CREATE_SMOOTH_GROUPS=True, use_smooth_groups=True,
CREATE_EDGES=True, use_edges=True,
SPLIT_OBJECTS=True, use_split_objects=True,
SPLIT_GROUPS=True, use_split_groups=True,
ROTATE_X90=True, use_rotate_x90=True,
IMAGE_SEARCH=True, use_image_search=True,
POLYGROUPS=False): use_groups_as_vgroups=False):
''' '''
Called by the user interface or another script. Called by the user interface or another script.
load_obj(path) - should give acceptable results. load_obj(path) - should give acceptable results.
...@@ -982,8 +982,8 @@ def load(operator, context, filepath, ...@@ -982,8 +982,8 @@ def load(operator, context, filepath,
filepath = filepath.encode() filepath = filepath.encode()
if SPLIT_OBJECTS or SPLIT_GROUPS: if use_split_objects or use_split_groups:
POLYGROUPS = False use_groups_as_vgroups = False
time_main = time.time() time_main = time.time()
...@@ -991,7 +991,7 @@ def load(operator, context, filepath, ...@@ -991,7 +991,7 @@ def load(operator, context, filepath,
verts_tex = [] verts_tex = []
faces = [] # tuples of the faces faces = [] # tuples of the faces
material_libs = [] # filanems to material libs this uses material_libs = [] # filanems to material libs this uses
vertex_groups = {} # when POLYGROUPS is true vertex_groups = {} # when use_groups_as_vgroups is true
# Get the string to float conversion func for this file- is 'float' for almost all files. # Get the string to float conversion func for this file- is 'float' for almost all files.
float_func = get_float_func(filepath) float_func = get_float_func(filepath)
...@@ -1074,7 +1074,7 @@ def load(operator, context, filepath, ...@@ -1074,7 +1074,7 @@ def load(operator, context, filepath,
vert_loc_index = int(obj_vert[0]) - 1 vert_loc_index = int(obj_vert[0]) - 1
# Add the vertex to the current group # Add the vertex to the current group
# *warning*, this wont work for files that have groups defined around verts # *warning*, this wont work for files that have groups defined around verts
if POLYGROUPS and context_vgroup: if use_groups_as_vgroups and context_vgroup:
vertex_groups[context_vgroup].append(vert_loc_index) vertex_groups[context_vgroup].append(vert_loc_index)
# Make relative negative vert indices absolute # Make relative negative vert indices absolute
...@@ -1100,7 +1100,7 @@ def load(operator, context, filepath, ...@@ -1100,7 +1100,7 @@ def load(operator, context, filepath,
if len(face_vert_loc_indices) > 4: if len(face_vert_loc_indices) > 4:
has_ngons = True has_ngons = True
elif CREATE_EDGES and (line.startswith(b'l ') or context_multi_line == b'l'): elif use_edges and (line.startswith(b'l ') or context_multi_line == b'l'):
# very similar to the face load function above with some parts removed # very similar to the face load function above with some parts removed
if context_multi_line: if context_multi_line:
...@@ -1138,7 +1138,7 @@ def load(operator, context, filepath, ...@@ -1138,7 +1138,7 @@ def load(operator, context, filepath,
face_vert_loc_indices.append(vert_loc_index) face_vert_loc_indices.append(vert_loc_index)
elif line.startswith(b's'): elif line.startswith(b's'):
if CREATE_SMOOTH_GROUPS: if use_smooth_groups:
context_smooth_group = line_value(line.split()) context_smooth_group = line_value(line.split())
if context_smooth_group == b'off': if context_smooth_group == b'off':
context_smooth_group = None context_smooth_group = None
...@@ -1146,16 +1146,16 @@ def load(operator, context, filepath, ...@@ -1146,16 +1146,16 @@ def load(operator, context, filepath,
unique_smooth_groups[context_smooth_group] = None unique_smooth_groups[context_smooth_group] = None
elif line.startswith(b'o'): elif line.startswith(b'o'):
if SPLIT_OBJECTS: if use_split_objects:
context_object = line_value(line.split()) context_object = line_value(line.split())
# unique_obects[context_object]= None # unique_obects[context_object]= None
elif line.startswith(b'g'): elif line.startswith(b'g'):
if SPLIT_GROUPS: if use_split_groups:
context_object = line_value(line.split()) context_object = line_value(line.split())
# print 'context_object', context_object # print 'context_object', context_object
# unique_obects[context_object]= None # unique_obects[context_object]= None
elif POLYGROUPS: elif use_groups_as_vgroups:
context_vgroup = line_value(line.split()) context_vgroup = line_value(line.split())
if context_vgroup and context_vgroup != b'(null)': if context_vgroup and context_vgroup != b'(null)':
vertex_groups.setdefault(context_vgroup, []) vertex_groups.setdefault(context_vgroup, [])
...@@ -1234,13 +1234,13 @@ def load(operator, context, filepath, ...@@ -1234,13 +1234,13 @@ def load(operator, context, filepath,
time_sub = time_new time_sub = time_new
print('\tloading materials and images...') print('\tloading materials and images...')
create_materials(filepath, material_libs, unique_materials, unique_material_images, IMAGE_SEARCH) create_materials(filepath, material_libs, unique_materials, unique_material_images, use_image_search)
time_new = time.time() time_new = time.time()
print("%.4f sec" % (time_new - time_sub)) print("%.4f sec" % (time_new - time_sub))
time_sub = time_new time_sub = time_new
if not ROTATE_X90: if not use_rotate_x90:
verts_loc[:] = [(v[0], v[2], -v[1]) for v in verts_loc] verts_loc[:] = [(v[0], v[2], -v[1]) for v in verts_loc]
# deselect all # deselect all
...@@ -1253,14 +1253,14 @@ def load(operator, context, filepath, ...@@ -1253,14 +1253,14 @@ def load(operator, context, filepath,
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)))
# Split the mesh by objects/materials, may # Split the mesh by objects/materials, may
if SPLIT_OBJECTS or SPLIT_GROUPS: if use_split_objects or use_split_groups:
SPLIT_OB_OR_GROUP = True SPLIT_OB_OR_GROUP = True
else: else:
SPLIT_OB_OR_GROUP = False SPLIT_OB_OR_GROUP = False
for verts_loc_split, faces_split, unique_materials_split, dataname in split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP): for verts_loc_split, faces_split, unique_materials_split, dataname in split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP):
# Create meshes from the data, warning 'vertex_groups' wont support splitting # Create meshes from the data, warning 'vertex_groups' wont support splitting
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, vertex_groups, dataname) create_mesh(new_objects, has_ngons, use_ngons, use_edges, verts_loc_split, verts_tex, faces_split, unique_materials_split, unique_material_images, unique_smooth_groups, vertex_groups, dataname)
# nurbs support # nurbs support
for context_nurbs in nurbs: for context_nurbs in nurbs:
...@@ -1276,7 +1276,7 @@ def load(operator, context, filepath, ...@@ -1276,7 +1276,7 @@ def load(operator, context, filepath,
axis_min = [1000000000] * 3 axis_min = [1000000000] * 3
axis_max = [-1000000000] * 3 axis_max = [-1000000000] * 3
if CLAMP_SIZE: if global_clamp_size:
# Get all object bounds # Get all object bounds
for ob in new_objects: for ob in new_objects:
for v in ob.bound_box: for v in ob.bound_box:
...@@ -1290,14 +1290,14 @@ def load(operator, context, filepath, ...@@ -1290,14 +1290,14 @@ def load(operator, context, filepath,
max_axis = max(axis_max[0] - axis_min[0], axis_max[1] - axis_min[1], axis_max[2] - axis_min[2]) max_axis = max(axis_max[0] - axis_min[0], axis_max[1] - axis_min[1], axis_max[2] - axis_min[2])
scale = 1.0 scale = 1.0
while CLAMP_SIZE < max_axis * scale: while global_clamp_size < max_axis * scale:
scale = scale / 10.0 scale = scale / 10.0
for obj in new_objects: for obj in new_objects:
obj.scale = scale, scale, scale obj.scale = scale, scale, scale
# Better rotate the vert locations # Better rotate the vert locations
#if not ROTATE_X90: #if not use_rotate_x90:
# for ob in new_objects: # for ob in new_objects:
# ob.RotX = -1.570796326794896558 # ob.RotX = -1.570796326794896558
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment