User Tools

Site Tools


dragengine:modules:dragonscript:behavior_component

ECBehaviorComponent

Behavior element behavior adding component support.

Components provide visual appearance to elements.

If the ECBehaviorCollider behavior is present in the behavior element before this behavior is added the component is statically attached. In this case the collider is a ColliderVolume and the rig assigned to the component is only used for animation purpose.

If the ECBehaviorCollider behavior is added after this behavior then a ColliderComponent is created. In this case the component is implicitly attached by ECBehaviorCollider and the component rig is used for collision detection. This is required if you intend to use per-bone collisions matching animation state or physical simulations like rag-dolls.

Hence these two use cases are possible depending on the order the behaviors are added: Shape Collision, Component Collision. See element_class_example.

See also:

Instance Counts

This behavior can be added multiple times to an element. Each instance creates one component which can be individually modified. Use the behavior identifier to tell them apart.

Element Class Properties

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

model

Set path of model resource to use.

  • Full name: component.model or component({id}).model
  • Type: string
  • Default Value: empty string
  • Expected File Type: *.demodel
  • Example (*.deeclass)
    <string name='component.model'>box.demodel</string>

skin

Set path of skin resource to use.

  • Full name: component.skin or component({id}).skin
  • Type: string
  • Default Value: empty string
  • Expected File Type: *.deskin
  • Example (*.deeclass)
    <string name='component.skin'>box.deskin</string>

rig

Set path of rig resource to use.

  • Full name: component.rig or component({id}).rig
  • Type: string
  • Default Value: empty string
  • Expected File Type: *.derig
  • Example (*.deeclass)
    <string name='component.rig'>box.derig</string>

occlusionMesh

Set path of occlusion mesh resource to use.

  • Full name: component.occlusionMesh or component({id}).occlusionMesh
  • Type: string
  • Default Value: empty string
  • Expected File Type: *.deoccmesh
  • Example (*.deeclass)
    <string name='component.occlusionMesh'>box.deoccmesh</string>

audioModel

Set path of audio model resource to use.

  • Full name: component.audioModel or component({id}).audioModel
  • Type: string
  • Default Value: empty string
  • Expected File Type: *.demodel
  • Example (*.deeclass)
    <string name='component.audioModel'>box.demodel</string>

renderEnvMap

Set if component is rendered in environment maps.

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

affectsAudio

Set if component is affecting audio.

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

hintMovement

Set movement hint.

  • Full name: component.hintMovement or component({id}).hintMovement
  • Type: enumeration
  • Allowed Values:

    ValueDescription
    stationaryComponent remains static for the entire lifetime.
    jitteringComponent remains mostly static jittering in a small area.
    dynamicComponent moves around freely.
  • Default Value: stationary
  • Example (*.deeclass)
    <string name='component.hintMovement'>dynamic</string>

enableGI

Set enable GI in graphic module if supported.

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

hintGIImportance

Set GI important hint. Value is in the range from 0 (very unimportant) to 4 (very important). This hint can be used by the graphic module to improve performance by excluding components with a GI important below a user chosen threashold.

  • Full name: component.hintGIImportance or component({id}).hintGIImportance
  • Type: integer
  • Default Value: 4
  • Restriction: At least 0 and at most 4
  • Example (*.deeclass)
    <integer name='component.hintGIImportance'>3</integer>

textureReplacements

Set texture replacements.

  • Full name: component.textureReplacements or component({id}).textureReplacements
  • Type: map
  • Default Value: 4
  • Restriction: At least 0 and at most 4
  • Example (*.deeclass)

    <map name='component.textureReplacements'>
      <!-- define texture replacement with unique identifier 'material' -->
      <map key='material'>
        <!-- optional: path to skin to replace texture with -->
        <string key='skin'>different_material.deskin</string>
     
        <!-- optional: apply tinting to material. requires color type renderable named 'tint' -->
        <color key='tint' r='0.5' g='0.8' b='1'/>
     
        <!-- optional: transform texture coordinates -->
        <map key='transform'>
          <!-- optional: texture coordinate scaling with center of texture as origin -->
          <vector2 key='scale' x='2' y='2'/>
     
          <!-- optional: texture coordinate rotation with center of texture as pivot point -->
          <float key='rotate'>90</float>
     
          <!-- optional: texture coordinate translation -->
          <vector2 key='translate' x='0.5' y='0'/>
        </map>
      </map>
    </map>

Events

This behavior has no events.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

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

API Documentation

ECBehaviorComponent.

Since DragonScript Module Version 1.0

Use Cases

  • Add visual presence to element.

Element Class Example

Use Case 1: Shape Collision. Component is only visual. For collision only static collision shape is used. The component is attached statically to the collider and does not collide. If collider is dynamic physics simulation will be done using collision shape only.

class MyElementClass extends BehaviorElementClass
  public var ECBehaviorCollider collider
  public var ECBehaviorComponent component
  func new()
    collider = ECBehaviorCollider.new(this, null)
    // assign collision shape or collision rig to the collider
    component = ECBehaviorComponent.new(this, collider)
  end
end

Use Case 2: Component Collision. Component is used for collision detection. If collider is dynamic component bones will be updated by the collider automatically.

class MyElementClass extends BehaviorElementClass
  public var ECBehaviorCollider collider
  public var ECBehaviorComponent component
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
  end
end

Behavior Factory

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

Use Case 1: Shape Collision

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorCollider'>
    <!-- no behavior has been added before so no component behavior will be used -->
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.physicsType'>dynamic</string>
  </behavior>
 
  <!-- adding the component will detect the previously added collider and use it -->
  <behavior type='ECBehaviorComponent'>
    <!-- optional: set layer mask as list of bits to set. default is '0' which means
                   BaseGameApp.WorldLayerBit.default -->
    <string name='layerMask'>0 1</string>
 
    <!-- optional: set render env map layer mask as list of bits to set. default is '1'
                   which means BaseGameApp.WorldLayerBit.envmap . if 'renderEnvMap' is
                   true this layer mask is OR combined with 'layerMask' -->
    <string name='layerMaskRenderEnvMap'>0 1</string>
 
    <!-- optional: set audio layer mask as list of bits to set. default is '2' which
                   means BaseGameApp.WorldLayerBit.audio . if 'affectsAudio' is
                   true this layer mask is OR combined with 'layerMask' -->
    <string name='layerMaskAffectsAudio'>0 1</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.model'>box.demodel</string>
  </behavior>
</elementClass>

Use Case 2: Component Collision.

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <!-- no collider is present yet so component will not use any collider -->
  <behavior type='ECBehaviorComponent'>
    ...
  </behavior>
 
  <behavior type='ECBehaviorCollider'>
    <!-- optional: by default the previously added component is detected and used.
                   to use a different component add one with a different id and
                   use the id here -->
    <string name='component'>second</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.physicsType'>dynamic</string>
  </behavior>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_component.txt · Last modified: 2025/03/12 19:35 by dragonlord