Debian Codegraph @

tests/manual/dynamic-model-loader-qml/main.qml

raw
1 // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 import QtQuick 2.2 as QQ2
5 import Qt3D.Core 2.12
6 import Qt3D.Render 2.0
7 import Qt3D.Input 2.0
8 import Qt3D.Extras 2.0
9
10 Entity {
11 id: sceneRoot
12
13 Camera {
14 id: camera
15 projectionType: CameraLens.PerspectiveProjection
16 fieldOfView: 45
17 aspectRatio: 16/9
18 nearPlane : 0.1
19 farPlane : 1000.0
20 position: Qt.vector3d( 0.0, 0.0, 40.0 )
21 upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
22 viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
23 }
24
25 OrbitCameraController { camera: camera }
26
27 components: [
28 RenderSettings {
29 activeFrameGraph: ForwardRenderer {
30 camera: camera
31 }
32 },
33 // Event Source will be set by the Qt3DQuickWindow
34 InputSettings { }
35 ]
36
37 QQ2.Timer {
38 id: timer
39 interval: 1000
40 running: true
41 repeat: true
42 property bool addMore: true
43 property bool odd: false
44
45 onTriggered: {
46 if (instantiator.model > 10 || instantiator.model < 2)
47 addMore = !addMore
48 instantiator.model += (addMore ? 1 : -1)
49 odd = !odd
50 }
51 }
52
53 PhongMaterial {
54 id: material
55 diffuse: "yellow"
56 }
57
58 NodeInstantiator {
59 id: instantiator
60 model: 2
61 readonly property real angleStep: 360.0 / Math.max(count, 1)
62 EntityLoader {
63 components: Transform {
64 id: revolutionTransform
65 matrix: {
66 var m = Qt.matrix4x4();
67 m.rotate(model.index * instantiator.angleStep, Qt.vector3d(0, 1, 0));
68 m.translate(Qt.vector3d(20, 0, 0));
69 return m;
70 }
71 }
72 source: model.index % 2 === 0 ? "qrc:/CuboidEntity.qml" : "qrc:/SphereEntity.qml"
73 }
74 }
75
76
77 EntityLoader {
78 sourceComponent: timer.odd ? cylEntityCmp : torusEntityCmp
79 }
80
81 QQ2.Component {
82 id: cylEntityCmp
83 Entity {
84 CylinderMesh {
85 id: cylMesh
86 }
87 PhongMaterial {
88 id: phong
89 }
90 components: [cylMesh, phong]
91 }
92
93 }
94
95 QQ2.Component {
96 id: torusEntityCmp
97 Entity {
98 TorusMesh {
99 id: torusMesh
100 radius: 5
101 minorRadius: 1
102 rings: 100
103 slices: 20
104 }
105
106 Transform {
107 id: torusTransform
108 scale3D: Qt.vector3d(1.5, 1, 0.5)
109 rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45)
110 }
111
112 components: [ torusMesh, material, torusTransform ]
113 }
114 }
115
116 }