-
Notifications
You must be signed in to change notification settings - Fork 319
logicnodes
We will make a new library to store the sources of custom logic nodes and keep them portable with no modifications to engine sources.
Locate your blend file and create a new Libraries
folder alongside it. Navigate to the Libraries
folder and create a new mynodes
folder in it to place your new node.
Next, we will create the logic node definition for Blender.
To do so, we have to create a file named blender.py
in Libraries/mynodes
folder. Armory automatically picks this file up once the library is loaded.
Define a simple node with single in/out socket like the one in the example below.
from bpy.types import Node
from arm.logicnode.arm_nodes import *
import arm.nodes_logic
class TestNode(Node, ArmLogicTreeNode):
'''Test node'''
bl_idname = 'LNTestNode'
bl_label = 'Test'
bl_icon = 'QUESTION'
def init(self, context):
self.inputs.new('ArmNodeSocketAction', 'In')
self.outputs.new('ArmNodeSocketAction', 'Out')
# Add custom nodes
add_node(TestNode, category='Action')
Restarting Blender and loading the project again, the new logic node is available for placement.
Before the project can be run, we need to implement the actual node logic in Haxe.
Start by creating the folder structure Sources/armory/logicnode/
in the same folder of blender.py
.
Next, create a TestNode.hx
file inside the logicnode
folder just created, and place the code from below in the file.
When the node gets executed, we let it print a 'Hello, World!' string.
package armory.logicnode;
class TestNode extends LogicNode {
public function new(tree:LogicTree) {
super(tree);
}
override function run(from:Int) {
// Logic for this node
trace("Hello, World!");
// Execute next action linked to this node
runOutput(0);
}
}
When implementing new logic nodes, browse the sources of existing nodes as a reference:
-
Python definitions of Armory nodes: https://github.com/armory3d/armory/tree/master/blender/arm/logicnode
-
Haxe implementation: https://github.com/armory3d/armory/tree/master/Sources/armory/logicnode