Mesh: Update addons for auto smooth removal #104609

Merged
Hans Goudey merged 10 commits from HooglyBoogly/blender-addons:refactor-mesh-corner-normals-lazy into main 2023-10-20 16:53:48 +02:00
18 changed files with 8 additions and 73 deletions
Showing only changes of commit ee40b70084 - Show all commits

View File

@ -416,7 +416,6 @@ class add_mesh_bolt(Operator, AddObjectHelper):
(context.active_object.data is not None) and ('Bolt' in context.active_object.data.keys()) and \
(self.change == True):
obj = context.active_object
use_auto_smooth = bool(obj.data.use_auto_smooth) # Copy value, do not take a reference
use_smooth = bool(obj.data.polygons[0].use_smooth) # Copy value, do not take a reference
mesh = createMesh.Create_New_Mesh(self, context)
@ -428,7 +427,6 @@ class add_mesh_bolt(Operator, AddObjectHelper):
bm.free()
# Preserve flat/smooth choice. New mesh is flat by default
obj.data.use_auto_smooth = use_auto_smooth
if use_smooth:
bpy.ops.object.shade_smooth()

View File

@ -148,9 +148,6 @@ def createMeshObject(context, verts, edges, faces, name):
# Make a mesh from a list of verts/edges/faces.
mesh.from_pydata(verts, edges, faces)
# Set mesh to use auto smoothing:
mesh.use_auto_smooth = True
# Update mesh geometry after adding stuff.
mesh.update()

View File

@ -17,7 +17,6 @@ def create_and_link_mesh(name, faces, face_nors, points, global_matrix):
if face_nors:
# 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()
lnors = tuple(chain(*chain(*zip(face_nors, face_nors, face_nors))))
mesh.loops.foreach_set("normal", lnors)
@ -33,8 +32,6 @@ def create_and_link_mesh(name, faces, face_nors, points, global_matrix):
mesh.polygons.foreach_set("use_smooth", [True] * len(mesh.polygons))
mesh.normals_split_custom_set(tuple(zip(*(iter(clnors),) * 3)))
mesh.use_auto_smooth = True
mesh.free_normals_split()
mesh.update()

View File

@ -1076,11 +1076,10 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
pivot_list[len(pivot_list) - 1] = mathutils.Vector(pivot)
elif new_chunk.ID == MORPH_SMOOTH and child.type == 'MESH': # Smooth angle
child.data.use_auto_smooth = True
temp_data = file.read(SZ_FLOAT)
smooth_angle = struct.unpack('<f', temp_data)[0]
new_chunk.bytes_read += SZ_FLOAT
child.data.auto_smooth_angle = smooth_angle
child.data.set_sharp_from_angle(smooth_angle)
elif KEYFRAME and new_chunk.ID == COL_TRACK_TAG and colortrack == 'AMBIENT': # Ambient
keyframe_data = {}

View File

@ -1142,7 +1142,6 @@ def fbx_data_mesh_elements(root, me_obj, scene_data, done_meshes):
# NOTE: this is not supported by importer currently.
# XXX Official docs says normals should use IndexToDirect,
# but this does not seem well supported by apps currently...
me.calc_normals_split()
ln_bl_dtype = np.single
ln_fbx_dtype = np.float64
@ -1242,8 +1241,6 @@ def fbx_data_mesh_elements(root, me_obj, scene_data, done_meshes):
# del t_lnw
me.free_tangents()
me.free_normals_split()
# Write VertexColor Layers.
colors_type = scene_data.settings.colors_type
vcolnumber = 0 if colors_type == 'NONE' else len(me.color_attributes)

View File

@ -1315,8 +1315,6 @@ def blen_read_geom_layer_smooth(fbx_obj, mesh):
1, 1, layer_id,
xform=np.logical_not,
)
# We only set sharp edges here, not face smoothing itself...
mesh.use_auto_smooth = True
return False
elif fbx_layer_mapping == b'ByPolygon':
blen_data = mesh.polygons
@ -1539,7 +1537,6 @@ def blen_read_geom(fbx_tmpl, fbx_obj, settings):
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:
@ -1560,13 +1557,9 @@ def blen_read_geom(fbx_tmpl, fbx_obj, settings):
# 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)))
mesh.use_auto_smooth = True
else:
mesh.calc_normals()
if settings.use_custom_normals:
mesh.free_normals_split()
if not ok_smooth:
mesh.polygons.foreach_set("use_smooth", np.full(len(mesh.polygons), True, dtype=bool))

View File

