Babylon.js v3.1 introduced a new component based tools: the behaviors. A behavior is a simple class that can be attached to a node where it will provide a specific set of features. Features will be triggered by defined events.
A behavior is defined by the following interface:
name
: Return the name of the behaviorattach(node)
: This function will be called when a behavior is attached to a node. This is where the behavior will hook into useful eventsdetach(node)
: This function will be called when a behavior is detached from a node. The behavior must clear any associated resources and unhook all eventsIf behaviors rely on animation, the following static properties will be available:
EasingFunction
: Define the easing function used animationsEasingMode
: Define the easing mode used by animationsYou can add behaviors to node objects (lights, cameras and meshes). Every node provides the following entry points:
addBehavior(behavior)
: Use this function to attach a behavior to a given noderemoveBehavior(behavior)
: Use this function to detach a behavior from a nodegetBehaviorByName(name)
: Return a behavior with the given name or null if not foundbehaviors
: This read-only property returns the list of behaviors associated with the nodeMost of the time, behaviors are designed to deal with a specific kind of nodes.
Currently the list of behaviors available in babylon.js core are camera behaviours.