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. How can I load a 3D model(like *.obj files etc.) in QT

How can I load a 3D model(like *.obj files etc.) in QT

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 23.6k 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.
  • Z Offline
    Z Offline
    z69333186
    wrote on 6 Apr 2017, 14:27 last edited by
    #1

    HI,
    Now, I am doing a project in which I want to display a 3D model(robot) and control it like moving its leg or arm.
    So, I am trying to load a *.obj files into QT, but I failed.
    I search on the Internet and some people say I can try the Assimp, but i can't find how to use it. I include <AssimpIO> but resulted in a "file not found" compiler error. it seems QT do not support Assimp now?
    Is there any way to load 3D model(like *.obj files etc.) into QT?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 Apr 2017, 14:41 last edited by
      #2

      Hi and welcome to devnet,

      Did you took a look at the Qt3D module documentation and the accompanying examples ?

      The Audio Visualizer Example loads .obj files.

      By the way, it's Qt. QT stands for Apple QuickTime which doesn't seem to be what you are looking for.

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

      Z 1 Reply Last reply 7 Apr 2017, 03:05
      2
      • Z Offline
        Z Offline
        z69333186
        wrote on 7 Apr 2017, 02:41 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • S SGaist
          6 Apr 2017, 14:41

          Hi and welcome to devnet,

          Did you took a look at the Qt3D module documentation and the accompanying examples ?

          The Audio Visualizer Example loads .obj files.

          By the way, it's Qt. QT stands for Apple QuickTime which doesn't seem to be what you are looking for.

          Z Offline
          Z Offline
          z69333186
          wrote on 7 Apr 2017, 03:05 last edited by
          #4

          @SGaist Thank you very much. Acctually I want find a example using C++ to load 3D model, but the Audio Visualizer Example still help me a lot. I will study this example carefully.
          I still very much appreciate your help~

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jiancaiyang
            wrote on 7 Apr 2017, 03:25 last edited by
            #5

            Qt 3D initially support obj modules without materials. Take a try.

            我们自己的论坛:http://qtdream.com
            擅长三维角色仿真动画。

            Z 1 Reply Last reply 7 Apr 2017, 12:02
            0
            • J jiancaiyang
              7 Apr 2017, 03:25

              Qt 3D initially support obj modules without materials. Take a try.

              Z Offline
              Z Offline
              z69333186
              wrote on 7 Apr 2017, 12:02 last edited by
              #6

              @jiancaiyang Thanks, I have found the Qt Documentation about the Qt 3D C++ Classes(https://doc.qt.io/qt-5/qt3d-cpp.html) and I know there is a AssimpIO Class(https://doc.qt.io/qt-5/qt3drender-assimpio.html), but i can't use it(I include <AssimpIO> but resulted in a "file not found" compiler error ) I don't whether QT don't support Assimp now or not. is there any way to load obj modules except AssimpIO Class?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 7 Apr 2017, 20:13 last edited by
                #7

                Which version of Qt are you using ?

                Did you add QT += 3drender to your .pro file ? If so, did you re-run qmake after that ?

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

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  guy incognito
                  wrote on 11 Apr 2017, 07:55 last edited by guy incognito 4 Nov 2017, 07:58
                  #8

                  I did it this way in Qt3D:

                  1. Create a .qrc file as resource
                  2. add it to your .pro:
                  RESOURCES += \
                            obj.qrc
                  
                  1. content of .qrc file looks like this, make sure the .obj file is in the right directory:
                  <RCC>
                      <qresource prefix="/">
                          <file>object1.obj</file>
                          <file>object2.obj</file>
                      </qresource>
                  </RCC>
                  
                  1. create a QEntity with all needed components like QTransform, QMaterial and especially QMesh
                  2. Add the .obj as source for the mesh:
                      Qt3DRender::QMesh *mesh = new Qt3DRender::QMesh();
                      mesh->setSource(QUrl(QStringLiteral("qrc:/object1.obj")));
                  
                  1. Add mesh and other components to entity:
                  Qt3DCore::QEntity *object = new Qt3DCore::QEntity(rootEntity);
                  object->addComponent(mesh);
                  
                  
                  1. Finished
                  Z 1 Reply Last reply 30 Apr 2017, 13:19
                  0
                  • Z Offline
                    Z Offline
                    z69333186
                    wrote on 30 Apr 2017, 13:12 last edited by
                    #9

                    Thanks for all the help.I have found to load the 3D model file(.obj) into Qt and control it.
                    Initially, I try to use C++ to complete all the function(display and control), but I find it a little complex for me. So I decide using QML to display the model and using C++ to control it.

                    I post the approach I used:

                    First, loading and displaying the 3D model using QML, you can refer to Qt 3D: Wireframe QML Example and Qt 3D: Scene3D QML Example. I think these two example include almost all the detail you need when loading and displaying the 3D model.

                    Second, i notice Entity has a property:Transform, which decide the position and angle of the 3D model displaying in the scene. The Transform accept scale, matrix, translation or rotation to define the property. So i define a C++ class, the class has some member variables that are QMatrix4x4 type. Obviously, I use QMatrix4x4 to store the coordinate matrix.

                    Third, I export the C ++ object into QML as a property that QML can use(refer to setContextProperty).

                    Fourth, bind property like this:
                    Transform {
                    id: transform
                    matrix: matrix.matrix
                    }

                    Fifth, when i want to change the position or angle, i just use C++ to change the QMatrix4x4 member variables, QML will update the scene automatically.

                    Finished~~~

                    1 Reply Last reply
                    0
                    • G guy incognito
                      11 Apr 2017, 07:55

                      I did it this way in Qt3D:

                      1. Create a .qrc file as resource
                      2. add it to your .pro:
                      RESOURCES += \
                                obj.qrc
                      
                      1. content of .qrc file looks like this, make sure the .obj file is in the right directory:
                      <RCC>
                          <qresource prefix="/">
                              <file>object1.obj</file>
                              <file>object2.obj</file>
                          </qresource>
                      </RCC>
                      
                      1. create a QEntity with all needed components like QTransform, QMaterial and especially QMesh
                      2. Add the .obj as source for the mesh:
                          Qt3DRender::QMesh *mesh = new Qt3DRender::QMesh();
                          mesh->setSource(QUrl(QStringLiteral("qrc:/object1.obj")));
                      
                      1. Add mesh and other components to entity:
                      Qt3DCore::QEntity *object = new Qt3DCore::QEntity(rootEntity);
                      object->addComponent(mesh);
                      
                      
                      1. Finished
                      Z Offline
                      Z Offline
                      z69333186
                      wrote on 30 Apr 2017, 13:19 last edited by
                      #10

                      @guy-incognito Thank you for your help. Finally I use QML to display the 3D model and C++ to control it, but you still help me a lot. Thanks

                      1 Reply Last reply
                      1

                      • Login

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