Qt Quick 3D - インスタンス化レンダリングの例
Qt Quick 3D でのインスタンス化レンダリングの実行方法を示します。

この例では、基本的なQML APIを使用してインスタンス化レンダリングを行う方法を示します。
宇宙船と小惑星のモデルは、Blender 3Dモデリングツールを使用して作成され、balsamでインポートされました。
ランダムなインスタンス化
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
}位置と回転は自由に変化させることができます。スケーリングは全方向で均一になるように設定され、色はグレースケールです。これはproportional 属性を設定することで実現されます。
宇宙船はInstanceList を使用して手動で配置します:
InstanceListEntry {
id: redShip
eulerRotation: Qt.vector3d(0, 180, 0)
color: "red"
PropertyAnimation on position {
from: Qt.vector3d(50, 10, 100)
to: Qt.vector3d(-70, 10, 100)
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 ]
}InstanceListEntry のプロパティはバインド可能です。ここでは、赤い宇宙船がカメラの経路を横切るようにアニメーションを設定しています。
最後に、インスタンス化テーブルをオブジェクトに適用します:
Asteroid {
instancing: randomInstancing
NumberAnimation on eulerRotation.x {
from: 0
to: 360
duration: 11000
loops: Animation.Infinite
}
}
SimpleSpaceship {
instancing: manualInstancing
}小惑星モデルの回転をアニメーション化することで、インスタンステーブルの内容を変更することなく、すべてのインスタンスが回転します。小惑星のインスタンスはランダムな回転角を持つため、すべての小惑星が異なる軸を中心に回転することになります。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.