From a0630692704c567a01516d8da823d6acd19f9843 Mon Sep 17 00:00:00 2001 From: gds Date: Sat, 13 Jan 2024 08:55:17 +0100 Subject: [PATCH] Fixup normals in add_mesh_solid generated meshes. Certain of the presets for add_mesh_solid have faces where their normals are inverted. This commit takes each mesh that's added and invokes `normals_make_consistent` on it to fix the normals. The presets that had bad normals were the Rhombicuboctahedron, Truncated Cuboctahedron, Snub Cube, Rhombicosidodecahedron, and Snub Dodecahedron. With this change, these solids are fixed as will be any new ones that happen to be added with faces ordered the wrong way. --- add_mesh_extra_objects/add_mesh_solid.py | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/add_mesh_extra_objects/add_mesh_solid.py b/add_mesh_extra_objects/add_mesh_solid.py index ef9cc541d..db72651c5 100644 --- a/add_mesh_extra_objects/add_mesh_solid.py +++ b/add_mesh_extra_objects/add_mesh_solid.py @@ -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'} -- 2.30.2