Fixup normals in add_mesh_solid generated meshes. #105117

Closed
gds wants to merge 1 commits from gds/blender-addons:fix-normals-on-solids into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Showing only changes of commit a063069270 - Show all commits

View File

@ -325,6 +325,26 @@ def createSolid(plato, vtrunc, etrunc, dual, snub):
return dvOutput, dfOutput
def fixup_normals(obj):
"""
Some of the presets have their faces with wrong normals. This fixes them.
"""
curr_active = bpy.context.view_layer.objects.active
# Select new object,
bpy.ops.object.select_all(action='DESELECT')
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT') # select all faces
bpy.ops.mesh.normals_make_consistent(inside=False)
bpy.ops.object.editmode_toggle() # return to object mode
# Reset to previously active
bpy.context.view_layer.objects.active = curr_active
class Solids(bpy.types.Operator):
"""Add one of the (regular) solids (mesh)"""
bl_idname = "mesh.primitive_solid_add"
@ -509,7 +529,10 @@ class Solids(bpy.types.Operator):
# Update mesh geometry after adding stuff.
mesh.update()
object_data_add(context, mesh, operator=None)
obj = object_data_add(context, mesh, operator=None)
fixup_normals(obj)
# object generation done
return {'FINISHED'}