| 1 |
// Copyright (C) 2018 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.Extras 2.0 |
| 7 |
import QtQuick.Window 2.0 |
| 8 |
|
| 9 |
Entity { |
| 10 |
id: sceneRoot |
| 11 |
|
| 12 |
Window { |
| 13 |
id: _view |
| 14 |
width: 600 |
| 15 |
height: 600 |
| 16 |
visible: true |
| 17 |
} |
| 18 |
|
| 19 |
Camera { |
| 20 |
id: camera |
| 21 |
projectionType: CameraLens.PerspectiveProjection |
| 22 |
fieldOfView: 45 |
| 23 |
aspectRatio: _view.width / 2 / _view.height |
| 24 |
nearPlane : 0.1 |
| 25 |
farPlane : 1000.0 |
| 26 |
position: Qt.vector3d( 0.0, 0.0, -10.0 ) |
| 27 |
upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) |
| 28 |
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) |
| 29 |
} |
| 30 |
|
| 31 |
Camera { |
| 32 |
id: camera2 |
| 33 |
projectionType: CameraLens.PerspectiveProjection |
| 34 |
fieldOfView: 45 |
| 35 |
aspectRatio: _view.width / _view.height |
| 36 |
nearPlane : 0.1 |
| 37 |
farPlane : 1000.0 |
| 38 |
position: Qt.vector3d( 0.0, 0.0, -20.0 ) |
| 39 |
upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) |
| 40 |
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) |
| 41 |
} |
| 42 |
|
| 43 |
FirstPersonCameraController { |
| 44 |
camera: camera |
| 45 |
} |
| 46 |
|
| 47 |
DirectionalLight { |
| 48 |
worldDirection: camera.viewVector.times(-1) |
| 49 |
} |
| 50 |
|
| 51 |
// Draw 2 viewports |
| 52 |
// one with the content, the other with content + debug volumes |
| 53 |
components: [ |
| 54 |
RenderSettings { |
| 55 |
Viewport { |
| 56 |
normalizedRect: Qt.rect(0.0, 0.0, 1.0, 1.0) |
| 57 |
|
| 58 |
RenderSurfaceSelector { |
| 59 |
surface: _view |
| 60 |
|
| 61 |
Viewport { |
| 62 |
normalizedRect: Qt.rect(0.0, 0.0, 0.5, 1.0) |
| 63 |
ClearBuffers { |
| 64 |
buffers : ClearBuffers.ColorDepthBuffer |
| 65 |
clearColor: "white" |
| 66 |
CameraSelector { |
| 67 |
camera: camera |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
Viewport { |
| 73 |
normalizedRect: Qt.rect(0.5, 0.0, 0.5, 1.0) |
| 74 |
CameraSelector { |
| 75 |
camera: camera2 |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
] |
| 82 |
|
| 83 |
CuboidMesh { id: cubeMesh } |
| 84 |
|
| 85 |
Entity { |
| 86 |
readonly property ObjectPicker objectPicker: ObjectPicker { |
| 87 |
onClicked: console.log("o1") |
| 88 |
} |
| 89 |
readonly property Transform transform: Transform { |
| 90 |
scale: 3 |
| 91 |
translation: Qt.vector3d(3, 0, 0) |
| 92 |
} |
| 93 |
readonly property PhongMaterial material: PhongMaterial { diffuse: "red" } |
| 94 |
|
| 95 |
components: [cubeMesh, transform, material, objectPicker ] |
| 96 |
} |
| 97 |
|
| 98 |
Entity { |
| 99 |
readonly property ObjectPicker objectPicker: ObjectPicker { |
| 100 |
objectName: "Picker2" |
| 101 |
onClicked: console.log("o2") |
| 102 |
} |
| 103 |
readonly property Transform transform: Transform { |
| 104 |
scale: 3 |
| 105 |
translation: Qt.vector3d(-3, 0, 0) |
| 106 |
} |
| 107 |
readonly property PhongMaterial material: PhongMaterial { diffuse: "green" } |
| 108 |
|
| 109 |
components: [cubeMesh, transform, material, objectPicker ] |
| 110 |
} |
| 111 |
} |