Debian Codegraph @

tests/manual/anim-viewer/main.qml

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 import QtQuick 2.0 as Quick
5 import QtQuick.Layouts 1.3
6 import QtQuick.Controls 1.4
7 import QtQuick.Controls.Styles 1.4
8
9 import Qt3D.Core 2.0
10 import Qt3D.Render 2.0
11 import Qt3D.Input 2.0
12 import Qt3D.Extras 2.9
13 import Qt3D.Animation 2.9
14 import QtQuick.Scene3D 2.0
15
16
17 Quick.Item {
18
19 width: 1250
20 height: 900
21
22 ColumnLayout {
23
24 anchors.fill: parent
25 anchors.margins: 0
26
27 Quick.Rectangle {
28 id: background
29 width: 1250
30 height: 700
31
32 color: "red"
33
34 Scene3D {
35
36 anchors.fill: parent
37 multisample: true
38 focus: true
39
40 aspects: ["input", "logic"]
41
42 Entity {
43 components: [
44 RenderSettings {
45 activeFrameGraph: ForwardRenderer {
46 clearColor: Qt.rgba(0, 0.5, 1, 1)
47 camera: camera
48 }
49 },
50 // Event Source will be set by the Qt3DQuickWindow
51 InputSettings { }
52 ]
53
54 Camera {
55 id: camera
56 projectionType: CameraLens.PerspectiveProjection
57 fieldOfView: 45
58 aspectRatio: 16/9
59 nearPlane : 0.1
60 farPlane : 1000.0
61 position: Qt.vector3d( 0.0, 1.0, 10.0 )
62 upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
63 viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
64 }
65
66 FirstPersonCameraController {
67 camera: camera
68 }
69
70 Entity {
71 id: scene2
72 components: [
73 Transform {
74 scale: 0.2
75 translation: Qt.vector3d(0.0, 0.0, 0.0)
76 },
77 SceneLoader {
78 id: animEntity
79 source: "qrc:/assets/gears.dae"
80
81 AnimationController {
82 id: animator
83 property bool initialized : false
84 onPositionChanged: {
85 slider.value = position
86 }
87 }
88 Quick.PropertyAnimation {
89 id: animPosition
90 target: animator
91 property: "position"
92 loops: Quick.Animation.Infinite
93 from: 0.0
94 }
95 onStatusChanged: {
96 console.log(status)
97 if (status === SceneLoader.Ready) {
98
99 animator.entity = null
100 animator.entity = scene2
101 animator.activeAnimationGroup = 0
102 var group = animator.getGroup(0)
103 animPosition.to = group.duration
104 animPosition.duration = group.duration * 1000
105 slider.maximumValue = group.duration
106
107 var animList = []
108 var groups = animator.animationGroups
109 for (var i = 0; i < groups.length; i++) {
110 if (groups[i].name === "")
111 groups[i].name = "UnnamedAnim" + i;
112 animList.push(groups[i].name)
113 }
114 comboBox.model = animList
115
116 animator.initialized = true
117 comboBox.currentIndex = 0
118 }
119 }
120 }
121 ]
122 }
123 }
124 }
125 }
126
127 ComboBox {
128 id: animationSelector
129 anchors.topMargin: 10
130 anchors.top: background.bottom
131 implicitWidth: 400
132 model: [ "Gears", "Blend Shape" ]
133 onCurrentIndexChanged: {
134
135 if (animPosition.running) {
136 animPosition.stop()
137 animator.position = 0
138 slider.value = 0
139 }
140
141 if (currentText === "Gears" && animEntity.source !== "qrc:/assets/gears.dae")
142 animEntity.source = "qrc:/assets/gears.dae"
143 else if (currentText === "Blend Shape"
144 && animEntity.source !== "qrc:/assets/blendshapeanimation.dae") {
145 animEntity.source = "qrc:/assets/blendshapeanimation.dae"
146 }
147 }
148 }
149
150 ComboBox {
151 id: comboBox
152 anchors.topMargin: 10
153 anchors.top: animationSelector.bottom
154 implicitWidth: 400
155 onCurrentIndexChanged: {
156 if (animator.initialized) {
157 animator.activeAnimationGroup = currentIndex
158 var group = animator.getGroup(currentIndex)
159 animPosition.to = group.duration
160 animPosition.duration = group.duration * 1000
161 slider.maximumValue = group.duration
162 }
163 }
164 }
165
166 RowLayout {
167 anchors.left: parent.left
168
169 Button {
170 text: "play"
171 onClicked: {
172 if (!animPosition.running || animPosition.paused)
173 animPosition.start()
174 }
175 }
176 Button {
177 text: "stop"
178 onClicked: {
179 if (animPosition.running) {
180 animPosition.stop()
181 animator.position = 0
182 slider.value = 0
183 }
184 }
185 }
186 Button {
187 text: "pause"
188 onClicked: {
189 if (!animPosition.paused && animPosition.running)
190 animPosition.pause()
191 }
192 }
193 }
194 Slider {
195 id: slider
196 anchors.bottomMargin: 10
197 anchors.left: parent.left
198 anchors.right: parent.right
199 value: 0.0
200 onValueChanged: {
201 if (pressed) {
202 animPosition.stop()
203 animator.position = value
204 }
205 }
206 }
207 }
208 }