Browse Source

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()`. :)
pull/6/head
Adam Johnson 10 years ago
parent
commit
4ecf262c61
  1. 25
      korman/operators/op_modifier.py
  2. 15
      korman/properties/modifiers/base.py
  3. 53
      korman/properties/modifiers/region.py
  4. 4
      korman/ui/modifiers/region.py

25
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"}

15
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 <http://www.gnu.org/licenses/>.
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

53
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"

4
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 <http://www.gnu.org/licenses/>.
def footstep(modifier, layout, context):
layout.prop(modifier, "bounds")
layout.prop(modifier, "surface")
def paniclink(modifier, layout, context):
split = layout.split()
col = split.column()

Loading…
Cancel
Save