[Bf-extensions-cvs] [3cc970e] master: OBJ IO: add some progress report for user.
Bastien Montagne
noreply at git.blender.org
Sat Jul 11 16:51:19 CEST 2015
Commit: 3cc970eaf5c896b8103a88d959ebb0776e4ad590
Author: Bastien Montagne
Date: Sat Jul 11 16:45:54 2015 +0200
Branches: master
https://developer.blender.org/rBA3cc970eaf5c896b8103a88d959ebb0776e4ad590
OBJ IO: add some progress report for user.
Use new 'progress_report' util module to do both a (basic) report of I/O progression,
together with some logging/timing of main steps.
We could probably go much further, but for now it will do.
Also, using files as context manager, too!
===================================================================
M io_scene_obj/__init__.py
M io_scene_obj/export_obj.py
M io_scene_obj/import_obj.py
===================================================================
diff --git a/io_scene_obj/__init__.py b/io_scene_obj/__init__.py
index b356da7..508445e 100644
--- a/io_scene_obj/__init__.py
+++ b/io_scene_obj/__init__.py
@@ -21,7 +21,7 @@
bl_info = {
"name": "Wavefront OBJ format",
"author": "Campbell Barton, Bastien Montagne",
- "version": (2, 1, 3),
+ "version": (2, 2, 0),
"blender": (2, 74, 0),
"location": "File > Import-Export",
"description": "Import-Export OBJ, Import OBJ mesh, UV's, "
diff --git a/io_scene_obj/export_obj.py b/io_scene_obj/export_obj.py
index d47555c..7399c2e 100644
--- a/io_scene_obj/export_obj.py
+++ b/io_scene_obj/export_obj.py
@@ -19,12 +19,13 @@
# <pep8 compliant>
import os
-import time
import bpy
import mathutils
import bpy_extras.io_utils
+from progress_report import ProgressReport, ProgressReportSubstep
+
def name_compat(name):
if name is None:
@@ -54,132 +55,129 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
source_dir = os.path.dirname(bpy.data.filepath)
dest_dir = os.path.dirname(filepath)
- file = open(filepath, "w", encoding="utf8", newline="\n")
- fw = file.write
-
- fw('# Blender MTL File: %r\n' % (os.path.basename(bpy.data.filepath) or "None"))
- fw('# Material Count: %i\n' % len(mtl_dict))
+ with open(filepath, "w", encoding="utf8", newline="\n") as f:
+ fw = f.write
- mtl_dict_values = list(mtl_dict.values())
- mtl_dict_values.sort(key=lambda m: m[0])
+ fw('# Blender MTL File: %r\n' % (os.path.basename(bpy.data.filepath) or "None"))
+ fw('# Material Count: %i\n' % len(mtl_dict))
- # Write material/image combinations we have used.
- # Using mtl_dict.values() directly gives un-predictable order.
- for mtl_mat_name, mat, face_img in mtl_dict_values:
+ mtl_dict_values = list(mtl_dict.values())
+ mtl_dict_values.sort(key=lambda m: m[0])
- # Get the Blender data for the material and the image.
- # Having an image named None will make a bug, dont do it :)
+ # Write material/image combinations we have used.
+ # Using mtl_dict.values() directly gives un-predictable order.
+ for mtl_mat_name, mat, face_img in mtl_dict_values:
+ # Get the Blender data for the material and the image.
+ # Having an image named None will make a bug, dont do it :)
- fw('\nnewmtl %s\n' % mtl_mat_name) # Define a new material: matname_imgname
+ fw('\nnewmtl %s\n' % mtl_mat_name) # Define a new material: matname_imgname
- if mat:
- use_mirror = mat.raytrace_mirror.use and mat.raytrace_mirror.reflect_factor != 0.0
+ if mat:
+ use_mirror = mat.raytrace_mirror.use and mat.raytrace_mirror.reflect_factor != 0.0
- # convert from blenders spec to 0 - 1000 range.
- if mat.specular_shader == 'WARDISO':
- tspec = (0.4 - mat.specular_slope) / 0.0004
- else:
- tspec = (mat.specular_hardness - 1) / 0.51
- fw('Ns %.6f\n' % tspec)
- del tspec
+ # convert from blenders spec to 0 - 1000 range.
+ if mat.specular_shader == 'WARDISO':
+ tspec = (0.4 - mat.specular_slope) / 0.0004
+ else:
+ tspec = (mat.specular_hardness - 1) / 0.51
+ fw('Ns %.6f\n' % tspec)
+ del tspec
- # Ambient
- if use_mirror:
- fw('Ka %.6f %.6f %.6f\n' % (mat.raytrace_mirror.reflect_factor * mat.mirror_color)[:])
- else:
- fw('Ka %.6f %.6f %.6f\n' % (mat.ambient, mat.ambient, mat.ambient)) # Do not use world color!
- fw('Kd %.6f %.6f %.6f\n' % (mat.diffuse_intensity * mat.diffuse_color)[:]) # Diffuse
- fw('Ks %.6f %.6f %.6f\n' % (mat.specular_intensity * mat.specular_color)[:]) # Specular
- if hasattr(mat, "raytrace_transparency") and hasattr(mat.raytrace_transparency, "ior"):
- fw('Ni %.6f\n' % mat.raytrace_transparency.ior) # Refraction index
- else:
- fw('Ni %.6f\n' % 1.0)
- fw('d %.6f\n' % mat.alpha) # Alpha (obj uses 'd' for dissolve)
-
- # See http://en.wikipedia.org/wiki/Wavefront_.obj_file for whole list of values...
- # Note that mapping is rather fuzzy sometimes, trying to do our best here.
- if mat.use_shadeless:
- fw('illum 0\n') # ignore lighting
- elif mat.specular_intensity == 0:
- fw('illum 1\n') # no specular.
- elif use_mirror:
- if mat.use_transparency and mat.transparency_method == 'RAYTRACE':
- if mat.raytrace_mirror.fresnel != 0.0:
- fw('illum 7\n') # Reflection, Transparency, Ray trace and Fresnel
+ # Ambient
+ if use_mirror:
+ fw('Ka %.6f %.6f %.6f\n' % (mat.raytrace_mirror.reflect_factor * mat.mirror_color)[:])
+ else:
+ fw('Ka %.6f %.6f %.6f\n' % (mat.ambient, mat.ambient, mat.ambient)) # Do not use world color!
+ fw('Kd %.6f %.6f %.6f\n' % (mat.diffuse_intensity * mat.diffuse_color)[:]) # Diffuse
+ fw('Ks %.6f %.6f %.6f\n' % (mat.specular_intensity * mat.specular_color)[:]) # Specular
+ if hasattr(mat, "raytrace_transparency") and hasattr(mat.raytrace_transparency, "ior"):
+ fw('Ni %.6f\n' % mat.raytrace_transparency.ior) # Refraction index
+ else:
+ fw('Ni %.6f\n' % 1.0)
+ fw('d %.6f\n' % mat.alpha) # Alpha (obj uses 'd' for dissolve)
+
+ # See http://en.wikipedia.org/wiki/Wavefront_.obj_file for whole list of values...
+ # Note that mapping is rather fuzzy sometimes, trying to do our best here.
+ if mat.use_shadeless:
+ fw('illum 0\n') # ignore lighting
+ elif mat.specular_intensity == 0:
+ fw('illum 1\n') # no specular.
+ elif use_mirror:
+ if mat.use_transparency and mat.transparency_method == 'RAYTRACE':
+ if mat.raytrace_mirror.fresnel != 0.0:
+ fw('illum 7\n') # Reflection, Transparency, Ray trace and Fresnel
+ else:
+ fw('illum 6\n') # Reflection, Transparency, Ray trace
+ elif mat.raytrace_mirror.fresnel != 0.0:
+ fw('illum 5\n') # Reflection, Ray trace and Fresnel
else:
- fw('illum 6\n') # Reflection, Transparency, Ray trace
- elif mat.raytrace_mirror.fresnel != 0.0:
- fw('illum 5\n') # Reflection, Ray trace and Fresnel
+ fw('illum 3\n') # Reflection and Ray trace
+ elif mat.use_transparency and mat.transparency_method == 'RAYTRACE':
+ fw('illum 9\n') # 'Glass' transparency and no Ray trace reflection... fuzzy matching, but...
else:
- fw('illum 3\n') # Reflection and Ray trace
- elif mat.use_transparency and mat.transparency_method == 'RAYTRACE':
- fw('illum 9\n') # 'Glass' transparency and no Ray trace reflection... fuzzy matching, but...
+ fw('illum 2\n') # light normaly
+
else:
+ # Write a dummy material here?
+ fw('Ns 0\n')
+ fw('Ka %.6f %.6f %.6f\n' % world_amb[:]) # Ambient, uses mirror color,
+ fw('Kd 0.8 0.8 0.8\n')
+ fw('Ks 0.8 0.8 0.8\n')
+ fw('d 1\n') # No alpha
fw('illum 2\n') # light normaly
- else:
- # Write a dummy material here?
- fw('Ns 0\n')
- fw('Ka %.6f %.6f %.6f\n' % world_amb[:]) # Ambient, uses mirror color,
- fw('Kd 0.8 0.8 0.8\n')
- fw('Ks 0.8 0.8 0.8\n')
- fw('d 1\n') # No alpha
- fw('illum 2\n') # light normaly
-
- # Write images!
- if face_img: # We have an image on the face!
- filepath = face_img.filepath
- if filepath: # may be '' for generated images
- # write relative image path
- filepath = bpy_extras.io_utils.path_reference(filepath, source_dir, dest_dir,
- path_mode, "", copy_set, face_img.library)
- fw('map_Kd %s\n' % filepath) # Diffuse mapping image
- del filepath
- else:
- # so we write the materials image.
- face_img = None
-
- if mat: # No face image. if we havea material search for MTex image.
- image_map = {}
- # backwards so topmost are highest priority
- for mtex in reversed(mat.texture_slots):
- if mtex and mtex.texture and mtex.texture.type == 'IMAGE':
- 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')):
- image_map["map_Kd"] = image
- if mtex.use_map_ambient:
- image_map["map_Ka"] = image
- # this is the Spec intensity channel but Ks stands for specular Color
- '''
- if mtex.use_map_specular:
- image_map["map_Ks"] = image
- '''
- if mtex.use_map_color_spec: # specular color
- image_map["map_Ks"] = image
- if mtex.use_map_hardness: # specular hardness/glossiness
- image_map["map_Ns"] = image
- if mtex.use_map_alpha:
- image_map["map_d"] = image
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list