Logic nodes for action playback
This commit is contained in:
parent
110b143bd2
commit
ea4347e4d2
21
Sources/armory/logicnode/AnimActionNode.hx
Normal file
21
Sources/armory/logicnode/AnimActionNode.hx
Normal file
|
@ -0,0 +1,21 @@
|
|||
package armory.logicnode;
|
||||
|
||||
class AnimActionNode extends LogicNode {
|
||||
|
||||
public var value:String;
|
||||
|
||||
public function new(tree:LogicTree, value = "") {
|
||||
super(tree);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
override function get(from:Int):Dynamic {
|
||||
if (inputs.length > 0) return inputs[0].get();
|
||||
return value;
|
||||
}
|
||||
|
||||
override function set(value:Dynamic) {
|
||||
if (inputs.length > 0) inputs[0].set(value);
|
||||
else this.value = value;
|
||||
}
|
||||
}
|
|
@ -14,6 +14,9 @@ class PlayActionNode extends LogicNode {
|
|||
|
||||
if (object == null) object = tree.object;
|
||||
|
||||
// Try first child if we are running from armature
|
||||
if (object.animation == null) object = object.children[0];
|
||||
|
||||
object.animation.play(action, function() {
|
||||
runOutputs(1);
|
||||
});
|
||||
|
|
|
@ -240,6 +240,9 @@ class Logic {
|
|||
else if (inp.type == 'OBJECT') {
|
||||
v = createClassInstance('ObjectNode', [tree, inp.default_value]);
|
||||
}
|
||||
else if (inp.type == 'ANIMACTION') {
|
||||
v = createClassInstance('StringNode', [tree, inp.default_value]);
|
||||
}
|
||||
else if (inp.type == 'VECTOR') {
|
||||
v = createClassInstance('VectorNode', [tree, inp.default_value[0], inp.default_value[1], inp.default_value[2]]);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class PlayActionNode(Node, ArmLogicTreeNode):
|
|||
def init(self, context):
|
||||
self.inputs.new('ArmNodeSocketAction', 'In')
|
||||
self.inputs.new('ArmNodeSocketObject', 'Object')
|
||||
self.inputs.new('NodeSocketString', 'Clip')
|
||||
self.inputs.new('ArmNodeSocketAnimAction', 'Action')
|
||||
self.outputs.new('ArmNodeSocketAction', 'Out')
|
||||
self.outputs.new('ArmNodeSocketAction', 'Done')
|
||||
|
||||
|
|
|
@ -72,6 +72,22 @@ class ArmNodeEyedropButton(bpy.types.Operator):
|
|||
object_sockets[self.socket_index].default_value = obj.name
|
||||
return{'FINISHED'}
|
||||
|
||||
class ArmAnimActionSocket(bpy.types.NodeSocket):
|
||||
bl_idname = 'ArmNodeSocketAnimAction'
|
||||
bl_label = 'Action Socket'
|
||||
default_value = StringProperty(name='Action', default='')
|
||||
|
||||
def draw(self, context, layout, node, text):
|
||||
if self.is_output:
|
||||
layout.label(self.name)
|
||||
elif self.is_linked:
|
||||
layout.label(self.name)
|
||||
else:
|
||||
layout.prop_search(self, 'default_value', bpy.data, 'actions', icon='NONE', text='')
|
||||
|
||||
def draw_color(self, context, node):
|
||||
return (0.8, 0.8, 0.8, 1)
|
||||
|
||||
class ArmNodeAddInputButton(bpy.types.Operator):
|
||||
'''Add new input'''
|
||||
bl_idname = 'arm.node_add_input'
|
||||
|
@ -132,6 +148,7 @@ def add_node(node_class, category):
|
|||
bpy.utils.register_class(ArmActionSocket)
|
||||
bpy.utils.register_class(ArmObjectSocket)
|
||||
bpy.utils.register_class(ArmNodeEyedropButton)
|
||||
bpy.utils.register_class(ArmAnimActionSocket)
|
||||
bpy.utils.register_class(ArmNodeAddInputButton)
|
||||
bpy.utils.register_class(ArmNodeRemoveInputButton)
|
||||
bpy.utils.register_class(ArmNodeAddOutputButton)
|
||||
|
|
16
blender/arm/logicnode/variable_action.py
Normal file
16
blender/arm/logicnode/variable_action.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
import bpy
|
||||
from bpy.props import *
|
||||
from bpy.types import Node, NodeSocket
|
||||
from arm.logicnode.arm_nodes import *
|
||||
|
||||
class AnimActionNode(Node, ArmLogicTreeNode):
|
||||
'''Anim action node'''
|
||||
bl_idname = 'LNAnimActionNode'
|
||||
bl_label = 'Action'
|
||||
bl_icon = 'GAME'
|
||||
|
||||
def init(self, context):
|
||||
self.inputs.new('ArmNodeSocketAnimAction', 'Action')
|
||||
self.outputs.new('ArmNodeSocketAnimAction', 'Action')
|
||||
|
||||
add_node(AnimActionNode, category='Variable')
|
|
@ -137,7 +137,11 @@ def build_default_node(inp):
|
|||
return inp_name
|
||||
if inp.bl_idname == 'ArmNodeSocketObject':
|
||||
inp_name = 'new armory.logicnode.ObjectNode(this, "' + str(inp.default_value) + '")'
|
||||
elif inp.type == 'VECTOR':
|
||||
return inp_name
|
||||
if inp.bl_idname == 'ArmNodeSocketAnimAction':
|
||||
inp_name = 'new armory.logicnode.StringNode(this, "' + str(inp.default_value) + '")'
|
||||
return inp_name
|
||||
if inp.type == 'VECTOR':
|
||||
inp_name = 'new armory.logicnode.VectorNode(this, ' + str(inp.default_value[0]) + ', ' + str(inp.default_value[1]) + ', ' + str(inp.default_value[2]) + ')'
|
||||
elif inp.type == 'RGBA':
|
||||
inp_name = 'new armory.logicnode.ColorNode(this, ' + str(inp.default_value[0]) + ', ' + str(inp.default_value[1]) + ', ' + str(inp.default_value[2]) + ', ' + str(inp.default_value[3]) + ')'
|
||||
|
|
|
@ -8,6 +8,8 @@ def socket_type(s):
|
|||
return 'ACTION'
|
||||
elif s == 'ArmNodeSocketObject':
|
||||
return 'OBJECT'
|
||||
elif s == 'ArmNodeSocketAnimAction':
|
||||
return 'ANIMACTION'
|
||||
elif s == 'NodeSocketShader':
|
||||
return 'SHADER'
|
||||
elif s == 'NodeSocketInt':
|
||||
|
|
Loading…
Reference in a new issue