summaryrefslogtreecommitdiffstats
path: root/doc/src/06-qml-reference/Behavior.qdoc
blob: da14c63858a97d611fb368e47441f535e7a161a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \qmltype Behavior
    \brief Technology Preview Behavior Integration

    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 \l {file-formats-effects.html}{effect}
    and \l {file-formats-material.html}{material} files.

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

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

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

    Secondly, the QML behavior script needs access to the QML module.
    \badcode
import QtStudio3D.Behavior 1.0
    \endcode

    Finally, the Behavior type needs to be implemented in the qml script.
    \badcode
Behavior {
    id: mybehavior

    function onInitialize() {
        ...
    }

    function onActivate() {
        ...
    }

    function onUpdate() {
        ...
    }

    function onDeactivate() {
        ...
    }

    function someHandlerName() {
        ...
        fireEvent("onSomeEvent")
    }
}
    \endcode
*/

/*!
    \qmlmethod float Behavior::getDeltaTime()

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

/*!
    \qmlmethod float Behavior::getAttribute(string attribute)

    Returns the value of the given \a attribute.
*/

/*!
    \qmlmethod void Behavior::setAttribute(string attribute, var value)

    Sets the \a value of the given \a attribute.
*/

/*!
    \qmlmethod void Behavior::setAttribute(string handle, string attribute, var value)

    Sets the \a value of the given \a attribute for a given \a handle.
*/

/*!
    \qmlmethod void Behavior::fireEvent(string event)

    Fires the given \a event.
*/

/*!
    \qmlmethod void Behavior::registerForEvent(string event, QJSValue function)

    Registers the script for an \a event with the handler \a function.
*/

/*!
    \qmlmethod void Behavior::registerForEvent(string handle, string event, QJSValue function)

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

/*!
    \qmlmethod void Behavior::unregisterForEvent(string event)

    Unregisters the script from an \a event.
*/

/*!
    \qmlmethod void Behavior::unregisterForEvent(string handle, string event)

    Unregisters the script from an \a event for a given \a handle.
*/

/*!
    \qmlmethod vector2d Behavior::getMousePosition()

    Returns the current position of the mouse in presentation coordinates.
*/

/*!
    \qmlmethod matrix4 Behavior::calculateGlobalTransform(string handle)

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

/*!
    \qmlmethod vector3d Behavior::lookAt(vector3d target)

    Returns the rotation angles of the look at \a target.
*/

/*!
    \qmlmethod string Behavior::getParent(string handle)

    Returns the parent of the given \a handle or parent element if the handle is
    empty string.
*/

/*!
    \qmlmethod vector3d Behavior::matrixToEuler(matrix4 matrix)

    Returns the euler angles extracted from the \a matrix rotations.
*/

/*!
    \qmlsignal void Behavior::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 \c{onInitialize} signaled once, even if it is deactivated and
    later reactivated.
 */

/*!
    \qmlsignal void Behavior::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 \c{onActivate} signaled. If
    multiple behaviors match this, the signal for parent elements will
    occur before their descendants.
 */

/*!
    \qmlsignal void Behavior::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 \c{onDeactivate} signaled. If
    multiple behaviors match this, the signal for parent elements will
    occur before their descendants.
 */

/*!
    \qmlsignal void Behavior::onUpdate()

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