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 Simple Model (.obj) Viewer?
QtWS25 Last Chance

Qt3D Simple Model (.obj) Viewer?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 9.8k 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.
  • O Offline
    O Offline
    oblivioncth
    wrote on 3 May 2016, 06:48 last edited by
    #1

    Hi,

    I am currently trying to use Qt3D to have just a simple Wavefront .obj viewer in a window that you can pan around using mouse input. It appears that Qt3D underwent a major overhaul somewhat recently and therefore the examples of documentation for it now seem somewhat sparse (at least as far as I could see). There is an old example that seems to do exactly what I want, thought it probably wouldn't work anymore and regardless the files have been removed from the Qt git: https://wiki.qt.io/Loading-a-3D-Model

    The closest I could find was this example: http://doc.qt.io/qt-5/qt3d-basicshapes-cpp-example.html

    which essentially does exactly what I want, except that instead of there being the random for shapes I want the view to be of a .obj file. It seems like a simple enough task that doesn't require anything too complicated, but all the other examples or information I can find seems way over complicated and not really what I am looking for. I imagine I may be able to modify that example in someway to do what I want but I am not sure how to load in a model instead of creating a blank scene. I looked through some of the Qt3D classes documentation but couldn't find much and it seems like it is a huge thing to just look through blindly.

    I was hoping that someone would have an idea on how to easily accomplish this. The old example didn't look to complicated, but again the code for it is gone and I doubt it works on the current version of Qt3D.

    Thanks.

    K 1 Reply Last reply 3 May 2016, 08:18
    0
    • O oblivioncth
      3 May 2016, 06:48

      Hi,

      I am currently trying to use Qt3D to have just a simple Wavefront .obj viewer in a window that you can pan around using mouse input. It appears that Qt3D underwent a major overhaul somewhat recently and therefore the examples of documentation for it now seem somewhat sparse (at least as far as I could see). There is an old example that seems to do exactly what I want, thought it probably wouldn't work anymore and regardless the files have been removed from the Qt git: https://wiki.qt.io/Loading-a-3D-Model

      The closest I could find was this example: http://doc.qt.io/qt-5/qt3d-basicshapes-cpp-example.html

      which essentially does exactly what I want, except that instead of there being the random for shapes I want the view to be of a .obj file. It seems like a simple enough task that doesn't require anything too complicated, but all the other examples or information I can find seems way over complicated and not really what I am looking for. I imagine I may be able to modify that example in someway to do what I want but I am not sure how to load in a model instead of creating a blank scene. I looked through some of the Qt3D classes documentation but couldn't find much and it seems like it is a huge thing to just look through blindly.

      I was hoping that someone would have an idea on how to easily accomplish this. The old example didn't look to complicated, but again the code for it is gone and I doubt it works on the current version of Qt3D.

      Thanks.

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 3 May 2016, 08:18 last edited by kshegunov 5 Mar 2016, 17:56
      #2

      @oblivioncth

      It should be something along the lines of:

      Qt3DCore::QEntity * meshEntity = new Qt3DCore::QEntity();
      
      Qt3DRender::QMesh * myMesh = new Qt3DRender::QMesh();
      myMesh->setSource(QUrl::fromLocalFile("/my/file/mesh.obj"));
      
      meshEntity->addComponent(myMesh);
      

      Read and abide by the Qt Code of Conduct

      O 2 Replies Last reply 3 May 2016, 17:58
      0
      • K kshegunov
        3 May 2016, 08:18

        @oblivioncth

        It should be something along the lines of:

        Qt3DCore::QEntity * meshEntity = new Qt3DCore::QEntity();
        
        Qt3DRender::QMesh * myMesh = new Qt3DRender::QMesh();
        myMesh->setSource(QUrl::fromLocalFile("/my/file/mesh.obj"));
        
        meshEntity->addComponent(myMesh);
        
        O Offline
        O Offline
        oblivioncth
        wrote on 3 May 2016, 17:58 last edited by
        #3

        @kshegunov

        Thanks a bunch, I'll try it out.

        1 Reply Last reply
        0
        • K kshegunov
          3 May 2016, 08:18

          @oblivioncth

          It should be something along the lines of:

          Qt3DCore::QEntity * meshEntity = new Qt3DCore::QEntity();
          
          Qt3DRender::QMesh * myMesh = new Qt3DRender::QMesh();
          myMesh->setSource(QUrl::fromLocalFile("/my/file/mesh.obj"));
          
          meshEntity->addComponent(myMesh);
          
          O Offline
          O Offline
          oblivioncth
          wrote on 4 May 2016, 00:21 last edited by oblivioncth 5 Apr 2016, 00:21
          #4

          @kshegunov

          I have modified and implemented the example code you provided and it mostly works (thanks again)!. The only problem is that the mesh that appears in the window (I am using that basic shapes example I linked to as a base) is partially invisible when viewed from one side. The .obj mesh I am using to test this is a smooth curved surface with some spike like portions coming off it. When viewed from the one side in the viewer only the spikes are visible and not the curved surface. When opening the .obj file using the Windows 3D Builder application this is not the case, and the entire model can be viewed from any angle.

          Is there some kind of interpretation setting that I need to change when loading the mesh? Is there more information contained within the Waveform file, other than just the mesh, that Windows 3D Builder sees but that I am not passing into the program with just the line:

          myMesh->setSource(QUrl::fromLocalFile("/my/file/mesh.obj"));
          

          ?

          Is there a setting I need to change with the camera?

          Sorry I don't really have any experience with 3D modeling I am just trying to implement this viewer into another program as a quick tool for part of a larger purpose.

          Here is the model in question: https://www.mediafire.com/?200ypclraebv4b9

          and here is what the code pretty much ended up being:

              //Model shape data
              Qt3DRender::QMesh * ModelMesh = new Qt3DRender::QMesh();
              ModelMesh->setSource(QUrl::fromLocalFile("C:/Users/Chris/Model.obj"));
          
          
              //Model Transform
              Qt3DRender::QPhongMaterial *ModelMaterial = new Qt3DRender::QPhongMaterial();
              ModelMaterial->setDiffuse(QColor(QRgb(0x665423)));
          
              // Model
              ModelEntity = new Qt3DCore::QEntity(m_rootEntity);
              ModelEntity->addComponent(ModelMesh);
              ModelEntity->addComponent(ModelMaterial);
          
          K 1 Reply Last reply 5 May 2016, 11:44
          0
          • O oblivioncth
            4 May 2016, 00:21

            @kshegunov

            I have modified and implemented the example code you provided and it mostly works (thanks again)!. The only problem is that the mesh that appears in the window (I am using that basic shapes example I linked to as a base) is partially invisible when viewed from one side. The .obj mesh I am using to test this is a smooth curved surface with some spike like portions coming off it. When viewed from the one side in the viewer only the spikes are visible and not the curved surface. When opening the .obj file using the Windows 3D Builder application this is not the case, and the entire model can be viewed from any angle.

            Is there some kind of interpretation setting that I need to change when loading the mesh? Is there more information contained within the Waveform file, other than just the mesh, that Windows 3D Builder sees but that I am not passing into the program with just the line:

            myMesh->setSource(QUrl::fromLocalFile("/my/file/mesh.obj"));
            

            ?

            Is there a setting I need to change with the camera?

            Sorry I don't really have any experience with 3D modeling I am just trying to implement this viewer into another program as a quick tool for part of a larger purpose.

            Here is the model in question: https://www.mediafire.com/?200ypclraebv4b9

            and here is what the code pretty much ended up being:

                //Model shape data
                Qt3DRender::QMesh * ModelMesh = new Qt3DRender::QMesh();
                ModelMesh->setSource(QUrl::fromLocalFile("C:/Users/Chris/Model.obj"));
            
            
                //Model Transform
                Qt3DRender::QPhongMaterial *ModelMaterial = new Qt3DRender::QPhongMaterial();
                ModelMaterial->setDiffuse(QColor(QRgb(0x665423)));
            
                // Model
                ModelEntity = new Qt3DCore::QEntity(m_rootEntity);
                ModelEntity->addComponent(ModelMesh);
                ModelEntity->addComponent(ModelMaterial);
            
            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 5 May 2016, 11:44 last edited by
            #5

            @oblivioncth said:

            Is there some kind of interpretation setting that I need to change when loading the mesh? Is there more information contained within the Waveform file, other than just the mesh, that Windows 3D Builder sees but that I am not passing into the program with just the line:

            I'm not intimate with Qt3D, I had played a bit with it some time ago, but the API was rapidly changing so I decided to wait a bit. That said it's possible that your model contains data that couldn't be parsed by the object loader in Qt3D. Perhaps you should make a first attempt with a standard mesh, something from here? (I know for a fact that the lamp.obj file should be loaded without problems).

            Is there a setting I need to change with the camera?

            Usually you set the projection type for the camera lens, but that should be already done if you're using the example as a base guide.

            Aside from that your code looks fine to me.

            Read and abide by the Qt Code of Conduct

            O 1 Reply Last reply 7 May 2016, 03:44
            0
            • K kshegunov
              5 May 2016, 11:44

              @oblivioncth said:

              Is there some kind of interpretation setting that I need to change when loading the mesh? Is there more information contained within the Waveform file, other than just the mesh, that Windows 3D Builder sees but that I am not passing into the program with just the line:

              I'm not intimate with Qt3D, I had played a bit with it some time ago, but the API was rapidly changing so I decided to wait a bit. That said it's possible that your model contains data that couldn't be parsed by the object loader in Qt3D. Perhaps you should make a first attempt with a standard mesh, something from here? (I know for a fact that the lamp.obj file should be loaded without problems).

              Is there a setting I need to change with the camera?

              Usually you set the projection type for the camera lens, but that should be already done if you're using the example as a base guide.

              Aside from that your code looks fine to me.

              O Offline
              O Offline
              oblivioncth
              wrote on 7 May 2016, 03:44 last edited by
              #6

              @kshegunov

              Ok, thanks for the insight. Ill try some things.

              1 Reply Last reply
              0

              5/6

              5 May 2016, 11:44

              • Login

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