User Tools

Site Tools


dragengine:modules:dragonscript:behavior_lightanimation

ECBehaviorLightAnimation

Behavior element behavior adding animation support to ECBehaviorLight

This behavior modifies the light parameters of ECBehaviorLight instances present in the element using move keyframes stored in an Animation or ECBehaviorComponent state. Animation playback starts when the light becomes activated and stops (and resets) if reactivated.

To use this behavior add first an ECBehaviorLight. Adding ECBehaviorLightAnimation will then register itself as listener to the ECBehaviorLight and also set it to use custom light handling.

Using Animation keyframes from a move is used to animate the light parameters.

Using ECBehaviorComponent the animated state is used to animate the light parameters. In this case the play time is 0 since the component state is typically driven by an animator or manually.

The input values obtained either from animation keyframes or component state is remapped before applying to the light parameter. This linearly maps the lower remap value (default 0) to 0 output value and the upper remap value (default 1) to 1 output value. Values outside the remap range are extrapolated.

Remapping is applied before scaling.

Instance Counts

Multiple ECBehaviorLightAnimation instances can be added to affect individual ECBehaviorLight instances like this example below.

class MyElement extends BehaviorElementClass
    func new()
        var ECBehaviorLight light1 = ECBehaviorLight.new(this)
        ECBehaviorLightAnimation.new(this, light1)
 
        var ECBehaviorLight light2 = ECBehaviorLight.new(this, "subLight")
        ECBehaviorLightAnimation.new(this, light2)
    end
end

Element Class Properties

Element class properties have the prefix lightAnimation. or lightAnimation({id}). if id is not empty.

animation

Set path to animation to use. Animation move based animation is used only if animation is set.

  • Full name: lightAnimation.animation or lightAnimation({id}).animation
  • Type: string
  • Default Value: empty string
  • Expected File Pattern: *.deanim (all supported animation type modules)
  • Example (*.deeclass)
    <string name='lightAnimation.animation'>light.deanim</string>

move

Set move name to use. Animation move based animation is used only if move is set.

  • Full name: lightAnimation.move or lightAnimation({id}).move
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='lightAnimation.move'>flicker</string>

enabled

Set if animation playback is enabled.

  • Full name: lightAnimation.enabled or lightAnimation({id}).enabled
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass)
    <boolean name='lightAnimation.enabled'>false</boolean>

playSpeed

Set playback speed. Value of 1 plays back at normal speed. Values larger than 1 play back faster. Values less then 1 play back slower.

  • Full name: lightAnimation.playSpeed or lightAnimation({id}).playSpeed
  • Type: float
  • Default Value: 1
  • Example (*.deeclass)
    <float name='lightAnimation.playSpeed'>0.5</float>

trigger

Set enabled trigger. If no trigger is set the state of enabled property is used.

  • Full name: lightAnimation.trigger or lightAnimation({id}).trigger
  • Type: string
  • Default Value: state of enabled
  • Example (*.deeclass)
    <string name='lightAnimation.trigger'>@switchOnLight & @powerEnabled</string>

light parameters

For each light parameter a set of properties can be defined. Replace <parameter> with one of the values from the following list:

ValueDescription
colorRedRed light color.
colorGreenGreen light color.
colorBlueBlue light color.
intensityLight intensity.
rangeLight range in meters. Beyond this range light has no effect.
halfIntensityDistanceLight half intensity distance (0 to 1). At this position the light dropped to 50% strength. Allows to shape fall-off curve. A value of 0.1 is natural fall-off. Values larger than 0.1 make light fall off faster near the light source. Values smaller than 0.1 make light fall off faster near the light range.
ambientRatioLight ambient ratio (0 to 1). Percentage of total light to use as ambient light.
spotAngleLight spot angle in degrees (opening angle).
spotRatioLight spot ratio as height divided by width (0 to 1). Hence this is the aspect ratio of the spot light.
spotSmoothnessLight spot smoothness (0 to 1). Percentage distance from border to center where light fall-off begins. A value of 0 produces constant light intensity across the entire spot cone. A value of 1 produces linear fade across the entire spot cone.
spotExponentLight spot exponent (0 or greater). Shape of light fall-off from spot center to spot border. A value of 1 is linear fall-off. Values larger than 0.1 make light fall off faster near the spot center. Values smaller than 0.1 make light fall off faster near the spot border.

<parameter>.target

Set target to obtain value from. If <parameter>.parameter is weight target is the name of the vertex position set to use. Otherwise target is the name of the bone to use.

  • Full name: lightAnimation.<parameter>.target or lightAnimation({id}).<parameter>.target
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='lightAnimation.colorRed.target'>color red</string>

<parameter>.parameter

Set which value to use of <parameter>.target.

  • Full name: lightAnimation.<parameter>.parameter or lightAnimation({id}).<parameter>.parameter
  • Type: enumeration
  • Allowed Values:

    ValueDescription
    positionXBone local position X coordinate.
    positionYBone local position Y coordinate.
    positionZBone local position Z coordinate.
    rotationXBone local rotation X coordinate in degrees.
    rotationYBone local rotation Y coordinate in degrees.
    rotationZBone local rotation Z coordinate in degrees.
    scaleXBone local scale X coordinate.
    scaleYBone local scale Y coordinate.
    scaleZBone local scale Z coordinate.
    weightVertex position set weight.
  • Default Value: positionZ
  • Example (*.deeclass)
    <string name='lightAnimation.colorRed.parameter'>positionZ</string>

<parameter>.remapLower

