Qt: Rotate 3D Model

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");
childObject->setProperty("rollAngle",this->roll);    
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.


Source: c++

Leave a Reply