| 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.9 |
| 6 |
import Qt3D.Input 2.0 |
| 7 |
import Qt3D.Extras 2.9 |
| 8 |
|
| 9 |
import QtQuick 2.0 as QQ2 |
| 10 |
|
| 11 |
Entity { |
| 12 |
id: sceneRoot |
| 13 |
|
| 14 |
Camera { |
| 15 |
id: camera |
| 16 |
projectionType: CameraLens.PerspectiveProjection |
| 17 |
fieldOfView: 45 |
| 18 |
aspectRatio: 16/9 |
| 19 |
nearPlane : 0.1 |
| 20 |
farPlane : 1000.0 |
| 21 |
position: Qt.vector3d( 0.0, 0.0, 20.0 ) |
| 22 |
upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) |
| 23 |
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) |
| 24 |
} |
| 25 |
|
| 26 |
OrbitCameraController { camera: camera } |
| 27 |
|
| 28 |
Entity { |
| 29 |
id: headlight |
| 30 |
components: [ |
| 31 |
DirectionalLight { |
| 32 |
color: Qt.rgba(0.8, 0.8, 0.8, 1.0) |
| 33 |
worldDirection: camera.viewVector |
| 34 |
} |
| 35 |
] |
| 36 |
} |
| 37 |
|
| 38 |
RenderSettings { |
| 39 |
id : external_forward_renderer |
| 40 |
activeFrameGraph : ForwardRenderer { |
| 41 |
camera: camera |
| 42 |
clearColor: "white" |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
// Event Source will be set by the Qt3DQuickWindow |
| 47 |
InputSettings { id: inputSettings } |
| 48 |
|
| 49 |
components: [external_forward_renderer, inputSettings] |
| 50 |
|
| 51 |
Entity { |
| 52 |
components: [ |
| 53 |
Transform { |
| 54 |
id: transform |
| 55 |
} |
| 56 |
] |
| 57 |
|
| 58 |
Entity { |
| 59 |
components: [ |
| 60 |
CylinderMesh { |
| 61 |
id: mesh |
| 62 |
radius: 1 |
| 63 |
length: 3 |
| 64 |
rings: 2 |
| 65 |
slices: sliceValues[lod.currentIndex] |
| 66 |
|
| 67 |
property var sliceValues: [20, 10, 6, 4] |
| 68 |
}, |
| 69 |
Transform { |
| 70 |
scale: 1.5 |
| 71 |
translation: Qt.vector3d(0, 0, 0) |
| 72 |
rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45) |
| 73 |
}, |
| 74 |
PhongMaterial { |
| 75 |
id: material |
| 76 |
diffuse: "lightgreen" |
| 77 |
}, |
| 78 |
LevelOfDetail { |
| 79 |
id: lod |
| 80 |
camera: camera |
| 81 |
thresholds: [1000, 600, 300, 180] |
| 82 |
thresholdType: LevelOfDetail.ProjectedScreenPixelSizeThreshold |
| 83 |
volumeOverride: lod.createBoundingSphere(Qt.vector3d(0, 0, 0), 2.0) |
| 84 |
} |
| 85 |
] |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
Entity { |
| 90 |
components: [ |
| 91 |
Transform { |
| 92 |
translation: transform.translation |
| 93 |
} |
| 94 |
] |
| 95 |
|
| 96 |
LevelOfDetailLoader { |
| 97 |
id: lodLoader |
| 98 |
components: [ Transform { |
| 99 |
scale: .5 |
| 100 |
translation: Qt.vector3d(-8, 0, 0) |
| 101 |
} ] |
| 102 |
|
| 103 |
camera: camera |
| 104 |
thresholds: [20, 35, 50, 65] |
| 105 |
thresholdType: LevelOfDetail.DistanceToCameraThreshold |
| 106 |
volumeOverride: lodLoader.createBoundingSphere(Qt.vector3d(0, 0, 0), -1) |
| 107 |
sources: ["qrc:/SphereEntity.qml", "qrc:/CylinderEntity.qml", "qrc:/ConeEntity.qml", "qrc:/CuboidEntity.qml"] |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
Entity { |
| 112 |
components: [ |
| 113 |
Transform { |
| 114 |
translation: transform.translation |
| 115 |
} |
| 116 |
] |
| 117 |
|
| 118 |
Entity { |
| 119 |
components: [ |
| 120 |
Transform { |
| 121 |
scale: .5 |
| 122 |
translation: Qt.vector3d(8, 0, 0) |
| 123 |
}, |
| 124 |
LevelOfDetailSwitch { |
| 125 |
camera: camera |
| 126 |
thresholds: [20, 35, 50, 65] |
| 127 |
thresholdType: LevelOfDetail.DistanceToCameraThreshold |
| 128 |
} |
| 129 |
] |
| 130 |
|
| 131 |
SphereEntity { |
| 132 |
enabled: false |
| 133 |
} |
| 134 |
CylinderEntity { |
| 135 |
enabled: false |
| 136 |
} |
| 137 |
ConeEntity { |
| 138 |
enabled: false |
| 139 |
} |
| 140 |
CuboidEntity { |
| 141 |
enabled: false |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
QQ2.SequentialAnimation { |
| 147 |
QQ2.Vector3dAnimation { |
| 148 |
target: transform |
| 149 |
properties: "translation" |
| 150 |
from: Qt.vector3d(0, 0, 10) |
| 151 |
to: Qt.vector3d(0, 0, -50) |
| 152 |
duration: 2500 |
| 153 |
easing.type: QQ2.Easing.InOutQuad |
| 154 |
} |
| 155 |
QQ2.PropertyAnimation { |
| 156 |
target: transform |
| 157 |
properties: "translation" |
| 158 |
from: Qt.vector3d(0, 0, -50) |
| 159 |
to: Qt.vector3d(0, 0, 10) |
| 160 |
duration: 2500 |
| 161 |
easing.type: QQ2.Easing.InOutQuad |
| 162 |
} |
| 163 |
|
| 164 |
loops: QQ2.Animation.Infinite |
| 165 |
running: true |
| 166 |
} |
| 167 |
} |