Qt3D how to insert entities instancied in cpp to a QML Framegraph?
Unsolved
General and Desktop
-
wrote on 13 Mar 2016, 12:40 last edited by
I have no issue to insert an Entity instancied in cpp containing everythings (models and framegraph) into a qml Scene3D, but I am trying to split it in a way to be able to declare the framegraph in qml and instancing models in cpp.
Here is my QML file :
import QtQuick 2.5 import Qt3D.Core 2.0 import Qt3D.Render 2.0 import QtQuick.Scene3D 2.0 Scene3D { anchors.fill: parent // entity: scene3DRootEntity Entity { id: emptyEntity } Entity { Camera { id: camera projectionType: CameraLens.PerspectiveProjection fieldOfView: 60 aspectRatio: 4.0 / 3.0 nearPlane : 0.1 farPlane : 1000.0 position: Qt.vector3d(60.0, 40.0, 100.0) upVector: Qt.vector3d(0.0, 1.0, 0.0) viewCenter: Qt.vector3d(0.0, 0.0, 0.0) } Configuration { controlledCamera: camera } Viewport { id: viewport rect: Qt.rect(0.0, 0.0, 1.0, 1.0) clearColor: Qt.rgba(64 / 255, 128 / 255, 128 / 255, 255 / 255) CameraSelector { id : cameraSelector camera: camera ClearBuffer { buffers : ClearBuffer.ColorDepthBuffer } } } components: [ FrameGraph { id: framgraph activeFrameGraph: viewport } ] /* Scene3D { // No error, but the model isn't visible entity: { if (typeof (elements) != 'undefined') return elements return emptyEntity } }*/ Entity { childNodes: { // Isn't exposed to qml, is it a bug? Because we can't instanciate a Node too. I have also tried with components, but I am not sure that it is valid to add an entity as component if (typeof (elements) != 'undefined') return [elements] return [emptyEntity] } } } }
And here is the cpp part :
void Scene::initialize() { mRootEntity = new QEntity(); mElementsEntity = new QEntity(/*mRootEntity*/); qmlContext->setContextProperty("scene3DRootEntity", mRootEntity); qmlContext->setContextProperty("elements", mElementsEntity); mRootEntity->setObjectName(QStringLiteral("rootEntity")); QEntity* objectEntity = new QEntity(mElementsEntity); loadModel(QString::fromUtf8(core::ResourceManager::singleton()->getResource("/3D/Model/abri_jardin.mod").c_str()), objectEntity); // loadModel(QString::fromUtf8(core::ResourceManager::singleton()->getResource("/3D/Model/abreuvoir_oiseaux.mod").c_str()), objectEntity); // Object Transform Qt3DCore::QTransform *objectTransforms = new Qt3DCore::QTransform(); objectTransforms->setTranslation(QVector3D(0.0f, 0.0f, 0.0f)); objectTransforms->setScale(20.0f); objectEntity->addComponent(objectTransforms); // Camera Qt3DCore::QCamera *cameraEntity = new Qt3DCore::QCamera(mRootEntity); cameraEntity->setObjectName(QStringLiteral("cameraEntity")); cameraEntity->lens()->setPerspectiveProjection(60.0f, 4.0f / 3.0f, 0.1f, 1000.0f); cameraEntity->setPosition(QVector3D(60, 40, 100.0f)); cameraEntity->setViewCenter(QVector3D(0, 0, 0)); cameraEntity->setUpVector(QVector3D(0, 1, 0)); // input->setCamera(cameraEntity); QFrameGraph* frameGraph = new QFrameGraph(); QTechniqueFilter* techniqueFilter = new QTechniqueFilter(); QViewport* viewport = new QViewport(techniqueFilter); QClearBuffer* clearBuffer = new QClearBuffer(viewport); QCameraSelector* cameraSelector = new QCameraSelector(clearBuffer); QCullFace* cullFace = new QCullFace(cameraSelector); QRenderPassFilter* renderPassFilter = new QRenderPassFilter(cullFace); // TechiqueFilter and renderPassFilter are not implement yet viewport->setRect(QRectF(0, 0, 1, 1)); viewport->setClearColor(QColor(64, 128, 128)); clearBuffer->setBuffers(QClearBuffer::ColorDepthBuffer); cameraSelector->setCamera(cameraEntity); frameGraph->setActiveFrameGraph(techniqueFilter); cullFace->setEnabled(false); // Setting the FrameGraph mRootEntity->addComponent(frameGraph); }
Does someone do something similar?
1/1