| 1 |
// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
import QtQuick 2.2 as QQ2 |
| 5 |
import Qt3D.Core 2.0 |
| 6 |
import Qt3D.Render 2.1 |
| 7 |
import Qt3D.Input 2.0 |
| 8 |
import Qt3D.Extras 2.0 |
| 9 |
|
| 10 |
Entity { |
| 11 |
id: sceneRoot |
| 12 |
|
| 13 |
function requestRenderCapture() |
| 14 |
{ |
| 15 |
return renderCapture.requestCapture() |
| 16 |
} |
| 17 |
|
| 18 |
Camera { |
| 19 |
id: camera |
| 20 |
projectionType: CameraLens.PerspectiveProjection |
| 21 |
fieldOfView: 45 |
| 22 |
aspectRatio: 1 |
| 23 |
nearPlane : 0.1 |
| 24 |
farPlane : 1000.0 |
| 25 |
position: Qt.vector3d(100.0, 100.0, 20.0) |
| 26 |
upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) |
| 27 |
viewCenter: Qt.vector3d(0.0, 0.0, -8.0) |
| 28 |
} |
| 29 |
|
| 30 |
Camera { |
| 31 |
id: camera2 |
| 32 |
projectionType: CameraLens.PerspectiveProjection |
| 33 |
fieldOfView: 15 |
| 34 |
aspectRatio: 1 |
| 35 |
nearPlane : 0.1 |
| 36 |
farPlane : 1000.0 |
| 37 |
position: Qt.vector3d( 0.0, 0.0, -40.0 ) |
| 38 |
upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) |
| 39 |
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) |
| 40 |
} |
| 41 |
|
| 42 |
OrbitCameraController { |
| 43 |
camera: camera |
| 44 |
} |
| 45 |
|
| 46 |
components: [ |
| 47 |
RenderSettings { |
| 48 |
activeFrameGraph: RenderSurfaceSelector { |
| 49 |
Viewport { |
| 50 |
normalizedRect: Qt.rect(0, 0, 1, 1) |
| 51 |
|
| 52 |
// Clear Back Buffer |
| 53 |
ClearBuffers { |
| 54 |
buffers: ClearBuffers.ColorDepthBuffer |
| 55 |
clearColor: Qt.rgba(0, 0.5, 1, 1) |
| 56 |
NoDraw { } |
| 57 |
} |
| 58 |
|
| 59 |
// Render to back buffer |
| 60 |
CameraSelector { |
| 61 |
camera: camera |
| 62 |
} |
| 63 |
|
| 64 |
// FBO |
| 65 |
RenderTargetSelector { |
| 66 |
target: RenderTarget { |
| 67 |
attachments: [ |
| 68 |
RenderTargetOutput { |
| 69 |
attachmentPoint: RenderTargetOutput.Color0 |
| 70 |
texture: Texture2D { |
| 71 |
id: colorTexture |
| 72 |
width: 400 |
| 73 |
height: 400 |
| 74 |
format: Texture.RGBAFormat |
| 75 |
generateMipMaps: false |
| 76 |
magnificationFilter: Texture.Linear |
| 77 |
minificationFilter: Texture.Linear |
| 78 |
wrapMode { |
| 79 |
x: WrapMode.ClampToEdge |
| 80 |
y: WrapMode.ClampToEdge |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
] |
| 85 |
} |
| 86 |
// Clear FBO |
| 87 |
ClearBuffers { |
| 88 |
buffers: ClearBuffers.ColorDepthBuffer |
| 89 |
clearColor: Qt.rgba(0, 0.5, 0.5, 1) |
| 90 |
NoDraw { } |
| 91 |
} |
| 92 |
|
| 93 |
// Render into FBO |
| 94 |
CameraSelector { |
| 95 |
camera: camera |
| 96 |
// Render Capture |
| 97 |
RenderCapture { |
| 98 |
id: renderCapture |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
}, |
| 105 |
// Event Source will be set by the Qt3DQuickWindow |
| 106 |
InputSettings { } |
| 107 |
] |
| 108 |
|
| 109 |
PhongMaterial { |
| 110 |
id: material |
| 111 |
} |
| 112 |
|
| 113 |
TorusMesh { |
| 114 |
id: torusMesh |
| 115 |
radius: 5 |
| 116 |
minorRadius: 1 |
| 117 |
rings: 100 |
| 118 |
slices: 20 |
| 119 |
} |
| 120 |
|
| 121 |
Transform { |
| 122 |
id: torusTransform |
| 123 |
scale3D: Qt.vector3d(1.5, 1, 0.5) |
| 124 |
rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45) |
| 125 |
} |
| 126 |
|
| 127 |
Entity { |
| 128 |
id: torusEntity |
| 129 |
components: [ torusMesh, material, torusTransform ] |
| 130 |
} |
| 131 |
|
| 132 |
SphereMesh { |
| 133 |
id: sphereMesh |
| 134 |
radius: 3 |
| 135 |
} |
| 136 |
|
| 137 |
Transform { |
| 138 |
id: sphereTransform |
| 139 |
property real userAngle: 0.0 |
| 140 |
matrix: { |
| 141 |
var m = Qt.matrix4x4(); |
| 142 |
m.rotate(userAngle, Qt.vector3d(0, 1, 0)); |
| 143 |
m.translate(Qt.vector3d(20, 0, 0)); |
| 144 |
return m; |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
QQ2.NumberAnimation { |
| 149 |
target: sphereTransform |
| 150 |
property: "userAngle" |
| 151 |
duration: 10000 |
| 152 |
from: 0 |
| 153 |
to: 360 |
| 154 |
|
| 155 |
loops: QQ2.Animation.Infinite |
| 156 |
running: true |
| 157 |
} |
| 158 |
|
| 159 |
Entity { |
| 160 |
id: sphereEntity |
| 161 |
components: [ sphereMesh, material, sphereTransform ] |
| 162 |
} |
| 163 |
} |