Table of Contents

,

Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorRenderableLight

ECBehaviorRenderableLight

Behavior element behavior matching renderable to light intensity.

This behavior is useful for model with an emissive texture where the emissivity intensity should be synchronized to light intensity. A typical example for this is a flashlight where the front side texture lights up if the flashlight is switched on.

To use this behavior add an ECBehaviorDynamicSkin and an ECBehaviorLight to the element class before adding this behavior. Create ECBehaviorRenderableLight behavior and set the dynamic skin and light identifier.

The current light intensity and color can be used for the renderable. If the respective renderable name is not empty string the value is applied. Each one adds an individual renderable if used.

If intensity is applied the renderable is of type DynamicSkinRenderableType.value with the value set to the light intensity multiplied by an intensity scaling factor. This factor defaults to 1 which roughly equals a light source covered by a diffuse glass panel. Usually emissivity is stronger than the light intensity. The value to use here depends on various physical properties and can go up to 32 to simulate looking straight into an uncovered light source.

If color is applied the renderable is of type DynamicSkinRenderableType.color with the value set to the light color multiplied component wise by a color scaling factor. This allows tinting textures depending on the light color.

See also:

Instance Counts

Multiple ECBehaviorRenderableLight instances can be added to affect individual dynamic skin textures synchronized to individual ECBehaviorLight instances using their identifiers.

Element Class Properties

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

renderableIntensity

Set name of renderable to create for intensity or empty string if not used.

scaleIntensity

Set scale factor to apply to light intensity.

renderableColor

Set name of renderable to create for color or empty string if not used.

scaleColor

Set scale factor to apply component wise to light color.

Events

This behavior has no events.

Required Behaviors

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

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

API Documentation

ECBehaviorRenderableLight.

Since DragonScript Module Version 1.0

Use Cases

Element Class Example

This example defines an element with a dynamic skin affected by light color.

class MyElement extends BehaviorElementClass
  public var ECBehaviorComponent component
  public var ECBehaviorCollider collider
  public var ECBehaviorLight light
  public var ECBehaviorDynamicSkin dynamicSkin
  public var ECBehaviorRenderableLight renderableLight
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
    light = ECBehaviorLight.new(this, collider)
    dynamicSkin = ECBehaviorDynamicSkin.new(this, collider)
    renderableLight = ECBehaviorRenderableLight.new(this, dynamicSkin, light)
  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='ECBehaviorComponent'/>
  <behavior type='ECBehaviorCollider'/>
  <behavior type='ECBehaviorLight'/>
  <behavior type='ECBehaviorDynamicSkin'/>
 
  <behavior type='ECBehaviorRenderableLight'>
    <!-- optional: use dynamic skin with id instead of empty string -->
    <string name='dynamicSkin'>second</string>
 
    <!-- optional: use light with id instead of empty string -->
    <string name='light'>second</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.renderableColor'>color</string>
    <string name='.renderableIntensity'>intensity</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorRenderableLight' id='second'/>
</elementClass>

Live Examples