Is it possible to embbed a 3dscene in qml Pane (Qt.QuickControl) type?
-
I am programming a graphical interface that I need to include a small 3DWindow inside a Pane type from Qt QuickControl.
Thus, I did the follwoing:
import QtQuick 2.4 import QtQuick.Controls 2.15 import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Input 2.0 import Qt3D.Extras 2.0 import QtQuick.Scene3D 2.0 Page { property alias _width_param: home_page.width property alias _height_param: home_page.height id: home_page title: "Home" transformOrigin: Item.Center header: Label { id: title_label text: home_page.title horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter font.weight: Font.Normal } Scene3D { id: scene3d anchors.fill: parent focus: true cameraAspectRatioMode: Scene3D.AutomaticAspectRatio aspects: ["input", "logic"] MyViewer { id: my aspectRatio: home_page.width / home_page.height } } }
which MyViewer is defined in MyViewer.qml
import QtQuick 2.4 import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Input 2.0 import Qt3D.Extras 2.0 import QtQuick.Scene3D 2.0 import QtQuick.Controls 2.15 Entity { id: entity_root property alias aspectRatio: mainCamera.aspectRatio // Render from the mainCamera components: [ RenderSettings { activeFrameGraph: ForwardRenderer { id: renderer camera: mainCamera } }, // Event Source will be set by the Qt3DQuickWindow InputSettings { } ] Camera { id: mainCamera projectionType: CameraLens.PerspectiveProjection fieldOfView: 22.5 //aspectRatio: _window.width / _window.height nearPlane: 0.01 farPlane: 1000.0 viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) } FirstPersonCameraController { camera: mainCamera } PhongMaterial { id: material } Mesh{ id:objMesh //source:"obj.ply" source:"file://home/joaopedro/qt_ws/qml3DExample/obj.ply" } Transform { id: objTransform scale3D: Qt.vector3d(10, 10, 10) rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45) } Entity { id: objEntity components: [ objMesh, material, objTransform ] } }
However the 3DScene is not plotting anything. Anyone can help me with that?
-
@ItzMeJP said in Is it possible to embbed a 3dscene in qml Pane (Qt.QuickControl) type?:
However the 3DScene is not plotting anything. Anyone can help me with that?
You haven't set the root entity of the scene.
Scene3D { ... entity: MyViewer { ... } }
should do it.
-
@kshegunov said in Is it possible to embbed a 3dscene in qml Pane (Qt.QuickControl) type?:
entity:
thank you, but it still crash my application. Is there any problem regarding my main.cpp code?
#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QGuiApplication app(argc, argv); QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); }
-
@ItzMeJP said in Is it possible to embbed a 3dscene in qml Pane (Qt.QuickControl) type?:
thank you, but it still crash my application.
What crash? You never said anything about a crash ...
Is there any problem regarding my main.cpp code?
Not that I can see.