Logic Node - On Swipe
The node for the swipe event.
Input parameters:
- Time - duration of the swipe (default value 0.15 s);
- Min Length (px) - the minimum length that the swipe must “pass” (default value 100 px).
Output parameters:
- Direction - normalized vector of the swipe direction;
- Length (px) - the length of the swipe (to assess the “strength”);
The Length output parameter is calculated by the vector value (without normalization) to relate to the input value.
- Angle (0-360) - swipe angle in the range from 0 to 360 degrees (0 is on the right, i.e. Vector (1, 0) = 0 degrees).
- States are states with direction output (Up, Down …). By default, they are not displayed, but if you press “Add 4 State”, then 4 states will appear (Up, Down, Left, Right) and if again, then 8 states will already be displayed.
Determining direction for a state:
for 4 directions - "circle" is divided into 4 segments of 90 degrees;
for 8 directions - "circle" is divided into 8 segments of 45 degrees.
2020-09-15 08:08:59 +02:00
|
|
|
from arm.logicnode.arm_nodes import *
|
|
|
|
|
|
|
|
# Custom class for add output parameters (in 4 directions)
|
|
|
|
class NodeAddOutputButton(bpy.types.Operator):
|
|
|
|
"""Add 4 States"""
|
|
|
|
bl_idname = 'arm.add_output_4_parameters'
|
|
|
|
bl_label = 'Add 4 States'
|
|
|
|
node_index: StringProperty(name='Node Index', default='')
|
|
|
|
socket_type: StringProperty(name='Socket Type', default='NodeSocketShader')
|
|
|
|
name_format: StringProperty(name='Name Format', default='Output {0}')
|
|
|
|
index_name_offset: IntProperty(name='Index Name Offset', default=0)
|
|
|
|
|
|
|
|
# Get name State
|
|
|
|
def get_name_state(self, id, min_outputs):
|
|
|
|
states = ['UP', 'DOWN', 'LEFT', 'RIGHT', 'UP-LEFT', 'UP-RIGHT', 'DOWN-LEFT', 'DOWN-RIGHT']
|
|
|
|
if ((id - min_outputs) < len(states)): return states[id - min_outputs]
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def execute(self, context):
|
2020-09-28 15:58:41 +02:00
|
|
|
global array_nodes
|
|
|
|
node = array_nodes[self.node_index]
|
|
|
|
outs = node.outputs
|
Logic Node - On Swipe
The node for the swipe event.
Input parameters:
- Time - duration of the swipe (default value 0.15 s);
- Min Length (px) - the minimum length that the swipe must “pass” (default value 100 px).
Output parameters:
- Direction - normalized vector of the swipe direction;
- Length (px) - the length of the swipe (to assess the “strength”);
The Length output parameter is calculated by the vector value (without normalization) to relate to the input value.
- Angle (0-360) - swipe angle in the range from 0 to 360 degrees (0 is on the right, i.e. Vector (1, 0) = 0 degrees).
- States are states with direction output (Up, Down …). By default, they are not displayed, but if you press “Add 4 State”, then 4 states will appear (Up, Down, Left, Right) and if again, then 8 states will already be displayed.
Determining direction for a state:
for 4 directions - "circle" is divided into 4 segments of 90 degrees;
for 8 directions - "circle" is divided into 8 segments of 45 degrees.
2020-09-15 08:08:59 +02:00
|
|
|
outs.new('NodeSocketBool', self.get_name_state(len(outs), node.min_outputs))
|
|
|
|
outs.new('NodeSocketBool', self.get_name_state(len(outs), node.min_outputs))
|
|
|
|
outs.new('NodeSocketBool', self.get_name_state(len(outs), node.min_outputs))
|
|
|
|
outs.new('NodeSocketBool', self.get_name_state(len(outs), node.min_outputs))
|
|
|
|
return{'FINISHED'}
|
|
|
|
|
|
|
|
# Custom class for remove output parameters (in 4 directions)
|
|
|
|
class NodeRemoveOutputButton(bpy.types.Operator):
|
|
|
|
"""Remove 4 last states"""
|
|
|
|
bl_idname = 'arm.remove_output_4_parameters'
|
|
|
|
bl_label = 'Remove 4 States'
|
|
|
|
node_index: StringProperty(name='Node Index', default='')
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
global array_nodes
|
|
|
|
node = array_nodes[self.node_index]
|
|
|
|
outs = node.outputs
|
|
|
|
min_outs = 0 if not hasattr(node, 'min_outputs') else node.min_outputs
|
|
|
|
if len(outs) > min_outs:
|
|
|
|
for i in range(4):
|
|
|
|
outs.remove(outs.values()[-1])
|
|
|
|
return{'FINISHED'}
|
|
|
|
|
|
|
|
# Class SwipeNode
|
|
|
|
class OnSwipeNode(ArmLogicTreeNode):
|
2020-10-05 19:55:56 +02:00
|
|
|
"""Activates the output when the given swipe action is done."""
|
Logic Node - On Swipe
The node for the swipe event.
Input parameters:
- Time - duration of the swipe (default value 0.15 s);
- Min Length (px) - the minimum length that the swipe must “pass” (default value 100 px).
Output parameters:
- Direction - normalized vector of the swipe direction;
- Length (px) - the length of the swipe (to assess the “strength”);
The Length output parameter is calculated by the vector value (without normalization) to relate to the input value.
- Angle (0-360) - swipe angle in the range from 0 to 360 degrees (0 is on the right, i.e. Vector (1, 0) = 0 degrees).
- States are states with direction output (Up, Down …). By default, they are not displayed, but if you press “Add 4 State”, then 4 states will appear (Up, Down, Left, Right) and if again, then 8 states will already be displayed.
Determining direction for a state:
for 4 directions - "circle" is divided into 4 segments of 90 degrees;
for 8 directions - "circle" is divided into 8 segments of 45 degrees.
2020-09-15 08:08:59 +02:00
|
|
|
bl_idname = 'LNOnSwipeNode'
|
|
|
|
bl_label = 'On Swipe'
|
|
|
|
arm_version = 1
|
|
|
|
min_outputs = 4
|
|
|
|
max_outputs = 12
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
array_nodes[str(id(self))] = self
|
|
|
|
|
2020-09-28 15:58:41 +02:00
|
|
|
def init(self, context):
|
|
|
|
super(OnSwipeNode, self).init(context)
|
Logic Node - On Swipe
The node for the swipe event.
Input parameters:
- Time - duration of the swipe (default value 0.15 s);
- Min Length (px) - the minimum length that the swipe must “pass” (default value 100 px).
Output parameters:
- Direction - normalized vector of the swipe direction;
- Length (px) - the length of the swipe (to assess the “strength”);
The Length output parameter is calculated by the vector value (without normalization) to relate to the input value.
- Angle (0-360) - swipe angle in the range from 0 to 360 degrees (0 is on the right, i.e. Vector (1, 0) = 0 degrees).
- States are states with direction output (Up, Down …). By default, they are not displayed, but if you press “Add 4 State”, then 4 states will appear (Up, Down, Left, Right) and if again, then 8 states will already be displayed.
Determining direction for a state:
for 4 directions - "circle" is divided into 4 segments of 90 degrees;
for 8 directions - "circle" is divided into 8 segments of 45 degrees.
2020-09-15 08:08:59 +02:00
|
|
|
self.inputs.new('NodeSocketFloat', 'Time')
|
|
|
|
self.inputs[-1].default_value = 0.15
|
|
|
|
self.inputs.new('NodeSocketInt', 'Min Length (px)')
|
|
|
|
self.inputs[-1].default_value = 100
|
|
|
|
self.outputs.new('ArmNodeSocketAction', 'Out')
|
|
|
|
self.outputs.new('NodeSocketVector', 'Direction')
|
|
|
|
self.outputs.new('NodeSocketInt', 'Length (px)')
|
|
|
|
self.outputs.new('NodeSocketInt', 'Angle (0-360)')
|
|
|
|
|
|
|
|
# Draw node buttons
|
|
|
|
def draw_buttons(self, context, layout):
|
2020-09-28 15:58:41 +02:00
|
|
|
row = layout.row(align=True)
|
Logic Node - On Swipe
The node for the swipe event.
Input parameters:
- Time - duration of the swipe (default value 0.15 s);
- Min Length (px) - the minimum length that the swipe must “pass” (default value 100 px).
Output parameters:
- Direction - normalized vector of the swipe direction;
- Length (px) - the length of the swipe (to assess the “strength”);
The Length output parameter is calculated by the vector value (without normalization) to relate to the input value.
- Angle (0-360) - swipe angle in the range from 0 to 360 degrees (0 is on the right, i.e. Vector (1, 0) = 0 degrees).
- States are states with direction output (Up, Down …). By default, they are not displayed, but if you press “Add 4 State”, then 4 states will appear (Up, Down, Left, Right) and if again, then 8 states will already be displayed.
Determining direction for a state:
for 4 directions - "circle" is divided into 4 segments of 90 degrees;
for 8 directions - "circle" is divided into 8 segments of 45 degrees.
2020-09-15 08:08:59 +02:00
|
|
|
column = row.column(align=True)
|
2020-09-28 15:58:41 +02:00
|
|
|
# Button add output
|
Logic Node - On Swipe
The node for the swipe event.
Input parameters:
- Time - duration of the swipe (default value 0.15 s);
- Min Length (px) - the minimum length that the swipe must “pass” (default value 100 px).
Output parameters:
- Direction - normalized vector of the swipe direction;
- Length (px) - the length of the swipe (to assess the “strength”);
The Length output parameter is calculated by the vector value (without normalization) to relate to the input value.
- Angle (0-360) - swipe angle in the range from 0 to 360 degrees (0 is on the right, i.e. Vector (1, 0) = 0 degrees).
- States are states with direction output (Up, Down …). By default, they are not displayed, but if you press “Add 4 State”, then 4 states will appear (Up, Down, Left, Right) and if again, then 8 states will already be displayed.
Determining direction for a state:
for 4 directions - "circle" is divided into 4 segments of 90 degrees;
for 8 directions - "circle" is divided into 8 segments of 45 degrees.
2020-09-15 08:08:59 +02:00
|
|
|
op = column.operator('arm.add_output_4_parameters', text='Add 4 States', icon='PLUS', emboss=True)
|
|
|
|
op.node_index = str(id(self))
|
|
|
|
# Disable/Enabled button
|
|
|
|
if (len(self.outputs) == self.max_outputs):
|
2020-09-28 15:58:41 +02:00
|
|
|
column.enabled = False
|
Logic Node - On Swipe
The node for the swipe event.
Input parameters:
- Time - duration of the swipe (default value 0.15 s);
- Min Length (px) - the minimum length that the swipe must “pass” (default value 100 px).
Output parameters:
- Direction - normalized vector of the swipe direction;
- Length (px) - the length of the swipe (to assess the “strength”);
The Length output parameter is calculated by the vector value (without normalization) to relate to the input value.
- Angle (0-360) - swipe angle in the range from 0 to 360 degrees (0 is on the right, i.e. Vector (1, 0) = 0 degrees).
- States are states with direction output (Up, Down …). By default, they are not displayed, but if you press “Add 4 State”, then 4 states will appear (Up, Down, Left, Right) and if again, then 8 states will already be displayed.
Determining direction for a state:
for 4 directions - "circle" is divided into 4 segments of 90 degrees;
for 8 directions - "circle" is divided into 8 segments of 45 degrees.
2020-09-15 08:08:59 +02:00
|
|
|
# Button remove output
|
|
|
|
column = row.column(align=True)
|
|
|
|
op2 = column.operator('arm.remove_output_4_parameters', text='', icon='X', emboss=True)
|
|
|
|
op2.node_index = str(id(self))
|
|
|
|
# Disable/Enabled button
|
|
|
|
if (len(self.outputs) == self.min_outputs):
|
|
|
|
column.enabled = False
|
|
|
|
|
|
|
|
# Register custom class
|
|
|
|
bpy.utils.register_class(NodeAddOutputButton)
|
|
|
|
bpy.utils.register_class(NodeRemoveOutputButton)
|
|
|
|
|
|
|
|
# Add Node
|
2020-09-25 00:49:21 +02:00
|
|
|
add_node(OnSwipeNode, category=PKG_AS_CATEGORY, section='Input')
|