From 4ecf262c613695927eea404c3267ecd92402fe26 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 8 Jun 2015 19:47:40 -0400 Subject: [PATCH] Footstep Region Modifier: Logic Node test case This commit adds a footstep region modifier that exports nothing at the moment. This is just a test case for logic node generation. If you want to bake footstep regions into logic nodes, select an object and execute `bpy.ops.object.plasma_logicwiz()`. :) --- korman/operators/op_modifier.py | 25 +++++++++++++ korman/properties/modifiers/base.py | 15 ++++++++ korman/properties/modifiers/region.py | 53 ++++++++++++++++++++++++++- korman/ui/modifiers/region.py | 4 ++ 4 files changed, 96 insertions(+), 1 deletion(-) diff --git a/korman/operators/op_modifier.py b/korman/operators/op_modifier.py index 6b5311f..6c4e882 100644 --- a/korman/operators/op_modifier.py +++ b/korman/operators/op_modifier.py @@ -15,6 +15,7 @@ import bpy from bpy.props import * +import time from ..properties import modifiers @@ -123,3 +124,27 @@ class ModifierMoveDownOperator(ModifierMoveOperator, bpy.types.Operator): if self.active_modifier < last: self.swap_modifier_ids(plmods, self.active_modifier, self.active_modifier+1) return {"FINISHED"} + + +class ModifierLogicWizOperator(ModifierOperator, bpy.types.Operator): + bl_idname = "object.plasma_logicwiz" + bl_label = "Plasma LogicWiz" + bl_description = "Generates logic nodes from a given modifier on the active object" + + modifier = StringProperty(name="Modifier", default="footstep") + + def execute(self, context): + obj = context.active_object + mod = getattr(obj.plasma_modifiers, self.modifier) + + print("--- Plasma LogicWiz ---") + print("Object: '{}'".format(obj.name)) + print("Modifier: '{}'".format(self.modifier)) + if not mod.enabled: + print("WRN: This modifier is not actually enabled!") + + start = time.process_time() + mod.logicwiz(obj) + end = time.process_time() + print("\nLogicWiz finished in {:.2f} seconds".format(end-start)) + return {"FINISHED"} diff --git a/korman/properties/modifiers/base.py b/korman/properties/modifiers/base.py index a8a5211..3432682 100644 --- a/korman/properties/modifiers/base.py +++ b/korman/properties/modifiers/base.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU General Public License # along with Korman. If not, see . +import abc import bpy from bpy.props import * @@ -48,3 +49,17 @@ class PlasmaModifierProperties(bpy.types.PropertyGroup): "default": True, "options": {"HIDDEN"}}) } + + +class PlasmaModifierLogicWiz: + @property + def node_tree(self): + name = "LOGICWIZ_{}".format(self.display_name) + try: + return bpy.data.node_groups[name] + except LookupError: + return bpy.data.node_groups.new(name, "PlasmaNodeTree") + + @abc.abstractmethod + def logicwiz(self, bo): + pass diff --git a/korman/properties/modifiers/region.py b/korman/properties/modifiers/region.py index 708b55e..c3c1152 100644 --- a/korman/properties/modifiers/region.py +++ b/korman/properties/modifiers/region.py @@ -17,7 +17,8 @@ import bpy from bpy.props import * from PyHSPlasma import * -from .base import PlasmaModifierProperties +from .base import PlasmaModifierProperties, PlasmaModifierLogicWiz +from .physics import bounds_types footstep_surface_ids = { "dirt": 0, @@ -53,6 +54,56 @@ footstep_surfaces = [("dirt", "Dirt", "Dirt"), ("woodfloor", "Wood Floor", "Wood Floor"), ("woodladder", "Wood Ladder", "Wood Ladder")] +class PlasmaFootstepRegion(PlasmaModifierProperties, PlasmaModifierLogicWiz): + pl_id = "footstep" + + bl_category = "Region" + bl_label = "Footstep" + bl_description = "Footstep Region" + + surface = EnumProperty(name="Surface", + description="What kind of surface are we walking on?", + items=footstep_surfaces, + default="stone") + bounds = EnumProperty(name="Region Bounds", + description="Physical object's bounds", + items=bounds_types, + default="hull") + + + def created(self, obj): + self.display_name = "{}_FootRgn".format(obj.name) + + def logicwiz(self, bo): + tree = self.node_tree + nodes = tree.nodes + nodes.clear() + + # Region Sensor + volsens = nodes.new("PlasmaVolumeSensorNode") + volsens.region = bo.data.name + volsens.bounds = self.bounds + volsens.find_input_socket("enter").allow = True + volsens.find_input_socket("exit").allow = True + + # LogicMod + logicmod = nodes.new("PlasmaLogicTriggerNode") + logicmod.link_input(tree, volsens, "satisfies", "condition") + + # Responder + respmod = nodes.new("PlasmaResponderNode") + respmod.link_input(tree, logicmod, "trigger", "whodoneit") + respstate = nodes.new("PlasmaResponderStateNode") + respstate.link_input(tree, respmod, "states", "whodoneit") + respstate.find_input_socket("whodoneit").default_state = True + respcmd = nodes.new("PlasmaResponderCommandNode") + respcmd.link_input(tree, respstate, "cmds", "whodoneit") + + # ArmatureEffectStateMsg + msg = nodes.new("PlasmaFootstepSoundMsgNode") + msg.link_input(tree, respcmd, "msg", "sender") + msg.surface = self.surface + class PlasmaPanicLinkRegion(PlasmaModifierProperties): pl_id = "paniclink" diff --git a/korman/ui/modifiers/region.py b/korman/ui/modifiers/region.py index 111967d..823e408 100644 --- a/korman/ui/modifiers/region.py +++ b/korman/ui/modifiers/region.py @@ -13,6 +13,10 @@ # You should have received a copy of the GNU General Public License # along with Korman. If not, see . +def footstep(modifier, layout, context): + layout.prop(modifier, "bounds") + layout.prop(modifier, "surface") + def paniclink(modifier, layout, context): split = layout.split() col = split.column()