Jetpack XR용 ARCore는 감지된 사용자의 손에 관한 정보를 제공하고 손과 관련 조인트의 포즈 정보를 제공할 수 있습니다. 이 손 데이터는 도구 메뉴와 같이 사용자 손에 엔티티와 모델을 연결하는 데 사용할 수 있습니다.
세션 가져오기
Android XR Session
를 통해 손 정보에 액세스합니다. Session
를 가져오려면 세션의 수명 주기 이해하기를 참고하세요.
세션 구성
손 추적은 XR 세션에서 기본적으로 사용 설정되지 않습니다. 손 데이터를 수신하려면 세션을 구성하고 HandTrackingMode.BOTH
모드를 설정합니다.
val newConfig = session.config.copy( handTracking = Config.HandTrackingMode.BOTH ) when (val result = session.configure(newConfig)) { is SessionConfigureConfigurationNotSupported -> TODO(/* Some combinations of configurations are not valid. Handle this failure case. */) is SessionConfigureSuccess -> TODO(/* Success! */) else -> TODO(/* A different unhandled exception was thrown. */) }
손 데이터 가져오기
손 데이터는 왼쪽과 오른쪽 손에 대해 별도로 제공됩니다. 각 손의 state
를 사용하여 각 관절의 포즈 위치에 액세스합니다.
Hand.left(session)?.state?.collect { handState -> // or Hand.right(session) // Hand state has been updated. // Use the state of hand joints to update an entity's position. renderPlanetAtHandPalm(handState) }
손에는 다음과 같은 속성이 있습니다.
trackingState
: 손이 추적되고 있는지 여부입니다.handJoints
: 손 관절과 포즈의 매핑입니다. 손 관절 포즈는 OpenXR 표준에 의해 지정됩니다.
앱에서 손 데이터 사용
사용자의 손 관절 위치를 사용하여 3D 객체를 고정할 수 있습니다. 예를 들어 모델을 왼쪽 손바닥에 연결할 수 있습니다.
val palmPose = leftHandState.handJoints[HandJointType.PALM] ?: return // the down direction points in the same direction as the palm val angle = Vector3.angleBetween(palmPose.rotation * Vector3.Down, Vector3.Up) palmEntity.setEnabled(angle > Math.toRadians(40.0)) val transformedPose = session.scene.perceptionSpace.transformPoseTo( palmPose, session.scene.activitySpace, ) val newPosition = transformedPose.translation + transformedPose.down * 0.05f palmEntity.setPose(Pose(newPosition, transformedPose.rotation))
또는 모델을 오른손 검지 손가락 끝에 연결하려면 다음을 실행하세요.
val tipPose = rightHandState.handJoints[HandJointType.INDEX_TIP] ?: return // the forward direction points towards the finger tip. val angle = Vector3.angleBetween(tipPose.rotation * Vector3.Forward, Vector3.Up) indexFingerEntity.setEnabled(angle > Math.toRadians(40.0)) val transformedPose = session.scene.perceptionSpace.transformPoseTo( tipPose, session.scene.activitySpace, ) val position = transformedPose.translation + transformedPose.forward * 0.03f val rotation = Quaternion.fromLookTowards(transformedPose.up, Vector3.Up) indexFingerEntity.setPose(Pose(position, rotation))
기본 손 동작 감지
손의 관절 포즈를 사용하여 기본적인 손동작을 감지합니다. 손 관절의 규칙을 참고하여 관절이 특정 포즈로 등록되기 위해 있어야 하는 포즈 범위를 확인하세요.
예를 들어 엄지와 검지로 핀치를 감지하려면 두 손가락 끝 관절 사이의 거리를 사용합니다.
val thumbTip = handState.handJoints[HandJointType.THUMB_TIP] ?: return false val thumbTipPose = session.scene.perceptionSpace.transformPoseTo(thumbTip, session.scene.activitySpace) val indexTip = handState.handJoints[HandJointType.INDEX_TIP] ?: return false val indexTipPose = session.scene.perceptionSpace.transformPoseTo(indexTip, session.scene.activitySpace) return Vector3.distance(thumbTipPose.translation, indexTipPose.translation) < 0.05
더 복잡한 동작의 예로는 '정지' 동작이 있습니다. 이 동작에서는 각 손가락이 뻗어 있어야 합니다. 즉, 각 손가락의 각 관절이 대략 같은 방향을 향해야 합니다.
val threshold = toRadians(angleInDegrees = 30f) fun pointingInSameDirection(joint1: HandJointType, joint2: HandJointType): Boolean { val forward1 = handState.handJoints[joint1]?.forward ?: return false val forward2 = handState.handJoints[joint2]?.forward ?: return false return Vector3.angleBetween(forward1, forward2) < threshold } return pointingInSameDirection(HandJointType.INDEX_PROXIMAL, HandJointType.INDEX_TIP) && pointingInSameDirection(HandJointType.MIDDLE_PROXIMAL, HandJointType.MIDDLE_TIP) && pointingInSameDirection(HandJointType.RING_PROXIMAL, HandJointType.RING_TIP)
손 동작의 맞춤 감지를 개발할 때는 다음 사항에 유의하세요.
- 사용자는 특정 동작을 다르게 해석할 수 있습니다. 예를 들어 손가락을 펼친 '정지' 동작을 고려하는 사람이 있는 반면 손가락을 모으는 것이 더 직관적이라고 생각하는 사람도 있습니다.
- 일부 동작은 유지하기 불편할 수 있습니다. 사용자의 손에 무리가 가지 않는 직관적인 동작을 사용합니다.
사용자의 보조 손 확인
Android 시스템은 사용자가 시스템 환경설정에서 지정한 대로 사용자의 기본 손에 시스템 탐색을 배치합니다. 시스템 탐색 동작과의 충돌을 방지하기 위해 맞춤 동작에 보조 손을 사용하세요.
val handedness = Hand.getPrimaryHandSide(activity.contentResolver) val secondaryHand = if (handedness == Hand.HandSide.LEFT) Hand.right(session) else Hand.left(session) val handState = secondaryHand?.state ?: return detectGesture(handState)
OpenXR™ 및 OpenXR 로고는 The Khronos Group Inc. 소유의 상표이며 중국, 유럽 연합, 일본, 영국에 상표로 등록되어 있습니다.