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
|
# SPDX-License-Identifier: GPL-2.0-or-later
import bpy
class AMTH_VIEW3D_PT_wire_toggle(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "View"
bl_label = "Wireframes "
bl_parent_id = "VIEW3D_PT_view3d_properties"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False # No animation.
scene = context.scene
row = layout.row(align=True)
row.operator(AMTH_OBJECT_OT_wire_toggle.bl_idname,
icon="MOD_WIREFRAME", text="Display").clear = False
row.operator(AMTH_OBJECT_OT_wire_toggle.bl_idname,
icon="X", text="Clear").clear = True
layout.separator()
col = layout.column(heading="Display", align=True)
col.prop(scene, "amth_wire_toggle_edges_all")
col.prop(scene, "amth_wire_toggle_optimal")
col = layout.column(heading="Apply to", align=True)
sub = col.row(align=True)
sub.active = not scene.amth_wire_toggle_scene_all
sub.prop(scene, "amth_wire_toggle_is_selected")
sub = col.row(align=True)
sub.active = not scene.amth_wire_toggle_is_selected
sub.prop(scene, "amth_wire_toggle_scene_all")
# FEATURE: Toggle Wire Display
class AMTH_OBJECT_OT_wire_toggle(bpy.types.Operator):
"""Turn on/off wire display on mesh objects"""
bl_idname = "object.amth_wire_toggle"
bl_label = "Display Wireframe"
bl_options = {"REGISTER", "UNDO"}
clear: bpy.props.BoolProperty(
default=False, name="Clear Wireframe",
description="Clear Wireframe Display")
def execute(self, context):
scene = context.scene
is_all_scenes = scene.amth_wire_toggle_scene_all
is_selected = scene.amth_wire_toggle_is_selected
is_all_edges = scene.amth_wire_toggle_edges_all
is_optimal = scene.amth_wire_toggle_optimal
clear = self.clear
if is_all_scenes:
which = bpy.data.objects
elif is_selected:
if not context.selected_objects:
self.report({"INFO"}, "No selected objects")
which = context.selected_objects
else:
which = scene.objects
if which:
for ob in which:
if ob and ob.type in {
"MESH", "EMPTY", "CURVE",
"META", "SURFACE", "FONT"}:
ob.show_wire = False if clear else True
ob.show_all_edges = is_all_edges
for mo in ob.modifiers:
if mo and mo.type == "SUBSURF":
mo.show_only_control_edges = is_optimal
return {"FINISHED"}
def init_properties():
scene = bpy.types.Scene
scene.amth_wire_toggle_scene_all = bpy.props.BoolProperty(
default=False,
name="All Scenes",
description="Toggle wire on objects in all scenes")
scene.amth_wire_toggle_is_selected = bpy.props.BoolProperty(
default=False,
name="Only Selected Objects",
description="Only toggle wire on selected objects")
scene.amth_wire_toggle_edges_all = bpy.props.BoolProperty(
default=True,
name="Draw All Edges",
description="Draw all the edges even on coplanar faces")
scene.amth_wire_toggle_optimal = bpy.props.BoolProperty(
default=False,
name="Optimal Display Subdivision",
description="Skip drawing/rendering of interior subdivided edges "
"on meshes with Subdivision Surface modifier")
def clear_properties():
props = (
'amth_wire_toggle_is_selected',
'amth_wire_toggle_scene_all',
"amth_wire_toggle_edges_all",
"amth_wire_toggle_optimal"
)
wm = bpy.context.window_manager
for p in props:
if p in wm:
del wm[p]
# //FEATURE: Toggle Wire Display
classes = (
AMTH_VIEW3D_PT_wire_toggle,
AMTH_OBJECT_OT_wire_toggle
)
def register():
init_properties()
from bpy.utils import register_class
for cls in classes:
register_class(cls)
def unregister():
clear_properties()
|