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 to load an STL file using QMesh

how to load an STL file using QMesh

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 9.4k 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.
  • D Offline
    D Offline
    Dimis
    wrote on 5 Dec 2017, 12:22 last edited by
    #1

    Hi all,

    I'm really new to Qt, using it only just a couple of weeks.

    I'm trying to find a way to load STL (stereolithography) files and display them. I've checked the documentation but there is no example of how to implement it.

    Is there any tutorial or past example that I could study for doing this?

    Thank you in advance for any help.

    R 1 Reply Last reply 5 Dec 2017, 14:19
    0
    • P Offline
      P Offline
      Pablo J. Rogina
      wrote on 5 Dec 2017, 14:09 last edited by
      #2

      @Dimis I'd say you can have a look at the variety of Qt 3D examples to get used to the framework, and then you may also take a look at some previous posts: here and here.

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • D Dimis
        5 Dec 2017, 12:22

        Hi all,

        I'm really new to Qt, using it only just a couple of weeks.

        I'm trying to find a way to load STL (stereolithography) files and display them. I've checked the documentation but there is no example of how to implement it.

        Is there any tutorial or past example that I could study for doing this?

        Thank you in advance for any help.

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 5 Dec 2017, 14:19 last edited by
        #3

        @Dimis
        I personally haven't used it yet, but by looking at the docs you should use the source property

        QMesh mesh = ...;
        mesh.setSource( QUrl::fromLocalFile("path/to/local/file.stl") );
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dimis
          wrote on 6 Dec 2017, 12:45 last edited by
          #4

          Thank you for your responses. I'll give a try.

          D 1 Reply Last reply 17 Jan 2018, 16:15
          0
          • D Dimis
            6 Dec 2017, 12:45

            Thank you for your responses. I'll give a try.

            D Offline
            D Offline
            Dimis
            wrote on 17 Jan 2018, 16:15 last edited by
            #5

            I've sort it out. Just for anyone interested in this, my code for loading STL files is below.

            QGuiApplication a(argc, argv);
            QUrl data = QUrl::fromLocalFile("C:/Qt/Examples/objloader2/cadtrainingblock24asc.stl");

            Qt3DExtras::Qt3DWindow view;
            
            Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity;
            Qt3DCore::QEntity *flyingwedge = new Qt3DCore::QEntity(rootEntity);
            
            Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial();
            material->setDiffuse(QColor(254, 254, 254));
            
            Qt3DRender::QMesh *flyingwedgeMesh = new Qt3DRender::QMesh;
            flyingwedgeMesh->setMeshName("FlyingWedge");
            flyingwedgeMesh->setSource(data);
            flyingwedge->addComponent(flyingwedgeMesh);
            flyingwedge->addComponent(material);
            
            Qt3DRender::QCamera *camera = view.camera();
            camera->lens()->setPerspectiveProjection(40.0f, 16.0f/9.0f, 0.1f, 1000.0f);
            camera->setPosition(QVector3D(0, 0, 40.0f));
            camera->setViewCenter(QVector3D(0, 0, 0));
            
            Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);
            Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);
            light->setColor("white");
            light->setIntensity(0.8f);
            lightEntity->addComponent(light);
            
            Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity);
            lightTransform->setTranslation(QVector3D(60, 0, 40.0f));
            lightEntity->addComponent(lightTransform);
            
            Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(rootEntity);
            camController->setCamera(camera);
            
            view.setRootEntity(rootEntity);
            view.show();
            
            return a.exec();
            
            1 Reply Last reply
            1
            • J Offline
              J Offline
              JoseAndresGT
              wrote on 4 Nov 2019, 15:00 last edited by
              #6

              Do you know how I can get the QVector3D from the "Entity"? I want to set the camera position (camera-> setPosition) with a dynamic QVector3D using the geometry of the scene entity

              https://www.marine.sener/foran

              FORAN capitalizes on SENER’s engineering and ship design know-how, as SENER is the only company that offers services of this kind and that has also developed a marine design system.

              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