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 Animation C++

Qt3D Animation C++

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++ qtqt3dc++3d modelanimation
7 Posts 4 Posters 2.9k 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.
  • L Offline
    L Offline
    Lukadriel
    wrote on 26 Apr 2018, 13:22 last edited by
    #1

    Hello everyone, I have recently started playing with the Qt Framework 3D Module.
    I however was unable to find any good example for animation in C++ most of them being in QML.
    I am trying to apply an animation I imported from blender( simple cube translation) using the Qt3d animation exporter blender plugin. I however don't know how to handle it. I tried using a QAnimationClipLoader and a QClipAnimator but to be honest I am going basically blind in this.
    Can anyone help me ? Just in case I added the code I used.

    
    #include <QApplication>
    #include <QWidget>
    #include <QPushButton>
    #include <QBoxLayout>
    
    #include <Qt3DCore>
    #include <Qt3DRender>
    #include <Qt3DExtras>
    #include <Qt3DAnimation>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        //Container window and 3d view
        Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();
        view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f)));
        QWidget *container = QWidget::createWindowContainer(view);
        QSize screenSize = view->screen()->size();
        container->setMinimumSize(QSize(200, 100));
        container->setMaximumSize(screenSize);
    
        //Main widget
        QWidget *widget = new QWidget;
        QHBoxLayout *hLayout = new QHBoxLayout(widget);
        QVBoxLayout *vLayout = new QVBoxLayout();
        vLayout->setAlignment(Qt::AlignTop);
        hLayout->addWidget(container, 1);
        hLayout->addLayout(vLayout);
    
        //To control input
        Qt3DInput::QInputAspect *input = new Qt3DInput::QInputAspect;
        view->registerAspect(input);
    
        // Root entity
        Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity();
    
        // Camera
        Qt3DRender::QCamera *cameraEntity = view->camera();
    
        cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
        cameraEntity->setPosition(QVector3D(0, 0, 20.0f));
        cameraEntity->setUpVector(QVector3D(0, 1, 0));
        cameraEntity->setViewCenter(QVector3D(0, 0, 0));
    
        //Light
        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(cameraEntity->position());
        lightEntity->addComponent(lightTransform);
    
        //Load mesh
    
        Qt3DRender::QMesh *mesh = new Qt3DRender::QMesh();
        mesh->setSource(QUrl::fromLocalFile("Data/Models/Wolf_One_obj.obj"));
    
    
        Qt3DCore::QTransform *meshTransform = new Qt3DCore::QTransform();
        meshTransform->setScale(5.f);
        //meshTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1.0f, 0.0f, 0.0f), 45.0f));
        meshTransform->setTranslation(QVector3D(-5.0f, 4.0f, -1.5));
        Qt3DExtras::QPhongMaterial *wolfMaterial = new Qt3DExtras::QPhongMaterial();
        wolfMaterial->setDiffuse(QColor(QRgb(0xa69929)));
    
        Qt3DCore::QEntity *meshEntity = new Qt3DCore::QEntity(rootEntity);
        meshEntity->addComponent(mesh);
        meshEntity->addComponent(meshTransform);
        meshEntity->addComponent(wolfMaterial);
    
        // Sphere shape data
        Qt3DExtras::QSphereMesh *sphereMesh = new Qt3DExtras::QSphereMesh();
        sphereMesh->setRings(20);
        sphereMesh->setSlices(20);
        sphereMesh->setRadius(2);
    
        // Sphere mesh transform
        Qt3DCore::QTransform *sphereTransform = new Qt3DCore::QTransform();
    
        sphereTransform->setScale(1.3f);
        sphereTransform->setTranslation(QVector3D(-5.0f, -4.0f, 0.0f));
    
        Qt3DExtras::QPhongMaterial *sphereMaterial = new Qt3DExtras::QPhongMaterial();
        sphereMaterial->setDiffuse(QColor(QRgb(0xa69929)));
    
        //Animation
        Qt3DAnimation::QAnimationClipLoader* m_animationClipLoader = new Qt3DAnimation::QAnimationClipLoader(QUrl::fromLocalFile("Data/Animations/simplemove.json"));
        Qt3DAnimation::QClipAnimator *m_animator = new Qt3DAnimation::QClipAnimator;
        m_animator->setClip(m_animationClipLoader);
        m_animator->setLoopCount(3);
        m_animator->start();
    
    
        // Sphere
        Qt3DCore::QEntity* m_sphereEntity = new Qt3DCore::QEntity(rootEntity);
        m_sphereEntity->addComponent(sphereMesh);
        m_sphereEntity->addComponent(sphereMaterial);
        m_sphereEntity->addComponent(sphereTransform);
        m_sphereEntity->addComponent(m_animator);
    
        // For camera controls
        Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(rootEntity);
        camController->setCamera(cameraEntity);
    
        // Set root object of the scene
        view->setRootEntity(rootEntity);
    
    
        widget->show();
        widget->resize(1200, 800);
    
        return a.exec();
    }
    
    
    1 Reply Last reply
    0
    • L Offline
      L Offline
      Lukadriel
      wrote on 29 Apr 2018, 13:11 last edited by
      #2

      Hey, I was just wondering if the reason there wasn't any documentation is that nobody uses the c++ version of Qt3d

      W 1 Reply Last reply 30 Apr 2018, 05:06
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 29 Apr 2018, 21:01 last edited by
        #3

        Hi and welcome to devnet,

        It's rather are more classic problem: the people developing the module are trying to provide as complete a documentation as possible but it also takes a lot of time to create meaningful examples and demos.

        I'd recommend bringing this question to the interest mailing list. You'll find there Qt3D's developers/maintainers. This forum is more user oriented.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        L 1 Reply Last reply 30 Apr 2018, 03:24
        0
        • S SGaist
          29 Apr 2018, 21:01

          Hi and welcome to devnet,

          It's rather are more classic problem: the people developing the module are trying to provide as complete a documentation as possible but it also takes a lot of time to create meaningful examples and demos.

          I'd recommend bringing this question to the interest mailing list. You'll find there Qt3D's developers/maintainers. This forum is more user oriented.

          L Offline
          L Offline
          Lukadriel
          wrote on 30 Apr 2018, 03:24 last edited by
          #4

          @SGaist Thank you very much for the answer, I am going to do as you advise

          1 Reply Last reply
          0
          • L Lukadriel
            29 Apr 2018, 13:11

            Hey, I was just wondering if the reason there wasn't any documentation is that nobody uses the c++ version of Qt3d

            W Offline
            W Offline
            wrosecrans
            wrote on 30 Apr 2018, 05:06 last edited by
            #5

            @Lukadriel

            Chicken and egg. Not many users of the C++ Qt 3D API's yet, so not as much focus on documenting them first, so not many people can figure out how to use it, so there aren't many users, so C++ Qt3D documentation isn't the top priority, so...

            L 1 Reply Last reply 30 Apr 2018, 12:27
            0
            • W wrosecrans
              30 Apr 2018, 05:06

              @Lukadriel

              Chicken and egg. Not many users of the C++ Qt 3D API's yet, so not as much focus on documenting them first, so not many people can figure out how to use it, so there aren't many users, so C++ Qt3D documentation isn't the top priority, so...

              L Offline
              L Offline
              Lukadriel
              wrote on 30 Apr 2018, 12:27 last edited by
              #6

              @wrosecrans
              Hoping I can get an answer from the mailing list. As soon as I figure it out I will post the solution here.

              O 1 Reply Last reply 13 Jun 2019, 12:08
              2
              • L Lukadriel
                30 Apr 2018, 12:27

                @wrosecrans
                Hoping I can get an answer from the mailing list. As soon as I figure it out I will post the solution here.

                O Offline
                O Offline
                Orad
                wrote on 13 Jun 2019, 12:08 last edited by
                #7

                @Lukadriel Hi, One year passed and still waiting for the proper example. Did they give any tips?

                1 Reply Last reply
                0

                • Login

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