[英]ARCore – Session, Frame, Camera and Pose
#關於ArSession
ArSession
是 AR 拼圖中最關鍵的元素。 Session 管理 AR 系統狀態並處理會話生命周期。 Session 類是 ARCore API 的主要入口點。 這個類允許用戶創建一個會話,配置,啟動或停止它,最重要的是,收到ArFrames
允許訪問ARCamera
圖像和設備姿態。
為了使用 ARCore,您需要一個
ArSession
。 ARCore 不渲染 3D 模型(Renderables
)。 這項工作適用於Sceneform
框架。
代碼示例:
private Session mSession;
Config config = new Config(mSession);
if (!mSession.isSupported(config)) {
showSnackbarMessage("This phone doesn't support AR", true);
}
mSession.configure(config);
Session 的配置也可以包括嵌套類:
Augmented Faces
子系統的行為)Config
的雲錨點模式)camera focus
子系統所需的行為)lighting estimation
子系統的行為)plane detection
子系統的行為)update()
的行為)#關於姿勢
Pose
表示從一個坐標空間到另一個坐標空間的不可變剛性變換。 正如所有 ARCore API 提供的那樣,姿勢總是描述從對象的局部坐標空間到世界坐標空間的轉換。 變換是使用圍繞原點的四元數旋轉和平移來定義的。
代碼示例:
float[] position = { 0, 0, -2.2 }; // { x, y, z } position
float[] rotation = { 0, 0, 0, 1 }; // { x, y, z, w } quaternion rotation
Session session = arFragment.getArSceneView().getSession();
Anchor myAnchor = session.createAnchor(new Pose(position, rotation));
#關於 ARCamera
ARCamera
代表一個虛擬攝像機,它決定了查看場景的視角。 如果相機是ArSceneView
一部分,則相機會自動跟蹤來自 ARCore 的相機姿勢。 ARCamera 是一個長期存在的對象,每次調用Session.update()
都會更新相機的屬性。Camera
類提供有關用於捕獲圖像的相機的信息以及每個ArFrame
內的附加信息。
代碼示例:
// Shared camera access with ARCore
sharedSession = new Session(this, EnumSet.of(Session.Feature.SHARED_CAMERA))
sharedCamera = sharedSession.getSharedCamera();
cameraId = sharedSession.getCameraConfig().getCameraId();
#關於ArFrame
當 ARCore 對環境的理解發生變化時,它會調整其世界模型以保持一致。 發生這種情況時,
ARCamera
和ARAnchors
的數字位置(坐標)會發生顯着變化,以保持它們所代表的物理位置的適當相對位置。這些變化意味着每個ArFrame
都應被視為處於完全唯一的世界坐標空間中。ARAnchors
和ARCamera
的數字坐標不應在檢索它們的渲染幀之外使用。
每個
ArFrame
存儲了以下有關 ARCore 狀態的信息:
代碼示例:
private void onUpdateFrame(FrameTime frameTime) {
Frame frame = arFragment.getArSceneView().getArFrame();
// .............
}
此外,您可以閱讀這篇有用的帖子。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.