Skip to content
Snippets Groups Projects
Commit 0225bffb authored by Bastien Montagne's avatar Bastien Montagne
Browse files

OBJ IO: More cleanup (mostly from pep8).

parent 7af50e62
No related branches found
No related tags found
No related merge requests found
...@@ -128,10 +128,8 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict): ...@@ -128,10 +128,8 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
image = mtex.texture.image image = mtex.texture.image
if image: if image:
# texface overrides others # texface overrides others
if (mtex.use_map_color_diffuse and if (mtex.use_map_color_diffuse and (face_img is None) and
(face_img is None) and (mtex.use_map_warp is False) and (mtex.texture_coords != 'REFLECTION')):
(mtex.use_map_warp is False) and
(mtex.texture_coords != 'REFLECTION')):
image_map["map_Kd"] = image image_map["map_Kd"] = image
if mtex.use_map_ambient: if mtex.use_map_ambient:
image_map["map_Ka"] = image image_map["map_Ka"] = image
...@@ -564,7 +562,7 @@ def write_file(filepath, objects, scene, ...@@ -564,7 +562,7 @@ def write_file(filepath, objects, scene,
# Write a null material, since we know the context has changed. # Write a null material, since we know the context has changed.
if EXPORT_GROUP_BY_MAT: if EXPORT_GROUP_BY_MAT:
# can be mat_image or (null) # can be mat_image or (null)
fw("g %s_%s\n" % (name_compat(ob.name), name_compat(ob.data.name))) # can be mat_image or (null) fw("g %s_%s\n" % (name_compat(ob.name), name_compat(ob.data.name)))
if EXPORT_MTL: if EXPORT_MTL:
fw("usemtl (null)\n") # mat, image fw("usemtl (null)\n") # mat, image
...@@ -595,7 +593,8 @@ def write_file(filepath, objects, scene, ...@@ -595,7 +593,8 @@ def write_file(filepath, objects, scene,
mtl_rev_dict[mtl_name] = key mtl_rev_dict[mtl_name] = key
if EXPORT_GROUP_BY_MAT: if EXPORT_GROUP_BY_MAT:
fw("g %s_%s_%s\n" % (name_compat(ob.name), name_compat(ob.data.name), mat_data[0])) # can be mat_image or (null) # can be mat_image or (null)
fw("g %s_%s_%s\n" % (name_compat(ob.name), name_compat(ob.data.name), mat_data[0]))
if EXPORT_MTL: if EXPORT_MTL:
fw("usemtl %s\n" % mat_data[0]) # can be mat_image or (null) fw("usemtl %s\n" % mat_data[0]) # can be mat_image or (null)
...@@ -611,23 +610,22 @@ def write_file(filepath, objects, scene, ...@@ -611,23 +610,22 @@ def write_file(filepath, objects, scene,
fw('s off\n') fw('s off\n')
contextSmooth = f_smooth contextSmooth = f_smooth
f_v = [(vi, me_verts[v_idx], l_idx) for vi, (v_idx, l_idx) in enumerate(zip(f.vertices, f.loop_indices))] f_v = [(vi, me_verts[v_idx], l_idx)
for vi, (v_idx, l_idx) in enumerate(zip(f.vertices, f.loop_indices))]
fw('f') fw('f')
if faceuv: if faceuv:
if EXPORT_NORMALS: if EXPORT_NORMALS:
for vi, v, li in f_v: for vi, v, li in f_v:
fw(" %d/%d/%d" % fw(" %d/%d/%d" % (totverts + v.index,
(totverts + v.index, totuvco + uv_face_mapping[f_index][vi],
totuvco + uv_face_mapping[f_index][vi], totno + loops_to_normals[li],
totno + loops_to_normals[li], )) # vert, uv, normal
)) # vert, uv, normal
else: # No Normals else: # No Normals
for vi, v, li in f_v: for vi, v, li in f_v:
fw(" %d/%d" % ( fw(" %d/%d" % (totverts + v.index,
totverts + v.index, totuvco + uv_face_mapping[f_index][vi],
totuvco + uv_face_mapping[f_index][vi], )) # vert, uv
)) # vert, uv
face_vert_index += len(f_v) face_vert_index += len(f_v)
...@@ -671,25 +669,25 @@ def write_file(filepath, objects, scene, ...@@ -671,25 +669,25 @@ def write_file(filepath, objects, scene,
def _write(context, filepath, def _write(context, filepath,
EXPORT_TRI, # ok EXPORT_TRI, # ok
EXPORT_EDGES, EXPORT_EDGES,
EXPORT_SMOOTH_GROUPS, EXPORT_SMOOTH_GROUPS,
EXPORT_SMOOTH_GROUPS_BITFLAGS, EXPORT_SMOOTH_GROUPS_BITFLAGS,
EXPORT_NORMALS, # not yet EXPORT_NORMALS, # ok
EXPORT_UV, # ok EXPORT_UV, # ok
EXPORT_MTL, EXPORT_MTL,
EXPORT_APPLY_MODIFIERS, # ok EXPORT_APPLY_MODIFIERS, # ok
EXPORT_BLEN_OBS, EXPORT_BLEN_OBS,
EXPORT_GROUP_BY_OB, EXPORT_GROUP_BY_OB,
EXPORT_GROUP_BY_MAT, EXPORT_GROUP_BY_MAT,
EXPORT_KEEP_VERT_ORDER, EXPORT_KEEP_VERT_ORDER,
EXPORT_POLYGROUPS, EXPORT_POLYGROUPS,
EXPORT_CURVE_AS_NURBS, EXPORT_CURVE_AS_NURBS,
EXPORT_SEL_ONLY, # ok EXPORT_SEL_ONLY, # ok
EXPORT_ANIMATION, EXPORT_ANIMATION,
EXPORT_GLOBAL_MATRIX, EXPORT_GLOBAL_MATRIX,
EXPORT_PATH_MODE, EXPORT_PATH_MODE, # Not used
): # Not used ):
base_name, ext = os.path.splitext(filepath) base_name, ext = os.path.splitext(filepath)
context_name = [base_name, '', '', ext] # Base name, scene name, frame number, extension context_name = [base_name, '', '', ext] # Base name, scene name, frame number, extension
......
...@@ -179,7 +179,7 @@ def create_materials(filepath, relpath, ...@@ -179,7 +179,7 @@ def create_materials(filepath, relpath,
if not os.path.exists(mtlpath): if not os.path.exists(mtlpath):
print("\tMaterial not found MTL: %r" % mtlpath) print("\tMaterial not found MTL: %r" % mtlpath)
else: else:
#print('\t\tloading mtl: %e' % mtlpath) # print('\t\tloading mtl: %e' % mtlpath)
context_material = None context_material = None
mtl = open(mtlpath, 'rb') mtl = open(mtlpath, 'rb')
for line in mtl: # .readlines(): for line in mtl: # .readlines():
...@@ -198,15 +198,18 @@ def create_materials(filepath, relpath, ...@@ -198,15 +198,18 @@ def create_materials(filepath, relpath,
elif context_material: elif context_material:
# we need to make a material to assign properties to it. # we need to make a material to assign properties to it.
if line_id == b'ka': if line_id == b'ka':
context_material.mirror_color = float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]) context_material.mirror_color = (
float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]))
elif line_id == b'kd': elif line_id == b'kd':
context_material.diffuse_color = float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]) context_material.diffuse_color = (
float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]))
elif line_id == b'ks': elif line_id == b'ks':
context_material.specular_color = float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]) context_material.specular_color = (
float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]))
elif line_id == b'ns': elif line_id == b'ns':
context_material.specular_hardness = int((float_func(line_split[1]) * 0.51)) context_material.specular_hardness = int((float_func(line_split[1]) * 0.51))
elif line_id == b'ni': # Refraction index elif line_id == b'ni': # Refraction index (between 1 and 3).
context_material.raytrace_transparency.ior = max(1, min(float_func(line_split[1]), 3)) # between 1 and 3 context_material.raytrace_transparency.ior = max(1, min(float_func(line_split[1]), 3))
context_material_vars.add("ior") context_material_vars.add("ior")
elif line_id == b'd': # dissolve (trancparency) elif line_id == b'd': # dissolve (trancparency)
context_material.alpha = float_func(line_split[1]) context_material.alpha = float_func(line_split[1])
...@@ -383,7 +386,8 @@ def split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP): ...@@ -383,7 +386,8 @@ def split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP):
if oldkey != key: if oldkey != key:
# Check the key has changed. # Check the key has changed.
verts_split, faces_split, unique_materials_split, vert_remap = face_split_dict.setdefault(key, ([], [], {}, {})) (verts_split, faces_split,
unique_materials_split, vert_remap) = face_split_dict.setdefault(key, ([], [], {}, {}))
oldkey = key oldkey = key
face_vert_loc_indices = face[0] face_vert_loc_indices = face[0]
...@@ -493,9 +497,9 @@ def create_mesh(new_objects, ...@@ -493,9 +497,9 @@ def create_mesh(new_objects,
context_smooth_group, context_smooth_group,
context_object, context_object,
[], [],
) )
for ngon in ngon_face_indices] for ngon in ngon_face_indices]
) )
tot_loops += 3 * len(ngon_face_indices) tot_loops += 3 * len(ngon_face_indices)
# edges to make ngons # edges to make ngons
...@@ -891,7 +895,8 @@ def load(operator, context, filepath, ...@@ -891,7 +895,8 @@ def load(operator, context, filepath,
line_split = line_split[1:] line_split = line_split[1:]
# Instantiate a face # Instantiate a face
face = create_face(context_material, context_smooth_group, context_object) face = create_face(context_material, context_smooth_group, context_object)
face_vert_loc_indices, face_vert_nor_indices, face_vert_tex_indices, _1, _2, _3, face_invalid_blenpoly = face (face_vert_loc_indices, face_vert_nor_indices, face_vert_tex_indices,
_1, _2, _3, face_invalid_blenpoly) = face
faces.append(face) faces.append(face)
face_items_usage.clear() face_items_usage.clear()
# Else, use face_vert_loc_indices and face_vert_tex_indices previously defined and used the obj_face # Else, use face_vert_loc_indices and face_vert_tex_indices previously defined and used the obj_face
...@@ -1058,7 +1063,8 @@ def load(operator, context, filepath, ...@@ -1058,7 +1063,8 @@ 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, relpath, material_libs, unique_materials, unique_material_images, use_image_search, float_func) create_materials(filepath, relpath, material_libs, unique_materials,
unique_material_images, use_image_search, float_func)
time_new = time.time() time_new = time.time()
print("%.4f sec" % (time_new - time_sub)) print("%.4f sec" % (time_new - time_sub))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment