public void SetSpatialMapping(LiveMessageResponseSpatialMapping msg) { Debug.Log("Receive Spatial Mapping! len=" + msg.mapData); List <Mesh> meshes = SimpleMeshSerializer.Deserialize(msg.mapData) as List <Mesh>; anchorController.SetSpatialMeshToObserver(meshes); waiting = false; waitingString = "Download spatial mapping OK!"; }
public void SendSpatialMapping() { List <MeshFilter> meshes = SpatialMappingManager.Instance.GetMeshFilters(); byte[] meshData = SimpleMeshSerializer.Serialize(meshes); //SpatialMappingManager.Instance.DrawVisualMeshes = true; LiveMessageResponseSpatialMapping msg = new LiveMessageResponseSpatialMapping(); msg.mapData = meshData; Debug.Log("Spatial Mapping bytes len=" + meshData.Length); Debug.Log("Send Spatial Mapping!"); syncClient.SendMessage(msg.Serialize()); }
private void CheckMessage() { float realTime = Time.realtimeSinceStartup; if (server != null) { //Debug.Log("Server Listening? " + server.IsListening); if (hololensConnected && !hololensHasInit && !waiting) { // 如果连上了,就开始初始化 SetHololensSynchronize(false); SetAnchorToHololens(true); // 这时需要把传输序列号清空,避免新接入的Hololens的同步消息被忽略 lastSyncIndex = int.MinValue; } while (SyncServer.SyncQueue.GetCount() > 0) { byte[] messageBytes = SyncServer.SyncQueue.Dequeue(); //Debug.Log("receive [" + messageBytes.Length + "] type=" + messageBytes[0]); // 处理消息 LiveMessage msg = LiveMessageManager.ParseMessage(messageBytes); switch (msg.type) { case LiveMessageConstant.BEV_MESSAGE_TYPE_SYNCHRONIZE_ALL: LiveMessageSynchronizeAll syncMsg = msg as LiveMessageSynchronizeAll; DealSyncMessage(syncMsg); break; case LiveMessageConstant.BEV_MESSAGE_TYPE_DOWNLOAD_ANCHOR_FINISH: LiveMessageDownloadFinish downloadFinishMsg = msg as LiveMessageDownloadFinish; waiting = false; if (downloadFinishMsg.result.success) { waitingString = "Download Anchors Success! "; } else { waitingString = downloadFinishMsg.result.errorString; } break; case LiveMessageConstant.BEV_MESSAGE_TYPE_SET_ANCHOR_FINISH: LiveMessageSetAnchorFinish anchorFinishMsg = msg as LiveMessageSetAnchorFinish; spectatorViewVersion = anchorFinishMsg.version; if (spectatorViewVersion < LiveHololens.version) { // SpectatorView版本太低! liveUI.ShowInfoDialog("Spectator View's verion is too old!"); hololensConnected = false; StopHololesServer(); } waiting = false; waitingString = "init OK!"; hololensHasInit = true; // 初始化完成,就先开启位置传输 SetHololensSynchronize(true); break; case LiveMessageConstant.BEV_MESSAGE_TYPE_SAVE_ANCHOR_FINISH: LiveMessageSaveAnchorFinish savehMsg = msg as LiveMessageSaveAnchorFinish; waiting = false; if (savehMsg.result.success) { waitingString = "Save Anchor OK!"; // 初始化完成,就先开启位置传输 // 此功能先取消,因为产生了许多误解 //SetHololensSynchronize(true); } else { waitingString = savehMsg.result.errorString; } break; case LiveMessageConstant.BEV_MESSAGE_TYPE_RESPONSE_SPATIAL_MAPPING: LiveMessageResponseSpatialMapping spatialMsg = msg as LiveMessageResponseSpatialMapping; SetSpatialMapping(spatialMsg); break; } } // 判断是否已经不传输了 if (lastSyncTime >= 0) { if (Time.time - lastSyncTime > syncTimeoutInterval) { hololensStartSynchronize = false; } } } if (useUDP && udpListener != null) { while (udpListener.UdpReceiveQueue.GetCount() > 0) { byte[] messageBytes = udpListener.UdpReceiveQueue.Dequeue(); //Debug.Log(messageBytes.Length + "---" + messageBytes[0]); LiveMessage msg = LiveMessageManager.ParseMessage(messageBytes); if (msg == null) { continue; } switch (msg.type) { case LiveMessageConstant.BEV_MESSAGE_TYPE_SYNCHRONIZE_ALL: LiveMessageSynchronizeAll syncMsg = msg as LiveMessageSynchronizeAll; //Debug.Log("-->"+syncMsg.seq); DealSyncMessage(syncMsg); break; } } } }
public static LiveMessage ParseMessage(byte[] bytes) { LiveMessage msg = null; if (bytes.Length == 0) { Debug.LogError("Error: Message length=0!"); return(msg); } switch (bytes[0]) { case LiveMessageConstant.BEV_MESSAGE_TYPE_START: msg = new LiveMessageStart(); break; case LiveMessageConstant.BEV_MESSAGE_TYPE_STOP: msg = new LiveMessageStop(); break; case LiveMessageConstant.BEV_MESSAGE_TYPE_DOWNLOAD_ANCHOR: msg = new LiveMessageDownload(); break; case LiveMessageConstant.BEV_MESSAGE_TYPE_SET_ANCHOR: msg = new LiveMessageSetAnchor(); break; case LiveMessageConstant.BEV_MESSAGE_TYPE_SYNCHRONIZE_ALL: msg = new LiveMessageSynchronizeAll(); break; case LiveMessageConstant.BEV_MESSAGE_TYPE_DOWNLOAD_ANCHOR_FINISH: msg = new LiveMessageDownloadFinish(); break; case LiveMessageConstant.BEV_MESSAGE_TYPE_SET_ANCHOR_FINISH: msg = new LiveMessageSetAnchorFinish(); break; case LiveMessageConstant.BEV_MESSAGE_TYPE_SAVE_ANCHOR: msg = new LiveMessageSaveAnchor(); break; case LiveMessageConstant.BEV_MESSAGE_TYPE_SAVE_ANCHOR_FINISH: msg = new LiveMessageSaveAnchorFinish(); break; case LiveMessageConstant.BEV_MESSAGE_TYPE_REQUEST_SPATIAL_MAPPING: msg = new LiveMessageRequestSpatialMapping(); break; case LiveMessageConstant.BEV_MESSAGE_TYPE_RESPONSE_SPATIAL_MAPPING: msg = new LiveMessageResponseSpatialMapping(); break; default: Debug.LogError("No such type message!"); return(msg); } try { msg.Deserialize(bytes); } catch (Exception e) { msg = null; Debug.LogError("Parse Message Error! " + e); } return(msg); }