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
|
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
//! [import]
import QtQuick
import QtQuick3D
import QtQuick3D.Helpers
//! [import]
Window {
id: window
width: 1280
height: 720
visible: true
View3D {
id: view
anchors.fill: parent
environment: SceneEnvironment {
clearColor: "black"
backgroundMode: SceneEnvironment.Color
}
PerspectiveCamera {
position: Qt.vector3d(0, 0, 300)
clipNear: 1.0
NumberAnimation on z {
from: 300
to: 0
duration: 10 * 1000
}
}
DirectionalLight {
eulerRotation.x: -30
eulerRotation.y: -70
ambientColor: Qt.rgba(0.5, 0.5, 0.5, 1.0)
}
//! [randomInstancing]
RandomInstancing {
id: randomInstancing
instanceCount: 1500
position: InstanceRange {
from: Qt.vector3d(-300, -200, -500)
to: Qt.vector3d(300, 200, 200)
}
scale: InstanceRange {
from: Qt.vector3d(1, 1, 1)
to: Qt.vector3d(10, 10, 10)
proportional: true
}
rotation: InstanceRange {
from: Qt.vector3d(0, 0, 0)
to: Qt.vector3d(360, 360, 360)
}
color: InstanceRange {
from: "grey"
to: "white"
proportional: true
}
randomSeed: 2021
}
//! [randomInstancing]
//! [manualInstancing]
InstanceListEntry {
id: redShip
position: Qt.vector3d(50, 10, 100)
eulerRotation: Qt.vector3d(0, 180, 0)
color: "red"
NumberAnimation on position.x {
from: 50
to: -70
duration: 8000
}
}
InstanceListEntry {
id: greenShip
position: Qt.vector3d(0, 0, -60)
eulerRotation: Qt.vector3d(-10, 0, 30)
color: "green"
}
InstanceListEntry {
id: blueShip
position: Qt.vector3d(-100, -100, 0)
color: "blue"
}
InstanceList {
id: manualInstancing
instances: [ redShip, greenShip, blueShip ]
}
//! [manualInstancing]
//! [objects]
Asteroid {
instancing: randomInstancing
NumberAnimation on eulerRotation.x {
from: 0
to: 360
duration: 11000
loops: Animation.Infinite
}
}
SimpleSpaceship {
instancing: manualInstancing
}
//! [objects]
}
}
|