コード例 #1
0
ファイル: LiveController.cs プロジェクト: comblox/METoolkit
        /// <summary>
        /// 将anchor信息存储到Hololens端
        /// </summary>
        public void SaveAnchorToHololens()
        {
            if (!hololensConnected)
            {
                return;
            }

            LiveMessageSaveAnchor msg = new LiveMessageSaveAnchor();

            msg.anchorData = new LiveMessageSaveAnchor.LiveMessageSetAnchorData();
            msg.anchorData.sendRotation = true;

            for (int i = 0; i < anchorController.anchorObjectList.Count; i++)
            {
                AnchorObjectInfo info = anchorController.anchorObjectList[i];
                msg.anchorData.anchorNameList.Add(info.anchorName);
                msg.anchorData.anchorPosition.Add(info.rootObject.transform.position);
                msg.anchorData.anchorForward.Add(info.rootObject.transform.eulerAngles);
            }

            Debug.Log("send message type=" + msg.type);

            if (handler != null)
            {
                handler.SendMessage(msg.Serialize(), null);
            }
            waiting       = true;
            waitingString = "Waiting for anchor init...";
        }
コード例 #2
0
ファイル: LiveHololens.cs プロジェクト: bianshifeng/DataMesh
        // Update is called once per frame
        void Update()
        {
            if (syncClient != null)
            {
                if (syncClient.Running)
                {
                    while (syncClient.SyncQueue.GetCount() > 0)
                    {
                        byte[] messageBytes = syncClient.SyncQueue.Dequeue();

                        // 处理消息
                        LiveMessage msg = LiveMessageManager.ParseMessage(messageBytes);
                        //Debug.Log("msg type=" + msg.type);
                        switch (msg.type)
                        {
                        case LiveMessageConstant.BEV_MESSAGE_TYPE_START:
                            synchronizing = true;
                            break;

                        case LiveMessageConstant.BEV_MESSAGE_TYPE_STOP:
                            synchronizing = false;
                            break;

                        case LiveMessageConstant.BEV_MESSAGE_TYPE_SET_ANCHOR:
                            LiveMessageSetAnchor msgSetAnchor = msg as LiveMessageSetAnchor;
                            // 这里也不能再同步了
                            synchronizing = false;
                            SetAnchors(msgSetAnchor);

                            // 重置同步消息序号
                            syncIndex = 0;

                            break;

                        case LiveMessageConstant.BEV_MESSAGE_TYPE_SAVE_ANCHOR:
                            LiveMessageSaveAnchor msgSaveAnchor = msg as LiveMessageSaveAnchor;
                            // 这里也不能再同步了
                            synchronizing = false;
                            SaveAnchors(msgSaveAnchor);
                            break;

                        case LiveMessageConstant.BEV_MESSAGE_TYPE_DOWNLOAD_ANCHOR:
                            DownloadAnchor();
                            break;

                        case LiveMessageConstant.BEV_MESSAGE_TYPE_REQUEST_SPATIAL_MAPPING:
                            SendSpatialMapping();
                            break;
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: LiveHololens.cs プロジェクト: bianshifeng/DataMesh
        /// <summary>
        /// 存储anchor
        /// </summary>
        /// <param name="msgSetAnchor"></param>
        private void SaveAnchors(LiveMessageSaveAnchor msgSetAnchor)
        {
            Debug.Log("Save Anchor! rotate=" + msgSetAnchor.anchorData.sendRotation);
            waitToSave = new List <AnchorObjectInfo>();
            for (int i = 0; i < msgSetAnchor.anchorData.anchorNameList.Count; i++)
            {
                string  anchorName = msgSetAnchor.anchorData.anchorNameList[i];
                Vector3 pos        = msgSetAnchor.anchorData.anchorPosition[i].ToVector3();
                Vector3 forward    = msgSetAnchor.anchorData.anchorForward[i].ToVector3();

                // 修改原有anchor
                AnchorObjectInfo info = anchorController.GetAnchorInfo(anchorName);
                if (info != null)
                {
                    anchorController.RemoveAnchor(info);

                    info.rootTrans.position = pos;
                    if (msgSetAnchor.anchorData.sendRotation)
                    {
                        info.rootTrans.eulerAngles = forward;
                    }
                    else
                    {
                        info.rootTrans.forward = forward;
                    }
                    //info.mark.followRoot = true;
                    //info.FollowRootObject();

                    anchorController.CreateAnchor(info);
                }
                waitToSave.Add(info);
                anchorController.SaveAllSceneRootAnchor();
            }

            anchorController.ShowAllMark(false);

            // 检查是否存储完毕
            StartCoroutine(CheckSave());
        }
コード例 #4
0
    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);
    }