Reputation: 11
I have a question regarding the "Qt 3D: Multi Viewport QML Example" Link
Is there a possibility to add a single view (one of the four in the example) into a separate widget. I tried to change the example but I only could add all four views to one widget.
The following code creates a camera which should be displayed in a separate Widget. see Picture
I am not sure if it is possible and how i can solve it.
SimpleCamera {
id: camera4
lens: cameraLens3
position: Qt.vector3d(100.0, 0.0, -6.0)
viewCenter: Qt.vector3d(0.0, 0.0, -6.0)
}
Upvotes: 1
Views: 745
Reputation: 3345
In the example, the four views are created using the classes Viewport and CameraSelector.
The Viewport class
The class Viewport
defines the portion of the screen that the branch of the framegraph (that the Viewport
node is part of) is rendered to. The portion is defined as (x, y, width, height)
. The coordinates of the whole screen are (0, 0, 1, 1)
.
If you have a look at the QuadViewportFrameGraph
class that is part of the example, you'll see four viewports defined - one for each camera. The top left camera renders to the rectangle (0, 0, 0.5, 0.5)
of the screen. The top right camera on the other hand renders to (0.5, 0, 0.5, 0.5)
, i.e. it uses half of the screen size as its x
offset.
The CameraSelector class
This class defines which camera the branch of the framegraph uses to render content. If you look into the example you'll see a CameraSelector { id: someCamera }
within each Viewport
instance. This way, each Viewport
gets its own camera.
Conclusion
If you only want one view, remove the four Viewports
within the main Viewport
and add one camera selector as the child of it. So your QuadViewportFrameGraph
should look like this (without import statements):
RenderSettings {
id: quadViewportFrameGraph
property alias camera: cameraSelector.camera;
property alias window: surfaceSelector.surface
activeFrameGraph: RenderSurfaceSelector {
id: surfaceSelector
Viewport {
id: mainViewport
normalizedRect: Qt.rect(0, 0, 1, 1)
ClearBuffers {
buffers: ClearBuffers.ColorDepthBuffer
clearColor: Qt.rgba(0.6, 0.6, 0.6, 1.0)
CameraSelector { id: cameraSelector }
}
}
}
}
Of course you also have to adjust the code where you instantiate the QuadViewportFrameGraph
and only set the one camera. If you now want all four views displayed in separate widgets you need to create four 3D windows and window containers and such a framegraph for each (with different cameras of course).
But be warned that the performance might be crappy if you create for distinct 3D windows. As far as I know, there are no other solutions to obtain 3D widgets.
Upvotes: 1