C

Behavior QML Type

Technology Preview Behavior Integration More...

Import Statement: import

Signals

Methods

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.

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 1.1

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

matrix4 calculateGlobalTransform(string handle)

Returns the current global transformation of the element specified by the handle or parent element if the handle is empty string.


void fireEvent(string event)

Fires the given event.


float getAttribute(string attribute)

Returns the value of the given attribute.


float getDeltaTime()

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


vector2d getMousePosition()

Returns the current position of the mouse in presentation coordinates.


string getParent(string handle)

Returns the parent of the given handle or parent element if the handle is empty string.


vector3d lookAt(vector3d target)

Returns the rotation angles of the look at target.


vector3d matrixToEuler(matrix4 matrix)

Returns the euler angles extracted from the matrix rotations.


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.


Available under certain Qt licenses.
Find out more.