parent
3c37fb7dc1
commit
22d9d53626
|
@ -12,6 +12,10 @@ Activate / deactivate layer opaticty according to prefix
|
|||
Activate / deactivate all masks using MA layers
|
||||
-->
|
||||
|
||||
0.3.4:
|
||||
|
||||
feat: swap cams button, code copied from `bg_plane_manager`
|
||||
|
||||
0.3.3:
|
||||
|
||||
fix: norm name : lowercase first (else bad naming break prefix)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import bpy
|
||||
|
||||
|
||||
class GPEXP_OT_render_scene_switch(bpy.types.Operator):
|
||||
bl_idname = "gp.render_scene_switch"
|
||||
bl_label = "Render Scene Switch"
|
||||
|
@ -37,8 +36,83 @@ class GPEXP_OT_render_scene_switch(bpy.types.Operator):
|
|||
bpy.context.window.scene = scn
|
||||
return {"FINISHED"}
|
||||
|
||||
def set_resolution_from_cam_prop(cam=None):
|
||||
if not cam:
|
||||
cam = bpy.context.scene.camera
|
||||
if not cam:
|
||||
return ('ERROR', 'No active camera')
|
||||
|
||||
res = cam.get('resolution')
|
||||
if not res:
|
||||
return ('ERROR', 'Cam has no resolution attribute')
|
||||
|
||||
rd = bpy.context.scene.render
|
||||
if rd.resolution_x == res[0] and rd.resolution_y == res[1]:
|
||||
return ('INFO', f'Resolution already at {res[0]}x{res[1]}')
|
||||
else:
|
||||
rd.resolution_x, rd.resolution_y = res[0], res[1]
|
||||
return ('INFO', f'Resolution to {res[0]}x{res[1]}')
|
||||
|
||||
class GPEXP_OT_swap_render_cams(bpy.types.Operator):
|
||||
bl_idname = "gp.swap_render_cams"
|
||||
bl_label = "Swap Cameras"
|
||||
bl_description = "Toggle between anim and bg cam"
|
||||
bl_options = {"REGISTER"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return True
|
||||
|
||||
def execute(self, context):
|
||||
anim_cam = bpy.context.scene.objects.get('anim_cam')
|
||||
bg_cam = bpy.context.scene.objects.get('bg_cam')
|
||||
|
||||
if not anim_cam or not bg_cam:
|
||||
self.report({'ERROR'}, 'anim_cam or bg_cam is missing')
|
||||
return {"CANCELLED"}
|
||||
|
||||
cam = context.scene.camera
|
||||
if not cam:
|
||||
context.scene.camera = anim_cam
|
||||
set_resolution_from_cam_prop()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
in_draw = False
|
||||
if cam.parent and cam.name in ('draw_cam', 'action_cam'):
|
||||
if cam.name == 'draw_cam':
|
||||
draw_cam = cam
|
||||
in_draw = True
|
||||
cam = cam.parent
|
||||
|
||||
## swap
|
||||
# context.scene.camera = bg_cam if cam is anim_cam else anim_cam
|
||||
if cam is anim_cam:
|
||||
main = context.scene.camera = bg_cam
|
||||
anim_cam.hide_viewport = True
|
||||
bg_cam.hide_viewport = False
|
||||
else:
|
||||
main = context.scene.camera = anim_cam
|
||||
anim_cam.hide_viewport = False
|
||||
bg_cam.hide_viewport = True
|
||||
|
||||
if in_draw:
|
||||
draw_cam.parent = main
|
||||
draw_cam.data = main.data
|
||||
# back in draw_cam
|
||||
context.scene.camera = draw_cam
|
||||
bg_cam.hide_viewport = anim_cam.hide_viewport = True
|
||||
|
||||
# set res
|
||||
ret = set_resolution_from_cam_prop(main)
|
||||
if ret:
|
||||
self.report({ret[0]}, ret[1])
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
classes=(
|
||||
GPEXP_OT_render_scene_switch,
|
||||
GPEXP_OT_swap_render_cams,
|
||||
)
|
||||
|
||||
def register():
|
||||
|
|
|
@ -2,7 +2,7 @@ bl_info = {
|
|||
"name": "GP Render",
|
||||
"description": "Organise export of gp layers through compositor output",
|
||||
"author": "Samuel Bernou",
|
||||
"version": (0, 3, 3),
|
||||
"version": (0, 3, 4),
|
||||
"blender": (2, 93, 0),
|
||||
"location": "View3D",
|
||||
"warning": "",
|
||||
|
|
16
ui.py
16
ui.py
|
@ -15,9 +15,23 @@ class GPEXP_PT_gp_node_ui(Panel):
|
|||
layout = self.layout
|
||||
layout.operator('gp.render_scene_switch', icon='SCENE_DATA', text='Switch Scene')
|
||||
|
||||
if not context.scene.use_nodes or not context.scene.node_tree:
|
||||
scn = context.scene
|
||||
if not scn.use_nodes or not scn.node_tree:
|
||||
return
|
||||
|
||||
## Camera swapping
|
||||
row = layout.row()
|
||||
cam = scn.camera
|
||||
if cam:
|
||||
text = f'{cam.name} : {scn.render.resolution_x}x{scn.render.resolution_y}' # Cam:
|
||||
else:
|
||||
text = f'None' # Cam:
|
||||
|
||||
layout.separator()
|
||||
# if cam and cam_name == 'draw_cam':
|
||||
# cam_name = f'{cam.parent.name} > {cam_name}'
|
||||
row.operator("gp.swap_render_cams", text=text, icon='OUTLINER_OB_CAMERA')
|
||||
|
||||
# TODO : add advanced bool checkbox to hide some options from the user
|
||||
|
||||
col = layout.column(align=True)
|
||||
|
|
Loading…
Reference in New Issue