Behavior QML Type | Runtime 2.1

Qt 3D Studio | Runtime | QML Types | Behavior QML Type

Qt 3D Studio Runtime 2.1 Manual

# Behavior QML Type

Technology Preview Behavior Integration. More...

Import Statement: | import .

- List of all members, including inherited members

## Signals

- void onActivate()
- void onDeactivate()
- void onInitialize()
- void onUpdate()

## Methods

- matrix4x4 calculateGlobalTransform(string handle)
- void fireEvent(string event)
- var getAttribute(string handle, string attribute)
- var getAttribute(string attribute)
- float getDeltaTime()
- vector3d lookAt(vector3d target)
- void registerForEvent(string handle, string event, QJSValue function)
- void registerForEvent(string event, QJSValue function)
- void setAttribute(string handle, string attribute, var value)
- void setAttribute(string attribute, var value)
- void setDataInputValue(string name, variant value)
- void unregisterForEvent(string handle, string event)
- void unregisterForEvent(string event)

## Detailed Description

This is a technology preview (API may change in upcoming version) of how Qt 3D Studio could support writing custom behavior scripts using QML and JavaScript. It enables interacting with the runtime using the Behavior QML class exposed to each behavior script.

Note: the Behavior type has its own import and is only available in `behavior scripts` that are attached to scene objects during the design phase in Qt 3D Studio. It is not usable in ordinary QML application code.

In QML behavior script, the integration to Qt 3D Studio is established by using the metadata tag system similar to the effect and material files.

      [[
      <Property name="somePropertyName" ... />

      <Handler name="someHandlerName" ... />

      <Event name="onSomeEvent" ... />
      ...
      ]]

Secondly, the QML behavior script needs access to the QML module.

      import QtStudio3D.Behavior 2.0

Finally, the Behavior type needs to be implemented in the qml script.

      Behavior {
          id: mybehavior

          function onInitialize() {
              ...
          }

          function onActivate() {
              ...
          }

          function onUpdate() {
              ...
          }

          function onDeactivate() {
              ...
          }

          function someHandlerName() {
              ...
              fireEvent("onSomeEvent")
          }
      }

## Signal Documentation

void onActivate()

This signal is emitted when the script becomes active. Any behaviors which were not active last frame that are active this frame will have their `onActivate` signaled. If multiple behaviors match this, the signal for parent elements will occur before their descendants.

void onDeactivate()

This signal is emitted when the script becomes inactive. Any behaviors which were active last frame that are not active this frame will have their `onDeactivate` signaled. If multiple behaviors match this, the signal for parent elements will occur before their descendants.

void onInitialize()

This signal is emitted when the script becomes active the first time. If multiple behaviors match this, the signal for parent elements will occur before their children/descendants.

Note: Each behavior will only have its `onInitialize` signaled once, even if it is deactivated and later reactivated.

void onUpdate()

This signal is emitted on each frame when the script is active. Any behaviors that are active this frame will have their `onUpdate` signaled. If multiple behaviors match this, the signal for parent elements will occur before their descendants.

## Method Documentation

matrix4x4 calculateGlobalTransform(string handle)

Returns the transformation matrix of the object identified with the handle.

void fireEvent(string event)

Fires the given event.

var getAttribute(string handle, string attribute)

Returns the value of the given attribute for a given handle.

var getAttribute(string attribute)

Returns the value of the given attribute.

float getDeltaTime()

Returns the delta time between this and previous frame in milliseconds.

vector3d lookAt(vector3d target)

Returns the euler angles for looking at the target.

void registerForEvent(string handle, string event, QJSValue function)

Registers the script for an event with the handler function for a given handle.

void registerForEvent(string event, QJSValue function)

Registers the script for an event with the handler function.

void setAttribute(string handle, string attribute, var value)

Sets the value of the given attribute for a given handle.

void setAttribute(string attribute, var value)

Sets the value of the given attribute.

void setDataInputValue(string name, variant value)

Sets the value of the data input identified with the name.

void unregisterForEvent(string handle, string event)

Unregisters the script from an event for a given handle.

void unregisterForEvent(string event)

Unregisters the script from an event.