forked from pitiwazou/Scripts-Blender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWazou_shading_menu
337 lines (251 loc) · 10.6 KB
/
Wazou_shading_menu
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# ##### BEGIN GPL LICENSE BLOCK #####
#
# 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 2
# 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
# MERCHANTABILITY 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
############# Add-on description (use by Blender)
bl_info = {
"name": "Shading_menu",
"description": 'Add a menu with shading options in the 3Dview',
"author": "Cedric Lepiller, Lapineige",
"version": (0, 1, 0),
"blender": (2, 70, 0),
"location": "View3D > Header > Shading_menu",
"warning": "", # used for warning icon and text in addons panel
"wiki_url": "",
"tracker_url": "http://www.pitiwazou.com",
"category": "3D View"}
##############
import bpy
from bpy.props import IntProperty, FloatProperty, BoolProperty
class ShadingMenuCACUserPrefs(bpy.types.AddonPreferences):
"""Creates the tools in a Panel, in the scene context of the properties editor"""
bl_idname = __name__
bpy.types.Scene.Enable_ShadinMenu_Tab_1 = bpy.props.BoolProperty(default=False)
bpy.types.Scene.Enable_ShadinMenu_Tab_2 = bpy.props.BoolProperty(default=False)
def draw(self, context):
layout = self.layout
layout.prop(context.scene, "Enable_ShadinMenu_Tab_1", text="Info", icon="QUESTION")
if context.scene.Enable_ShadinMenu_Tab_1:
row = layout.row()
layout.label(text="This Addons is a Menu with shading options")
layout.prop(context.scene, "Enable_ShadinMenu_Tab_2", text="URL's", icon="URL")
if context.scene.Enable_ShadinMenu_Tab_2:
row = layout.row()
row.operator("wm.url_open", text="Pitiwazou.com").url = "http://www.pitiwazou.com/"
row.operator("wm.url_open", text="Wazou's Ghitub").url = "https://github.com/pitiwazou/Scripts-Blender"
row.operator("wm.url_open", text="BlenderLounge Forum ").url = "http://blenderlounge.fr/forum/"
return {'FINISHED'}
#Solid All
class SolidAll(bpy.types.Operator):
bl_idname = "object.solid_all"
bl_label = "Solid All"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
for obj in bpy.data.objects:
if obj.draw_type == 'BOUNDS':
obj.draw_type = 'SOLID'
elif obj.draw_type == 'SOLID':
obj.draw_type = 'SOLID'
else:
obj.draw_type = 'BOUNDS'
return {'FINISHED'}
#Bounds Unselected
class BoundsUnselected(bpy.types.Operator):
bl_idname = "object.draw_bu"
bl_label = "bounds"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
for obj in bpy.data.objects:
if not obj.select:
if obj.draw_type == 'SOLID':
obj.draw_type = 'BOUNDS'
obj.show_all_edges = False
obj.show_wire = False
elif obj.draw_type == 'BOUNDS':
obj.draw_type = 'BOUNDS'
else:
obj.draw_type = 'SOLID'
for obj in bpy.data.objects:
if obj.select:
obj.draw_type = 'SOLID'
return {'FINISHED'}
#auto smooth Menu
class AutoSmoothMenu(bpy.types.Menu):
bl_idname = "auto.smooth_menu"
bl_label = "Auto_Smooth_Menu"
def draw(self, context):
layout = self.layout
layout.operator("auto.smooth_30", text="Auto Smooth 30", icon='MESH_DATA')
layout.operator("auto.smooth_45", text="Auto Smooth 45", icon='MESH_DATA')
layout.operator("auto.smooth_89", text="Auto Smooth 89", icon='MESH_DATA')
#AutoSmooth_89
class AutoSmooth89(bpy.types.Operator):
bl_idname = "auto.smooth_89"
bl_label = "Auto Smooth"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
bpy.context.object.data.auto_smooth_angle = 1.55334
return {'FINISHED'}
#AutoSmooth_30
class AutoSmooth30(bpy.types.Operator):
bl_idname = "auto.smooth_30"
bl_label = "Auto Smooth"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
bpy.context.object.data.auto_smooth_angle = 0.523599
return {'FINISHED'}
#AutoSmooth_45
class AutoSmooth45(bpy.types.Operator):
bl_idname = "auto.smooth_45"
bl_label = "Auto Smooth"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
bpy.context.object.data.auto_smooth_angle = 0.785398
return {'FINISHED'}
#Wire on all objects
class WireAll(bpy.types.Operator):
bl_idname = "object.wireall"
bl_label = "Wire All"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
for obj in bpy.data.objects:
if obj.show_wire:
obj.show_all_edges = False
obj.show_wire = False
else:
obj.show_all_edges = True
obj.show_wire = True
return {'FINISHED'}
#Grid show/hide with axes
class ToogleGridAxis(bpy.types.Operator):
bl_idname = "scene.tooglegridaxis"
bl_label = "Toogle Grid and Axis in 3D view"
def execute(self, context):
bpy.context.space_data.show_axis_y = not bpy.context.space_data.show_axis_y
bpy.context.space_data.show_axis_x = not bpy.context.space_data.show_axis_x
bpy.context.space_data.show_floor = not bpy.context.space_data.show_floor
return {'FINISHED'}
#Shading Smooth
class ShadingSmooth(bpy.types.Operator):
bl_idname = "shading.smooth"
bl_label = "Shading Smooth"
def execute(self, context):
if bpy.context.object.mode == "OBJECT":
bpy.ops.object.shade_smooth()
elif bpy.context.object.mode == "EDIT":
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.shade_smooth()
bpy.ops.object.mode_set(mode = 'EDIT')
return {'FINISHED'}
#Shading Flat
class ShadingFlat(bpy.types.Operator):
bl_idname = "shading.flat"
bl_label = "Shading Flat"
def execute(self, context):
if bpy.context.object.mode == "OBJECT":
bpy.ops.object.shade_flat()
elif bpy.context.object.mode == "EDIT":
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.shade_flat()
bpy.ops.object.mode_set(mode = 'EDIT')
return {'FINISHED'}
#shading Menu
class Shading(bpy.types.Menu):
bl_label = "Shading"
def draw(self, context):
layout = self.layout
obj = context.object
view = context.space_data
col = layout.column()
if context.space_data.show_floor:
col.operator("scene.tooglegridaxis", text="Grid", icon = 'CHECKBOX_HLT')
else:
col.operator("scene.tooglegridaxis", text="Grid", icon = 'CHECKBOX_DEHLT')
col = layout.column()
col.prop(view, "use_matcap")
col = layout.column()
col.prop(view, "lock_camera")
col = layout.column()
col.prop(view, "show_only_render")
layout.separator()
layout.menu("auto.smooth_menu", text="Auto Smooth Values", icon='MESH_DATA')
col = layout.column()
col.prop(obj.data, "use_auto_smooth")
col = layout.column()
col.prop(obj.data, "show_normal_face", text = "Show Normals")
layout.operator("shading.flat", icon = 'ALIASED')
layout.operator("shading.smooth", icon = 'ANTIALIASED')
layout.separator()
col = layout.column()
col.prop(obj.data, "show_double_sided")
col = layout.column()
col.prop(view, "show_backface_culling")
col = layout.column()
col.prop(view, "use_occlude_geometry", text="Limit to Visible")
col = layout.column()
col.prop(view, "show_occlude_wire")
col = layout.column()
col.prop(obj, "show_x_ray", text="X-Ray")
layout.separator()
layout.operator("object.solid_all", text="Solid All", icon='MESH_CUBE')
layout.operator("object.draw_bu", text="Bounds Unselected", icon='GROUP_VERTEX')
layout.operator("object.wire_selected", text="Wire Selected", icon='WIRE')
layout.operator("object.wireall", text="Wire All", icon='WIRE')
def view3d_Shading_menu(self, context):
layout = self.layout
layout.menu("Shading")
def register():
bpy.types.VIEW3D_HT_header.append(view3d_Shading_menu)
bpy.utils.register_class(Shading)
bpy.utils.register_class(ToogleGridAxis)
bpy.utils.register_class(WireAll)
bpy.utils.register_class(SolidAll)
bpy.utils.register_class(BoundsUnselected)
bpy.utils.register_class(AutoSmoothMenu)
bpy.utils.register_class(AutoSmooth89)
bpy.utils.register_class(AutoSmooth30)
bpy.utils.register_class(AutoSmooth45)
bpy.utils.register_class(ShadingFlat)
bpy.utils.register_class(ShadingSmooth)
bpy.utils.register_class(ShadingMenuCACUserPrefs)
def unregister():
bpy.types.VIEW3D_HT_header.remove(view3d_Shading_menu)
bpy.utils.unregister_class(Shading)
bpy.utils.unregister_class(ToogleGridAxis)
bpy.utils.unregister_class(WireAll)
bpy.utils.unregister_class(SolidAll)
bpy.utils.unregister_class(BoundsUnselected)
bpy.utils.unregister_class(AutoSmoothMenu)
bpy.utils.unregister_class(AutoSmooth89)
bpy.utils.unregister_class(AutoSmooth30)
bpy.utils.unregister_class(AutoSmooth45)
bpy.utils.unregister_class(ShadingFlat)
bpy.utils.unregister_class(ShadingSmooth)
bpy.utils.unregister_class(ShadingMenuCACUserPrefs)
if __name__ == "__main__":
register()