2022-06-08 12:47:24 +00:00
|
|
|
// Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
|
2024-02-23 14:41:04 +00:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
2017-01-21 15:53:09 +00:00
|
|
|
|
|
|
|
import Qt3D.Core 2.0
|
|
|
|
import Qt3D.Render 2.0
|
|
|
|
import Qt3D.Input 2.0
|
2017-02-16 15:15:47 +00:00
|
|
|
import Qt3D.Animation 2.9
|
2017-01-21 15:53:09 +00:00
|
|
|
import Qt3D.Extras 2.0
|
|
|
|
|
|
|
|
DefaultSceneEntity {
|
|
|
|
id: scene
|
|
|
|
|
|
|
|
Entity {
|
|
|
|
id: cube
|
|
|
|
|
|
|
|
components: [
|
2017-01-26 16:45:00 +00:00
|
|
|
Transform {
|
|
|
|
id: cubeTransform
|
|
|
|
|
|
|
|
onTranslationChanged: console.log("t = " + translation)
|
|
|
|
},
|
2020-07-30 11:03:46 +00:00
|
|
|
CuboidMesh {
|
2017-01-21 15:53:09 +00:00
|
|
|
},
|
|
|
|
PhongMaterial {
|
2017-01-23 10:56:01 +00:00
|
|
|
id: cubeMaterial
|
2017-01-21 15:53:09 +00:00
|
|
|
ambient: Qt.rgba(0.02, 0.02, 0.02, 1.0)
|
|
|
|
diffuse: "blue"
|
|
|
|
shininess: 50
|
|
|
|
},
|
2017-01-26 16:45:00 +00:00
|
|
|
ObjectPicker {
|
2017-09-10 12:52:46 +00:00
|
|
|
onClicked: {
|
|
|
|
if (animator.running == false) {
|
2020-09-25 09:41:24 +00:00
|
|
|
animator.normalizedTime = 0
|
|
|
|
animator.running = true
|
2017-09-10 12:52:46 +00:00
|
|
|
} else {
|
|
|
|
switch (pick.button) {
|
|
|
|
case PickEvent.RightButton:
|
2020-09-25 09:41:24 +00:00
|
|
|
animationClock.playbackRate *= 2.0
|
2017-09-10 12:52:46 +00:00
|
|
|
break;
|
|
|
|
case PickEvent.LeftButton:
|
2020-09-25 09:41:24 +00:00
|
|
|
animationClock.playbackRate /= 2.0
|
2017-09-10 12:52:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-21 15:53:09 +00:00
|
|
|
},
|
|
|
|
ClipAnimator {
|
2017-01-26 16:45:00 +00:00
|
|
|
id: animator
|
2017-01-28 15:22:19 +00:00
|
|
|
loops: 3
|
2017-01-26 16:45:00 +00:00
|
|
|
onRunningChanged: console.log("running = " + running)
|
|
|
|
|
2017-09-10 12:52:46 +00:00
|
|
|
clock: Clock {
|
|
|
|
id: animationClock
|
|
|
|
playbackRate: 1
|
|
|
|
}
|
|
|
|
|
2017-04-03 10:21:55 +00:00
|
|
|
clip: AnimationClipLoader {
|
2020-09-25 09:41:24 +00:00
|
|
|
source: "qrc:///cubeanimation.json"
|
2017-01-25 19:25:15 +00:00
|
|
|
onDurationChanged: console.log("duration = " + duration)
|
2017-01-21 15:53:09 +00:00
|
|
|
}
|
2017-01-23 10:56:01 +00:00
|
|
|
|
|
|
|
// By default introspect parent Entity and try
|
|
|
|
// to map fcurve groups to properties of QTransform
|
|
|
|
// mapping: AutomaticAnimationMapping {}
|
|
|
|
|
|
|
|
// To do more, we can be explicit
|
2017-01-25 10:41:32 +00:00
|
|
|
channelMapper: ChannelMapper {
|
2017-01-23 10:56:01 +00:00
|
|
|
mappings: [
|
|
|
|
ChannelMapping { channelName: "Location"; target: cubeTransform; property: "translation" },
|
|
|
|
ChannelMapping { channelName: "Rotation"; target: cubeTransform; property: "rotation" },
|
|
|
|
ChannelMapping { channelName: "Diffuse Color"; target: cubeMaterial; property: "diffuse" }
|
|
|
|
]
|
|
|
|
}
|
2017-01-21 15:53:09 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
camera: Camera {
|
2017-01-26 16:45:00 +00:00
|
|
|
position: Qt.vector3d(10, 3, 15)
|
|
|
|
viewCenter: Qt.vector3d(2.5, 1, 0)
|
2017-01-21 15:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OrbitCameraController {
|
|
|
|
camera: scene.camera
|
|
|
|
linearSpeed: 8
|
|
|
|
lookSpeed: 180
|
|
|
|
}
|
|
|
|
}
|