2021-09-14 18:54:30 +02:00
|
|
|
import bpy
|
2023-01-17 15:50:10 +01:00
|
|
|
from .import fn
|
2024-04-16 18:01:10 +02:00
|
|
|
from .constant import RD_SCENE_NAME
|
2021-09-14 18:54:30 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-04-16 18:01:10 +02:00
|
|
|
scene : bpy.props.StringProperty(default='', options={'SKIP_SAVE'})
|
2021-09-14 18:54:30 +02:00
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
scenes = bpy.data.scenes
|
|
|
|
if len(scenes) < 2:
|
|
|
|
self.report({'ERROR'},'No other scene to go to')
|
|
|
|
return {"CANCELLED"}
|
2023-01-18 14:28:27 +01:00
|
|
|
|
2024-04-16 18:01:10 +02:00
|
|
|
## Case where a scene name is passed
|
|
|
|
if self.scene:
|
|
|
|
scn = bpy.data.scenes.get(self.scene)
|
|
|
|
if not scn:
|
|
|
|
self.report({'ERROR'},f'No scene "{self.scene}"')
|
|
|
|
return {"CANCELLED"}
|
|
|
|
self.report({'INFO'},f'Switched to scene "{scn.name}"')
|
|
|
|
bpy.context.window.scene = scn
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
if context.scene.name == RD_SCENE_NAME:
|
2021-09-14 18:54:30 +02:00
|
|
|
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)]
|
2023-01-18 14:28:27 +01:00
|
|
|
|
2021-09-14 18:54:30 +02:00
|
|
|
else:
|
2024-04-16 18:01:10 +02:00
|
|
|
scn = fn.get_render_scene(create=False)
|
2021-09-14 18:54:30 +02:00
|
|
|
if not scn:
|
2024-04-16 18:01:10 +02:00
|
|
|
self.report({'ERROR'},f'No "{RD_SCENE_NAME}" scene yet')
|
2021-09-14 18:54:30 +02:00
|
|
|
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
|
|
|
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"}
|
|
|
|
|
|
|
|
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"}
|
2023-01-18 14:28:27 +01:00
|
|
|
|
2021-09-22 15:01:49 +02:00
|
|
|
cam = context.scene.camera
|
|
|
|
if not cam:
|
|
|
|
context.scene.camera = anim_cam
|
2023-01-17 15:50:10 +01:00
|
|
|
fn.set_resolution_from_cam_prop()
|
2021-09-22 15:01:49 +02:00
|
|
|
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
|
2023-01-17 15:50:10 +01:00
|
|
|
ret = fn.set_resolution_from_cam_prop(main)
|
2021-09-22 15:01:49 +02:00
|
|
|
if ret:
|
|
|
|
self.report({ret[0]}, ret[1])
|
2023-01-17 15:50:10 +01:00
|
|
|
|
2021-09-22 15:01:49 +02:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
2023-01-17 16:50:42 +01:00
|
|
|
class GPEXP_OT_set_gp_render_workspace(bpy.types.Operator):
|
|
|
|
bl_idname = "gp.set_gp_render_workspace"
|
|
|
|
bl_label = 'Set GP Render Workspace'
|
|
|
|
bl_description = "Switch to GP render workspace, append and activate if not exists"
|
|
|
|
bl_options = {'REGISTER', 'INTERNAL'}
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
fn.activate_workspace(name='GP Render', context=context)
|
|
|
|
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,
|
2023-01-17 16:50:42 +01:00
|
|
|
GPEXP_OT_set_gp_render_workspace,
|
2021-09-14 18:54:30 +02:00
|
|
|
)
|
|
|
|
|
2023-01-18 14:28:27 +01:00
|
|
|
def register():
|
2021-09-14 18:54:30 +02:00
|
|
|
for cls in classes:
|
|
|
|
bpy.utils.register_class(cls)
|
|
|
|
|
|
|
|
def unregister():
|
|
|
|
for cls in reversed(classes):
|
|
|
|
bpy.utils.unregister_class(cls)
|