Files
LNXSDK/leenkx/blender/lnx/logicnode/physics/LN_on_contact.py

53 lines
2.0 KiB
Python

from lnx.logicnode.lnx_nodes import *
def toggle_second_input(self, context):
"""Show/hide the second input socket based on the 'On Any Object' checkbox"""
if self.property1: # "On Any Object" is enabled
# Hide the second input socket
if len(self.inputs) > 1:
self.inputs.remove(self.inputs.values()[-1])
else: # "On Any Object" is disabled
# Show the second input socket if it doesn't exist
if len(self.inputs) == 1:
self.add_input('LnxNodeSocketObject', 'RB 2')
class OnContactNode(LnxLogicTreeNode):
"""Activates the output when the rigid body make contact with
another rigid body.
@option Begin: the output is activated on the first frame when the
two objects have contact
@option End: the output is activated on the frame after the last
frame when the two objects had contact
@option Overlap: the output is activated on each frame the object
have contact
"""
bl_idname = 'LNOnContactNode'
bl_label = 'On Contact'
lnx_section = 'contact'
lnx_version = 1
property0: HaxeEnumProperty(
'property0',
items = [('begin', 'Begin', 'The contact between the rigid bodies begins'),
('overlap', 'Overlap', 'The contact between the rigid bodies is happening'),
('end', 'End', 'The contact between the rigid bodies ends')],
name='', default='begin')
property1: HaxeBoolProperty(
'property1',
name='On Any Object',
description='If enabled, triggers on contact with any object instead of a specific object',
default=False,
update=toggle_second_input)
def lnx_init(self, context):
self.add_input('LnxNodeSocketObject', 'RB 1')
self.add_input('LnxNodeSocketObject', 'RB 2')
self.add_output('LnxNodeSocketAction', 'Out')
def draw_buttons(self, context, layout):
layout.prop(self, 'property0')
layout.prop(self, 'property1') # "On Any Object" checkbox