summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMäättä Antti <antti.maatta@qt.io>2017-11-14 09:57:33 +0200
committerAntti Määttä <antti.maatta@qt.io>2017-11-14 12:26:45 +0000
commitfb0d5d7d4685d092e887b7c0f1e8993b8d3e0bf7 (patch)
tree594550006a0f3dbc7009d2a7721a8101353fb8c0 /examples
parent8be3eebadf0baa25d2d5d218a51227754e2b9fb8 (diff)
Cleanup QML behavior scripts
Add Qt3DSQmlBehavior in QtStudio3D.Behavior, which can only be used from qml behavior scripts. Impement onInitialize, onUpdate and others as signals. Implement predefined function inside the new type and remove the Qt3DSRuntime context type. Task-number: QT3DS-408 Change-Id: Iefb1d8c39afa5f09a625b6f9131ddc790fa1e4a3 Reviewed-by: Jere Tuliniemi <jere.tuliniemi@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/studio3d/qmlbehaviors/scripts/Billboard.qml42
-rw-r--r--examples/studio3d/qmlbehaviors/scripts/CatchEvents.qml10
-rw-r--r--examples/studio3d/qmlbehaviors/scripts/DateTime.qml6
-rw-r--r--examples/studio3d/qmlbehaviors/scripts/Keyboard.qml14
-rw-r--r--examples/studio3d/qmlbehaviors/scripts/SineWave.qml16
-rw-r--r--examples/studio3d/qmlbehaviors/scripts/Toggle.qml20
6 files changed, 54 insertions, 54 deletions
diff --git a/examples/studio3d/qmlbehaviors/scripts/Billboard.qml b/examples/studio3d/qmlbehaviors/scripts/Billboard.qml
index 45259f1e..7b97dec5 100644
--- a/examples/studio3d/qmlbehaviors/scripts/Billboard.qml
+++ b/examples/studio3d/qmlbehaviors/scripts/Billboard.qml
@@ -58,9 +58,9 @@
<Handler name="stop" formalName="Stop" category="Billboard" description="Stop rotating the parent object." />
]]*/
-import QtQml 2.2
+import QtStudio3D.Behavior 1.0
-QtObject {
+Qt3DSBehavior {
//External:
property string renderCamera
property string billboardType
@@ -78,7 +78,7 @@ QtObject {
running = false;
}
- function onInitialize() {
+ onInitialize: {
if (billboardType === "Face Camera") {
if (!yOnly)
updateFunction = faceCamera;
@@ -96,7 +96,7 @@ QtObject {
start();
}
- function onUpdate() {
+ onUpdate: {
if (!running)
return;
@@ -104,12 +104,12 @@ QtObject {
}
function faceCamera() {
- var cameraTransform = Qt3DSRuntime.calculateGlobalTransform(renderCamera);
+ var cameraTransform = calculateGlobalTransform(renderCamera);
var cameraSpot = cameraTransform.row(3).toVector3d();
- var myTransform = Qt3DSRuntime.calculateGlobalTransform();
+ var myTransform = calculateGlobalTransform();
var mySpot = myTransform.row(3).toVector3d();
- var matrix = Qt3DSRuntime.calculateGlobalTransform(Qt3DSRuntime.getParent()).inverted();
+ var matrix = calculateGlobalTransform(getParent()).inverted();
matrix.m41 = 0;
matrix.m42 = 0;
matrix.m43 = 0;
@@ -118,14 +118,14 @@ QtObject {
.minus(mySpot)
.times(matrix);
- var rotation = Qt3DSRuntime.lookAt(rotateRay);
+ var rotation = lookAt(rotateRay);
setAttributeVector("rotation", rotation);
}
function faceCameraGlobalY() {
- var cameraTransform = Qt3DSRuntime.calculateGlobalTransform(renderCamera);
+ var cameraTransform = calculateGlobalTransform(renderCamera);
var cameraSpot = cameraTransform.row(3).toVector3d();
- var myTransform = Qt3DSRuntime.calculateGlobalTransform();
+ var myTransform = calculateGlobalTransform();
var mySpot = myTransform.row(3).toVector3d();
var rotateRay = cameraSpot.minus(mySpot);
@@ -136,10 +136,10 @@ QtObject {
}
function matchRotation() {
- var cameraTransform = Qt3DSRuntime.calculateGlobalTransform(renderCamera);
+ var cameraTransform = calculateGlobalTransform(renderCamera);
var cameraSpot = cameraTransform.row(3).toVector3d();
- var matrix = Qt3DSRuntime.calculateGlobalTransform(Qt3DSRuntime.getParent()).inverted();
+ var matrix = calculateGlobalTransform(getParent()).inverted();
matrix.m41 = 0;
matrix.m42 = 0;
matrix.m43 = 0;
@@ -149,12 +149,12 @@ QtObject {
.minus(cameraSpot)
.times(matrix);
- var rotation = Qt3DSRuntime.lookAt(rotateRay);
+ var rotation = lookAt(rotateRay);
setAttributeVector("rotation", rotation);
}
function matchRotationGlobalY() {
- var cameraTransform = Qt3DSRuntime.calculateGlobalTransform(renderCamera);
+ var cameraTransform = calculateGlobalTransform(renderCamera);
var cameraSpot = cameraTransform.row(3).toVector3d();
var rotateRay = Qt.vector3d(0, 0, 1)
@@ -162,21 +162,21 @@ QtObject {
.minus(cameraSpot)
var rotation = getAttributeVector("rotation");
- rotation.y = Qt3DSRuntime.lookAt(rotateRay).y;
+ rotation.y = lookAt(rotateRay).y;
setAttributeVector("rotation", rotation);
}
function getAttributeVector(name) {
var vec = Qt.vector3d(0, 0, 0);
- Qt3DSRuntime.getAttribute(name + ".x", vec.x);
- Qt3DSRuntime.getAttribute(name + ".y", vec.y);
- Qt3DSRuntime.getAttribute(name + ".z", vec.z);
+ getAttribute(name + ".x", vec.x);
+ getAttribute(name + ".y", vec.y);
+ getAttribute(name + ".z", vec.z);
return vec;
}
function setAttributeVector(name, vec) {
- Qt3DSRuntime.setAttribute(name + ".x", vec.x);
- Qt3DSRuntime.setAttribute(name + ".y", vec.y);
- Qt3DSRuntime.setAttribute(name + ".z", vec.z);
+ setAttribute(name + ".x", vec.x);
+ setAttribute(name + ".y", vec.y);
+ setAttribute(name + ".z", vec.z);
}
}
diff --git a/examples/studio3d/qmlbehaviors/scripts/CatchEvents.qml b/examples/studio3d/qmlbehaviors/scripts/CatchEvents.qml
index 2aadbc96..45e2bb25 100644
--- a/examples/studio3d/qmlbehaviors/scripts/CatchEvents.qml
+++ b/examples/studio3d/qmlbehaviors/scripts/CatchEvents.qml
@@ -48,12 +48,12 @@
**
****************************************************************************/
-import QtQml 2.2
+import QtStudio3D.Behavior 1.0
-QtObject {
- function onInitialize() {
- Qt3DSRuntime.registerForEvent("onPressureDown", onMouseDown);
- Qt3DSRuntime.registerForEvent("onPressureUp", onMouseUp);
+Qt3DSBehavior {
+ onInitialize: {
+ registerForEvent("onPressureDown", onMouseDown);
+ registerForEvent("onPressureUp", onMouseUp);
}
function onMouseDown() {
diff --git a/examples/studio3d/qmlbehaviors/scripts/DateTime.qml b/examples/studio3d/qmlbehaviors/scripts/DateTime.qml
index bab6db34..11dc2fd8 100644
--- a/examples/studio3d/qmlbehaviors/scripts/DateTime.qml
+++ b/examples/studio3d/qmlbehaviors/scripts/DateTime.qml
@@ -48,13 +48,13 @@
**
****************************************************************************/
-import QtQml 2.2
+import QtStudio3D.Behavior 1.0
-QtObject {
+Qt3DSBehavior {
function onUpdate() {
var date = new Date();
var timeString = date.getDate() + "/" + (date.getMonth()+1) + "/" + date.getFullYear()
+ " " + date.getHours() + ":" + date.getMinutes() + "." + date.getSeconds();
- Qt3DSRuntime.setAttribute("textstring", timeString);
+ setAttribute("textstring", timeString);
}
}
diff --git a/examples/studio3d/qmlbehaviors/scripts/Keyboard.qml b/examples/studio3d/qmlbehaviors/scripts/Keyboard.qml
index 2cdfb8e4..fe1f935e 100644
--- a/examples/studio3d/qmlbehaviors/scripts/Keyboard.qml
+++ b/examples/studio3d/qmlbehaviors/scripts/Keyboard.qml
@@ -59,9 +59,9 @@
<Event name="onDOWNUp" category="Navigation" />
]]*/
-import QtQml 2.2
+import QtStudio3D.Behavior 1.0
-QtObject {
+Qt3DSBehavior {
property var keyNames: ["NOKEY",
"ESCAPE",
"1",
@@ -184,16 +184,16 @@ QtObject {
"PAUSE",
"SCALE"]
- function onInitialize() {
- Qt3DSRuntime.registerForEvent("onKeyDown", onKeyDown);
- Qt3DSRuntime.registerForEvent("onKeyUp", onKeyUp);
+ onInitialize: {
+ registerForEvent("onKeyDown", onKeyDown);
+ registerForEvent("onKeyUp", onKeyUp);
}
function onKeyDown(keyCode) {
- Qt3DSRuntime.fireEvent("on" + keyNames[keyCode] + "Down");
+ fireEvent("on" + keyNames[keyCode] + "Down");
}
function onKeyUp(keyCode) {
- Qt3DSRuntime.fireEvent("on" + keyNames[keyCode] + "Up");
+ fireEvent("on" + keyNames[keyCode] + "Up");
}
}
diff --git a/examples/studio3d/qmlbehaviors/scripts/SineWave.qml b/examples/studio3d/qmlbehaviors/scripts/SineWave.qml
index 179dc370..61303ae2 100644
--- a/examples/studio3d/qmlbehaviors/scripts/SineWave.qml
+++ b/examples/studio3d/qmlbehaviors/scripts/SineWave.qml
@@ -64,9 +64,9 @@
<Event name="onStopped" description="Fires when the Sine Wave is stopped." />
]]*/
-import QtQml 2.2
+import QtStudio3D.Behavior 1.0
-QtObject {
+Qt3DSBehavior {
//External:
property string attribute
property real ampOffset
@@ -82,14 +82,14 @@ QtObject {
function start() {
if (!running) {
running = true;
- Qt3DSRuntime.fireEvent("onStarted");
+ fireEvent("onStarted");
}
}
function stop() {
if (running) {
running = false;
- Qt3DSRuntime.fireEvent("onStopped");
+ fireEvent("onStopped");
}
}
@@ -100,7 +100,7 @@ QtObject {
start();
}
- function onInitialize() {
+ onInitialize: {
if (attribute.indexOf("rotation") != -1)
inDegrees = true;
@@ -108,7 +108,7 @@ QtObject {
start();
}
- function onUpdate() {
+ onUpdate: {
if (!running)
return;
@@ -117,8 +117,8 @@ QtObject {
amplitude *= (Math.PI / 180);
}
- elapsedTime += Qt3DSRuntime.getDeltaTime();
+ elapsedTime += getDeltaTime();
var value = ampOffset + amplitude * Math.cos(elapsedTime * Math.PI * 2 / period);
- Qt3DSRuntime.setAttribute(attribute, value);
+ setAttribute(attribute, value);
}
}
diff --git a/examples/studio3d/qmlbehaviors/scripts/Toggle.qml b/examples/studio3d/qmlbehaviors/scripts/Toggle.qml
index 4c91c117..a6921477 100644
--- a/examples/studio3d/qmlbehaviors/scripts/Toggle.qml
+++ b/examples/studio3d/qmlbehaviors/scripts/Toggle.qml
@@ -62,9 +62,9 @@
<Event name="onUntoggle" description="Fires when untoggled." />
]]*/
-import QtQml 2.2
+import QtStudio3D.Behavior 1.0
-QtObject {
+Qt3DSBehavior {
//External:
property string attribute
property real firstValue
@@ -78,7 +78,7 @@ QtObject {
function start() {
running = true;
- Qt3DSRuntime.setAttribute(attribute, firstValue);
+ setAttribute(attribute, firstValue);
}
function stop() {
@@ -87,27 +87,27 @@ QtObject {
function toggle() {
if (index == 0) {
- Qt3DSRuntime.setAttribute(attribute, secondValue);
- Qt3DSRuntime.fireEvent("onToggle");
+ setAttribute(attribute, secondValue);
+ fireEvent("onToggle");
} else if (index == 1) {
- Qt3DSRuntime.setAttribute(attribute, firstValue);
- Qt3DSRuntime.fireEvent("onUntoggle");
+ setAttribute(attribute, firstValue);
+ fireEvent("onUntoggle");
}
index++;
if (index > 1)
index = 0;
}
- function onInitialize() {
+ onInitialize: {
if (startImmediately)
start();
}
- function onUpdate() {
+ onUpdate: {
if (!running)
return;
- timer += Qt3DSRuntime.getDeltaTime();
+ timer += getDeltaTime();
var interval = timerInterval / 1000;
while (timer >= interval) {
timer -= interval;