Пример #1
0
        private LiveMessageSynchronizeAll CreateSyncMessage()
        {
            LiveMessageSynchronizeAll msg = new LiveMessageSynchronizeAll();

            msg.seq = syncIndex;
            syncIndex++;
            msg.position = mainCameraTransform.transform.position;
            msg.rotation = mainCameraTransform.transform.rotation;

            msg.anchorCount        = anchorController.anchorObjectList.Count;
            msg.anchorPositionList = new Vector3[msg.anchorCount];
            msg.anchorRotationList = new Quaternion[msg.anchorCount];
            msg.anchorIsLocated    = new bool[msg.anchorCount];
            for (int i = 0; i < anchorController.anchorObjectList.Count; i++)
            {
                AnchorObjectInfo info = anchorController.anchorObjectList[i];
                msg.anchorPositionList[i] = info.rootTrans.position;
                msg.anchorRotationList[i] = info.rootTrans.rotation;
                if (info.anchor != null)
                {
                    msg.anchorIsLocated[i] = info.anchor.isLocated;
                }
                else
                {
                    msg.anchorIsLocated[i] = false;
                }
            }

            return(msg);
        }
Пример #2
0
        /// <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...";
        }
Пример #3
0
        /// <summary>
        /// 从文件中读取所有Anchor和主摄像机的位置
        /// </summary>
        public void LoadTransformByFile(LoadTransType type)
        {
            string path = GetSavePath();

            Dictionary <string, string> data = AppConfig.AnalyseConfigFile(path);
            Vector3 v;

            if (data != null)
            {
                if (type == LoadTransType.Camera || type == LoadTransType.CameraAndAnchor)
                {
                    if (data.ContainsKey("CameraPos"))
                    {
                        if (FillVectorFromString(data["CameraPos"], out v))
                        {
                            mainCameraTransform.position = v;
                            holoCameraTransform.position = mainCameraTransform.position;
                        }
                    }
                    if (data.ContainsKey("CameraRot"))
                    {
                        if (FillVectorFromString(data["CameraRot"], out v))
                        {
                            mainCameraTransform.eulerAngles = v;
                            holoCameraTransform.rotation    = mainCameraTransform.rotation;
                        }
                    }
                }

                if (type == LoadTransType.Anchor || type == LoadTransType.CameraAndAnchor)
                {
                    for (int i = 0; i < anchorController.anchorObjectList.Count; i++)
                    {
                        AnchorObjectInfo info = anchorController.anchorObjectList[i];

                        if (data.ContainsKey("[" + info.anchorName + "]pos"))
                        {
                            if (FillVectorFromString(data["[" + info.anchorName + "]pos"], out v))
                            {
                                info.SetPosition(v);
                            }
                        }

                        if (data.ContainsKey("[" + info.anchorName + "]rot"))
                        {
                            if (FillVectorFromString(data["[" + info.anchorName + "]rot"], out v))
                            {
                                info.SetEular(v);
                            }
                        }
                    }
                }
            }
            else
            {
                Debug.Log("Can not fild Anchor save file.");
            }
        }
Пример #4
0
        /// <summary>
        /// 存储所有Anchor以及主摄像机的位置到文件之中
        /// </summary>
        public void SaveTransformToFile()
        {
            string path = GetSavePath();

            Dictionary <string, string> data = new Dictionary <string, string>();

            data.Add("CameraPos", GetVectorString(mainCamera.transform.position));
            data.Add("CameraRot", GetVectorString(mainCamera.transform.eulerAngles));

            for (int i = 0; i < anchorController.anchorObjectList.Count; i++)
            {
                AnchorObjectInfo info = anchorController.anchorObjectList[i];

                data.Add("[" + info.anchorName + "]pos", GetVectorString(info.rootObject.transform.position));
                data.Add("[" + info.anchorName + "]rot", GetVectorString(info.rootObject.transform.eulerAngles));
            }

            //Debug.Log("Save Anchor file [" + path + "]");
            AppConfig.SaveConfigFile(path, data);
        }
