OBJ IO: More cleanup (mostly from pep8).
This commit is contained in:
parent
7af50e62d3
commit
0225bffb98
|
@ -128,10 +128,8 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
|
|||
image = mtex.texture.image
|
||||
if image:
|
||||
# texface overrides others
|
||||
if (mtex.use_map_color_diffuse and
|
||||
(face_img is None) and
|
||||
(mtex.use_map_warp is False) and
|
||||
(mtex.texture_coords != 'REFLECTION')):
|
||||
if (mtex.use_map_color_diffuse and (face_img is None) and
|
||||
(mtex.use_map_warp is False) and (mtex.texture_coords != 'REFLECTION')):
|
||||
image_map["map_Kd"] = image
|
||||
if mtex.use_map_ambient:
|
||||
image_map["map_Ka"] = image
|
||||
|
@ -564,7 +562,7 @@ def write_file(filepath, objects, scene,
|
|||
# Write a null material, since we know the context has changed.
|
||||
if EXPORT_GROUP_BY_MAT:
|
||||
# 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:
|
||||
fw("usemtl (null)\n") # mat, image
|
||||
|
||||
|
@ -595,7 +593,8 @@ def write_file(filepath, objects, scene,
|
|||
mtl_rev_dict[mtl_name] = key
|
||||
|
||||
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:
|
||||
fw("usemtl %s\n" % mat_data[0]) # can be mat_image or (null)
|
||||
|
||||
|
@ -611,23 +610,22 @@ def write_file(filepath, objects, scene,
|
|||
fw('s off\n')
|
||||
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')
|
||||
if faceuv:
|
||||
if EXPORT_NORMALS:
|
||||
for vi, v, li in f_v:
|
||||
fw(" %d/%d/%d" %
|
||||
(totverts + v.index,
|
||||
totuvco + uv_face_mapping[f_index][vi],
|
||||
totno + loops_to_normals[li],
|
||||
)) # vert, uv, normal
|
||||
fw(" %d/%d/%d" % (totverts + v.index,
|
||||
totuvco + uv_face_mapping[f_index][vi],
|
||||
totno + loops_to_normals[li],
|
||||
)) # vert, uv, normal
|
||||
else: # No Normals
|
||||
for vi, v, li in f_v:
|
||||
fw(" %d/%d" % (
|
||||
totverts + v.index,
|
||||
totuvco + uv_face_mapping[f_index][vi],
|
||||
)) # vert, uv
|
||||
fw(" %d/%d" % (totverts + v.index,
|
||||
totuvco + uv_face_mapping[f_index][vi],
|
||||
)) # vert, uv
|
||||
|
||||
face_vert_index += len(f_v)
|
||||
|
||||
|
@ -671,25 +669,25 @@ def write_file(filepath, objects, scene,
|
|||
|
||||
|
||||
def _write(context, filepath,
|
||||
EXPORT_TRI, # ok
|
||||
EXPORT_EDGES,
|
||||
EXPORT_SMOOTH_GROUPS,
|
||||
EXPORT_SMOOTH_GROUPS_BITFLAGS,
|
||||
EXPORT_NORMALS, # not yet
|
||||
EXPORT_UV, # ok
|
||||
EXPORT_MTL,
|
||||
EXPORT_APPLY_MODIFIERS, # ok
|
||||
EXPORT_BLEN_OBS,
|
||||
EXPORT_GROUP_BY_OB,
|
||||
EXPORT_GROUP_BY_MAT,
|
||||
EXPORT_KEEP_VERT_ORDER,
|
||||
EXPORT_POLYGROUPS,
|
||||
EXPORT_CURVE_AS_NURBS,
|
||||
EXPORT_SEL_ONLY, # ok
|
||||
EXPORT_ANIMATION,
|
||||
EXPORT_GLOBAL_MATRIX,
|
||||
EXPORT_PATH_MODE,
|
||||
): # Not used
|
||||
EXPORT_TRI, # ok
|
||||
EXPORT_EDGES,
|
||||
EXPORT_SMOOTH_GROUPS,
|
||||
EXPORT_SMOOTH_GROUPS_BITFLAGS,
|
||||
EXPORT_NORMALS, # ok
|
||||
EXPORT_UV, # ok
|
||||
EXPORT_MTL,
|
||||
EXPORT_APPLY_MODIFIERS, # ok
|
||||
EXPORT_BLEN_OBS,
|
||||
EXPORT_GROUP_BY_OB,
|
||||
EXPORT_GROUP_BY_MAT,
|
||||
EXPORT_KEEP_VERT_ORDER,
|
||||
EXPORT_POLYGROUPS,
|
||||
EXPORT_CURVE_AS_NURBS,
|
||||
EXPORT_SEL_ONLY, # ok
|
||||
EXPORT_ANIMATION,
|
||||
EXPORT_GLOBAL_MATRIX,
|
||||
EXPORT_PATH_MODE, # Not used
|
||||
):
|
||||
|
||||
base_name, ext = os.path.splitext(filepath)
|
||||
context_name = [base_name, '', '', ext] # Base name, scene name, frame number, extension
|
||||
|
|
|
@ -179,7 +179,7 @@ def create_materials(filepath, relpath,
|
|||
if not os.path.exists(mtlpath):
|
||||
print("\tMaterial not found MTL: %r" % mtlpath)
|
||||
else:
|
||||
#print('\t\tloading mtl: %e' % mtlpath)
|
||||
# print('\t\tloading mtl: %e' % mtlpath)
|
||||
context_material = None
|
||||
mtl = open(mtlpath, 'rb')
|
||||
for line in mtl: # .readlines():
|
||||
|
@ -198,15 +198,18 @@ def create_materials(filepath, relpath,
|
|||
elif context_material:
|
||||
# we need to make a material to assign properties to it.
|
||||
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':
|
||||
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':
|
||||
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':
|
||||
context_material.specular_hardness = int((float_func(line_split[1]) * 0.51))
|
||||
elif line_id == b'ni': # Refraction index
|
||||
context_material.raytrace_transparency.ior = max(1, min(float_func(line_split[1]), 3)) # between 1 and 3
|
||||
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))
|
||||
context_material_vars.add("ior")
|
||||
elif line_id == b'd': # dissolve (trancparency)
|
||||
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):
|
|||
|
||||
if oldkey != key:
|
||||
# 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
|
||||
|
||||
face_vert_loc_indices = face[0]
|
||||
|
@ -493,9 +497,9 @@ def create_mesh(new_objects,
|
|||
context_smooth_group,
|
||||
context_object,
|
||||
[],
|
||||
)
|
||||
)
|
||||
for ngon in ngon_face_indices]
|
||||
)
|
||||
)
|
||||
tot_loops += 3 * len(ngon_face_indices)
|
||||
|
||||
# edges to make ngons
|
||||
|
@ -891,7 +895,8 @@ def load(operator, context, filepath,
|
|||
line_split = line_split[1:]
|
||||
# Instantiate a face
|
||||
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)
|
||||
face_items_usage.clear()
|
||||
# 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,
|
|||
time_sub = time_new
|
||||
|
||||
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()
|
||||
print("%.4f sec" % (time_new - time_sub))
|
||||
|
|
Loading…
Reference in New Issue