Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QtQuick3D scene node geometry



  • Using QtQuick3D/Qt3D module, got one problem with getting geometry data from scene nodes.
    I am creating a simple scene with one scene node(cube mesh in this example):
    @ QGLBuilder builder;
    builder << QGLCube();
    sceneNode = builder.finalizedSceneNode();@

    I am trying to use this for vertices, but it doesn't work. It is an infinite loop, which provides wrong data (example: Iter->x() = 4.2039e-44, Iter->y() = 2.27723e-39 and Iter->z() = 861307000.0).
    @ QVector3DArray::iterator Iter;
    for(Iter=sceneNode->geometry().vertices().begin(); Iter!=sceneNode->geometry().vertices().begin(); Iter=Iter.Next())
    {
    //Taking coordinates from each vertex
    }@
    How I can get all data from scene node(vertices,normals,texture coordinates, etc)?
    I need to get every x,y,z coordinate and write all collected data to file.



  • If you've copied and pasted that code verbatim, you've got a typo in there: you mean to say .end() for the second clause in the for statement, and instead you've repeated begin().
    e.g. @Iter!=sceneNode->geometry().vertices().begin()@ should be
    @Iter!=sceneNode->geometry().vertices().end()@
    (I assume).



  • Hi,
    I think that when you do a
    @builder.finalizedSceneNode()@
    the data is uploaded to the card and
    @sceneNode->geometry()@
    is empty.

    Try to use nested nodes to build your scene like this documentation example :
    @
    QGLBuilder builder;
    builder << CarWheel(5.0f); // some car wheel geometry
    QGLSceneNode * wheel = builder.finalizedSceneNode();
    QGLSceneNode * frontLeft = new QGLSceneNode(m_sceneRoot);
    frontLeft->addNode(wheel);
    frontLeft->setPosition(QVector3D(1.0f, 2.0f, 0.0f));
    QGLSceneNode * frontRight = new QGLSceneNode(m_sceneRoot);
    frontRight->addNode(wheel);
    frontRight->setPosition(QVector3D(-1.0f, 2.0f, 0.0f));
    QGLSceneNode * backLeft = new QGLSceneNode(m_sceneRoot);
    backLeft->addNode(wheel);
    backLeft->setPosition(QVector3D(1.0f, -2.0f, 0.0f));
    QGLSceneNode * backRight = new QGLSceneNode(m_sceneRoot);
    backRight->addNode(wheel);
    backRight->setPosition(QVector3D(-1.0f, -2.0f, 0.0f));
    @

    Regards.
    G.



  • [quote author="kmedghaith" date="1323764400"]Hi,
    I think that when you do a
    @builder.finalizedSceneNode()@
    the data is uploaded to the card and
    @sceneNode->geometry()@
    is empty.

    Try to use nested nodes to build your scene like this documentation example :
    @
    QGLBuilder builder;
    builder << CarWheel(5.0f); // some car wheel geometry
    QGLSceneNode * wheel = builder.finalizedSceneNode();
    QGLSceneNode * frontLeft = new QGLSceneNode(m_sceneRoot);
    frontLeft->addNode(wheel);
    frontLeft->setPosition(QVector3D(1.0f, 2.0f, 0.0f));
    QGLSceneNode * frontRight = new QGLSceneNode(m_sceneRoot);
    frontRight->addNode(wheel);
    frontRight->setPosition(QVector3D(-1.0f, 2.0f, 0.0f));
    QGLSceneNode * backLeft = new QGLSceneNode(m_sceneRoot);
    backLeft->addNode(wheel);
    backLeft->setPosition(QVector3D(1.0f, -2.0f, 0.0f));
    QGLSceneNode * backRight = new QGLSceneNode(m_sceneRoot);
    backRight->addNode(wheel);
    backRight->setPosition(QVector3D(-1.0f, -2.0f, 0.0f));
    @

    Regards.
    G.[/quote]

    Using this:
    @ QGeometryData m_sceneRoot;
    QGLBuilder builder;
    builder << QGLCube(5.0f); // some car wheel geometry
    QGLSceneNode * wheel = builder.finalizedSceneNode();
    QGLSceneNode * frontLeft = new QGLSceneNode(m_sceneRoot);
    frontLeft->addNode(wheel);
    frontLeft->setPosition(QVector3D(1.0f, 2.0f, 0.0f));
    QGLSceneNode * frontRight = new QGLSceneNode(m_sceneRoot);
    frontRight->addNode(wheel);
    frontRight->setPosition(QVector3D(-1.0f, 2.0f, 0.0f));
    QGLSceneNode * backLeft = new QGLSceneNode(m_sceneRoot);
    backLeft->addNode(wheel);
    backLeft->setPosition(QVector3D(1.0f, -2.0f, 0.0f));
    QGLSceneNode * backRight = new QGLSceneNode(m_sceneRoot);
    backRight->addNode(wheel);
    backRight->setPosition(QVector3D(-1.0f, -2.0f, 0.0f));
    if(!wheel->geometry().vertices().isEmpty())
    QMessageBox::information(this,"Info","Not Empty",QMessageBox::Ok);@

    Geometry data is still empty.

    It is not empty when I use:
    @ QGLBuilder builder;
    QGeometryData triangle;
    QVector3D a(2, 2, 0);
    QVector3D b(-2, 2, 0);
    QVector3D c(0, -2, 0);
    triangle.appendVertex(a, b, c);

    // When adding geometry, QGLBuilder automatically creates lighting normals
    builder << triangle;
    
    // obtain the scene from the builder
    sceneNode = builder.finalizedSceneNode();
    if(!triangle.vertices().isEmpty())
            QMessageBox::information(this,"Info","Not Empty",QMessageBox::Ok);@
    

    How I can draw the number of vertices and normals when loading 3d model from .obj or .3ds file?
    I am using
    @QGLAbstractScene *abstr = QGLAbstractScene::loadScene(...);@
    then:
    @sceneNode = abstr->mainNode();@
    3D model is loading without any problems, but sceneNode->geometry is still empty.



  • I know this post is a bit old but I'm encountering the same problem, did you find a solution ?



  • Replying to myself : as explained here http://permalink.gmane.org/gmane.comp.lib.qt.3d/126 :

    bq. Very often when you build an object it has more than one scene node in it, hence the builder returns always a single root node, under which are the other nodes containing the actual geometry.


Log in to reply