Set lower remap value. Input values obtained from target is remapped before applying to the light parameter. This linearly maps the lower remap value (default 0) to 0 output value and the upper remap value (default 1) to 1 output value. Values outside the remap range are extrapolated.

  • Full name: lightAnimation.<parameter>.remapLower or lightAnimation({id}).<parameter>.remapLower
  • Type: float
  • Default Value: 0
  • Example (*.deeclass)
    <float name='lightAnimation.colorRed.remapLower'>0.5</float>

<parameter>.remapUpper

Set upper remap value. Input values obtained from target is remapped before applying to the light parameter. This linearly maps the lower remap value (default 0) to 0 output value and the upper remap value (default 1) to 1 output value. Values outside the remap range are extrapolated.

  • Full name: lightAnimation.<parameter>.remapUpper or lightAnimation({id}).<parameter>.remapUpper
  • Type: float
  • Default Value: 1
  • Example (*.deeclass)
    <float name='lightAnimation.colorRed.remapUpper'>1.5</float>

Events

This behavior provides no events:

Behavior Tree Actions

This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace lightAnimation with lightAnimation(id).

lightAnimation.set

Set one or more light parameters.

ParameterValueDescription
enabledtrue, falseSet if animation is enabled
timefloatSet animation time in seconds
time.relativefloatSet animation time in percentage from 0 (begin) to 1 (end)

This is an example of using this action:

<action name='lightAnimation.set'>
  <parameter name='enabled'>true</parameter>
</action>

lightAnimation.check

Check one or more light parameters. Action succeeds if all parameter value matches their respective light parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a light parameter matches (or not).

ParameterValueDescription
enabledtrue, falseAnimation is enabled
time.lessfloatAnimation time is less than value in seconds
time.greaterfloatAnimation time is greater than value in seconds
time.relative.lessfloatRelative animation time (0=begin, 1=end) is less than value in seconds
time.relative.greaterfloatRelative animation time (0=begin, 1=end) is greater than value in seconds
wait If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled

This is an example of using this action:

<sequence>
  <action name='lightAnimation.check'>
    <parameter name='enabled'>true</parameter>
    <parameter name='time.less'>3</parameter>
  </action>
  <!-- actions here run only if animation is enabled and playback time is less than 3 seconds -->
</sequence>

Behavior Tree Conditions

This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace lightAnimation with lightAnimation(id).

lightAnimation.check

Check one or more light parameters. Conditions returns true if all parameter value match their respective light parameter. This condition is typically used to run an action or sequence of actions as long as light conditions are true.

ParameterValueDescription
lightAnimation.enabledtrue, falseAnimation is enabled
lightAnimation.time.lessfloatAnimation time is less than value in seconds
lightAnimation.time.greaterfloatAnimation time is greater than value in seconds
lightAnimation.time.relative.lessfloatRelative animation time (0=begin, 1=end) is less than value in seconds
lightAnimation.time.relative.greaterfloatRelative animation time (0=begin, 1=end) is greater than value in seconds

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='lightAnimation.enabled'>true</parameter>
  <parameter name='lightAnimation.time.less'>3</parameter>
  <condition>lightAnimation.check</condition>
</action>

State Machine Actions

State Machine Conditions

State Machine Events

This behavior sends no state machine events.

Required Behaviors

Optional Behaviors

Persistency

This behavior does support element class to be persistable (setPersistable).

API Documentation

ECBehaviorLightAnimation.

Since DragonScript Module Version 1.28

Use Cases

  • Animate light parameters for example to create a flickering light bulb.
  • Animate light parameters depending on the animation state of a component for example a robot arm location.

Element Class Example

This example defines an element which contains a light which is animated.

class MyElement extends BehaviorElementClass
  public var ECBehaviorLight light
  public var ECBehaviorLightAnimation lightAnimation
  func new()
    light = ECBehaviorLight.new(this, null)
    light.getLight().getColor().setColor(Color.white)
    light.getLight().getIntensity().setValue(10)
    
    lightAnimation = ECBehaviorLightAnimation.new(this, light)
    lightAnimation.getAnimation().setPath("/content/light/bulb.deanim")
    lightAnimation.getMove().setValue("flicker")
    lightAnimation.getLightParameter(ECBehaviorLightAnimation.LightParameter.intensity).getTarget().setValue("light.intensity")
  end
end

Behavior Factory

Using element class supporting adding behaviors the behavior can be added like this:

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorLight'>
    <color name='.color' r='1' g='1' b='1'/>
    <float name='.intensity'>10</float>
  </behavior>
 
  <behavior type='ECBehaviorLightAnimation'>
    <!-- optional: use BaseGameApp trigger table. game can add more supported values.
                  default value is 'default' -->
    <string name='triggerTable'>default</string>
 
    <!-- optional: identifier of ECBehaviorTriggered to synchronize with or empty
                   string to not synchronize. default is empty string. -->
    <string name='trigger.synchronize'>other</string>
 
    <!-- optional: use behavior tree with id instead of empty string -->
    <string name='behaviorTree'>second</string>
 
    <!-- optional: use state machine with id instead of empty string -->
    <string name='stateMachine'>second</string>
 
    <!-- optional: light behavior to use instead of default one -->
    <string name='light'>other</string>
 
    <!-- optional: component behavior to use instead of default one if present -->
    <string name='component'>second</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.animation'>/content/light/bulb.deanim</string>
    <string name='.move'>flicker</string>
    <string name='.intensity.target'>intensity</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorLightAnimation' id='second'/>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_lightanimation.txt · Last modified: 2025/07/06 12:55 by dragonlord