@ -58,8 +58,6 @@ class PrimitiveCreator:
self.blender_object = self.export_settings['vtree'].nodes[self.uuid_for_skined_data].blender_object
self.use_normals = self.export_settings['gltf_normals']
if self.use_normals:
self.blender_mesh.calc_normals_split()
self.use_tangents = False
if self.use_normals and self.export_settings['gltf_tangents']:
@ -711,7 +709,6 @@ class PrimitiveCreator:
self.normals = np.array(self.normals, dtype=np.float32)
else:
self.normals = np.empty(len(self.blender_mesh.loops) * 3, dtype=np.float32)
self.blender_mesh.calc_normals_split()
self.blender_mesh.loops.foreach_get('normal', self.normals)
self.normals = self.normals.reshape(len(self.blender_mesh.loops), 3)

View File

@ -60,10 +60,9 @@ def do_primitives(gltf, mesh_idx, skin_idx, mesh, ob):
# Use a class here, to be able to pass data by reference to hook (to be able to change them inside hook)
class IMPORT_mesh_options:
def __init__(self, skinning: bool = True, skin_into_bind_pose: bool = True, use_auto_smooth: bool = True):
def __init__(self, skinning: bool = True, skin_into_bind_pose: bool = True):
self.skinning = skinning
self.skin_into_bind_pose = skin_into_bind_pose
self.use_auto_smooth = use_auto_smooth
mesh_options = IMPORT_mesh_options()
import_user_extensions('gather_import_mesh_options', gltf, mesh_options, pymesh, skin_idx)
@ -469,9 +468,7 @@ def do_primitives(gltf, mesh_idx, skin_idx, mesh, ob):
mesh.update(calc_edges_loose=has_loose_edges)
if has_normals:
mesh.create_normals_split()
mesh.normals_split_custom_set_from_vertices(vert_normals)
mesh.use_auto_smooth = mesh_options.use_auto_smooth
def points_edges_tris(mode, indices):

View File

