Qt Quick 3D - XR シンプルなタッチの例
Qt Quick 3D Xr でのハンドトラッキング入力をデモします。
この例では、Qt Quick 3D XrのハンドトラッキングAPIを使用して、シーン内の2Dおよび3Dオブジェクトと対話する方法を示します。xr_simpleの基本的な構成に従います。
2つの手をサポートする必要があるので、繰り返しを避けるために、それぞれの手に必要なすべてのロジックをカプセル化するコンポーネントを作成することから始めます:
component Hand : Node { id: handComponentRoot property color color: "#ddaa88" required property int touchId property alias hand: handModel.hand property vector3d touchPosition: handController.pokePosition onTouchPositionChanged: { const scenePos = theOrigin.mapPositionToScene(touchPosition) const touchOffset = xrView.processTouch(scenePos, handComponentRoot.touchId) handModel.position = touchOffset buttons.handleTouch(scenePos) } XrController { id: handController controller: handComponentRoot.hand } XrHandModel { id: handModel materials: PrincipledMaterial { baseColor: handComponentRoot.color roughness: 0.5 } } }
このコンポーネントには、人差し指の3D位置を示すXrController 、手の位置を示すXrHandModel 。onTouchPositionChanged
ハンドラーは、マジックが起こる場所です。XrView.processTouch ()を呼び出します:3Dタッチ位置をXrItem の2D位置にマップしようとし、アイテムが見つかればタッチイベントを送信します。そして、3D位置から2Dサーフェス上のタッチポイントまでのオフセットを返します。そのオフセットを使ってXrHandModel の位置をずらし、手がサーフェスで止まっているように見せます。
注意: Apple Vision Proでは、ユーザーの実際の手が表示され、XrHandModel が表示されないため、この効果は働きません。
最後に、3Dインタラクションを行います。ここで、buttons
は、handleTouch
の機能を持つ3Dボタンのグループです。(この実装はXRに特化したものではないので、詳細はここでは説明しない)。
XrOrigin の中にハンドコンポーネントのインスタンスを2つ作成します:
XrOrigin { id: theOrigin z: 50 Hand { id: rightHandModel hand: XrHandModel.RightHand touchId: 0 } Hand { id: leftHandModel hand: XrHandModel.LeftHand touchId: 1 } } xrOrigin: theOrigin
また、原点はシーンの原点から50センチメートルの位置にあります。
シーンの残りの部分には、いくつかの3Dモデルと、タッチ・イベントに反応するXrItem 。
© 2025 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.