aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick3d/particles3d/ModelShape.qml
blob: 50f5966b8a3692f5e86a091ed4d2ec32e788af1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick
import QtQuick3D
import QtQuick3D.Particles3D

Item {
    id: mainWindow
    anchors.fill: parent
    property real fontSize: width * 0.012

    View3D {
        id: view
        anchors.fill: parent

        environment: SceneEnvironment {
            clearColor: "#202020"
            backgroundMode: SceneEnvironment.Color
            antialiasingMode: SceneEnvironment.MSAA
            antialiasingQuality: SceneEnvironment.High
        }

        PerspectiveCamera {
            id: camera
            property real cameraAnim: 0
            SequentialAnimation {
                running: true
                loops: Animation.Infinite
                NumberAnimation {
                    target: camera
                    property: "cameraAnim"
                    to: 1
                    duration: 4000
                    easing.type: Easing.InOutQuad
                }
                NumberAnimation {
                    target: camera
                    property: "cameraAnim"
                    to: 0
                    duration: 4000
                    easing.type: Easing.InOutQuad
                }
            }
            position: Qt.vector3d(500 * Math.sin(cameraAnim * Math.PI * 2), 0, 500 * Math.cos(cameraAnim * Math.PI * 2))
            eulerRotation: Qt.vector3d(0, cameraAnim * 360, 0)
        }

        Timer {
            running: true
            repeat: true
            interval: 4000
            onTriggered: {
                if (shape1.delegate === cube) {
                    shape1.delegate = suzanne;
                    shape2.delegate = suzanne;
                } else if (shape1.delegate === suzanne) {
                    shape1.delegate = cube;
                    shape2.delegate = cube;
                }
            }
        }

        ParticleSystem3D {
            id: psystem

            SpriteParticle3D {
                id: particleFire
                sprite: Texture {
                    source: "images/sphere.png"
                }
                colorTable: Texture {
                    source: "images/colorTable.png"
                }
                maxAmount: 6000
                color: "#ffffff"
                billboard: true
                blendMode: SpriteParticle3D.Screen
            }

            Component {
                id: suzanne
                Model {
                    source: "meshes/suzanne.mesh"
                    scale: Qt.vector3d(100, 100, 100)
                    materials: DefaultMaterial { diffuseColor: "red" }
                }
            }

            Component {
                id: cube
                Model {
                    source: "#Cube"
                    scale: Qt.vector3d(2, 2, 2)
                    materials: DefaultMaterial { diffuseColor: "red" }
                }
            }

            ParticleEmitter3D {
                particle: particleFire
                position: Qt.vector3d(-150, 0, 0)
                particleScale: 1
                particleScaleVariation: 1
                velocity: VectorDirection3D {
                    direction: Qt.vector3d(0, 60, 0)
                    directionVariation: Qt.vector3d(6, 6, 6)
                }
                emitRate: 3000
                lifeSpan: 1000
                shape: ParticleModelShape3D {
                    id: shape1
                    delegate: suzanne
                }
                Node {
                    x: -30
                    y: 150
                    Text {
                        anchors.verticalCenter: parent.verticalCenter
                        text: "Filled"
                        font.pointSize: mainWindow.fontSize
                        color: "#ffffff"
                    }
                }
            }

            ParticleEmitter3D {
                particle: particleFire
                position: Qt.vector3d(150, 0, 0)
                particleScale: 1
                particleScaleVariation: 1
                velocity: VectorDirection3D {
                    direction: Qt.vector3d(0, 60, 0)
                    directionVariation: Qt.vector3d(6, 6, 6)
                }
                emitRate: 3000
                lifeSpan: 1000
                shape: ParticleModelShape3D {
                    id: shape2
                    delegate: suzanne
                    fill: false
                }
                Node {
                    x: -30
                    y: 150
                    Text {
                        anchors.verticalCenter: parent.verticalCenter
                        text: "Surface"
                        font.pointSize: mainWindow.fontSize
                        color: "#ffffff"
                    }
                }
            }
        }
    }

    LoggingView {
        anchors.bottom: parent.bottom
        particleSystems: [psystem]
    }
}