Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Rotate 3D Model
QtWS25 Last Chance

Rotate 3D Model

Scheduled Pinned Locked Moved QML and Qt Quick
qt 5.5qt3dqml
6 Posts 2 Posters 4.0k 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.
  • N Offline
    N Offline
    nothing
    wrote on 28 Jul 2015, 08:59 last edited by nothing
    #1

    I had a custom QML object "Model.qml" to load and rotate 3D model.

    Entity {
    id: root
    property Material material
    property alias myRoll : transform.rollAngle
    components: [ transform, mesh, root.material ]
    Transform {
        id: transform
        objectName: "MyModel"
        property real rollAngle : 0
        property real pitchAngle : 20
        Translate { id: translation }
        Scale { id: scaleTransform }
        Rotate { 
            objectName: "rotateRoll"
            axis : Qt.vector3d(1, 0, 0)
            angle : transform.rollAngle
        }
    }
    Mesh {
        id: mesh
        source: "qrc:/3dmodel/Drone.obj"
    }
    }
    

    And in drone.cpp i update property "rollAngle" to rotate model whenever this property changed but it doesn't work anyway. Here is the code I use to update "rollAngle"

    QQmlEngine engine;
    QQmlComponent component(&engine, QUrl("qrc:/src/Model.qml"));
    QObject *object = component.create();    
    QObject *rotateObject = object->findChild<QObject *>("rotateRoll");  
    rotateObject->setProperty("angle", this->roll);    
    qDebug() << "Property value:" << rotateObject->property("angle").toFloat();
    engine.destroyed();
    

    "rollAngle" changes but 3D model doesn't rotate. I use SequenceAnimation instead but it can't run too. Can anyone give me some advice?

    Thks.

    P 1 Reply Last reply 28 Jul 2015, 14:44
    0
    • N nothing
      28 Jul 2015, 08:59

      I had a custom QML object "Model.qml" to load and rotate 3D model.

      Entity {
      id: root
      property Material material
      property alias myRoll : transform.rollAngle
      components: [ transform, mesh, root.material ]
      Transform {
          id: transform
          objectName: "MyModel"
          property real rollAngle : 0
          property real pitchAngle : 20
          Translate { id: translation }
          Scale { id: scaleTransform }
          Rotate { 
              objectName: "rotateRoll"
              axis : Qt.vector3d(1, 0, 0)
              angle : transform.rollAngle
          }
      }
      Mesh {
          id: mesh
          source: "qrc:/3dmodel/Drone.obj"
      }
      }
      

      And in drone.cpp i update property "rollAngle" to rotate model whenever this property changed but it doesn't work anyway. Here is the code I use to update "rollAngle"

      QQmlEngine engine;
      QQmlComponent component(&engine, QUrl("qrc:/src/Model.qml"));
      QObject *object = component.create();    
      QObject *rotateObject = object->findChild<QObject *>("rotateRoll");  
      rotateObject->setProperty("angle", this->roll);    
      qDebug() << "Property value:" << rotateObject->property("angle").toFloat();
      engine.destroyed();
      

      "rollAngle" changes but 3D model doesn't rotate. I use SequenceAnimation instead but it can't run too. Can anyone give me some advice?

      Thks.

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 28 Jul 2015, 14:44 last edited by
      #2

      Hi @nothing and Welcome
      One thing I have noticed is you dont set a visual parent to the object that you create using component.create(). It can be done using setParentItem. For that you will ned to cast it to QQuickItem. I dont know that will make your problem solve but it is something that should be done.

      P.S: I have formatted your code by adding tags. You can edit the post to see how it is done.

      157

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nothing
        wrote on 29 Jul 2015, 03:36 last edited by
        #3

        Hi @p3c0 ,

        Can you give some tutorial about "set visual parent" or a simple example, I'm confuse how to apply this into my codes.

        P.S: Thks for editing my post :)

        P 1 Reply Last reply 29 Jul 2015, 11:15
        0
        • N nothing
          29 Jul 2015, 03:36

          Hi @p3c0 ,

          Can you give some tutorial about "set visual parent" or a simple example, I'm confuse how to apply this into my codes.

          P.S: Thks for editing my post :)

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 29 Jul 2015, 11:15 last edited by
          #4

          @nothing Can you post your complete code ? I tried the same with this example (http://doc.qt.io/qt-5/qt3drenderer-simple-qml-example.html) and it worked. However I was not able to use your example. Loading Model.qml in QQmlComponent didn't work.

          157

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nothing
            wrote on 4 Aug 2015, 04:04 last edited by
            #5

            @p3c0 I dont use setProperty anymore. I create Q_PROPERTY attribute roll in Drone.h that links to attribute roll of object Model.qml and set rootContext to Drone. Then Q_EMIT the function rollchange() notify with roll (in Drone.h) and the Rotate object in Model.qml we change to drone.roll . And finally it works :)

            P 1 Reply Last reply 4 Aug 2015, 07:29
            0
            • N nothing
              4 Aug 2015, 04:04

              @p3c0 I dont use setProperty anymore. I create Q_PROPERTY attribute roll in Drone.h that links to attribute roll of object Model.qml and set rootContext to Drone. Then Q_EMIT the function rollchange() notify with roll (in Drone.h) and the Rotate object in Model.qml we change to drone.roll . And finally it works :)

              P Offline
              P Offline
              p3c0
              Moderators
              wrote on 4 Aug 2015, 07:29 last edited by
              #6

              @nothing Congratulations and thanks for sharing :)

              157

              1 Reply Last reply
              0

              4/6

              29 Jul 2015, 11:15

              • Login

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