Пример #5
0
        /// <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());
        }
Пример #6
0
        /// <summary>
        /// 将anchor信息初始化到Hololens端
        /// </summary>
        public void SetAnchorToHololens(bool isInit)
        {
            if (!hololensConnected)
            {
                return;
            }

            StratLog();

            LiveMessageSetAnchor msg = new LiveMessageSetAnchor();

            msg.anchorData               = new LiveMessageSetAnchor.LiveMessageSetAnchorData();
            msg.anchorData.serverHost    = anchorController.serverHost;
            msg.anchorData.serverPort    = anchorController.serverPort;
            msg.anchorData.appId         = anchorController.appId;
            msg.anchorData.roomId        = anchorController.roomId;
            msg.anchorData.useUDP        = this.useUDP;
            msg.anchorData.serverPortUDP = this.listenPortUDP;
            msg.anchorData.sendRotation  = true;
            msg.anchorData.logIndex      = currentLogIndex;

            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 Set Anchor msg type=" + msg.type);
            if (handler != null)
            {
                handler.SendMessage(msg.Serialize(), null);
            }
            waiting       = true;
            waitingString = "Waiting for anchor init...";
        }
Пример #7
0
        private void CheckSyncTransform()
        {
            if (syncMsgList.Count == 0)
            {
                return;
            }

            float curTime    = Time.realtimeSinceStartup - LiveParam.SyncDelayTime;
            float timeBefore = curTime + LiveParam.AntiShakeBeforeTime;
            float timeAfter  = curTime + LiveParam.AntiShakeAfterTime;

            LinkedListNode <LiveMessageSynchronizeAll> node = syncMsgList.First;

            syncCameraPos     = Vector3.zero;
            syncCameraRot     = Quaternion.identity;
            syncCameraRotTemp = Vector4.zero;

            int anchorCount = anchorController.anchorObjectList.Count;

            InitSyncAnchorData(ref syncAnchorPos, anchorCount);
            InitSyncAnchorData(ref syncAnchorRot, anchorCount);
            InitSyncAnchorData(ref syncAnchorRotFirst, anchorCount);
            InitSyncAnchorData(ref syncAnchorRotTemp, anchorCount);

            int count = 0;

            anchorLocated = true;
            LiveMessageSynchronizeAll lastMsg = null;

            while (node != null)
            {
                LiveMessageSynchronizeAll syncMsg = node.Value;
                LinkedListNode <LiveMessageSynchronizeAll> removeNode = null;
                if (syncMsg.receiveTime <= timeBefore)
                {
                    lastMsg    = syncMsg;
                    removeNode = node;
                }
                else if (syncMsg.receiveTime <= timeAfter)
                {
                    CountOneSyncMessage(ref count, syncMsg);
                }

                node = node.Next;
                if (removeNode != null)
                {
                    syncMsgList.Remove(removeNode);
                }
            }

            if (count == 0 && lastMsg != null)
            {
                // 如果时间窗口内没有任何对象,并且有删除,则取之前删除的最后一个对象
                CountOneSyncMessage(ref count, lastMsg);
            }

            if (count > 0)
            {
                mainCameraTransform.position = syncCameraPos / (float)count;
                mainCameraTransform.rotation = syncCameraRot;

                for (int i = 0; i < anchorController.anchorObjectList.Count; i++)
                {
                    AnchorObjectInfo info = anchorController.anchorObjectList[i];
                    info.rootObject.transform.position = syncAnchorPos[i] / (float)count;
                    info.rootObject.transform.rotation = syncAnchorRot[i];

                    //Debug.Log(" --->Set Anchor [" + info.anchorName + "] to " + syncMsg.anchorPositionList[i] + " | " + syncMsg.anchorRotationList[i]);
                }
            }

            saveAnchorDirty = true;
        }