From 42ffe2c2288934ec4ab0944760ca332ae37b3145 Mon Sep 17 00:00:00 2001 From: Thomas Barlow Date: Fri, 1 Dec 2023 03:19:47 +0000 Subject: [PATCH 1/2] FBX IO: Update for new meshes being smooth by default Blender 3.6 changed newly created meshes to be smooth by default, therefore, it is no longer necessary to remove the "sharp_face" attribute if face smoothing was not set when importing a mesh. The only time when "sharp_face" needs to be removed is if we create the attribute when attempting to set face smoothing, but setting face smoothing fails. No changes to the import of .fbx files are expected with this patch. --- io_scene_fbx/import_fbx.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py index 6152c3804..755dbd682 100644 --- a/io_scene_fbx/import_fbx.py +++ b/io_scene_fbx/import_fbx.py @@ -1638,7 +1638,7 @@ def blen_read_geom_layer_smooth(fbx_obj, mesh): fbx_layer = elem_find_first(fbx_obj, b'LayerElementSmoothing') if fbx_layer is None: - return False + return # all should be valid (fbx_layer_name, @@ -1651,13 +1651,13 @@ def blen_read_geom_layer_smooth(fbx_obj, mesh): # udk has 'Direct' mapped, with no Smoothing, not sure why, but ignore these if fbx_layer_data is None: - return False + return if fbx_layer_mapping == b'ByEdge': # some models have bad edge data, we can't use this info... if not mesh.edges: print("warning skipping sharp edges data, no valid edges...") - return False + return blen_data = MESH_ATTRIBUTE_SHARP_EDGE.ensure(mesh.attributes).data fbx_item_size = 1 @@ -1669,21 +1669,23 @@ def blen_read_geom_layer_smooth(fbx_obj, mesh): 1, fbx_item_size, layer_id, xform=np.logical_not, # in FBX, 0 (False) is sharp, but in Blender True is sharp. ) - return False elif fbx_layer_mapping == b'ByPolygon': - blen_data = MESH_ATTRIBUTE_SHARP_FACE.ensure(mesh.attributes).data + sharp_face = MESH_ATTRIBUTE_SHARP_FACE.ensure(mesh.attributes) + blen_data = sharp_face.data fbx_item_size = 1 assert(fbx_item_size == MESH_ATTRIBUTE_SHARP_FACE.item_size) - return blen_read_geom_array_mapped_polygon( + sharp_face_set_successfully = blen_read_geom_array_mapped_polygon( mesh, blen_data, MESH_ATTRIBUTE_SHARP_FACE.foreach_attribute, MESH_ATTRIBUTE_SHARP_FACE.dtype, fbx_layer_data, None, fbx_layer_mapping, fbx_layer_ref, 1, fbx_item_size, layer_id, xform=lambda s: (s == 0), # smoothgroup bitflags, treat as booleans for now ) + if not sharp_face_set_successfully: + mesh.attributes.remove(sharp_face) else: print("warning layer %r mapping type unsupported: %r" % (fbx_layer.id, fbx_layer_mapping)) - return False + def blen_read_geom_layer_edge_crease(fbx_obj, mesh): fbx_layer = elem_find_first(fbx_obj, b'LayerElementEdgeCrease') @@ -1883,7 +1885,7 @@ def blen_read_geom(fbx_tmpl, fbx_obj, settings): print("ERROR: No polygons, but edges exist. Ignoring the edges!") # must be after edge, face loading. - ok_smooth = blen_read_geom_layer_smooth(fbx_obj, mesh) + blen_read_geom_layer_smooth(fbx_obj, mesh) blen_read_geom_layer_edge_crease(fbx_obj, mesh) @@ -1905,23 +1907,12 @@ def blen_read_geom(fbx_tmpl, fbx_obj, settings): clnors = np.empty(len(mesh.loops) * 3, dtype=bl_nors_dtype) mesh.attributes["temp_custom_normals"].data.foreach_get("vector", clnors) - if not ok_smooth: - sharp_face = MESH_ATTRIBUTE_SHARP_FACE.get(attributes) - if sharp_face: - attributes.remove(sharp_face) - ok_smooth = True - # Iterating clnors into a nested tuple first is faster than passing clnors.reshape(-1, 3) directly into # normals_split_custom_set. We use clnors.data since it is a memoryview, which is faster to iterate than clnors. mesh.normals_split_custom_set(tuple(zip(*(iter(clnors.data),) * 3))) if settings.use_custom_normals: mesh.attributes.remove(mesh.attributes["temp_custom_normals"]) - if not ok_smooth: - sharp_face = MESH_ATTRIBUTE_SHARP_FACE.get(attributes) - if sharp_face: - attributes.remove(sharp_face) - if settings.use_custom_props: blen_read_custom_properties(fbx_obj, mesh, settings) -- 2.30.2 From 81a2af62fdcf39c80553155cdc694db634b0e418 Mon Sep 17 00:00:00 2001 From: Thomas Barlow Date: Tue, 5 Dec 2023 02:38:57 +0000 Subject: [PATCH 2/2] Increase FBX version --- io_scene_fbx/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index 784cfcc74..780db2cbe 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -5,7 +5,7 @@ bl_info = { "name": "FBX format", "author": "Campbell Barton, Bastien Montagne, Jens Restemeier, @Mysteryem", - "version": (5, 11, 0), + "version": (5, 11, 1), "blender": (4, 1, 0), "location": "File > Import-Export", "description": "FBX IO meshes, UVs, vertex colors, materials, textures, cameras, lamps and actions", -- 2.30.2