Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Bake operator activation #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 67 additions & 21 deletions addons/io_hubs_addon/components/definitions/reflection_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ class ReflectionProbeSceneProps(PropertyGroup):
description="Controls whether the baked images will be processed by the compositor after baking", default=False)


class BakeProbeOperator(Operator):
bl_idname = "render.hubs_render_reflection_probe"
bl_label = "Render Hubs Reflection Probe"

class BakeProbeOperator():
_timer = None
done = False
rendering = False
Expand Down Expand Up @@ -160,15 +157,6 @@ def description(cls, context, properties):

return description_text

@ classmethod
def poll(cls, context):
if hasattr(context, 'bake_active_probe') and is_linked(context.active_object):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set(f"{cls.disabled_message}.")
return False

return not probe_baking and hasattr(bpy.context.scene, "cycles")

def render_post(self, scene, depsgraph):
print("Finished render")

Expand Down Expand Up @@ -392,6 +380,63 @@ def setup_probe_render(self, context):
self.probe_is_setup = True


class BakeProbeOperatorActive(Operator, BakeProbeOperator):
bl_idname = "render.hubs_render_reflection_probe_active"
bl_label = "Render Active Hubs Reflection Probe"

def __init__(self) -> None:
super().__init__()

self.bake_mode = 'ACTIVE'

@ classmethod
def poll(cls, context):
if is_linked(context.active_object):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set(f"{cls.disabled_message}.")
return False

return not probe_baking and hasattr(bpy.context.scene, "cycles")


class BakeProbeOperatorSelected(Operator, BakeProbeOperator):
bl_idname = "render.hubs_render_reflection_probe_selected"
bl_label = "Render Selected Hubs Reflection Probe"

def __init__(self) -> None:
super().__init__()

self.bake_mode = 'SELECTED'

@ classmethod
def poll(cls, context):
if all(is_linked(ob) for ob in context.selected_objects):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set(f"{cls.disabled_message}.")
return False

return not probe_baking and hasattr(bpy.context.scene, "cycles")


class BakeProbeOperatorAll(Operator, BakeProbeOperator):
bl_idname = "render.hubs_render_reflection_probe_all"
bl_label = "Render All Hubs Reflection Probe"

def __init__(self) -> None:
super().__init__()

self.bake_mode = 'ALL'

@ classmethod
def poll(cls, context):
if all(is_linked(ob) for ob in get_probes(include_linked=True, include_locked=True)):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set(f"{cls.disabled_message}.")
return False

return not probe_baking and hasattr(bpy.context.scene, "cycles")


class OpenReflectionProbeEnvMap(Operator):
bl_idname = "image.hubs_open_reflection_probe_envmap"
bl_label = "Open EnvMap"
Expand Down Expand Up @@ -785,13 +830,11 @@ def draw(self, context, layout, panel):

global bake_mode
row = layout.row()
row.context_pointer_set("bake_active_probe", None)
bake_msg = "Baking..." if probe_baking and bake_mode == 'ACTIVE' else "Bake"
bake_op = row.operator(
"render.hubs_render_reflection_probe",
"render.hubs_render_reflection_probe_active",
text=bake_msg
)
bake_op.bake_mode = 'ACTIVE'

if self.locked:
row.enabled = False
Expand Down Expand Up @@ -863,16 +906,15 @@ def draw_global(cls, context, layout, panel):
row = col.row()
bake_msg = "Baking..." if probe_baking and bake_mode == 'ALL' else "Bake All"
bake_op = row.operator(
"render.hubs_render_reflection_probe",
"render.hubs_render_reflection_probe_all",
text=bake_msg
)
bake_op.bake_mode = 'ALL'
bake_msg = "Baking..." if probe_baking and bake_mode == 'SELECTED' else "Bake Selected"
bake_op = row.operator(
"render.hubs_render_reflection_probe",
"render.hubs_render_reflection_probe_selected",
text=bake_msg
)
bake_op.bake_mode = 'SELECTED'

if not hasattr(bpy.context.scene, "cycles"):
row = col.row()
Expand All @@ -886,7 +928,9 @@ def poll(cls, context, panel_type):

@ staticmethod
def register():
bpy.utils.register_class(BakeProbeOperator)
bpy.utils.register_class(BakeProbeOperatorActive)
bpy.utils.register_class(BakeProbeOperatorSelected)
bpy.utils.register_class(BakeProbeOperatorAll)
bpy.utils.register_class(ReflectionProbeSceneProps)
bpy.utils.register_class(OpenReflectionProbeEnvMap)
bpy.utils.register_class(ImportReflectionProbeEnvMaps)
Expand All @@ -900,7 +944,9 @@ def register():

@ staticmethod
def unregister():
bpy.utils.unregister_class(BakeProbeOperator)
bpy.utils.unregister_class(BakeProbeOperatorActive)
bpy.utils.unregister_class(BakeProbeOperatorSelected)
bpy.utils.unregister_class(BakeProbeOperatorAll)
bpy.utils.unregister_class(ReflectionProbeSceneProps)
bpy.utils.unregister_class(OpenReflectionProbeEnvMap)
bpy.utils.unregister_class(ImportReflectionProbeEnvMaps)
Expand Down