[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33879] trunk/blender/release/scripts/op/ io_scene_obj/export_obj.py: fix for exporting OBJ, materials when no world was set.

Campbell Barton ideasman42 at gmail.com
Fri Dec 24 05:21:07 CET 2010


Revision: 33879
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33879
Author:   campbellbarton
Date:     2010-12-24 05:21:05 +0100 (Fri, 24 Dec 2010)

Log Message:
-----------
fix for exporting OBJ, materials when no world was set. also use slicing to get tuples.

Modified Paths:
--------------
    trunk/blender/release/scripts/op/io_scene_obj/export_obj.py

Modified: trunk/blender/release/scripts/op/io_scene_obj/export_obj.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_obj/export_obj.py	2010-12-24 03:51:34 UTC (rev 33878)
+++ trunk/blender/release/scripts/op/io_scene_obj/export_obj.py	2010-12-24 04:21:05 UTC (rev 33879)
@@ -34,7 +34,10 @@
 def write_mtl(scene, filepath, copy_images, mtl_dict):
 
     world = scene.world
-    worldAmb = world.ambient_color
+    if world:
+        worldAmb = world.ambient_color[:]
+    else:
+        worldAmb = 0.0, 0.0, 0.0
 
     dest_dir = os.path.dirname(filepath)
 
@@ -69,10 +72,10 @@
         file.write('newmtl %s\n' % mtl_mat_name) # Define a new material: matname_imgname
 
         if mat:
-            file.write('Ns %.6f\n' % ((mat.specular_hardness-1) * 1.9607843137254901) ) # Hardness, convert blenders 1-511 to MTL's
-            file.write('Ka %.6f %.6f %.6f\n' %  tuple([c*mat.ambient for c in worldAmb])  ) # Ambient, uses mirror colour,
-            file.write('Kd %.6f %.6f %.6f\n' % tuple([c*mat.diffuse_intensity for c in mat.diffuse_color]) ) # Diffuse
-            file.write('Ks %.6f %.6f %.6f\n' % tuple([c*mat.specular_intensity for c in mat.specular_color]) ) # Specular
+            file.write('Ns %.6f\n' % ((mat.specular_hardness-1) * 1.9607843137254901)) # Hardness, convert blenders 1-511 to MTL's
+            file.write('Ka %.6f %.6f %.6f\n' %  tuple(c * mat.ambient for c in worldAmb)) # Ambient, uses mirror colour,
+            file.write('Kd %.6f %.6f %.6f\n' % tuple(c * mat.diffuse_intensity for c in mat.diffuse_color)) # Diffuse
+            file.write('Ks %.6f %.6f %.6f\n' % tuple(c * mat.specular_intensity for c in mat.specular_color)) # Specular
             if hasattr(mat, "ior"):
                 file.write('Ni %.6f\n' % mat.ior) # Refraction index
             else:
@@ -90,7 +93,7 @@
         else:
             #write a dummy material here?
             file.write('Ns 0\n')
-            file.write('Ka %.6f %.6f %.6f\n' %  tuple([c for c in worldAmb])  ) # Ambient, uses mirror colour,
+            file.write('Ka %.6f %.6f %.6f\n' %  tuple(c for c in worldAmb)) # Ambient, uses mirror colour,
             file.write('Kd 0.8 0.8 0.8\n')
             file.write('Ks 0.8 0.8 0.8\n')
             file.write('d 1\n') # No alpha
@@ -485,7 +488,7 @@
 
             # Vert
             for v in me_verts:
-                file.write('v %.6f %.6f %.6f\n' % tuple(v.co))
+                file.write('v %.6f %.6f %.6f\n' % v.co[:])
 
             # UV
             if faceuv:





More information about the Bf-blender-cvs mailing list