Qt Quick 3D - XR 심플 터치 예시

Qt Quick 3D Xr에서 손 추적 입력을 시연합니다.

이 예제는 Qt Quick 3D Xr에서 손 추적 API를 사용하여 장면의 2D 및 3D 오브젝트와 상호 작용하는 방법을 보여줍니다. xr_simple 예제의 기본 구조를 따릅니다.

먼저 각 손에 필요한 모든 로직을 캡슐화하는 재사용 가능한 컴포넌트 TouchHand 를 생성합니다. 이 컴포넌트는 별도의 하위 프로젝트 xr_shared 에 있으므로 다른 프로젝트에서 쉽게 재사용할 수 있습니다.

// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import QtQuick3D
import QtQuick3D.Xr

Node {
    id: root
    property color color: "#ddaa88"
    required property int touchId
    required property int hand
    required property XrView view

    property alias touchPosition: handController.scenePos
    property bool touchActive: false

    XrController {
        id: handController
        controller: root.hand

        property vector3d scenePos: view.xrOrigin.mapPositionToScene(pokePosition)

        onScenePosChanged: {
            const touchOffset = view.processTouch(scenePos, root.touchId)
            handModel.position = touchOffset
        }
    }

    XrHandModel {
        id: handModel
        hand: root.hand
        materials: PrincipledMaterial {
            baseColor: root.color
            roughness: 0.5
        }
    }
}

이 컴포넌트에는 검지의 3D 위치를 알려주는 XrController 과 손의 위치를 표시하는 XrHandModel 이 포함되어 있습니다. onTouchPositionChanged 핸들러는 마법이 일어나는 곳입니다. XrView.processTouch ()를 호출하여 무거운 작업을 수행합니다: 3D 터치 위치를 XrItem 의 2D 위치에 매핑하고 항목을 찾으면 터치 이벤트를 전송합니다. 그런 다음 3D 위치에서 2D 표면의 터치 지점까지의 오프셋을 반환합니다. 그런 다음 이 오프셋을 사용하여 XrHandModel 의 위치를 이동하여 손이 서페이스에 멈춘 것처럼 보이게 합니다.

참고: 이 효과는 시스템이 사용자의 실제 손을 표시하고 XrHandModel 이 표시되지 않으므로 Apple Vision Pro에서는 작동하지 않습니다.

XrOrigin 안에 TouchHand 컴포넌트의 인스턴스를 각 손마다 하나씩 두 개씩 생성합니다:

XrOrigin {
    id: theOrigin
    z: 50
    TouchHand {
        id: rightHandModel
        hand: XrHandModel.RightHand
        view: xrView
        touchId: 0
        onTouchPositionChanged: buttons.handleTouch(touchPosition)
    }
    TouchHand {
        id: leftHandModel
        hand: XrHandModel.LeftHand
        view: xrView
        touchId: 1
        onTouchPositionChanged: buttons.handleTouch(touchPosition)
    }
}
xrOrigin: theOrigin

여기서 buttonshandleTouch 함수가 있는 3D 버튼 그룹입니다. (구현은 XR 전용이 아니므로 자세한 내용은 여기에 문서화되지 않았습니다.)

XrOrigin 을 씬의 원점에서 50센티미터 떨어진 곳에 배치하는데, 이는 편안한 터치 거리가 될 것입니다.

나머지 씬에는 일부 3D 모델과 터치 이벤트에 반응하는 XrItem 이 포함됩니다.

예제 프로젝트 @ code.qt.io

© 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.