Jetpack XR용 ARCore는 사용자의 감지된 손에 관한 정보를 제공하고 손과 관련 관절의 자세 정보를 제공할 수 있습니다. 이 손 데이터는 사용자의 손에 엔터티와 모델을 연결하는 데 사용할 수 있습니다(예: 도구 메뉴).
세션 가져오기
Android XR Session
를 통해 손 정보에 액세스합니다. Session
를 가져오려면 세션 수명 주기 이해하기를 참고하세요.
세션 구성
XR 세션에서는 기본적으로 손 추적이 사용 설정되어 있지 않습니다. 손 데이터를 수신하려면 세션을 구성합니다.
val newConfig = session.config.copy( handTracking = Config.HandTrackingMode.Enabled ) when (val result = session.configure(newConfig)) { is SessionConfigureConfigurationNotSupported -> TODO(/* Some combinations of configurations are not valid. Handle this failure case. */) is SessionConfigurePermissionsNotGranted -> TODO(/* The required permissions in result.permissions have not been granted. */) is SessionConfigureSuccess -> TODO(/* Success! */) }
손 데이터 검색
손 데이터는 왼손과 오른손에 대해 별도로 사용할 수 있습니다. 각 손의 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) }
손에는 다음과 같은 속성이 있습니다.
isActive
: 손이 추적되고 있는지 여부입니다.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.setHidden(angle > Math.toRadians(40.0)) val transformedPose = scenecoreSession.perceptionSpace.transformPoseTo( palmPose, scenecoreSession.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.setHidden(angle > Math.toRadians(40.0)) val transformedPose = scenecoreSession.perceptionSpace.transformPoseTo( tipPose, scenecoreSession.activitySpace, ) val position = transformedPose.translation + transformedPose.forward * 0.03f val rotation = Quaternion.fromLookTowards(transformedPose.up, Vector3.Up) indexFingerEntity.setPose(Pose(position, rotation))