[Interest] real time data input in Qt3D scene

Dimitrios Anagnostakis danagnostak at gmail.com
Wed Jan 31 15:02:55 CET 2018


Hi all,

 

I'm trying to make a scene in Qt3D which shows an STL object model and a 3D
point which is updated with real time data from a tracking software.

 

What I have so far is to display the object and a 3d sphere as a 3d point.
Below is my code:

The position of the sphere is set using the
sphereTransform->setTranslation(QVector3D(-1.0f, 10.0f, 7.0f));

 

How can I set this to be updated directly by the incoming data which is in
the form of QVector3d with x, y and z?

 

Thank you in advance for any help.

 

Regards, Dimis.

 

In the scenemodifier.cpp:

 

SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity)
    : m_rootEntity(rootEntity)
{
 
LoadSTL();
displayPoints();
 
}

 

 

void SceneModifier::LoadSTL()

{

    QUrl data = QUrl::fromLocalFile("C:/Qt/Examples/stylus_tip/block1.stl");

    Qt3DRender::QMesh *partMesh = new Qt3DRender::QMesh;

    partMesh->setSource(data);

 

        // Part Transform

        Qt3DCore::QTransform *partTransform = new Qt3DCore::QTransform();

        //partTransform->setScale(4.0f);

        //partTransform->setTranslation(QVector3D(5.0f, -4.0f, 0.0f));

 

        // Part material

        Qt3DExtras::QPhongMaterial *partMaterial = new
Qt3DExtras::QPhongMaterial();

        partMaterial->setDiffuse(QColor(0, 200, 255));

 

        //part (STL model)

        m_partEntity = new Qt3DCore::QEntity(m_rootEntity);

        m_partEntity->addComponent(partMesh);

        m_partEntity->addComponent(partMaterial);

        m_partEntity->addComponent(partTransform);

}

 

void SceneModifier::displayPoints()

{

    // Sphere shape data

    Qt3DExtras::QSphereMesh *sphereMesh = new Qt3DExtras::QSphereMesh();

    sphereMesh->setRadius(0.75f);;

 

    // Sphere mesh transform

    Qt3DCore::QTransform *sphereTransform = new Qt3DCore::QTransform();

    sphereTransform->setTranslation(QVector3D(-1.0f, 10.0f, 7.0f));

    sphereTransform->setScale(1.3f);

 

    // Sphere material

    Qt3DExtras::QPhongMaterial *sphereMaterial = new
Qt3DExtras::QPhongMaterial();

    sphereMaterial->setDiffuse(QColor(250, 250, 0));

 

    // Sphere

    m_sphereEntity = new Qt3DCore::QEntity(m_rootEntity);

    m_sphereEntity->addComponent(sphereMesh);

    m_sphereEntity->addComponent(sphereMaterial);

    m_sphereEntity->addComponent(sphereTransform);

 

}

 

In the main:

 

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
 
    Qt3DExtras::Qt3DWindow view;
 
    Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity;
 
    Qt3DRender::QCamera *camera = view.camera();
    camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f,
1000.0f);
    camera->setPosition(QVector3D(0, 0, 320.0f));
    camera->setUpVector(QVector3D(0, 1, 0));
    camera->setViewCenter(QVector3D(0, 0, 0));
 
    Qt3DExtras::QOrbitCameraController *camController = new
Qt3DExtras::QOrbitCameraController(rootEntity);
    camController->setCamera(camera);
 
    Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);
    Qt3DRender::QPointLight *light = new
Qt3DRender::QPointLight(lightEntity);
    light->setColor("white");
    light->setIntensity(1);
    lightEntity->addComponent(light);
 
    Qt3DCore::QTransform *lightTransform = new
Qt3DCore::QTransform(lightEntity);
    lightTransform->setTranslation(QVector3D(50, -50, -150.0f));
    lightEntity->addComponent(lightTransform);
 
    Qt3DCore::QEntity *lightEntity2 = new Qt3DCore::QEntity(rootEntity);
    Qt3DRender::QPointLight *light2 = new
Qt3DRender::QPointLight(lightEntity2);
    light2->setColor("white");
    light2->setIntensity(1);
    lightEntity2->addComponent(light2);
 
    Qt3DCore::QTransform *lightTransform2 = new
Qt3DCore::QTransform(lightEntity2);
    lightTransform2->setTranslation(QVector3D(-50, 50, 150.0f));
    lightEntity2->addComponent(lightTransform2);
 
   SceneModifier *modifier = new SceneModifier(rootEntity);
 
   view.setRootEntity(rootEntity);
   view.show();
 
    return a.exec();
}

 

The display is:

 



 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180131/350cbd35/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 9607 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180131/350cbd35/attachment.jpg>


More information about the Interest mailing list