ARCore สำหรับ Jetpack XR สามารถให้ข้อมูลเกี่ยวกับมือที่ตรวจพบของผู้ใช้ รวมถึงให้ข้อมูลท่าทางของมือและข้อต่อที่เกี่ยวข้อง ข้อมูลมือนี้ใช้เพื่อแนบเอนทิตีและโมเดลกับมือของผู้ใช้ได้ เช่น เมนูเครื่องมือ
รับเซสชัน
เข้าถึงข้อมูลมือผ่าน 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
ใช้ข้อมูลมือในแอป
ตำแหน่งข้อต่อของมือผู้ใช้สามารถใช้เพื่อยึดวัตถุ 3 มิติไว้กับมือของผู้ใช้ เช่น ยึดโมเดลไว้กับฝ่ามือซ้าย
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))