2021-09-14 18:54:30 +02:00
|
|
|
import bpy
|
|
|
|
|
|
|
|
class GPEXP_OT_render_scene_switch(bpy.types.Operator):
|
|
|
|
bl_idname = "gp.render_scene_switch"
|
|
|
|
bl_label = "Render Scene Switch"
|
|
|
|
bl_description = "Switch between render"
|
|
|
|
bl_options = {"REGISTER"}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
return True
|
|
|
|
|
|
|
|
# mode : bpy.props.StringProperty(default='NORMAL', options={'SKIP_SAVE'})
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
scenes = bpy.data.scenes
|
|
|
|
if len(scenes) < 2:
|
|
|
|
self.report({'ERROR'},'No other scene to go to')
|
|
|
|
return {"CANCELLED"}
|
|
|
|
|
|
|
|
if context.scene.name == 'Render':
|
|
|
|
scn = scenes.get('Scene')
|
|
|
|
if not scn: # get the next available scene
|
|
|
|
self.report({'WARNING'},'No scene named "Scene"')
|
|
|
|
slist = [s.name for s in scenes]
|
|
|
|
scn = scenes[(slist.index(bpy.context.scene.name) + 1) % len(scenes)]
|
|
|
|
|
|
|
|
else:
|
|
|
|
scn = scenes.get('Render')
|
|
|
|
if not scn:
|
|
|
|
self.report({'ERROR'},'No "Render" scene yet')
|
|
|
|
return {"CANCELLED"}
|
|
|
|
|
|
|
|
|
|
|
|
self.report({'INFO'},f'Switched to scene "{scn.name}"')
|
|
|
|
bpy.context.window.scene = scn
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
2021-09-22 15:01:49 +02:00
|
|
|
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"}
|
|
|
|
|
2021-09-14 18:54:30 +02:00
|
|
|
classes=(
|
|
|
|
GPEXP_OT_render_scene_switch,
|
2021-09-22 15:01:49 +02:00
|
|
|
GPEXP_OT_swap_render_cams,
|
2021-09-14 18:54:30 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def register():
|
|
|
|
for cls in classes:
|
|
|
|
bpy.utils.register_class(cls)
|
|
|
|
|
|
|
|
def unregister():
|
|
|
|
for cls in reversed(classes):
|
|
|
|
bpy.utils.unregister_class(cls)
|