Qt Quick 3D - ピッキングの例
モデルの選択方法を示しています。
この例では、ピッキングの動作を示します。ピッキング可能な3種類のアニメーション付きモデルがあります。モデルがピッキングされると、アニメーションが停止し、どのモデルが選択されたかが一目でわかるよう、モデルの色が変更されます。ピッキング結果の詳細情報は、アプリケーションウィンドウの上部に表示されます。

モデルを選択可能にする
モデルを選択可能にするには、pickable プロパティをtrue に設定する必要があります。また、選択されたモデルの名前を表示できるように、objectName も追加します。
Model {
id: cubeModel
objectName: "Cube"
source: "#Cube"
pickable: true
property bool isPicked: falseisPicked プロパティは、アニメーションと色の表示/非表示を切り替えるために追加されました。
materials: PrincipledMaterial {
baseColor: cubeModel.isPicked ? "#41cd52" : "#09102b"
...
SequentialAnimation on eulerRotation {
running: !cubeModel.isPicked選択結果の取得
実際の選択を行うには、View3D 全体をカバーするようにMouseArea を追加する必要があります。
MouseArea {
anchors.fill: viewマウス領域の `onClicked ` ハンドラ内で、`pick ` メソッドを使用して、ピック操作の実際の結果を取得します。
var result = view.pick(mouse.x, mouse.y);結果にtarget object が含まれている場合は、結果の詳細を確認し、アプリケーションビュー上部のテキストフィールドに表示します。
if (result.objectHit) {
var pickedObject = result.objectHit;
// Toggle the isPicked property for the model
pickedObject.isPicked = !pickedObject.isPicked;
// Get picked model name
pickName.text = pickedObject.objectName;
// Get other pick specifics
uvPosition.text = "("
+ result.uvPosition.x.toFixed(2) + ", "
+ result.uvPosition.y.toFixed(2) + ")";
distance.text = result.distance.toFixed(2);
scenePosition.text = "("
+ result.scenePosition.x.toFixed(2) + ", "
+ result.scenePosition.y.toFixed(2) + ", "
+ result.scenePosition.z.toFixed(2) + ")";
localPosition.text = "("
+ result.position.x.toFixed(2) + ", "
+ result.position.y.toFixed(2) + ", "
+ result.position.z.toFixed(2) + ")";
worldNormal.text = "("
+ result.sceneNormal.x.toFixed(2) + ", "
+ result.sceneNormal.y.toFixed(2) + ", "
+ result.sceneNormal.z.toFixed(2) + ")";
localNormal.text = "("
+ result.normal.x.toFixed(2) + ", "
+ result.normal.y.toFixed(2) + ", "
+ result.normal.z.toFixed(2) + ")";© 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.