Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt3D how to insert entities instancied in cpp to a QML Framegraph?
Forum Update on Monday, May 27th 2025

Qt3D how to insert entities instancied in cpp to a QML Framegraph?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 697 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IanMoone
    wrote on 13 Mar 2016, 12:40 last edited by
    #1

    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 Reply Last reply
    0

    1/1

    13 Mar 2016, 12:40

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved