1 # space_view_3d_display_tools.py Copyright (C) 2014, Jordi Vall-llovera
2 # Multiple display tools for fast navigate/interact with the viewport
3 # wire tools by Lapineige
5 # ***** BEGIN GPL LICENSE BLOCK *****
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software Foundation,
19 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 # ***** END GPL LICENCE BLOCK *****
25 from bpy
.types
import Operator
26 from bpy
.props
import (
32 # define base dummy class for inheritance
35 def poll(cls
, context
):
39 class View3D_AF_Wire_All(Operator
):
40 bl_idname
= "af_ops.wire_all"
41 bl_label
= "Wire on All Objects"
42 bl_description
= "Toggle Wire on all objects in the scene"
45 def poll(cls
, context
):
46 return (context
.active_object
is not None and
47 not context
.scene
.display_tools
.WT_handler_enable
)
49 def execute(self
, context
):
51 for obj
in bpy
.data
.objects
:
61 class DisplayDrawChange(Operator
, BasePollCheck
):
62 bl_idname
= "view3d.display_draw_change"
63 bl_label
= "Draw Type"
64 bl_description
= "Change Display objects' mode"
66 drawing
= EnumProperty(
67 items
=[('TEXTURED', 'Texture', 'Texture display mode'),
68 ('SOLID', 'Solid', 'Solid display mode'),
69 ('WIRE', 'Wire', 'Wire display mode'),
70 ('BOUNDS', 'Bounds', 'Bounds display mode'),
76 def execute(self
, context
):
78 view
= context
.space_data
79 view
.viewport_shade
= 'TEXTURED'
80 context
.scene
.game_settings
.material_mode
= 'GLSL'
81 selection
= context
.selected_objects
84 for obj
in bpy
.data
.objects
:
85 obj
.display_type
= self
.drawing
88 obj
.display_type
= self
.drawing
90 self
.report({'ERROR'}, "Setting Draw Type could not be applied")
97 class DisplayBoundsSwitch(Operator
, BasePollCheck
):
98 bl_idname
= "view3d.display_bounds_switch"
100 bl_description
= "Display/Hide Bounding box overlay"
102 bounds
= BoolProperty(default
=False)
104 def execute(self
, context
):
106 scene
= context
.scene
.display_tools
107 selection
= context
.selected_objects
110 for obj
in bpy
.data
.objects
:
111 obj
.show_bounds
= self
.bounds
113 obj
.display_bounds_type
= scene
.BoundingMode
115 for obj
in selection
:
116 obj
.show_bounds
= self
.bounds
118 obj
.display_bounds_type
= scene
.BoundingMode
120 self
.report({'ERROR'}, "Display/Hide Bounding box overlay failed")
126 # Double Sided switch
127 class DisplayDoubleSidedSwitch(Operator
, BasePollCheck
):
128 bl_idname
= "view3d.display_double_sided_switch"
130 bl_description
= "Turn on/off face double shaded mode"
132 double_side
= BoolProperty(default
=False)
134 def execute(self
, context
):
136 selection
= bpy
.context
.selected_objects
139 for mesh
in bpy
.data
.meshes
:
140 mesh
.show_double_sided
= self
.double_side
142 for sel
in selection
:
143 if sel
.type == 'MESH':
145 mesh
.show_double_sided
= self
.double_side
147 self
.report({'ERROR'}, "Turn on/off face double shaded mode failed")
154 class DisplayXRayOn(Operator
, BasePollCheck
):
155 bl_idname
= "view3d.display_x_ray_switch"
157 bl_description
= "X-Ray display on/off"
159 xrays
= BoolProperty(default
=False)
161 def execute(self
, context
):
163 selection
= context
.selected_objects
166 for obj
in bpy
.data
.objects
:
167 obj
.show_in_front
= self
.xrays
169 for obj
in selection
:
170 obj
.show_in_front
= self
.xrays
172 self
.report({'ERROR'}, "Turn on/off X-ray mode failed")
178 # wire tools by Lapineige
179 class WT_HideAllWire(Operator
):
180 bl_idname
= "object.wt_hide_all_wire"
181 bl_label
= "Hide Wire And Edges"
182 bl_description
= "Hide All Objects' wire and edges"
185 def poll(cls
, context
):
186 return not context
.scene
.display_tools
.WT_handler_enable
188 def execute(self
, context
):
189 for obj
in bpy
.data
.objects
:
190 if hasattr(obj
, "show_wire"):
191 obj
.show_wire
, obj
.show_all_edges
= False, False
195 class WT_SelectionHandlerToggle(Operator
):
196 bl_idname
= "object.wt_selection_handler_toggle"
197 bl_label
= "Wire Selection (auto)"
198 bl_description
= "Display the wire of the selection, auto update when selecting another object"
199 bl_options
= {'INTERNAL'}
201 def execute(self
, context
):
202 display_tools
= context
.scene
.display_tools
203 if display_tools
.WT_handler_enable
:
205 bpy
.app
.handlers
.scene_update_post
.remove(wire_on_selection_handler
)
207 self
.report({'INFO'},
208 "Wire Selection: auto mode exit seems to have failed. If True, reload the file")
210 display_tools
.WT_handler_enable
= False
211 if hasattr(context
.object, "show_wire"):
212 context
.object.show_wire
, context
.object.show_all_edges
= False, False
214 bpy
.app
.handlers
.scene_update_post
.append(wire_on_selection_handler
)
215 display_tools
.WT_handler_enable
= True
216 if hasattr(context
.object, "show_wire"):
217 context
.object.show_wire
, context
.object.show_all_edges
= True, True
222 def wire_on_selection_handler(scene
):
223 obj
= bpy
.context
.object
225 if not scene
.display_tools
.WT_handler_previous_object
:
226 if hasattr(obj
, "show_wire"):
227 obj
.show_wire
, obj
.show_all_edges
= True, True
228 scene
.display_tools
.WT_handler_previous_object
= obj
.name
230 if scene
.display_tools
.WT_handler_previous_object
!= obj
.name
:
231 previous_obj
= bpy
.data
.objects
[scene
.display_tools
.WT_handler_previous_object
]
232 if hasattr(previous_obj
, "show_wire"):
233 previous_obj
.show_wire
, previous_obj
.show_all_edges
= False, False
235 scene
.display_tools
.WT_handler_previous_object
= obj
.name
237 if hasattr(obj
, "show_wire"):
238 obj
.show_wire
, obj
.show_all_edges
= True, True
243 bpy
.utils
.register_module(__name__
)
247 bpy
.utils
.unregister_module(__name__
)
250 if __name__
== "__main__":