Skip to content

Commit

Permalink
add setRigBoneAttr
Browse files Browse the repository at this point in the history
  • Loading branch information
IzaZed committed Jun 23, 2024
1 parent 75510f4 commit ad6a52b
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 37 deletions.
16 changes: 1 addition & 15 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"A Node System to create game logic."
),
"author": "pgi, Leopold A-C (Iza Zed)",
"version": (3, 2),
"version": (3, 2, 1),
"blender": (4, 1, 0),
"location": "View Menu",
"category": "Game Engine",
Expand Down Expand Up @@ -307,20 +307,6 @@ class LogicNodeTreeReference(bpy.types.PropertyGroup):
_registered_classes.extend(_menu_items)


###################################################
# DEBUG
###################################################
# text = ''

# for node in _nodes:
# text +=f"- {'(deprecated) ' if node.deprecated else ''}{node.bl_label}\n"
# text += f'Total Nodes: {len(_nodes)}'

# with open("D:/Data/nodes.txt", 'w') as f:
# f.write(text)
# f.close()
###################################################

def _get_key_for_class(c):
if hasattr(c, "bl_label"):
return c.bl_label
Expand Down
2 changes: 1 addition & 1 deletion editor/enum_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
("cross", "Cross Product", "Project A onto B"),
None,
("normalize", "Normalize", "Rescale all values to 0 - 1"),
("lerp", "Lerp", "Linear Interpolation between the two vectors"),
("lerp", "Mix (Lerp)", "Linear Interpolation between the two vectors"),
("slerp", "Spherical Lerp", "Spherical Interpolation between the two vectors"),
("negate", "Negate", "Multiply all values by -1")
]
Expand Down
1 change: 1 addition & 0 deletions editor/nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .actions.setuiwidgetattr import LogicNodeSetUIWidgetAttr
from .actions.togglefilter import LogicNodeToggleFilter
from .actions.draw import LogicNodeDraw
from .actions.setrigboneattribute import LogicNodeSetRigBoneAttribute

from .actions.gamepadvibration import LogicNodeGamepadVibration
from .actions.addobject import LogicNodeAddObject
Expand Down
91 changes: 91 additions & 0 deletions editor/nodes/actions/setrigboneattribute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from bpy.types import Context, UILayout
from ..node import node_type
from ..node import LogicNodeActionType
from ...sockets import NodeSocketLogicCondition
from ...sockets import NodeSocketLogicString
from ...sockets import NodeSocketLogicArmature
from ...sockets import NodeSocketLogicBone
from ...sockets import NodeSocketLogicVectorXYZ
from ...sockets import NodeSocketLogicBoolean
from bpy.props import EnumProperty


_attrs = [
("name", "Name", "Name of the Bone"), # String
None,
("head", "Head", "Location of head end of the bone relative to its parent"), # Vector
("head_local", "Local Head", "Location of head end of the bone relative to armature"), # Vector
("tail", "Tail", "Location of tail end of the bone relative to its parent"), # Vector
("tail_local", "Local Tail", "Location of tail end of the bone relative to armature"), # Vector
None,
("inherit_scale", "Inherit Scale", "Specifies how the bone inherits scaling from the parent bone"), # Enum
("inherit_rotation", "Inherit Rotation", "Bone inherits rotation or scale from parent bone"), # Boolean
None,
("connected", "Connected", "When bone has a parent, bone's head is stuck to the parent's tail"), # Boolean
("deform", "Deform", "Enable Bone to deform geometry"), # Boolean
("local_location", "Use Local", "Bone location is set in local space"), # Boolean
("relative_parent", "Use Relative Parent", "Object children will use relative transform, like deform"), # Boolean
("scale_easing", "Scale Easing", "Multiply the final easing values by the Scale In/Out Y factors"), # Boolean
]


_scale_modes = [
("NONE", "None", "Completely ignore parent scaling"),
("FULL", "Full", "Inherit all effects of parent scaling."),
None,
("NONE_LEGACY", "None (Legacy)", "Ignore parent scaling without compensating for parent shear. Replicates the effect of disabling the original Inherit Scale checkbox"),
("FIX_SHEAR", "Fix Shear", "Inherit scaling, but remove shearing of the child in the rest orientation"),
("ALIGNED", "Aligned", "Rotate non-uniform parent scaling to align with the child, applying parent X scale to child X axis, and so forth"),
("AVERAGE", "Average", "Inherit uniform scaling representing the overall change in the volume of the parent")
]


