aboutsummaryrefslogtreecommitdiffstats
path: root/tests/manual/loader/main.qml
blob: d9ea5fc5d7f2ce3852be670e6b24da5a3a7065bb (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
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

import QtQuick
import QtQuick.Window
import QtQuick3D

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Loader Test")

    Component {
        id: cubeModel
        Model {
            source: "#Cube"
            materials: DefaultMaterial {
                diffuseColor: "red"
            }
            PropertyAnimation on eulerRotation.x {
                from: 0
                to: 360
                running: true
                duration: 1000
                loops: Animation.Infinite
            }
        }
    }

    View3D {
        id: view
        anchors.fill: parent

        DirectionalLight {

        }

        PerspectiveCamera {
            z: 600
        }
        Repeater3D {
            model: 100
            Loader3D {
                id: modelLoader
                position: Qt.vector3d(randomWithRange(-300, 300),
                                      randomWithRange(-300, 300),
                                      randomWithRange(-300, 300))
                source: "TestModel.qml"

                Timer {
                    interval: 1000
                    running: true
                    repeat: true
                    property bool toggle: true
                    onTriggered: {
                        if (toggle)
                            modelLoader.sourceComponent = cubeModel;
                        else
                            modelLoader.source = "TestModel.qml"
                        toggle = !toggle;
                    }
                }
            }
        }
    }

    function randomWithRange(min, max) {
        return Math.floor(Math.random() * (max - min + 1) ) + min;
    }

}