-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhardify.py
80 lines (64 loc) · 2.79 KB
/
hardify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
bl_info = {
"name" : "Hardify",
"author" : "Simon Storl-Schulke",
"description" : "Shade Object smooth and turn on Autosmooth + Optional Weighted Normals Modifier",
"version" : (1, 0, 0),
"blender" : (3, 10, 0),
"location" : "Object Mode > Select Mesh Object > Object Context menu (Rightclick or W)",
"warning" : "",
"doc_url": "https://github.com/SimonStorlSchulke/blender-addons",
"tracker_url": "https://github.com/SimonStorlSchulke/blender-addons/issues",
"category" : "Mesh"
}
import bpy
import math
class OT_hardify(bpy.types.Operator):
bl_idname = "object.hardify"
bl_label = "Hardify Object"
bl_description = "Shade Object smooth and turn on Autosmooth + Optional Weighted Normals Modifier"
bl_options = {"REGISTER", "UNDO"}
autosmooth_angle: bpy.props.FloatProperty(
name = "Autosmooth Angle",
description = "Autosmooth Angle",
default = 30,
)
use_weighted_normal: bpy.props.BoolProperty(
name = "Use Weighted Normals",
description = "Use Weighted Normals",
default = False,
)
@classmethod
def poll(cls, context):
return bpy.context.object and context.object.type == 'MESH'
def execute(self, context):
bpy.ops.object.shade_smooth()
bpy.context.object.data.use_auto_smooth = True
bpy.context.object.data.auto_smooth_angle = math.radians(self.autosmooth_angle)
if self.use_weighted_normal:
for modifier in bpy.context.object.modifiers:
if modifier.type == "WEIGHTED_NORMAL":
return {"FINISHED"}
bpy.ops.object.modifier_add(type='WEIGHTED_NORMAL')
return {"FINISHED"}
def add_contextmenu_entry(self, context):
if context.object is not None and context.object.type == 'MESH':
layout = self.layout
layout.operator(OT_hardify.bl_idname, text="Hardify", icon="MOD_NORMALEDIT")
def register():
bpy.utils.register_class(OT_hardify)
bpy.types.VIEW3D_MT_object_context_menu.prepend(add_contextmenu_entry)
def unregister():
bpy.utils.unregister_class(OT_hardify)
bpy.types.VIEW3D_MT_object_context_menu.remove(add_contextmenu_entry)