網頁

2018年6月22日 星期五

HoloLens 的 sharing 功能

在網路上可以找到的多人共享功能與文件,少之又少。
所以這個問題花了我頗多時間,才能完全搞懂他的邏輯。

為了解這個問題,主要從三個方向進行:



一、MR Sharing 240 Tutorial

微軟網站關於Hololens,提供一系列Tutorial,只要按著操作就可以。
其中的MR Sharing 240 [連結]就是在講如何讓多人看相同Hologram,
基本上一步步跟著操作即可。

示範內容是讓一個像太空站的東西(EnergyHub)放在房間的某處,
不同HoloLens看到的EnergyHub都正就是放在那個位置。
不同HoloLens都可以對EnergyHub發射子彈,直到把它打爆,
緊接著出現挖深入地底的一個畫面。

我當初這一整段都有完成,但後來我並沒有從MR Sharing 240作為入門。

其原因是,我目前的專案主要是用HoloToolkit完成,裡面已經寫好按鈕及其許多相關功能,
但是MR Sharing 240等同另一套專案,它有自己的namespace,叫做Academy.xxx.xxx之類的。

要將兩者做整併,有兩種解法,第一種是將我寫的專案整併進去MR Sharing 240。我試著在MR Sharing 240 專案灌 HoloToolkit,但可惜兩者並不相容,原本我寫的程式可以用的功能,就不能用了。

第二種解法,是反過來,將MR Sharing 240會用到的script,貼到我的專案來用。
但是MR Sharing 240大多用到的namespace,是一個叫做Academy.xxx.xxx之類的,
貼過來用,要做的維修,恐怕遠超過我能力所及。
尤其是還不清楚,sharing真正功能以及每段程式碼的意義的前提下。

基於這兩項理由,我暫時放棄走微軟所提供 MR Sharing 240 的 Tutorial 這一條路。


二、MixedRealityToolkit-Unity/Asset/HoloToolkit/Sharing/

想要了解Sharing,並快速入門的話,強烈建議從此處後,就要仔細看懂

先上GitHub網站 [連結] 看一下,裡頭有關於Sharing的基本介紹,
然後直接從SharingTest.unity 以及 SharingSpawntest.unity這兩個範例開始著手。

關於這兩個範例,有一個人錄了一段影片[連結],講得蠻清楚的,可以先去聽一下。
其實,這段影片我第一次聽的時候,本來覺得幹嘛講這麼多,真的有我要的東西嗎?
後來我試著測試的SharingTest.unity以及SharingSpawntest.unity,幾乎等同他影片最後的講解。

1. SharingTest.unity
    這個範例的重點是他即時秀出來的關於Debug的那些訊息,
    譬如:現在正在 upload Anchor,或者update anchor,或者downloading anchor
    整個流程如果完成,他會跟你說success,如果沒有完成,他會跟你說failure。
 
    剛開始寫sharing功能時,一直覺得怪怪的,它為什麼不反應,它在幹嘛 ....
    找到SharingTest.unity之後,仔細閱讀旁邊的Debug訊息,
    就可以知道到底有沒有連結到server 了。
 
    此處的最大關鍵,確認HoloLens (Client) 有連線到 PC上開啟的Sharing Service
 
2. SharingSpawntest.unity [連結]
    這個示範的內容是這樣的,把它發佈到兩台或兩台以上的HoloLens,
    開啟後,可以用聲音指令(SpawnBasic)驅動事件,接著會出現藍色的小方塊,
    每一台HoloLens都可以用聲控來讓藍色方塊出現,而且每台都會即時看到藍色方塊出現。
 
    後來只要把我要丟去做共享的Hologram做成prefab,
    藍色小方塊改為我要共享的Hologram,不同HoloLens就都可以看到我共享的Hologram了。

目前所整理出來的Sharing 功能主要有二:
第一、讓多台HoloLens共享相同座標Anchor。
第二、讓多台HoloLens即時看到受指令被trigger出來的prefab。

但是,此prefab一旦在視野中生成實體,之後所做的修改並不會被共享。
若修改要被共享,就要一直做新的prefab丟上去做共享。
也就是說,一旦出現prefab後,HoloLens A如果對prefab做點擊而變色,在HoloLens B是看不到的。HoloLens A 與 HoloLens B 對實體prefab的獨立操作,彼此並不會共享。

關於這個問題我上論壇找了好久,終於找到一點資料。


三、GitHub 論壇

我在GitHub論壇找到 StephenHodgson 以及saidbet 的對話,請參考以下這篇討論。
Which one is the most reliable? Unet sharing or HTK sharing [連結]

兩人對於共享功能的觀點有些許不同,以下將其對話略作節錄:

StephenHodgson 認為sharing目的就是把你要給別人看到Hologram共享就好,
                            所以一次就給一個Hologram,不管Hologram有多少按鈕,
                            多少功能,給出去就給出去。
                            local端要怎麼跟這個Hologram互動,是client自己的問題,
                           不管互動過程如何,也就沒有所謂共享不共享的問題。

saidbet  發現共享時,如果prefab是具有nested GameObject,
             也就是說有parent, child這種階層關係時,情況會變得很複雜。
           
             他講到最後,就說使用spectator來傳送video stream,
             就不用透過Sharing Server將資料傳上傳下的,那其實也就不會有這個問題。
           
             以下直接節錄,比較清楚。 
恕刪
In addition to that, we have a "SyncMessage" GameObject for each device, and each device has a reference to other devices' SyncMessage. That GameObject is used as an event trigger, and as a simple way to send data along with the event. This probably causes a lot of traffic.
We use this system for visual effects like highlights, and click effects, and also for a bunch of other stuff, because sharing the transforms of nested GameObjects is a bit complicated: for example, when you have let's say a menu, and this menu has buttons as child GameObjects, and you want to share the transform of the menu as well as the transform of the buttons, well you can't because when a new device connects to the session, it will try to instantiate the child GameObject before the Menu GameObject (which is the parent).
To sum up, it will instantiate the GameObjects in reverse order (last spawned object is instantiated first) or maybe in random order, I'm not really sure, but everytime we've tried, it tried to instantiate the child before the parent and raised an exception because the parent didn't exist yet.
For the spectator side, the Hololens sends the video stream directly to the computer without going through the SharingService, so this shouldn't be the problem.
The server is running in the cloud, and we have at least 50 mbps up and down on each side, I think it should be enough. 
恕刪
StephenHodgson 對於saidbet想做的事的comment是:
Sounds like you guys are a little over engineered. ....


這段對話,讓我停下腳步重新思考,我的專案在共享這部分,要如何繼續寫下去。
因為若照StephenHodgson對於SharingSpawntest.unity邏輯,那麼我正在寫的專案等於必須重寫,而且得寫非常多零零碎碎的prefab,低結構的程式是不容易維護,也容易出錯的。
換言之,接下來就會步上saidbet的後塵,而over engineered。



參考資料
1. Hololens Academy MR Sharing 240 [連結]
2. GitHub 論壇
    Which one is the most reliable? Unet sharing or HTK sharing [連結]
3. Youtube 影片
    HoloLens Sharing [連結]
3. MixedRealityToolkit-Unity/Assets/HoloToolkit/Sharing [連結]


沒有留言:

張貼留言