Android XR SDK พร้อมใช้งานในเวอร์ชันตัวอย่างสำหรับนักพัฒนาแอปแล้ว เราอยากฟังความคิดเห็นจากคุณ โปรดไปที่
หน้าการสนับสนุนเพื่อติดต่อเรา
ตรวจหาเครื่องบินโดยใช้ ARCore สำหรับ Jetpack XR
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ARCore สำหรับ Jetpack XR สามารถตรวจจับพื้นผิวเรียบในสภาพแวดล้อมของผู้ใช้และ
ให้ข้อมูลเกี่ยวกับพื้นผิวเหล่านั้น เช่น ท่าทาง ขนาด และการวางแนว ซึ่งจะช่วยให้แอปค้นหาพื้นผิวต่างๆ เช่น โต๊ะ เพื่อวางออบเจ็กต์ได้
สร้างเซสชัน ARCore สำหรับ Jetpack XR
เข้าถึงข้อมูลระนาบผ่านเซสชัน ARCore สำหรับ Jetpack XR ดูทําความเข้าใจวงจรของเซสชันเพื่อรับ Session
ระบบไม่ได้เปิดใช้การตรวจจับระนาบโดยค่าเริ่มต้นในเซสชัน XR หากต้องการเปิดใช้การติดตามระนาบ ให้กำหนดค่าเซสชันและตั้งค่าโหมด PlaneTrackingMode.HORIZONTAL_AND_VERTICAL
ดังนี้
val newConfig = session.config.copy(
planeTracking = Config.PlaneTrackingMode.HORIZONTAL_AND_VERTICAL,
)
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. */)
}
เรียกข้อมูลสถานะของเครื่องบินที่ตรวจพบ
ARCore สำหรับ Jetpack XR จะให้สถานะของระนาบผ่าน
StateFlow
ที่ปล่อยสถานะของระนาบ การติดตาม
เครื่องบินในเซสชันจะแจ้งเตือนแอปของคุณเมื่อมีการเพิ่ม อัปเดต หรือ
นำเครื่องบินออก
Plane.subscribe(session).collect { planes ->
// Planes have changed; update plane rendering
}
ระนาบมีคุณสมบัติดังต่อไปนี้
การทดสอบการยิงรังสีเป็นวิธีการคำนวณจุดตัดของรังสีกับออบเจ็กต์ที่เซสชันติดตาม
การใช้งานการทดสอบการแตะที่พบบ่อยคือการชี้ไปที่โต๊ะและวางออบเจ็กต์ในตำแหน่งนั้น การทดสอบการตรวจหาการแตะจะส่งผลให้ได้
รายการออบเจ็กต์ที่ตรวจพบการแตะ กล่าวคือ การทดสอบการคลิกไม่ได้หยุดที่ออบเจ็กต์แรกที่คลิก
อย่างไรก็ตาม บ่อยครั้งที่คุณอาจสนใจเฉพาะการเข้าชมออบเจ็กต์แรกของ
ประเภทที่กำหนด
หากต้องการทำการทดสอบการเข้าชม ให้ใช้ Interaction.hitTest()
กับ Ray
ดังนี้
val results = androidx.xr.arcore.hitTest(session, ray)
// When interested in the first Table hit:
val tableHit = results.firstOrNull {
val trackable = it.trackable
trackable is Plane && trackable.state.value.label == Plane.Label.TABLE
}
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-28 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-08-28 UTC"],[],[],null,["ARCore for Jetpack XR can detect flat surfaces in the user's environment and\nprovide information on them such as their pose, size, and orientation. This can\nhelp your app find surfaces like tables to place objects on.\n\nCreate an ARCore for Jetpack XR session\n\nAccess plane information through an ARCore for Jetpack XR session. See\n[Understand a Session's lifecycle](/develop/xr/jetpack-xr-sdk/work-with-arcore#session-lifecycle) to obtain a [`Session`](/reference/kotlin/androidx/xr/runtime/Session).\n\nConfigure the Session\n\nPlane detection is not enabled by default on XR sessions. To enable plane\ntracking, configure the session and set the\n[`PlaneTrackingMode.HORIZONTAL_AND_VERTICAL`](/reference/kotlin/androidx/xr/runtime/Config.PlaneTrackingMode#HORIZONTAL_AND_VERTICAL()) mode:\n\n\n```kotlin\nval newConfig = session.config.copy(\n planeTracking = Config.PlaneTrackingMode.HORIZONTAL_AND_VERTICAL,\n)\nwhen (val result = session.configure(newConfig)) {\n is SessionConfigureConfigurationNotSupported -\u003e\n TODO(/* Some combinations of configurations are not valid. Handle this failure case. */)\n is SessionConfigureSuccess -\u003e TODO(/* Success! */)\n else -\u003e\n TODO(/* A different unhandled exception was thrown. */)\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/xr/src/main/java/com/example/xr/arcore/Planes.kt#L30-L39\n```\n\n\u003cbr /\u003e\n\n| **Note:** Plane tracking requires the `android.permission.SCENE_UNDERSTANDING_COARSE` [runtime permission](/training/permissions/requesting) to be granted to your app.\n\nRetrieve the state of perceived planes\n\nARCore for Jetpack XR provides the state of planes through a\n[`StateFlow`](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/) that emits the state of planes. Subscribing to\nplanes in a session notifies your app when planes are added, updated, or\nremoved.\n\n\n```kotlin\nPlane.subscribe(session).collect { planes -\u003e\n // Planes have changed; update plane rendering\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/xr/src/main/java/com/example/xr/arcore/Planes.kt#L45-L47\n```\n\n\u003cbr /\u003e\n\nA plane has the following properties:\n\n- [`label`](/reference/kotlin/androidx/xr/arcore/Plane.State#label()): a semantic description of a given [`Plane`](/reference/kotlin/androidx/xr/arcore/Plane). Could be a [`WALL`](/reference/kotlin/androidx/xr/arcore/Plane.Label#WALL()), [`FLOOR`](/reference/kotlin/androidx/xr/arcore/Plane.Label#FLOOR()), [`CEILING`](/reference/kotlin/androidx/xr/arcore/Plane.Label#CEILING()), or [`TABLE`](/reference/kotlin/androidx/xr/arcore/Plane.Label#TABLE()).\n- [`centerPose`](/reference/kotlin/androidx/xr/arcore/Plane.State#centerPose()): The pose of the center of the detected plane.\n- [`extents`](/reference/kotlin/androidx/xr/arcore/Plane.State#extents()): The dimensions of the detected plane, in meters.\n- [`vertices`](/reference/kotlin/androidx/xr/arcore/Plane.State#vertices()): A list of vertices of a convex polygon that approximates the plane.\n\nPerform a hit-test against planes\n\nA hit-test is a method of calculating the intersection of a ray with objects\ntracked by the session. A common application of a hit-test is to point at a\ntable and place an object at that location. Conducting a hit-test results in a\nlist of hit objects. In other words, a hit-test doesn't stop at the first object\nhit. However, often you may only be interested in the first object hit of a\ngiven type.\n\nTo perform a hit-test, use [`Interaction.hitTest()`](/reference/kotlin/androidx/xr/arcore/package-summary#hittest) with a [`Ray`](/reference/kotlin/androidx/xr/runtime/math/Ray):\n\n\n```kotlin\nval results = androidx.xr.arcore.hitTest(session, ray)\n// When interested in the first Table hit:\nval tableHit = results.firstOrNull {\n val trackable = it.trackable\n trackable is Plane && trackable.state.value.label == Plane.Label.TABLE\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/xr/src/main/java/com/example/xr/arcore/Planes.kt#L55-L60\n```\n\n\u003cbr /\u003e"]]