Debian Codegraph @

tests/manual/scene3d-visibility/main.qml

raw
1 // Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 import QtQuick 2.14
5 import Qt3D.Core 2.14
6 import Qt3D.Render 2.14
7 import Qt3D.Input 2.14
8 import Qt3D.Extras 2.14
9 import QtQuick.Scene3D 2.14
10
11 Item {
12 id: root
13
14 Timer {
15 running: true
16 repeat: true
17 interval: 2000
18 onTriggered: scene3d.visible = !scene3d.visible
19 }
20
21 // Scene3D
22 Scene3D {
23 id: scene3d
24 visible: false
25 readonly property double halfWidth: width * 0.5
26
27 focus: true
28 anchors.fill: parent
29 // Make sure to define the input aspect if we want to handle inputs
30 aspects: ["render", "input"]
31 multisample: false
32
33 Entity { // Root
34 id: sceneRoot
35 components: [
36 RenderSettings {
37 activeFrameGraph: ForwardRenderer {
38 id: forwardRenderer
39 camera: mainCamera
40 clearColor: "yellow"
41 }
42 },
43 // Event Source is the Scene3D in that case
44 InputSettings { }
45 ]
46
47 Camera {
48 id: mainCamera
49 projectionType: CameraLens.PerspectiveProjection
50 fieldOfView: 45
51 nearPlane : 0.1
52 farPlane : 1000.0
53 position: Qt.vector3d( 0.0, 0.0, -40.0 )
54 upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
55 viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
56 }
57
58 PhongMaterial {
59 id: material
60 }
61
62 TorusMesh {
63 id: torusMesh
64 radius: 5
65 minorRadius: 1
66 rings: 100
67 slices: 20
68 }
69
70 SphereMesh {
71 id: sphereMesh
72 radius: 3
73 }
74
75 Transform {
76 id: torusTransform
77 scale3D: Qt.vector3d(1.5, 1, 0.5)
78 rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45)
79 }
80
81 Transform {
82 id: sphereTransform
83 property real userAngle: 0.0
84 matrix: {
85 var m = Qt.matrix4x4();
86 m.rotate(userAngle, Qt.vector3d(0, 1, 0));
87 m.translate(Qt.vector3d(20, 0, 0));
88 return m;
89 }
90
91 onWorldMatrixChanged: console.log("Sphere WorldMatrix " + worldMatrix)
92 }
93
94 NumberAnimation {
95 target: sphereTransform
96 property: "userAngle"
97 duration: 1000
98 from: 0
99 to: 360
100 loops: Animation.Infinite
101 running: true
102 }
103
104 Entity {
105 id: torusEntity
106 components: [ torusMesh, material, torusTransform ]
107 }
108 Entity {
109 id: sphereEntity
110 components: [ sphereMesh, material, sphereTransform ]
111 }
112 }
113 }
114 }