@node_type
class LogicNodeSetRigBoneAttribute(LogicNodeActionType):
bl_idname = "LogicNodeSetRigBoneAttribute"
bl_label = "Set Bone Attribute"
nl_module = 'uplogic.nodes.actions'
nl_class = "SetRigBoneAttributeNode"

def update_draw(self, context=None):
attr = self.attribute
if attr == 'inherit_scale':
self.inputs[3].enabled = False
self.inputs[4].enabled = False
self.inputs[5].enabled = False
elif attr == 'name':
self.inputs[3].enabled = True
self.inputs[4].enabled = False
self.inputs[5].enabled = False
elif attr in ['head', 'head_local', 'tail', 'tail_local']:
self.inputs[3].enabled = False
self.inputs[4].enabled = True
self.inputs[5].enabled = False
else:
self.inputs[3].enabled = False
self.inputs[4].enabled = False
self.inputs[5].enabled = True

attribute: EnumProperty(items=_attrs, name='Attribute', update=update_draw)
scale_mode: EnumProperty(items=_scale_modes, name='Scale Mode', update=update_draw)

def draw_buttons(self, context: Context, layout: UILayout) -> None:
layout.prop(self, 'attribute', text='')
if self.attribute == 'inherit_scale':
layout.prop(self, 'scale_mode', text='')

def get_attributes(self):
return [
('attribute', repr(self.attribute)),
('scale_mode', repr(self.scale_mode))
]

def init(self, context):
self.add_input(NodeSocketLogicCondition, "Condition", 'condition')
self.add_input(NodeSocketLogicArmature, "", 'armature')
self.add_input(NodeSocketLogicBone, "", 'bone', settings={'ref_index': 1})
self.add_input(NodeSocketLogicString, "", 'value')
self.add_input(NodeSocketLogicVectorXYZ, "Vector", 'value')
self.add_input(NodeSocketLogicBoolean, "Bool", 'value')
self.add_output(NodeSocketLogicCondition, 'Done', 'DONE')
LogicNodeActionType.init(self, context)
4 changes: 2 additions & 2 deletions editor/nodes/actions/vehicleaccelerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ..node import LogicNodeActionType
from ...sockets import NodeSocketLogicCondition
from ...sockets import NodeSocketLogicObject
from ...sockets import NodeSocketLogicFloatPositive
from ...sockets import NodeSocketLogicFloat
from ...sockets import NodeSocketLogicIntegerPositive
from ...enum_types import _enum_vehicle_axis
from bpy.props import EnumProperty
Expand Down Expand Up @@ -32,7 +32,7 @@ def init(self, context):
self.add_input(NodeSocketLogicCondition, "Condition", 'condition')
self.add_input(NodeSocketLogicObject, "Vehicle", 'vehicle')
self.add_input(NodeSocketLogicIntegerPositive, "Wheels", 'wheelcount', {'default_value': 2})
self.add_input(NodeSocketLogicFloatPositive, "Power", 'power', {'default_value': 1})
self.add_input(NodeSocketLogicFloat, "Power", 'power', {'default_value': 1})
self.add_output(NodeSocketLogicCondition, 'Done', 'OUT')
LogicNodeActionType.init(self, context)

Expand Down
32 changes: 21 additions & 11 deletions editor/sockets/armaturesocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,31 @@ def draw(self, context, layout, node, text):
else:
if not self.use_owner:
col = layout.column(align=False)
row = col.row()
row = col.row(align=True)
if self.name:
row.label(text=self.name)
row.prop(self, 'use_owner', icon='USER', text='')
col.prop_search(
self,
'default_value',
bpy.context.scene,
'objects',
icon='NONE',
text=''
)
row.prop(self, 'use_owner', icon='USER', text='')
col.prop_search(
self,
'default_value',
bpy.context.scene,
'objects',
icon='NONE',
text=''
)
else:
row.prop_search(
self,
'default_value',
bpy.context.scene,
'objects',
icon='NONE',
text=''
)
row.prop(self, 'use_owner', icon='USER', text='')
else:
row = layout.row()
row.label(text=self.name)
row.label(text='Owner Object')
row.prop(self, 'use_owner', icon='USER', text='')

def get_unlinked_value(self):
Expand Down
2 changes: 1 addition & 1 deletion editor/sockets/bitmasksocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class NodeSocketLogicBitMask(NodeSocket, NodeSocketLogic):
size=16,
default=[True for x in range(16)],
name='Mask',
subtype='LAYER_MEMBER'
# subtype='LAYER_MEMBER' XXX: Reactivate if fixed
)
selected_bit: IntProperty()