@ -370,10 +370,6 @@ def write_file(filepath, objects, depsgraph, scene,
ob_for_convert.to_mesh_clear()
continue # dont bother with this mesh.
if EXPORT_NORMALS and face_index_pairs:
me.calc_normals_split()
# No need to call me.free_normals_split later, as this mesh is deleted anyway!
loops = me.loops
if (EXPORT_SMOOTH_GROUPS or EXPORT_SMOOTH_GROUPS_BITFLAGS) and face_index_pairs:

View File

@ -703,7 +703,6 @@ def create_mesh(new_objects,
if verts_nor and me.loops:
# Note: we store 'temp' normals in loops, since validate() may alter final mesh,
# we can only set custom lnors *after* calling it.
me.create_normals_split()
loops_nor = tuple(no for (_, face_vert_nor_indices, _, _, _, _, _) in faces
for face_noidx in face_vert_nor_indices
for no in verts_nor[face_noidx])
@ -759,7 +758,6 @@ def create_mesh(new_objects,
me.polygons.foreach_set("use_smooth", [True] * len(me.polygons))
me.normals_split_custom_set(tuple(zip(*(iter(clnors),) * 3)))
me.use_auto_smooth = True
ob = bpy.data.objects.new(me.name, me)
new_objects.append(ob)

View File

@ -817,10 +817,6 @@ def export(file,
# --- Write IndexedFaceSet Attributes (same as IndexedTriangleSet)
fw('solid="%s"\n' % bool_as_str(material and material.use_backface_culling))
if is_smooth:
# use Auto-Smooth angle, if enabled. Otherwise make
# the mesh perfectly smooth by creaseAngle > pi.
fw(ident_step + 'creaseAngle="%.4f"\n' % (mesh.auto_smooth_angle if mesh.use_auto_smooth else 4.0))
if use_normals:
# currently not optional, could be made so:

View File

@ -3011,8 +3011,7 @@ def importShape_ProcessObject(
# solid=false, we don't support it yet.
creaseAngle = geom.getFieldAsFloat('creaseAngle', None, ancestry)
if creaseAngle is not None:
bpydata.auto_smooth_angle = creaseAngle
bpydata.use_auto_smooth = True
bpydata.set_sharp_from_angle(creaseAngle)
# Only ever 1 material per shape
if bpymat:

View File

@ -675,8 +675,7 @@ def mu_set_auto_smooth(self, angle, affect, set_smooth_shading):
#bpy.ops.object.shade_smooth()
object.data.use_auto_smooth = 1
object.data.auto_smooth_angle = angle # 35 degrees as radians
object.data.set_sharp_from_angle(angle) # 35 degrees as radians
objects_affected += 1

View File

@ -800,7 +800,6 @@ def tessellate_patch(props):
n2 = n2[masked_faces][:,None,:]
else:
if normals_mode == 'CUSTOM':
me0.calc_normals_split()
normals_split = [0]*len(me0.loops)*3
vertex_indexes = [0]*len(me0.loops)
me0.loops.foreach_get('normal', normals_split)

View File

@ -331,8 +331,7 @@ def CreateBevel(context, CurrentObject):
bpy.ops.object.shade_smooth()
context.object.data.use_auto_smooth = True
context.object.data.auto_smooth_angle = 1.0471975
context.object.data.set_sharp_from_angle(1.0471975)
# Restore the active object
context.view_layer.objects.active = SavActive

View File

@ -178,7 +178,6 @@ def pov_cylinder_define(context, op, ob, radius, loc, loc_cap):
ob.name = ob.data.name = "PovCylinder"
ob.pov.cylinder_radius = radius
ob.pov.cylinder_location_cap = vec
ob.data.use_auto_smooth = True
ob.pov.object_as = "CYLINDER"
ob.update_tag() # as prop set via python not updated in depsgraph
@ -324,7 +323,6 @@ def pov_sphere_define(context, op, ob, loc):
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.hide(unselected=False)
bpy.ops.object.mode_set(mode="OBJECT")
ob.data.use_auto_smooth = True
bpy.ops.object.shade_smooth()
ob.pov.object_as = "SPHERE"
ob.update_tag() # as prop set via python not updated in depsgraph
@ -469,7 +467,6 @@ def pov_cone_define(context, op, ob):
ob.pov.cone_height = height
ob.pov.cone_base_z = zb
ob.pov.cone_cap_z = zc
ob.data.use_auto_smooth = True
bpy.ops.object.shade_smooth()
ob.pov.object_as = "CONE"
ob.update_tag() # as prop set via python not updated in depsgraph
@ -657,9 +654,7 @@ def pov_torus_define(context, op, ob):
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.hide(unselected=False)
bpy.ops.object.mode_set(mode="OBJECT")
ob.data.use_auto_smooth = True
ob.data.auto_smooth_angle = 0.6
bpy.ops.object.shade_smooth()
ob.data.set_sharp_from_angle(0.6)
ob.pov.object_as = "TORUS"
ob.update_tag() # as prop set via python not updated in depsgraph

View File

@ -169,8 +169,7 @@ def pov_superellipsoid_define(context, op, ob):
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.hide(unselected=False)
bpy.ops.object.mode_set(mode="OBJECT")
ob.data.auto_smooth_angle = 1.3
bpy.ops.object.shade_smooth()
ob.data.set_sharp_from_angle(1.3)
ob.pov.object_as = "SUPERELLIPSOID"
ob.update_tag() # as prop set via python not updated in depsgraph
@ -1049,8 +1048,7 @@ def pov_parametric_define(context, op, ob):
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.hide(unselected=False)
bpy.ops.object.mode_set(mode="OBJECT")
ob.data.auto_smooth_angle = 0.6
bpy.ops.object.shade_smooth()
ob.data.set_sharp_from_angle(0.6)
ob.pov.object_as = "PARAMETRIC"
ob.update_tag() # as prop set via python not updated in depsgraph
return{'FINISHED'}
@ -1178,8 +1176,6 @@ class POV_OT_polygon_to_circle_add(Operator):
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.hide(unselected=False)
bpy.ops.object.mode_set(mode="OBJECT")
#ob.data.auto_smooth_angle = 0.1
#bpy.ops.object.shade_smooth()
ob.pov.object_as = "POLYCIRCLE"
ob.update_tag() # as prop set via python not updated in depsgraph
return {"FINISHED"}

View File

@ -180,21 +180,6 @@ class VIEW3D_OT_selecteditVertsEdgesFaces(Operator):
return {'FINISHED'}
# ********** Normals / Auto Smooth Menu **********
# Thanks to marvin.k.breuer for the Autosmooth part of the menu
def menu_func(self, context):
layout = self.layout
obj = context.object
obj_data = context.active_object.data
layout.separator()
layout.prop(obj_data, "use_auto_smooth", text="Normals: Auto Smooth")
# Auto Smooth Angle - two tab spaces to align it with the rest of the menu
layout.prop(obj_data, "auto_smooth_angle",
text=" Auto Smooth Angle")
# List The Classes #
classes = (
@ -215,7 +200,6 @@ def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.VIEW3D_MT_edit_mesh_normals.append(menu_func)
# Unregister Classes & Hotkeys #
def unregister():
@ -223,7 +207,6 @@ def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
bpy.types.VIEW3D_MT_edit_mesh_normals.remove(menu_func)
if __name__ == "__main__":
register()