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. Importing a 3D object in to the window
Forum Updated to NodeBB v4.3 + New Features

Importing a 3D object in to the window

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 4 Posters 4.9k Views 2 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.
  • hareeshqtH Offline
    hareeshqtH Offline
    hareeshqt
    wrote on last edited by hareeshqt
    #1

    Hi, I have created a window with buttons like forward and backward etc...so how can I import a 3D image(.obj from blender) so that I can control that robot in the same window.

    import Qt3D.Core 2.0
    import Qt3D.Render 2.0
    import QtQuick 2.2 as QQ2

    Entity {
    id: carMesh

        source: "untitled.3ds"
    

    }
    Item3D {
    Mesh: carMesh
    }
    }

    It's saying syntax error near Item3D. can someone help me please....

    1 Reply Last reply
    0
    • Ni.SumiN Offline
      Ni.SumiN Offline
      Ni.Sumi
      wrote on last edited by
      #2

      Hi @hareeshqt ,

      Did you try these 3D models ?

      hareeshqtH 1 Reply Last reply
      0
      • Ni.SumiN Ni.Sumi

        Hi @hareeshqt ,

        Did you try these 3D models ?

        hareeshqtH Offline
        hareeshqtH Offline
        hareeshqt
        wrote on last edited by
        #3

        @Ni.Sumi I have tried the wavefront model but I need the buttons and the 3D model in the same window...

        1 Reply Last reply
        0
        • Ni.SumiN Offline
          Ni.SumiN Offline
          Ni.Sumi
          wrote on last edited by
          #4

          @hareeshqt , you are talking some thing like in AudioVisualizer ? Like the stop , play and controlling the mesh ?

          hareeshqtH 1 Reply Last reply
          0
          • Ni.SumiN Ni.Sumi

            @hareeshqt , you are talking some thing like in AudioVisualizer ? Like the stop , play and controlling the mesh ?

            hareeshqtH Offline
            hareeshqtH Offline
            hareeshqt
            wrote on last edited by
            #5

            @Ni.Sumi Yes, we need to control a robotic arm here

            ? 1 Reply Last reply
            0
            • hareeshqtH hareeshqt

              @Ni.Sumi Yes, we need to control a robotic arm here

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @hareeshqt Hi! I've built a small demo for you, see a video here and get the sources here.

              Looks like this:

              Code is:

              main.cpp

              #include <QGuiApplication>
              #include <QQmlApplicationEngine>
              
              int main(int argc, char *argv[])
              {
                  QGuiApplication app(argc, argv);
              
                  QQmlApplicationEngine engine;
                  engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
              
                  return app.exec();
              }
              

              main.qml

              import QtQuick 2.5
              import Qt3D.Core 2.0
              import Qt3D.Render 2.0
              import QtQuick.Scene3D 2.0
              import QtQuick.Window 2.2
              import QtQuick.Controls 1.4
              
              ApplicationWindow {
                  visible: true
                  width: 640
                  height: 480
              
                  // Background
                  Rectangle {
                      id: backgroundRectangle
                      anchors.fill: parent
                      gradient: Gradient {
                          GradientStop { position: 0.0; color: "#5A6B9B" }
                          GradientStop { position: 1.0; color: "#E4E4E4" }
                      }
                  }
              
                  // 3D scene
                  Scene3D {
                      id: scene3d
                      anchors.fill: parent
                      aspects: "input"
              
                      Entity {
                          id: root
              
                          components: [
                              FrameGraph {
                                  activeFrameGraph: Viewport {
                                      rect: Qt.rect(0.0, 0.0, 1.0, 1.0)
                                      clearColor: "transparent"
              
                                      CameraSelector {
                                          camera: mainCamera
                                          ClearBuffer {
                                              buffers: ClearBuffer.ColorDepthBuffer
                                          }
              
                                      }
                                  }
                              }
                          ]
              
                          Camera {
                              id: mainCamera
                              projectionType: CameraLens.PerspectiveProjection
                              fieldOfView: 45.0 / 8.0
                              nearPlane:   0.1
                              farPlane:    1000.0
                              viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
                              upVector:   Qt.vector3d( 0.0, 1.0, 0.0 )
                              position: Qt.vector3d( 0.0, 0.0, 10.0 )
                              aspectRatio: scene3d.width / scene3d.height
                          }
              
                          Configuration  {
                              controlledCamera: mainCamera
                          }
              
                          Mesh {
                              id: myMesh
                              source: "qrc:/assets/gear.obj"
                          }
              
                          PhongMaterial {
                              id: myMaterial
                              ambient: Qt.rgba( 0.3, 0.3, 0.3, 1.0 )
                              diffuse: Qt.rgba( 0.7, 0.7, 0.7, 1.0 )
                          }
              
                          Transform {
                              id: myTransform
                              property real userAngle: 0.0
                              property real userDistance: 0.0
                              matrix: {
                                  var m = Qt.matrix4x4();
                                  m.rotate(userAngle, Qt.vector3d(1, 1, 0));
                                  m.translate(Qt.vector3d(userDistance, 0, 0));
                                  return m;
                              }
                          }
              
                          Entity {
                              id: myEntity
                              components: [ myMesh, myMaterial, myTransform ]
                          }
                      }
                  }
              
              
                  // Controls overlay
                  Row {
                      Button {
                          text: "Rotate XY+"
                          onClicked: myTransform.userAngle += 10
                      }
                      Button {
                          text: "Rotate XY-"
                          onClicked: myTransform.userAngle -= 10
                      }
                      Button {
                          text: "Transform X+"
                          onClicked: myTransform.userDistance += 0.05
                      }
                      Button {
                          text: "Transform X-"
                          onClicked: myTransform.userDistance -= 0.05
                      }
                      Button {
                          text: "Reset transformation"
                          onClicked: {
                              myTransform.userAngle = 0.0
                              myTransform.userDistance = 0.0
                          }
                      }
                      Button {
                          text: "Exit"
                          onClicked: Qt.quit()
                      }
                  }
              }
              
              hareeshqtH S 3 Replies Last reply
              1
              • ? A Former User

                @hareeshqt Hi! I've built a small demo for you, see a video here and get the sources here.

                Looks like this:

                Code is:

                main.cpp

                #include <QGuiApplication>
                #include <QQmlApplicationEngine>
                
                int main(int argc, char *argv[])
                {
                    QGuiApplication app(argc, argv);
                
                    QQmlApplicationEngine engine;
                    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
                
                    return app.exec();
                }
                

                main.qml

                import QtQuick 2.5
                import Qt3D.Core 2.0
                import Qt3D.Render 2.0
                import QtQuick.Scene3D 2.0
                import QtQuick.Window 2.2
                import QtQuick.Controls 1.4
                
                ApplicationWindow {
                    visible: true
                    width: 640
                    height: 480
                
                    // Background
                    Rectangle {
                        id: backgroundRectangle
                        anchors.fill: parent
                        gradient: Gradient {
                            GradientStop { position: 0.0; color: "#5A6B9B" }
                            GradientStop { position: 1.0; color: "#E4E4E4" }
                        }
                    }
                
                    // 3D scene
                    Scene3D {
                        id: scene3d
                        anchors.fill: parent
                        aspects: "input"
                
                        Entity {
                            id: root
                
                            components: [
                                FrameGraph {
                                    activeFrameGraph: Viewport {
                                        rect: Qt.rect(0.0, 0.0, 1.0, 1.0)
                                        clearColor: "transparent"
                
                                        CameraSelector {
                                            camera: mainCamera
                                            ClearBuffer {
                                                buffers: ClearBuffer.ColorDepthBuffer
                                            }
                
                                        }
                                    }
                                }
                            ]
                
                            Camera {
                                id: mainCamera
                                projectionType: CameraLens.PerspectiveProjection
                                fieldOfView: 45.0 / 8.0
                                nearPlane:   0.1
                                farPlane:    1000.0
                                viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
                                upVector:   Qt.vector3d( 0.0, 1.0, 0.0 )
                                position: Qt.vector3d( 0.0, 0.0, 10.0 )
                                aspectRatio: scene3d.width / scene3d.height
                            }
                
                            Configuration  {
                                controlledCamera: mainCamera
                            }
                
                            Mesh {
                                id: myMesh
                                source: "qrc:/assets/gear.obj"
                            }
                
                            PhongMaterial {
                                id: myMaterial
                                ambient: Qt.rgba( 0.3, 0.3, 0.3, 1.0 )
                                diffuse: Qt.rgba( 0.7, 0.7, 0.7, 1.0 )
                            }
                
                            Transform {
                                id: myTransform
                                property real userAngle: 0.0
                                property real userDistance: 0.0
                                matrix: {
                                    var m = Qt.matrix4x4();
                                    m.rotate(userAngle, Qt.vector3d(1, 1, 0));
                                    m.translate(Qt.vector3d(userDistance, 0, 0));
                                    return m;
                                }
                            }
                
                            Entity {
                                id: myEntity
                                components: [ myMesh, myMaterial, myTransform ]
                            }
                        }
                    }
                
                
                    // Controls overlay
                    Row {
                        Button {
                            text: "Rotate XY+"
                            onClicked: myTransform.userAngle += 10
                        }
                        Button {
                            text: "Rotate XY-"
                            onClicked: myTransform.userAngle -= 10
                        }
                        Button {
                            text: "Transform X+"
                            onClicked: myTransform.userDistance += 0.05
                        }
                        Button {
                            text: "Transform X-"
                            onClicked: myTransform.userDistance -= 0.05
                        }
                        Button {
                            text: "Reset transformation"
                            onClicked: {
                                myTransform.userAngle = 0.0
                                myTransform.userDistance = 0.0
                            }
                        }
                        Button {
                            text: "Exit"
                            onClicked: Qt.quit()
                        }
                    }
                }
                
                hareeshqtH Offline
                hareeshqtH Offline
                hareeshqt
                wrote on last edited by
                #7

                @Wieland OK Many Many thanks....I think you have completed majority of my task....trying the model now...

                1 Reply Last reply
                0
                • ? A Former User

                  @hareeshqt Hi! I've built a small demo for you, see a video here and get the sources here.

                  Looks like this:

                  Code is:

                  main.cpp

                  #include <QGuiApplication>
                  #include <QQmlApplicationEngine>
                  
                  int main(int argc, char *argv[])
                  {
                      QGuiApplication app(argc, argv);
                  
                      QQmlApplicationEngine engine;
                      engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
                  
                      return app.exec();
                  }
                  

                  main.qml

                  import QtQuick 2.5
                  import Qt3D.Core 2.0
                  import Qt3D.Render 2.0
                  import QtQuick.Scene3D 2.0
                  import QtQuick.Window 2.2
                  import QtQuick.Controls 1.4
                  
                  ApplicationWindow {
                      visible: true
                      width: 640
                      height: 480
                  
                      // Background
                      Rectangle {
                          id: backgroundRectangle
                          anchors.fill: parent
                          gradient: Gradient {
                              GradientStop { position: 0.0; color: "#5A6B9B" }
                              GradientStop { position: 1.0; color: "#E4E4E4" }
                          }
                      }
                  
                      // 3D scene
                      Scene3D {
                          id: scene3d
                          anchors.fill: parent
                          aspects: "input"
                  
                          Entity {
                              id: root
                  
                              components: [
                                  FrameGraph {
                                      activeFrameGraph: Viewport {
                                          rect: Qt.rect(0.0, 0.0, 1.0, 1.0)
                                          clearColor: "transparent"
                  
                                          CameraSelector {
                                              camera: mainCamera
                                              ClearBuffer {
                                                  buffers: ClearBuffer.ColorDepthBuffer
                                              }
                  
                                          }
                                      }
                                  }
                              ]
                  
                              Camera {
                                  id: mainCamera
                                  projectionType: CameraLens.PerspectiveProjection
                                  fieldOfView: 45.0 / 8.0
                                  nearPlane:   0.1
                                  farPlane:    1000.0
                                  viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
                                  upVector:   Qt.vector3d( 0.0, 1.0, 0.0 )
                                  position: Qt.vector3d( 0.0, 0.0, 10.0 )
                                  aspectRatio: scene3d.width / scene3d.height
                              }
                  
                              Configuration  {
                                  controlledCamera: mainCamera
                              }
                  
                              Mesh {
                                  id: myMesh
                                  source: "qrc:/assets/gear.obj"
                              }
                  
                              PhongMaterial {
                                  id: myMaterial
                                  ambient: Qt.rgba( 0.3, 0.3, 0.3, 1.0 )
                                  diffuse: Qt.rgba( 0.7, 0.7, 0.7, 1.0 )
                              }
                  
                              Transform {
                                  id: myTransform
                                  property real userAngle: 0.0
                                  property real userDistance: 0.0
                                  matrix: {
                                      var m = Qt.matrix4x4();
                                      m.rotate(userAngle, Qt.vector3d(1, 1, 0));
                                      m.translate(Qt.vector3d(userDistance, 0, 0));
                                      return m;
                                  }
                              }
                  
                              Entity {
                                  id: myEntity
                                  components: [ myMesh, myMaterial, myTransform ]
                              }
                          }
                      }
                  
                  
                      // Controls overlay
                      Row {
                          Button {
                              text: "Rotate XY+"
                              onClicked: myTransform.userAngle += 10
                          }
                          Button {
                              text: "Rotate XY-"
                              onClicked: myTransform.userAngle -= 10
                          }
                          Button {
                              text: "Transform X+"
                              onClicked: myTransform.userDistance += 0.05
                          }
                          Button {
                              text: "Transform X-"
                              onClicked: myTransform.userDistance -= 0.05
                          }
                          Button {
                              text: "Reset transformation"
                              onClicked: {
                                  myTransform.userAngle = 0.0
                                  myTransform.userDistance = 0.0
                              }
                          }
                          Button {
                              text: "Exit"
                              onClicked: Qt.quit()
                          }
                      }
                  }
                  
                  hareeshqtH Offline
                  hareeshqtH Offline
                  hareeshqt
                  wrote on last edited by hareeshqt
                  #8

                  @Wieland HI, Thank you very much for the model,I have tried my 3d model and it's working perfectly fine but in my model I need to move only some specific parts like the arms or the gripper and I have selected the vertices of that parts from blender (X=0.2354,Y=0.3547,Z=2.3356) like this, so which command should I use to make that parts move.....

                  ? 1 Reply Last reply
                  0
                  • hareeshqtH hareeshqt

                    @Wieland HI, Thank you very much for the model,I have tried my 3d model and it's working perfectly fine but in my model I need to move only some specific parts like the arms or the gripper and I have selected the vertices of that parts from blender (X=0.2354,Y=0.3547,Z=2.3356) like this, so which command should I use to make that parts move.....

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    @hareeshqt You need to but each part into its own .obj file. In the demo the gear represents a single movable part. You need to create a mesh (in qml) from each .obj file and create a dedicated transformation (in qml) for each of these meshes. You can then control the parts individually. To form kinematic chains you need to concatenate the transformations.

                    hareeshqtH 1 Reply Last reply
                    0
                    • ? A Former User

                      @hareeshqt You need to but each part into its own .obj file. In the demo the gear represents a single movable part. You need to create a mesh (in qml) from each .obj file and create a dedicated transformation (in qml) for each of these meshes. You can then control the parts individually. To form kinematic chains you need to concatenate the transformations.

                      hareeshqtH Offline
                      hareeshqtH Offline
                      hareeshqt
                      wrote on last edited by
                      #10

                      @Wieland Yes I have created meshes for each part individually and they have different vertices.

                      // onClicked: myTransform.userAngle += 10
                      
                      should I use those vertices here...
                      ? 1 Reply Last reply
                      0
                      • hareeshqtH hareeshqt

                        @Wieland Yes I have created meshes for each part individually and they have different vertices.

                        // onClicked: myTransform.userAngle += 10
                        
                        should I use those vertices here...
                        ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #11

                        @hareeshqt Sorry dude, I really don't understand your question. Do you know how transformation matrices work?

                        hareeshqtH 1 Reply Last reply
                        0
                        • ? A Former User

                          @hareeshqt Sorry dude, I really don't understand your question. Do you know how transformation matrices work?

                          hareeshqtH Offline
                          hareeshqtH Offline
                          hareeshqt
                          wrote on last edited by
                          #12

                          @Wieland No, I don't have the idea. I thought that by using these vertices in the qml code we can move only those parts in the model. Is there any example to learn regarding this?

                          ? 1 Reply Last reply
                          0
                          • hareeshqtH hareeshqt

                            @Wieland No, I don't have the idea. I thought that by using these vertices in the qml code we can move only those parts in the model. Is there any example to learn regarding this?

                            ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by
                            #13

                            @hareeshqt I've sent you a link to a book on the chat.

                            1 Reply Last reply
                            0
                            • ? A Former User

                              @hareeshqt Hi! I've built a small demo for you, see a video here and get the sources here.

                              Looks like this:

                              Code is:

                              main.cpp

                              #include <QGuiApplication>
                              #include <QQmlApplicationEngine>
                              
                              int main(int argc, char *argv[])
                              {
                                  QGuiApplication app(argc, argv);
                              
                                  QQmlApplicationEngine engine;
                                  engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
                              
                                  return app.exec();
                              }
                              

                              main.qml

                              import QtQuick 2.5
                              import Qt3D.Core 2.0
                              import Qt3D.Render 2.0
                              import QtQuick.Scene3D 2.0
                              import QtQuick.Window 2.2
                              import QtQuick.Controls 1.4
                              
                              ApplicationWindow {
                                  visible: true
                                  width: 640
                                  height: 480
                              
                                  // Background
                                  Rectangle {
                                      id: backgroundRectangle
                                      anchors.fill: parent
                                      gradient: Gradient {
                                          GradientStop { position: 0.0; color: "#5A6B9B" }
                                          GradientStop { position: 1.0; color: "#E4E4E4" }
                                      }
                                  }
                              
                                  // 3D scene
                                  Scene3D {
                                      id: scene3d
                                      anchors.fill: parent
                                      aspects: "input"
                              
                                      Entity {
                                          id: root
                              
                                          components: [
                                              FrameGraph {
                                                  activeFrameGraph: Viewport {
                                                      rect: Qt.rect(0.0, 0.0, 1.0, 1.0)
                                                      clearColor: "transparent"
                              
                                                      CameraSelector {
                                                          camera: mainCamera
                                                          ClearBuffer {
                                                              buffers: ClearBuffer.ColorDepthBuffer
                                                          }
                              
                                                      }
                                                  }
                                              }
                                          ]
                              
                                          Camera {
                                              id: mainCamera
                                              projectionType: CameraLens.PerspectiveProjection
                                              fieldOfView: 45.0 / 8.0
                                              nearPlane:   0.1
                                              farPlane:    1000.0
                                              viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
                                              upVector:   Qt.vector3d( 0.0, 1.0, 0.0 )
                                              position: Qt.vector3d( 0.0, 0.0, 10.0 )
                                              aspectRatio: scene3d.width / scene3d.height
                                          }
                              
                                          Configuration  {
                                              controlledCamera: mainCamera
                                          }
                              
                                          Mesh {
                                              id: myMesh
                                              source: "qrc:/assets/gear.obj"
                                          }
                              
                                          PhongMaterial {
                                              id: myMaterial
                                              ambient: Qt.rgba( 0.3, 0.3, 0.3, 1.0 )
                                              diffuse: Qt.rgba( 0.7, 0.7, 0.7, 1.0 )
                                          }
                              
                                          Transform {
                                              id: myTransform
                                              property real userAngle: 0.0
                                              property real userDistance: 0.0
                                              matrix: {
                                                  var m = Qt.matrix4x4();
                                                  m.rotate(userAngle, Qt.vector3d(1, 1, 0));
                                                  m.translate(Qt.vector3d(userDistance, 0, 0));
                                                  return m;
                                              }
                                          }
                              
                                          Entity {
                                              id: myEntity
                                              components: [ myMesh, myMaterial, myTransform ]
                                          }
                                      }
                                  }
                              
                              
                                  // Controls overlay
                                  Row {
                                      Button {
                                          text: "Rotate XY+"
                                          onClicked: myTransform.userAngle += 10
                                      }
                                      Button {
                                          text: "Rotate XY-"
                                          onClicked: myTransform.userAngle -= 10
                                      }
                                      Button {
                                          text: "Transform X+"
                                          onClicked: myTransform.userDistance += 0.05
                                      }
                                      Button {
                                          text: "Transform X-"
                                          onClicked: myTransform.userDistance -= 0.05
                                      }
                                      Button {
                                          text: "Reset transformation"
                                          onClicked: {
                                              myTransform.userAngle = 0.0
                                              myTransform.userDistance = 0.0
                                          }
                                      }
                                      Button {
                                          text: "Exit"
                                          onClicked: Qt.quit()
                                      }
                                  }
                              }
                              
                              S Offline
                              S Offline
                              sofiane
                              wrote on last edited by
                              #14

                              Could you make an update to the code you just showed, I couldn't run it, it does not recognize Configurations, controlled camera, Thank you

                              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