? ? ? ? 空間錨提供了一種能夠?qū)⑽矬w保留在特定位置和旋轉(zhuǎn)狀態(tài)上的方法。這保證了全息對象的穩(wěn)定性,同時提供了后續(xù)在真實世界中保持全息對象位置的能力。MRTK官方給的方法是基于Azure云來實現(xiàn)的,這個云目前個人無法注冊,所以暫時只能本地化來實現(xiàn),本地化其實就是單機(jī)版運行,但是其他Hololens設(shè)備無法共享這些位置信息,這里可以借助Hololens的門戶系統(tǒng)把空間和錨點數(shù)據(jù)導(dǎo)出來共享給其他Hololens設(shè)備使用。
本地空間錨點實現(xiàn)
? ? ? ? 這里使用的是?OpenXR ,所以用到的方法是基于?ARAnchorManager,如果是用的老版本Unity,使用的方法是基于WorldAnchor。
在Unity工程中添加空對象,然后添加ArSessionOrigin和ArAnchorManager,如下圖:
?下面主要介紹ARAnchorManager相關(guān)代碼文章來源:http://www.zghlxwxcb.cn/news/detail-562051.html
// 獲取錨點存儲器
XRAnchorStore _anchorStore = await _arAnchorManager.subsystem.LoadAnchorStoreAsync();
// 獲取已經(jīng)保存過的錨點名稱
List<String> names = _anchorStore.PersistedAnchorNames;
// 通過名稱加載錨點
// 加載描點之后會調(diào)用 _arAnchorManager.anchorsChanged 事件,在事件中可以獲取到錨點的位置信息
var anchorId = _anchorStore.LoadAnchor(name);
// 事件demo案例
private void AnchorsChanged(ARAnchorsChangedEventArgs obj)
{
if (obj.added.Count > 0)
{
// 描點對象信息
var _currentAnchor = a.gameObject
}
}
// 保存錨點
public void AddAnchor()
{
// 根據(jù)位置、角度加載錨點預(yù)制體
var _currentAnchor = AnchorContent(placingGameObject.transform.position, placingGameObject.transform.rotation, anchorPrefab);
var anchor = _currentAnchor.GetComponent<ARAnchor>();
// 如果名稱存在,刪除
if (_anchorStore.PersistedAnchorNames.Contains(AnchorName))
{
_anchorStore.UnpersistAnchor(AnchorName);
}
// 保存錨點數(shù)據(jù)
_anchorStore.TryPersistAnchor(anchor.trackableId, AnchorName);
}
錨點本地化保存比較簡單,下篇文章介紹如何把本地化數(shù)據(jù)通過門戶系統(tǒng)接口,把空間錨點數(shù)據(jù)導(dǎo)出出來,給其他設(shè)備使用,達(dá)到空間位置共享的目的。文章來源地址http://www.zghlxwxcb.cn/news/detail-562051.html
到了這里,關(guān)于Hololens2實現(xiàn)空間描點(本地化)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!