Skip to content

Commit

Permalink
Implement the runtime
Browse files Browse the repository at this point in the history
Just something basic that can go through the node tree
  • Loading branch information
alexmro committed Feb 11, 2024
1 parent 86b2bcb commit 69be5ca
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
52 changes: 52 additions & 0 deletions core/runtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import bpy

from datetime import datetime

from ..ui.nodes.nodetree import MotorNodeTree
from ..ui.nodes.onstart import MotorOnStartNode
from ..ui.nodes.console import MotorConsoleNode
from ..ui.nodes.sockets import MotorActionSocket


def run_scene():
"""Interpret the entire node tree and run the scene"""
on_start_nodes = []

for node_group in bpy.data.node_groups:
if node_group.bl_idname == MotorNodeTree.bl_idname:
for node in node_group.nodes:
if node.bl_idname == MotorOnStartNode.bl_idname:
on_start_nodes.append(node)

for start_node in on_start_nodes:
for output in start_node.outputs:
if output.enabled and output.is_output and output.is_linked:
for link in output.links:
if link.to_node.bl_idname == MotorConsoleNode.bl_idname:
to_node = link.to_node
message = ""
if output.bl_idname == MotorActionSocket.bl_idname:
message = f"'{start_node.bl_label}' output '{output.bl_label}'"
show_time_prop = to_node.get("show_time_prop")
type_prop = to_node.get("type_prop")

if type_prop == 3:
message = "ERROR: " + message
elif type_prop == 2:
message = "WARNING: " + message
else:
message = "INFO: " + message

if show_time_prop:
now = datetime.now()
dt_string = now.strftime("[%d/%m/%Y %H:%M:%S] ")

message = dt_string + message

print(message)

return True


def stop_scene():
print("Scene stopped")
9 changes: 9 additions & 0 deletions ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
from bpy.types import Operator
from bpy.utils import register_classes_factory

from ..core.runtime import run_scene, stop_scene


class MotorRunOperator(Operator):
"""Operator that enters interactive mode and runs the scene"""
bl_idname = "motor.run"
bl_label = "Enter interactive mode"
bl_description = "Enter interactive mode and disable UI"
Expand All @@ -22,6 +25,7 @@ def invoke(self, context, event):


def switch_interactive_mode(enabled):
"""Enter or exit interactive mode. Start or stop running the scene"""
area = bpy.context.area
window = bpy.context.window
if area.type == 'VIEW_3D':
Expand Down Expand Up @@ -63,6 +67,11 @@ def switch_interactive_mode(enabled):
else:
bpy.ops.view3d.view_lock_clear()

if enabled:
run_scene()
else:
stop_scene()


classes = (
MotorRunOperator,
Expand Down

0 comments on commit 69be5ca

Please sign in to comment.