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. Loading OBJ Files from Resource
Qt 6.11 is out! See what's new in the release blog

Loading OBJ Files from Resource

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 3.2k Views 1 Watching
  • 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.
  • webzoidW Offline
    webzoidW Offline
    webzoid
    wrote on last edited by
    #1

    I have a QWidgets application which loads an OBJ file from a resource into a Qt3DRender::QMesh instance.

    When running the application via QtCreator in debug and release mode, the OBJ mesh is displayed correctly in my QWidget (via the Qt3DExtras::Qt3DWindow).

    However, if I run the application in its installation directory on a local machine (i.e. C:\Program Files\MyApp\MyApp.exe) then the OBJ files are not loaded and the QWidget is empty.

    I've ensured that all the relevant resource-related files are part of the installation image and I've also copied across the OBJ files to the installation dir. Unfortunately none of this solves the issue.

    What could I be missing?

    For reference, the code for creating and loading the 3D stuff is as follows:

    // Create the view
    m_view = new Qt3DExtras::Qt3DWindow();
    m_view->defaultFrameGraph()->setClearColor(bg);
    
    // Create the container widget
    m_container = QWidget::createWindowContainer(m_view);
    
    // Add the container to the layout
    this->layout()->addWidget(m_container);
    
    // Create a root entity
    m_root = new Qt3DCore::QEntity;
    
    // Update scene camera
    m_camera = m_view->camera();
    m_camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
    m_camera->setPosition(QVector3D(0, 0, 8.0f));
    m_camera->setUpVector(QVector3D(0, 1, 0));
    m_camera->setViewCenter(QVector3D(0, 0, 0));
    
    // Set up the scene lighting
    m_light = new Qt3DCore::QEntity(m_root);
    
    m_point = new Qt3DRender::QPointLight(m_light);
    m_point->setColor("silver");
    m_point->setIntensity(1);
    m_light->addComponent(m_point);
    m_lightTransform = new Qt3DCore::QTransform(m_light);
    m_lightTransform->setTranslation(m_camera->position());
    m_light->addComponent(m_lightTransform);
    
    m_model = new Qt3DCore::QEntity(m_root);
    m_mesh = new Qt3DRender::QMesh();
    m_mesh->setSource(QUrl("qrc:/Resources/Models/MyModel.obj"));
    
    m_material = new Qt3DExtras::QPhongMaterial;
    m_material->setDiffuse(QColor(Qt::darkGray));
    
    m_transform = new Qt3DCore::QTransform;
    m_transform->setScale(1.0);
    m_transform->setRotation(QQuaternion::fromEulerAngles(0.0, 0.0, 0.0));
    
    m_model->addComponent(m_mesh);
    m_model->addComponent(m_transform);
    m_model->addComponent(m_material);
    
    m_view->setRootEntity(m_root);
    
    VRoninV 1 Reply Last reply
    0
    • webzoidW webzoid

      I have a QWidgets application which loads an OBJ file from a resource into a Qt3DRender::QMesh instance.

      When running the application via QtCreator in debug and release mode, the OBJ mesh is displayed correctly in my QWidget (via the Qt3DExtras::Qt3DWindow).

      However, if I run the application in its installation directory on a local machine (i.e. C:\Program Files\MyApp\MyApp.exe) then the OBJ files are not loaded and the QWidget is empty.

      I've ensured that all the relevant resource-related files are part of the installation image and I've also copied across the OBJ files to the installation dir. Unfortunately none of this solves the issue.

      What could I be missing?

      For reference, the code for creating and loading the 3D stuff is as follows:

      // Create the view
      m_view = new Qt3DExtras::Qt3DWindow();
      m_view->defaultFrameGraph()->setClearColor(bg);
      
      // Create the container widget
      m_container = QWidget::createWindowContainer(m_view);
      
      // Add the container to the layout
      this->layout()->addWidget(m_container);
      
      // Create a root entity
      m_root = new Qt3DCore::QEntity;
      
      // Update scene camera
      m_camera = m_view->camera();
      m_camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
      m_camera->setPosition(QVector3D(0, 0, 8.0f));
      m_camera->setUpVector(QVector3D(0, 1, 0));
      m_camera->setViewCenter(QVector3D(0, 0, 0));
      
      // Set up the scene lighting
      m_light = new Qt3DCore::QEntity(m_root);
      
      m_point = new Qt3DRender::QPointLight(m_light);
      m_point->setColor("silver");
      m_point->setIntensity(1);
      m_light->addComponent(m_point);
      m_lightTransform = new Qt3DCore::QTransform(m_light);
      m_lightTransform->setTranslation(m_camera->position());
      m_light->addComponent(m_lightTransform);
      
      m_model = new Qt3DCore::QEntity(m_root);
      m_mesh = new Qt3DRender::QMesh();
      m_mesh->setSource(QUrl("qrc:/Resources/Models/MyModel.obj"));
      
      m_material = new Qt3DExtras::QPhongMaterial;
      m_material->setDiffuse(QColor(Qt::darkGray));
      
      m_transform = new Qt3DCore::QTransform;
      m_transform->setScale(1.0);
      m_transform->setRotation(QQuaternion::fromEulerAngles(0.0, 0.0, 0.0));
      
      m_model->addComponent(m_mesh);
      m_model->addComponent(m_transform);
      m_model->addComponent(m_material);
      
      m_view->setRootEntity(m_root);
      
      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @webzoid said in Loading OBJ Files from Resource:

      C:\Program Files\MyApp\MyApp.exe

      I guess you are on windows. did you use windeployqt.exe to build your installation folder?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • webzoidW Offline
        webzoidW Offline
        webzoid
        wrote on last edited by
        #3

        @VRonin Indeed, I did.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          You might be missing the Qt3DAnimation .dll. There's a patch in review for windeployqt for that.

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

          webzoidW 1 Reply Last reply
          2
          • SGaistS SGaist

            Hi,

            You might be missing the Qt3DAnimation .dll. There's a patch in review for windeployqt for that.

            webzoidW Offline
            webzoidW Offline
            webzoid
            wrote on last edited by
            #5

            @SGaist Unfortunately this doesn't solve the issue.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Do you have the geometryloaders, renderplugins and sceneparsers plugins deployed ?

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

              webzoidW 1 Reply Last reply
              4
              • SGaistS SGaist

                Do you have the geometryloaders, renderplugins and sceneparsers plugins deployed ?

                webzoidW Offline
                webzoidW Offline
                webzoid
                wrote on last edited by
                #7

                @SGaist I had the renderplugins and sceneparsers but not the geometryloaders.

                Having now copied across the relevant files into a geometryloaders directory, this now works perfectly.

                Thank you!

                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