|
|
|
@ -15,6 +15,7 @@
|
|
|
|
|
|
|
|
|
|
import bpy |
|
|
|
|
from bpy.props import * |
|
|
|
|
import mathutils |
|
|
|
|
from PyHSPlasma import * |
|
|
|
|
|
|
|
|
|
from .base import PlasmaModifierProperties, PlasmaModifierLogicWiz |
|
|
|
@ -22,6 +23,67 @@ from ...exporter.explosions import ExportError
|
|
|
|
|
from ...helpers import find_modifier |
|
|
|
|
from ... import idprops |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PlasmaLadderModifier(PlasmaModifierProperties): |
|
|
|
|
pl_id = "laddermod" |
|
|
|
|
|
|
|
|
|
bl_category = "Avatar" |
|
|
|
|
bl_label = "Ladder" |
|
|
|
|
bl_description = "Climbable Ladder" |
|
|
|
|
bl_icon = "COLLAPSEMENU" |
|
|
|
|
|
|
|
|
|
is_enabled = BoolProperty(name="Enabled", |
|
|
|
|
description="Ladder enabled by default at Age start", |
|
|
|
|
default=True) |
|
|
|
|
direction = EnumProperty(name="Direction", |
|
|
|
|
description="Direction of climb", |
|
|
|
|
items=[("UP", "Up", "The avatar will mount the ladder and climb upward"), |
|
|
|
|
("DOWN", "Down", "The avatar will mount the ladder and climb downward"),], |
|
|
|
|
default="DOWN") |
|
|
|
|
num_loops = IntProperty(name="Loops", |
|
|
|
|
description="How many full animation loops after the first to play before dismounting", |
|
|
|
|
min=0, default=4) |
|
|
|
|
facing_object = PointerProperty(name="Facing Object", |
|
|
|
|
description="Target object the avatar must be facing through this region to trigger climb (optional)", |
|
|
|
|
type=bpy.types.Object, |
|
|
|
|
poll=idprops.poll_mesh_objects) |
|
|
|
|
|
|
|
|
|
def export(self, exporter, bo, so): |
|
|
|
|
# Create the ladder modifier |
|
|
|
|
mod = exporter.mgr.find_create_object(plAvLadderMod, so=so, name=self.key_name) |
|
|
|
|
mod.type = plAvLadderMod.kBig |
|
|
|
|
mod.loops = self.num_loops |
|
|
|
|
mod.enabled = self.is_enabled |
|
|
|
|
mod.goingUp = self.direction == "UP" |
|
|
|
|
|
|
|
|
|
# Create vector pointing from the Facing Object to the Detector. |
|
|
|
|
# Animation only activates if the avatar is facing it within |
|
|
|
|
# engine-defined (45 degree) tolerance |
|
|
|
|
if self.facing_object is not None: |
|
|
|
|
# Use object if one has been selected |
|
|
|
|
ladderVec = self.facing_object.matrix_world.translation - bo.matrix_world.translation |
|
|
|
|
else: |
|
|
|
|
# Make our own artificial target -1.0 units back on the local Y axis. |
|
|
|
|
world = bo.matrix_world.copy() |
|
|
|
|
world.invert() |
|
|
|
|
target = bo.location - (mathutils.Vector((0.0, 1.0, 0.0)) * world) |
|
|
|
|
ladderVec = target - bo.matrix_local.translation |
|
|
|
|
mod.ladderView = hsVector3(ladderVec.x, ladderVec.y, 0.0) |
|
|
|
|
mod.ladderView.normalize() |
|
|
|
|
|
|
|
|
|
# Generate the detector's physical bounds |
|
|
|
|
det_name = "{}_LadderDetector".format(self.id_data.name) |
|
|
|
|
bounds = bo.plasma_modifiers.collision.bounds |
|
|
|
|
simIface, physical = exporter.physics.generate_physical(bo, so, bounds, det_name) |
|
|
|
|
physical.memberGroup = plSimDefs.kGroupDetector |
|
|
|
|
physical.reportGroup |= 1 << plSimDefs.kGroupAvatar |
|
|
|
|
physical.boundsType = plSimDefs.kHullBounds |
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
def requires_actor(self): |
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sitting_approach_flags = [("kApproachFront", "Front", "Approach from the font"), |
|
|
|
|
("kApproachLeft", "Left", "Approach from the left"), |
|
|
|
|
("kApproachRight", "Right", "Approach from the right"), |
|
|
|
|