Skip to content

Commit

Permalink
add logger class, fix pause not being reset when render is started, b…
Browse files Browse the repository at this point in the history
…ump version
  • Loading branch information
Theverat committed Jun 28, 2018
1 parent 24615a7 commit 2a299f4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
5 changes: 3 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
}
Expand All @@ -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())


Expand Down
10 changes: 10 additions & 0 deletions engine/__init__.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand All @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions utils/log.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2a299f4

Please sign in to comment.