-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffsetfacesOt.py
130 lines (84 loc) · 4.22 KB
/
offsetfacesOt.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Name : Offset All Faces
# Description : Offset All Faces using a solidify modifier
# Author : Neltulz (Neil V. Moore)
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
import bpy
import bmesh
from . import miscFunc
from . import miscLay
from bpy.props import (StringProperty, BoolProperty, IntProperty, FloatProperty, FloatVectorProperty, EnumProperty, PointerProperty)
from bpy.types import (Panel, Operator, AddonPreferences, PropertyGroup)
class VIEW3D_OT_ntzbu_offset_all_faces(Operator):
bl_idname = "view3d.ntzbu_offset_all_faces"
bl_label = "NTZBU : Offset All Faces"
bl_description = "Offset All Faces using a solidify modifier"
bl_options = {'REGISTER', 'UNDO',
#'PRESET'
}
objectModeAtBegin : StringProperty () #determined in invoke()
keepModifier : BoolProperty(
name="Keep Modifier",
description='Does not apply the solidify modifier when finished so that the user may continue to modify its settings',
default = False
)
offsetAmount : FloatProperty (
name="Offset Amount",
description='Amount to offset faces by',
default=0,
soft_min=-10,
soft_max=10,
)
@classmethod
def poll(cls, context):
activeObj = context.view_layer.objects.active
if activeObj is not None:
if activeObj.type == "MESH":
return True
def execute(self, context):
activeObjAtBegin = bpy.context.view_layer.objects.active
if activeObjAtBegin is not None:
if activeObjAtBegin.type == "MESH":
offsetAmount = self.offsetAmount * -1
if self.objectModeAtBegin in ["OBJECT", "EDIT"]:
if self.objectModeAtBegin == "EDIT":
bpy.ops.object.mode_set(mode='OBJECT')
neltulzOffsetModifier = miscFunc.findModifier(self, context, activeObjAtBegin, "Neltulz - Offset Faces") #declare
if neltulzOffsetModifier is None:
activeObjAtBegin.modifiers.new(name="Neltulz - Offset Faces", type='SOLIDIFY')
neltulzOffsetModifier = miscFunc.findModifier(self, context, activeObjAtBegin, "Neltulz - Offset Faces")
if self.offsetAmount > 0:
use_flip_normals = False
else:
use_flip_normals = True
neltulzOffsetModifier.show_on_cage = True
neltulzOffsetModifier.thickness = offsetAmount
neltulzOffsetModifier.use_flip_normals = use_flip_normals
neltulzOffsetModifier.use_even_offset = True
neltulzOffsetModifier.use_quality_normals = True
neltulzOffsetModifier.use_rim = True
neltulzOffsetModifier.use_rim_only = True
if not self.keepModifier:
bpy.ops.object.modifier_apply(modifier="Neltulz - Offset Faces")
bpy.ops.object.mode_set(mode=self.objectModeAtBegin) #switch back to mode at begin
return {'FINISHED'}
def draw(self, context):
scn = context.scene
layout = self.layout.column(align=True)
offsetAmountRow = layout.row(align=True)
offsetAmountRow.prop(self, "offsetAmount", slider=True)
offsetAmountRow.separator()
layout.separator()
row = layout.row(align=True)
row.prop(self, "keepModifier")
#END draw()
def invoke(self, context, event):
try:
#try to determine objectMode
objectModeAtBegin = bpy.context.object.mode
except:
objectModeAtBegin = "OBJECT"
self.objectModeAtBegin = objectModeAtBegin
return self.execute(context)
#END invoke()
#END Operator()