[Bf-extensions-cvs] [db79c2a] master: FBX Import: Add option to not import custom normals.

Bastien Montagne noreply at git.blender.org
Sun Jul 12 12:41:49 CEST 2015


Commit: db79c2aa5eed872e44f8462cfbc793011b4a8162
Author: Bastien Montagne
Date:   Sun Jul 12 12:40:24 2015 +0200
Branches: master
https://developer.blender.org/rBAdb79c2aa5eed872e44f8462cfbc793011b4a8162

FBX Import: Add option to not import custom normals.

===================================================================

M	io_scene_fbx/__init__.py
M	io_scene_fbx/fbx_utils.py
M	io_scene_fbx/import_fbx.py

===================================================================

diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py
index b91696d..184e667 100644
--- a/io_scene_fbx/__init__.py
+++ b/io_scene_fbx/__init__.py
@@ -21,7 +21,7 @@
 bl_info = {
     "name": "FBX format",
     "author": "Campbell Barton, Bastien Montagne, Jens Restemeier",
-    "version": (3, 4, 4),
+    "version": (3, 4, 5),
     "blender": (2, 74, 0),
     "location": "File > Import-Export",
     "description": "FBX IO meshes, UV's, vertex colors, materials, textures, cameras, lamps and actions",
@@ -90,6 +90,12 @@ class ImportFBX(bpy.types.Operator, ImportHelper, IOFBXOrientationHelper):
             default=False,
             )
 
+    use_custom_normals = BoolProperty(
+            name="Import Normals",
+            description="Import custom normals, if available (otherwise Blender will recompute them)",
+            default=True,
+            )
+
     use_image_search = BoolProperty(
             name="Image Search",
             description="Search subdirs for any associated images (Warning, may be slow)",
@@ -181,6 +187,8 @@ class ImportFBX(bpy.types.Operator, ImportHelper, IOFBXOrientationHelper):
         layout.prop(self, "global_scale")
         layout.prop(self, "bake_space_transform")
 
+        layout.prop(self, "use_custom_normals")
+
         layout.prop(self, "use_image_search")
         # layout.prop(self, "use_alpha_decals")
         layout.prop(self, "decal_offset")
diff --git a/io_scene_fbx/fbx_utils.py b/io_scene_fbx/fbx_utils.py
index 85b64e5..651cac7 100644
--- a/io_scene_fbx/fbx_utils.py
+++ b/io_scene_fbx/fbx_utils.py
@@ -1223,7 +1223,7 @@ FBXExportData = namedtuple("FBXExportData", (
 FBXImportSettings = namedtuple("FBXImportSettings", (
     "report", "to_axes", "global_matrix", "global_scale",
     "bake_space_transform", "global_matrix_inv", "global_matrix_inv_transposed",
-    "use_cycles", "use_image_search",
+    "use_custom_normals", "use_cycles", "use_image_search",
     "use_alpha_decals", "decal_offset",
     "anim_offset",
     "use_custom_props", "use_custom_props_enum_as_string",
diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index b9384eb..e667693 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -1183,15 +1183,17 @@ def blen_read_geom(fbx_tmpl, fbx_obj, settings):
     # must be after edge, face loading.
     ok_smooth = blen_read_geom_layer_smooth(fbx_obj, mesh)
 
-    # Note: we store 'temp' normals in loops, since validate() may alter final mesh,
-    #       we can only set custom lnors *after* calling it.
-    mesh.create_normals_split()
-    if geom_mat_no is None:
-        ok_normals = blen_read_geom_layer_normal(fbx_obj, mesh)
-    else:
-        def nortrans(v):
-            return geom_mat_no * Vector(v)
-        ok_normals = blen_read_geom_layer_normal(fbx_obj, mesh, nortrans)
+    ok_normals = False
+    if settings.use_custom_normals:
+        # Note: we store 'temp' normals in loops, since validate() may alter final mesh,
+        #       we can only set custom lnors *after* calling it.
+        mesh.create_normals_split()
+        if geom_mat_no is None:
+            ok_normals = blen_read_geom_layer_normal(fbx_obj, mesh)
+        else:
+            def nortrans(v):
+                return geom_mat_no * Vector(v)
+            ok_normals = blen_read_geom_layer_normal(fbx_obj, mesh, nortrans)
 
     mesh.validate(clean_customdata=False)  # *Very* important to not remove lnors here!
 
@@ -1209,7 +1211,8 @@ def blen_read_geom(fbx_tmpl, fbx_obj, settings):
     else:
         mesh.calc_normals()
 
-    mesh.free_normals_split()
+    if settings.use_custom_normals:
+        mesh.free_normals_split()
 
     if not ok_smooth:
         mesh.polygons.foreach_set("use_smooth", [True] * len(mesh.polygons))
@@ -2182,6 +2185,7 @@ def load(operator, context, filepath="",
          axis_up='Y',
          global_scale=1.0,
          bake_space_transform=False,
+         use_custom_normals=True,
          use_cycles=True,
          use_image_search=False,
          use_alpha_decals=False,
@@ -2311,7 +2315,7 @@ def load(operator, context, filepath="",
     settings = FBXImportSettings(
         operator.report, (axis_up, axis_forward), global_matrix, global_scale,
         bake_space_transform, global_matrix_inv, global_matrix_inv_transposed,
-        use_cycles, use_image_search,
+        use_custom_normals, use_cycles, use_image_search,
         use_alpha_decals, decal_offset,
         anim_offset,
         use_custom_props, use_custom_props_enum_as_string,



More information about the Bf-extensions-cvs mailing list