Expand Down
8 changes: 6 additions & 2 deletions editor/sockets/stringsocket.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from .socket import SOCKET_COLOR_STRING, SOCKET_TYPE_VALUE, SOCKET_TYPE_STRING, NodeSocketLogic
from .socket import SOCKET_COLOR_STRING
from .socket import SOCKET_TYPE_VALUE
from .socket import SOCKET_TYPE_STRING
from .socket import SOCKET_TYPE_GENERIC
from .socket import NodeSocketLogic
from .socket import socket_type
from .socket import update_draw
from bpy.types import NodeSocket
Expand All @@ -14,7 +18,7 @@ class Base(NodeSocket, NodeSocketLogic):
formatted: BoolProperty(update=update_draw)

nl_color = SOCKET_COLOR_STRING
nl_type = SOCKET_TYPE_STRING
nl_type = SOCKET_TYPE_GENERIC

valid_sockets = [
SOCKET_TYPE_VALUE,
Expand Down
6 changes: 4 additions & 2 deletions ops/addcomponent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..utilities import notify, preferences
from ..utilities import notify, preferences, error, debug
from .operator import operator
from .operator import _enum_components
from .operator import reload_texts
Expand Down Expand Up @@ -47,7 +47,7 @@ def execute(self, context):
continue
if 'args=' in line.body:
in_args = True
if '])' in line.body:
if '])' in line.body and in_args:
cargs += line.body
break
if in_args:
Expand All @@ -61,6 +61,8 @@ def execute(self, context):
select_text.clear()
select_text.write(body)
except Exception as e:
error(f'Could not add component {mod_name}.{comp_name} to object {context.active_object.name}!')
debug(f'Content:\n\n{select_text.as_string()}\n')
select_text.clear()
select_text.write(body)
self.report({"ERROR"}, str(e))
Expand Down
2 changes: 1 addition & 1 deletion ops/nodesearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def add(self):

@operator
class LOGIC_NODES_OT_node_search(bpy.types.Operator):
bl_idname = "bge_netlogic.node_search"
bl_idname = "logic_nodes.node_search"
bl_label = "Node Search"
bl_options = {"REGISTER"}
bl_description = "Search for registered Logic Nodes"
Expand Down
18 changes: 16 additions & 2 deletions ui/node_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,22 @@ class ArmatureRigMenu(bpy.types.Menu):
def draw(self, context):
layout = self.layout
insertNode(layout, "NLParameterBoneStatus", "Bone Status")
# insertNode(layout, "NLActionEditBoneNode", "Edit Bone")
insertNode(layout, "NLActionSetBonePos", "Set Bone Position")
insertNode(layout, "LogicNodeSetRigBoneAttribute", "Set Bone Name", settings={'attribute': repr('name')})
layout.separator()
insertNode(layout, "LogicNodeSetRigBoneAttribute", "Set Bone Head", settings={'attribute': repr('head')})
insertNode(layout, "LogicNodeSetRigBoneAttribute", "Set Bone Local Head", settings={'attribute': repr('head_local')})
insertNode(layout, "LogicNodeSetRigBoneAttribute", "Set Bone Tail", settings={'attribute': repr('tail')})
insertNode(layout, "LogicNodeSetRigBoneAttribute", "Set Bone Local Tail", settings={'attribute': repr('tail_local')})
layout.separator()
insertNode(layout, "LogicNodeSetRigBoneAttribute", "Set Bone Inherit Scale", settings={'attribute': repr('inherit_scale')})
insertNode(layout, "LogicNodeSetRigBoneAttribute", "Set Bone Inherit Rotation", settings={'attribute': repr('use_inherit_rotation')})
layout.separator()
insertNode(layout, "LogicNodeSetRigBoneAttribute", "Set Bone Connected", settings={'attribute': repr('use_connect')})
insertNode(layout, "LogicNodeSetRigBoneAttribute", "Set Bone Deform", settings={'attribute': repr('use_deform')})
insertNode(layout, "LogicNodeSetRigBoneAttribute", "Set Bone Local", settings={'attribute': repr('use_local_location')})
insertNode(layout, "LogicNodeSetRigBoneAttribute", "Set Bone Relative Parent", settings={'attribute': repr('use_relative_parent')})
insertNode(layout, "LogicNodeSetRigBoneAttribute", "Set Bone Scale Easing", settings={'attribute': repr('use_scale_easing')})
# insertNode(layout, "NLActionSetBonePos", "Set Bone Position")


@menu_item
Expand Down

0 comments on commit ad6a52b

Please sign in to comment.