glTF exporter: Fix Real children of instance collection visibility check
[blender-addons.git] / space_view3d_3d_navigation.py
blob88cce0cacd2cf6d50ef6fef0ee06c7c39ec92a8d
1 # SPDX-FileCopyrightText: 2010-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # 3D NAVIGATION TOOLBAR v1.2 - 3Dview Addon - Blender 2.5x
6 # contributed to by: Demohero, uriel, jbelcik, meta-androcto
8 bl_info = {
9 "name": "3D Navigation",
10 "author": "Demohero, uriel",
11 "version": (1, 2, 6),
12 "blender": (2, 92, 0),
13 "location": "View3D > Sidebar > View Tab",
14 "description": "Navigate the Camera & 3D Viewport from the Sidebar",
15 "warning": "",
16 "doc_url": "{BLENDER_MANUAL_URL}/addons/3d_view/3d_navigation.html",
17 "category": "3D View",
20 import bpy
21 from bpy.types import (
22 AddonPreferences,
23 Operator,
24 Panel,
26 from bpy.props import StringProperty
29 # main class of this toolbar
31 # re-ordered (reversed) Orbit Operators
32 class VIEW3D_OT_OrbitUpView1(Operator):
33 bl_idname = "opr.orbit_up_view1"
34 bl_label = "Orbit Up View"
35 bl_description = "Orbit the view towards you"
37 def execute(self, context):
38 bpy.ops.view3d.view_orbit(type='ORBITUP')
39 return {'FINISHED'}
42 class VIEW3D_OT_OrbitLeftView1(Operator):
43 bl_idname = "opr.orbit_left_view1"
44 bl_label = "Orbit Left View"
45 bl_description = "Orbit the view around to your Right"
47 def execute(self, context):
48 bpy.ops.view3d.view_orbit(type='ORBITLEFT')
49 return {'FINISHED'}
52 class VIEW3D_OT_OrbitRightView1(Operator):
53 bl_idname = "opr.orbit_right_view1"
54 bl_label = "Orbit Right View"
55 bl_description = "Orbit the view around to your Left"
57 def execute(self, context):
58 bpy.ops.view3d.view_orbit(type='ORBITRIGHT')
59 return {'FINISHED'}
62 class VIEW3D_OT_OrbitDownView1(Operator):
63 bl_idname = "opr.orbit_down_view1"
64 bl_label = "Orbit Down View"
65 bl_description = "Orbit the view away from you"
67 def execute(self, context):
68 bpy.ops.view3d.view_orbit(type='ORBITDOWN')
69 return {'FINISHED'}
72 # re-ordered (reversed) Pan Operators
73 # just pass the enum from the VIEW3D_PT_pan_navigation1 Panel
74 class VIEW3D_OT_PanUpViewsAll(Operator):
75 bl_idname = "opr.pan_up_views_all"
76 bl_label = "Pan View"
77 bl_description = "Pan the 3D View"
79 panning: StringProperty(
80 default="PANUP",
81 options={"HIDDEN"}
84 def execute(self, context):
85 try:
86 bpy.ops.view3d.view_pan("INVOKE_REGION_WIN", type=self.panning)
87 except Exception as e:
88 self.report({"WARNING"},
89 "Pan Views could not be completed. Operation Cancelled")
90 print("\n[3D Navigation]\nOperator: opr.pan_up_views_all\n {}\n".format(e))
92 return {"CANCELLED"}
94 return {'FINISHED'}
97 # Zoom Operators
98 class VIEW3D_OT_ZoomInView1(Operator):
99 bl_idname = "opr.zoom_in_view1"
100 bl_label = "Zoom In View"
101 bl_description = "Zoom In the View/Camera View"
103 def execute(self, context):
104 bpy.ops.view3d.zoom(delta=1)
105 return {'FINISHED'}
108 class VIEW3D_OT_ZoomOutView1(Operator):
109 bl_idname = "opr.zoom_out_view1"
110 bl_label = "Zoom Out View"
111 bl_description = "Zoom out In the View/Camera View"
113 def execute(self, context):
114 bpy.ops.view3d.zoom(delta=-1)
115 return {'FINISHED'}
118 # Roll Operators
119 class VIEW3D_OT_RollLeftView1(Operator):
120 bl_idname = "opr.roll_left_view1"
121 bl_label = "Roll Left View"
122 bl_description = "Roll the view Left"
124 def execute(self, context):
125 bpy.ops.view3d.view_roll(angle=-0.261799)
126 return {'FINISHED'}
129 class VIEW3D_OT_RollRightView1(Operator):
130 bl_idname = "opr.roll_right_view1"
131 bl_label = "Roll Right View"
132 bl_description = "Roll the view Right"
134 def execute(self, context):
135 bpy.ops.view3d.view_roll(angle=0.261799)
136 return {'FINISHED'}
139 # View Operators
140 class VIEW3D_OT_LeftViewpoint1(Operator):
141 bl_idname = "opr.left_viewpoint1"
142 bl_label = "Left Viewpoint"
143 bl_description = "View from the Left"
145 def execute(self, context):
146 bpy.ops.view3d.view_axis(type='LEFT')
147 return {'FINISHED'}
150 class VIEW3D_OT_RightViewpoint1(Operator):
151 bl_idname = "opr.right_viewpoint1"
152 bl_label = "Right Viewpoint"
153 bl_description = "View from the Right"
155 def execute(self, context):
156 bpy.ops.view3d.view_axis(type='RIGHT')
157 return {'FINISHED'}
160 class VIEW3D_OT_FrontViewpoint1(Operator):
161 bl_idname = "opr.front_viewpoint1"
162 bl_label = "Front Viewpoint"
163 bl_description = "View from the Front"
165 def execute(self, context):
166 bpy.ops.view3d.view_axis(type='FRONT')
167 return {'FINISHED'}
170 class VIEW3D_OT_BackViewpoint1(Operator):
171 bl_idname = "opr.back_viewpoint1"
172 bl_label = "Back Viewpoint"
173 bl_description = "View from the Back"
175 def execute(self, context):
176 bpy.ops.view3d.view_axis(type='BACK')
177 return {'FINISHED'}
180 class VIEW3D_OT_TopViewpoint1(Operator):
181 bl_idname = "opr.top_viewpoint1"
182 bl_label = "Top Viewpoint"
183 bl_description = "View from the Top"
185 def execute(self, context):
186 bpy.ops.view3d.view_axis(type='TOP')
187 return {'FINISHED'}
190 class VIEW3D_OT_BottomViewpoint1(Operator):
191 bl_idname = "opr.bottom_viewpoint1"
192 bl_label = "Bottom Viewpoint"
193 bl_description = "View from the Bottom"
195 def execute(self, context):
196 bpy.ops.view3d.view_axis(type='BOTTOM')
197 return {'FINISHED'}
200 # Panel class of this toolbar
201 class VIEW3D_PT_3dnavigationPanel(Panel):
202 bl_space_type = "VIEW_3D"
203 bl_region_type = "UI"
204 bl_label = "3D Navigation"
205 bl_category = "View"
206 bl_options = {'DEFAULT_CLOSED'}
208 def draw(self, context):
209 layout = self.layout
210 view = context.space_data
212 # Triple buttons
213 col = layout.column(align=True)
214 col.operator("view3d.localview", text="View Global/Local")
215 col.operator("view3d.view_persportho", text="Perspective/Orthographic")
216 col.operator("view3d.view_camera", text="View Camera", icon='CAMERA_DATA')
218 # group of 6 buttons
219 col = layout.column(align=True)
220 col.label(text="Align view from:", icon="VIEW3D")
221 row = col.row()
222 row.operator("view3d.view_axis", text="Front").type = 'FRONT'
223 row.operator("view3d.view_axis", text="Back").type = 'BACK'
224 row = col.row()
225 row.operator("view3d.view_axis", text="Left").type = 'LEFT'
226 row.operator("view3d.view_axis", text="Right").type = 'RIGHT'
227 row = col.row()
228 row.operator("view3d.view_axis", text="Top").type = 'TOP'
229 row.operator("view3d.view_axis", text="Bottom").type = 'BOTTOM'
231 # group of 2 buttons
232 col = layout.column(align=True)
233 col.label(text="Lock View to Object:", icon="LOCKED")
234 col.prop(view, "lock_object", text="")
235 col.operator("view3d.view_selected", text="View to Selected")
237 col = layout.column(align=True)
238 col.label(text="Cursor:", icon='PIVOT_CURSOR')
239 row = col.row(align=True)
240 row.operator("view3d.snap_cursor_to_center", text="World Origin")
241 row.operator("view3d.view_center_cursor", text="View")
242 col.operator("view3d.snap_cursor_to_selected", text="Cursor to Selected")
245 class VIEW3D_PT_3dnavigationPanel2(Panel):
246 bl_space_type = "VIEW_3D"
247 bl_region_type = "UI"
248 bl_label = "Pan Orbit Zoom Roll"
249 bl_category = "View"
250 bl_options = {'DEFAULT_CLOSED'}
252 def draw(self, context):
253 layout = self.layout
254 layout.label(text="Screen View Perspective")
256 row = layout.row()
257 row.label(text="Pan:")
258 row = layout.row()
260 row.operator("opr.pan_up_views_all", text="Up",
261 icon="TRIA_UP").panning = "PANDOWN"
262 row.operator("opr.pan_up_views_all", text="Down",
263 icon="TRIA_DOWN").panning = "PANUP"
265 row = layout.row()
266 row.operator("opr.pan_up_views_all", text="Left",
267 icon="BACK").panning = "PANRIGHT"
268 row.operator("opr.pan_up_views_all", text="Right",
269 icon="FORWARD").panning = "PANLEFT"
271 row = layout.row()
272 row.label(text="Orbit:")
273 row = layout.row()
274 row.operator("opr.orbit_down_view1", text="Up", icon="TRIA_UP")
275 row.operator("opr.orbit_up_view1", text="Down", icon="TRIA_DOWN")
277 row = layout.row()
278 row.operator("opr.orbit_right_view1", text="Left", icon="BACK")
279 row.operator("opr.orbit_left_view1", text="Right", icon="FORWARD")
281 row = layout.row()
282 row.label(text="Zoom:")
283 row = layout.row()
284 row.operator("opr.zoom_in_view1", text="In", icon='ADD')
285 row.operator("opr.zoom_out_view1", text="Out", icon='REMOVE')
287 row = layout.row()
288 row.label(text="Roll:")
289 row = layout.row()
290 row.operator("opr.roll_left_view1", text="Left", icon="LOOP_BACK")
291 row.operator("opr.roll_right_view1", text="Right", icon="LOOP_FORWARDS")
294 # Add-ons Preferences Update Panel
296 # Define Panel classes for updating
297 panels = (
298 VIEW3D_PT_3dnavigationPanel,
299 VIEW3D_PT_3dnavigationPanel2,
303 def update_panel(self, context):
304 message = ": Updating Panel locations has failed"
305 try:
306 for panel in panels:
307 if "bl_rna" in panel.__dict__:
308 bpy.utils.unregister_class(panel)
310 for panel in panels:
311 panel.bl_category = context.preferences.addons[__name__].preferences.category
312 bpy.utils.register_class(panel)
314 except Exception as e:
315 print("\n[{}]\n{}\n\nError:\n{}".format(__name__, message, e))
316 pass
319 class NavAddonPreferences(AddonPreferences):
320 # this must match the addon name, use '__package__'
321 # when defining this in a submodule of a python package.
322 bl_idname = __name__
324 category: StringProperty(
325 name="Tab Category",
326 description="Choose a name for the category of the panel",
327 default="View",
328 update=update_panel
331 def draw(self, context):
332 layout = self.layout
334 row = layout.row()
335 col = row.column()
336 col.label(text="Tab Category:")
337 col.prop(self, "category", text="")
340 classes = (
341 VIEW3D_PT_3dnavigationPanel,
342 VIEW3D_PT_3dnavigationPanel2,
343 VIEW3D_OT_OrbitUpView1,
344 VIEW3D_OT_OrbitLeftView1,
345 VIEW3D_OT_OrbitRightView1,
346 VIEW3D_OT_OrbitDownView1,
347 VIEW3D_OT_ZoomInView1,
348 VIEW3D_OT_ZoomOutView1,
349 VIEW3D_OT_RollLeftView1,
350 VIEW3D_OT_RollRightView1,
351 VIEW3D_OT_LeftViewpoint1,
352 VIEW3D_OT_RightViewpoint1,
353 VIEW3D_OT_FrontViewpoint1,
354 VIEW3D_OT_BackViewpoint1,
355 VIEW3D_OT_TopViewpoint1,
356 VIEW3D_OT_BottomViewpoint1,
357 VIEW3D_OT_PanUpViewsAll,
358 NavAddonPreferences,
362 # Register
363 def register():
364 for cls in classes:
365 bpy.utils.register_class(cls)
366 update_panel(None, bpy.context)
369 def unregister():
370 for cls in classes:
371 bpy.utils.unregister_class(cls)
374 if __name__ == "__main__":
375 register()