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

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

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

두 손을 지원해야 하므로 반복을 피하기 위해 각 손에 필요한 모든 로직을 캡슐화하는 컴포넌트를 만드는 것부터 시작합니다:

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 의 위치를 이동하여 손이 서페이스에 멈춘 것처럼 보이게 합니다.

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

마지막으로 3D 상호 작용을 수행합니다. 여기서 buttonshandleTouch 기능이 있는 3D 버튼 그룹입니다. (구현은 XR 전용이 아니므로 자세한 내용은 여기에 문서화되지 않았습니다.)

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

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 이 포함됩니다.

예제 프로젝트 @ 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.