[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4691] trunk/py/scripts/addons/ io_scene_obj: fix [#36432] Exporting obj with normalmap creates opacity map in the mtl file instead

Campbell Barton ideasman42 at gmail.com
Wed Aug 21 10:21:01 CEST 2013


Revision: 4691
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4691
Author:   campbellbarton
Date:     2013-08-21 08:21:01 +0000 (Wed, 21 Aug 2013)
Log Message:
-----------
fix [#36432] Exporting obj with normalmap creates opacity map in the mtl file instead
- r3954/patch [#32914], introduced incorrect displacement map name, corrected.
- added support for reading displacement maps.
- remove checks that added alpha support for diffuce images, OBJ has alpha material settings for this.

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3954

Modified Paths:
--------------
    trunk/py/scripts/addons/io_scene_obj/export_obj.py
    trunk/py/scripts/addons/io_scene_obj/import_obj.py

Modified: trunk/py/scripts/addons/io_scene_obj/export_obj.py
===================================================================
--- trunk/py/scripts/addons/io_scene_obj/export_obj.py	2013-08-21 04:32:25 UTC (rev 4690)
+++ trunk/py/scripts/addons/io_scene_obj/export_obj.py	2013-08-21 08:21:01 UTC (rev 4691)
@@ -148,16 +148,16 @@
                             image_map["map_d"] = image
                         if mtex.use_map_translucency:
                             image_map["map_Tr"] = image
-                        if mtex.use_map_normal and (mtex.texture.use_normal_map is True):
+                        if mtex.use_map_normal:
                             image_map["map_Bump"] = image
-                        if mtex.use_map_normal and (mtex.texture.use_normal_map is False):
-                            image_map["map_Disp"] = image                      
+                        if mtex.use_map_displacement:
+                            image_map["disp"] = image                      
                         if mtex.use_map_color_diffuse and (mtex.texture_coords == 'REFLECTION'):
-                            image_map["map_refl"] = image
+                            image_map["refl"] = image
                         if mtex.use_map_emit:
                             image_map["map_Ke"] = image
 
-            for key, image in image_map.items():
+            for key, image in sorted(image_map.items()):
                 filepath = bpy_extras.io_utils.path_reference(image.filepath, source_dir, dest_dir,
                                                               path_mode, "", copy_set, image.library)
                 fw('%s %s\n' % (key, repr(filepath)[1:-1]))

Modified: trunk/py/scripts/addons/io_scene_obj/import_obj.py
===================================================================
--- trunk/py/scripts/addons/io_scene_obj/import_obj.py	2013-08-21 04:32:25 UTC (rev 4690)
+++ trunk/py/scripts/addons/io_scene_obj/import_obj.py	2013-08-21 08:21:01 UTC (rev 4691)
@@ -106,45 +106,20 @@
 
         # Absolute path - c:\.. etc would work here
         image = obj_image_load(imagepath, DIR, use_image_search, relpath)
-        has_data = False
-        image_depth = 0
 
         if image is not None:
             texture.image = image
-            # note, this causes the image to load, see: [#32637]
-            # which makes the following has_data work as expected.
-            image_depth = image.depth
-            has_data = image.has_data
 
         # Adds textures for materials (rendering)
         if type == 'Kd':
-            if image_depth in {32, 128}:
-                # Image has alpha
+            mtex = blender_material.texture_slots.add()
+            mtex.texture = texture
+            mtex.texture_coords = 'UV'
+            mtex.use_map_color_diffuse = True
 
-                mtex = blender_material.texture_slots.add()
-                mtex.texture = texture
-                mtex.texture_coords = 'UV'
-                mtex.use_map_color_diffuse = True
-                mtex.use_map_alpha = True
-
-                texture.use_mipmap = True
-                texture.use_interpolation = True
-                if image is not None:
-                    image.use_alpha = True
-                blender_material.use_transparency = True
-                if "alpha" not in context_material_vars:
-                    blender_material.alpha = 0.0
-
-                blender_material.game_settings.alpha_blend = 'ALPHA'
-            else:
-                mtex = blender_material.texture_slots.add()
-                mtex.texture = texture
-                mtex.texture_coords = 'UV'
-                mtex.use_map_color_diffuse = True
-
             # adds textures to faces (Textured/Alt-Z mode)
             # Only apply the diffuse texture to the face if the image has not been set with the inline usemat func.
-            unique_material_images[context_material_name] = image, has_data  # set the texface image
+            unique_material_images[context_material_name] = image  # set the texface image
 
         elif type == 'Ka':
             mtex = blender_material.texture_slots.add()
@@ -183,6 +158,14 @@
                 blender_material.alpha = 0.0
             # Todo, unset deffuse material alpha if it has an alpha channel
 
+        elif type == 'disp':
+            mtex = blender_material.texture_slots.add()
+            mtex.use_map_color_diffuse = False
+
+            mtex.texture = texture
+            mtex.texture_coords = 'UV'
+            mtex.use_map_displacement = True
+
         elif type == 'refl':
             mtex = blender_material.texture_slots.add()
             mtex.use_map_color_diffuse = False
@@ -374,6 +357,11 @@
                         if img_filepath:
                             load_material_image(context_material, context_material_name, img_filepath, 'D')
 
+                    elif line_lower.startswith((b'map_disp', b'disp')):  # reflectionmap
+                        img_filepath = line_value(line.split())
+                        if img_filepath:
+                            load_material_image(context_material, context_material_name, img_filepath, 'disp')
+
                     elif line_lower.startswith((b'map_refl', b'refl')):  # reflectionmap
                         img_filepath = line_value(line.split())
                         if img_filepath:
@@ -635,7 +623,7 @@
                 blender_tface = me.tessface_uv_textures[0].data[i]
 
                 if context_material:
-                    image, has_data = unique_material_images[context_material]
+                    image = unique_material_images[context_material]
                     if image:  # Can be none if the material dosnt have an image.
                         blender_tface.image = image
 



More information about the Bf-extensions-cvs mailing list