| 1 |
// Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
import Qt3D.Core 2.0 |
| 5 |
import Qt3D.Render 2.0 |
| 6 |
import Qt3D.Input 2.0 |
| 7 |
import Qt3D.Animation 2.9 |
| 8 |
import Qt3D.Extras 2.0 |
| 9 |
|
| 10 |
DefaultSceneEntity { |
| 11 |
id: scene |
| 12 |
|
| 13 |
Entity { |
| 14 |
id: cube |
| 15 |
|
| 16 |
components: [ |
| 17 |
Transform { |
| 18 |
id: cubeTransform |
| 19 |
|
| 20 |
onTranslationChanged: console.log("t = " + translation) |
| 21 |
}, |
| 22 |
CuboidMesh { |
| 23 |
}, |
| 24 |
PhongMaterial { |
| 25 |
id: cubeMaterial |
| 26 |
ambient: Qt.rgba(0.02, 0.02, 0.02, 1.0) |
| 27 |
diffuse: "blue" |
| 28 |
shininess: 50 |
| 29 |
}, |
| 30 |
ObjectPicker { |
| 31 |
onClicked: { |
| 32 |
if (animator.running == false) { |
| 33 |
animator.normalizedTime = 0 |
| 34 |
animator.running = true |
| 35 |
} else { |
| 36 |
switch (pick.button) { |
| 37 |
case PickEvent.RightButton: |
| 38 |
animationClock.playbackRate *= 2.0 |
| 39 |
break; |
| 40 |
case PickEvent.LeftButton: |
| 41 |
animationClock.playbackRate /= 2.0 |
| 42 |
break; |
| 43 |
default: |
| 44 |
break; |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
}, |
| 49 |
ClipAnimator { |
| 50 |
id: animator |
| 51 |
loops: 3 |
| 52 |
onRunningChanged: console.log("running = " + running) |
| 53 |
|
| 54 |
clock: Clock { |
| 55 |
id: animationClock |
| 56 |
playbackRate: 1 |
| 57 |
} |
| 58 |
|
| 59 |
clip: AnimationClipLoader { |
| 60 |
source: "qrc:///cubeanimation.json" |
| 61 |
onDurationChanged: console.log("duration = " + duration) |
| 62 |
} |
| 63 |
|
| 64 |
// By default introspect parent Entity and try |
| 65 |
// to map fcurve groups to properties of QTransform |
| 66 |
// mapping: AutomaticAnimationMapping {} |
| 67 |
|
| 68 |
// To do more, we can be explicit |
| 69 |
channelMapper: ChannelMapper { |
| 70 |
mappings: [ |
| 71 |
ChannelMapping { channelName: "Location"; target: cubeTransform; property: "translation" }, |
| 72 |
ChannelMapping { channelName: "Rotation"; target: cubeTransform; property: "rotation" }, |
| 73 |
ChannelMapping { channelName: "Diffuse Color"; target: cubeMaterial; property: "diffuse" } |
| 74 |
] |
| 75 |
} |
| 76 |
} |
| 77 |
] |
| 78 |
} |
| 79 |
|
| 80 |
camera: Camera { |
| 81 |
position: Qt.vector3d(10, 3, 15) |
| 82 |
viewCenter: Qt.vector3d(2.5, 1, 0) |
| 83 |
} |
| 84 |
|
| 85 |
OrbitCameraController { |
| 86 |
camera: scene.camera |
| 87 |
linearSpeed: 8 |
| 88 |
lookSpeed: 180 |
| 89 |
} |
| 90 |
} |