diff --git a/__init__.py b/__init__.py index 7b739e07..b30f054a 100644 --- a/__init__.py +++ b/__init__.py @@ -20,6 +20,7 @@ halt, image_tools, light, lightgroups, material, particle, postpro, render, render_layer, scene, texture, units, viewport, world, ) +from .utils.log import LuxCoreLog bl_info = { "name": "LuxCore", @@ -29,7 +30,7 @@ "category": "Render", "location": "Info header, render engine menu", "description": "LuxCore integration for Blender", - "warning": "alpha1", + "warning": "alpha2", "wiki_url": "https://wiki.luxcorerender.org/", "tracker_url": "https://github.com/LuxCoreRender/BlendLuxCore/issues/new", } @@ -46,7 +47,7 @@ def register(): properties.init() # Has to be called at least once, can be called multiple times - pyluxcore.Init() + pyluxcore.Init(LuxCoreLog.add) print("pyluxcore version:", pyluxcore.Version()) diff --git a/engine/__init__.py b/engine/__init__.py index 3ea2a55b..7192a3b6 100644 --- a/engine/__init__.py +++ b/engine/__init__.py @@ -1,6 +1,7 @@ import bpy from . import final, preview, viewport from ..handlers.draw_imageeditor import TileStats +from ..utils.log import LuxCoreLog class LuxCoreRenderEngine(bpy.types.RenderEngine): @@ -33,6 +34,12 @@ def __del__(self): self.session.Stop() del self.session + def log_listener(self, msg): + if "Direct light sampling cache entries" in msg: + self.update_stats("", msg) + # elif "BCD progress" in msg: # TODO For some weird reason this does not work + # self.update_stats("", msg) + def render(self, scene): if self.is_preview: self.render_preview(scene) @@ -42,7 +49,9 @@ def render(self, scene): def render_final(self, scene): try: LuxCoreRenderEngine.final_running = True + scene.luxcore.display.paused = False TileStats.reset() + LuxCoreLog.add_listener(self.log_listener) final.render(self, scene) except Exception as error: self.report({"ERROR"}, str(error)) @@ -59,6 +68,7 @@ def render_final(self, scene): scene.luxcore.active_layer_index = -1 LuxCoreRenderEngine.final_running = False TileStats.reset() + LuxCoreLog.remove_listener(self.log_listener) def render_preview(self, scene): try: diff --git a/utils/log.py b/utils/log.py new file mode 100644 index 00000000..edcb282d --- /dev/null +++ b/utils/log.py @@ -0,0 +1,26 @@ +# import collections + + +class LuxCoreLog: + # _history = collections.deque(maxlen=50) + _listeners = [] + + @staticmethod + def add(msg): + print(msg) + # LuxCoreLog._history.append(msg) + + for listener in LuxCoreLog._listeners: + listener(msg) + + @classmethod + def clear(cls): + cls._history.clear() + + @classmethod + def add_listener(cls, listener): + cls._listeners.append(listener) + + @classmethod + def remove_listener(cls, listener): + cls._listeners.remove(listener)