Qt Quick 3D - Particles 3D Testbed Example

Image non disponible

This example demonstrates different ways to use the QtQuick3D.Particles3D module features. Particles Testbed contains a collection of examples, some emphasizing a particular feature and some combining more features for achieving the desired appearance.

Common Features

The examples inside the Testbed share some common features. To exit the example back to launching screen, press the back arrow at the top-left corner.

Bottom-right corner of each example contain an icon that opens the logging view. From this view, you can see different debug data about the particles. Each ParticleSystem3D has its own row showing its ParticleSystem3DLogging data.

Image non disponible

Top-right corner of the most examples contain a settings view which can be shown or hidden by clicking its icon. These settings help to demonstrate individual API features as well as the dynamic behavior of the particle systems.

Image non disponible

Snowing Example

Let's go through the basics of Particles3D by looking at the Snowing example.

Image non disponible

First, import the QtQuick3D.Particles3D module with the following statement:

 
Sélectionnez
import QtQuick3D.Particles3D

ParticleSystem3D is the root of the particle system which handles the system timing and groups all the other related elements like particles, emitters, and affectors together.

 
Sélectionnez
ParticleSystem3D {
    id: psystem

    // Start so that the snowing is in full steam
    startTime: 15000

Then we create a SpriteParticle3D which is a visual 2D texture particle. If we would need a 3D model particles we could alternatively use ModelParticle3D. Defining the amount of particles with maxAmount is important so that optimal buffer sizes get allocated. Here our snowflakes are white, with varied opacity and they fade in and out in 1000ms.

 
Sélectionnez
SpriteParticle3D {
    id: snowParticle
    sprite: Texture {
        source: "images/snowflake.png"
    }
    maxAmount: 1500 * sliderIntensity.sliderValue
    color: "#ffffff"
    colorVariation: Qt.vector4d(0.0, 0.0, 0.0, 0.5);
    fadeInDuration: 1000
    fadeOutDuration: 1000
}

Next we will need ParticleEmitter3D to emit the above snowParticle particles. The shape property defines area where emitting is done. Here we define snowflakes to have varied rotation and size. With the velocity property you can define the initial direction of speed of the emitted particles. Each snowflake particle exists for 15 seconds and the emiting rate is controlled with the settings sliders.

 
Sélectionnez
ParticleEmitter3D {
    id: emitter
    particle: snowParticle
    position