IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Qt Quick 3D - Morphing Example

Demonstrates how to control morphing animations in Qt Quick 3D.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

Qt Quick 3D - Morphing Example▲

Image non disponible

This example shows how to control morphing animation on a model that has been imported from an external tool.

Creating a mesh▲

The mesh for the model was created using the Blender 3D modeling tool. In addition to the base shape, the mesh contains three morph targets (called shape keys in Blender).

Image non disponible

It was exported from Blender as a glTF file, and imported using https://.

Controlling the morph targets▲

Normally, morphing is controlled by a https:// or a property animation. In this example, we use sliders instead, to make it possible to experiment freely with combining different weights:

 
Sélectionnez
            Label { text: "Mouth:"; }
            RealSlider {
                id: mouthSlider
                from: 0.0
                to: 1.0
            }
            Label { text: "Ears and eyebrows:" }
            RealSlider {
                id: earSlider
                from: 0.0
                to: 1.0
            }
            Label { text: "Cubify:" }
            RealSlider {
                id: cubeSlider
                from: 0.0
                to: 1.0
            }

(RealSlider is a simple slider that provides a floating point value. It is borrowed from the effects example.)

We define a https:// for each of the the targets in the mesh. Morph targets are the objects we bind to to control the morphing. Typically, they will be animated, but in this example we bind to the slider values:

 
Sélectionnez
        MorphTarget {
            id: morphtarget0
            weight: mouthSlider.value
            attributes: MorphTarget.Position | MorphTarget.Normal
        }
        MorphTarget {
            id: morphtarget1
            weight: earSlider.value
            attributes: MorphTarget.Position | MorphTarget.Normal
        }
        MorphTarget {
            id: morphtarget2
            weight: cubeSlider.value
            attributes: MorphTarget.Position | MorphTarget.Normal
        }

Finally we create a model and bind the morph targets to the targets in the mesh:

 
Sélectionnez
        Model {
            source: "suzanne.mesh"
            morphTargets: [
                morphtarget0,
                morphtarget1,
                morphtarget2
            ]
            materials: PrincipledMaterial {
                baseColor: "#41cd52"
                roughness: 0.1
            }
            SequentialAnimation on eulerRotation.y {
                NumberAnimation { from: -45; to: 45; duration: 10000 }
                NumberAnimation { from: 45; to: -45; duration: 10000 }
                loops: Animation.Infinite
            }
        }

Note that the targets are matched by their position in the list: the names are not significant.

List of Files▲

Files:

List of Files▲

  • morphing/CMakeLists.txt

  • morphing/RealSlider.qml

  • morphing/main.cpp

  • morphing/main.qml

  • morphing/morphing.pro

  • morphing/qml.qrc

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+   

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.