public bool IsEqual(ClientObjectAttribute clientObjectAttributeA, ClientObjectAttribute clientObjectAttributeB) { if (clientObjectAttributeA.Param != clientObjectAttributeB.Param) { return(false); } if (clientObjectAttributeA.CameraPosX != clientObjectAttributeB.CameraPosX) { return(false); } if (clientObjectAttributeA.CameraPosY != clientObjectAttributeB.CameraPosY) { return(false); } if (clientObjectAttributeA.CameraPosZ != clientObjectAttributeB.CameraPosZ) { return(false); } if (clientObjectAttributeA.CameraRotX != clientObjectAttributeB.CameraRotX) { return(false); } if (clientObjectAttributeA.CameraRotY != clientObjectAttributeB.CameraRotY) { return(false); } if (clientObjectAttributeA.CameraRotZ != clientObjectAttributeB.CameraRotZ) { return(false); } return(true); }
public double DistanceBtw(ClientObjectAttribute clientObjectAttributeA, ClientObjectAttribute clientObjectAttributeB) { return(Math.Sqrt( Math.Pow((clientObjectAttributeA.CameraPosX - clientObjectAttributeB.CameraPosX), 2) + Math.Pow((clientObjectAttributeA.CameraPosY - clientObjectAttributeB.CameraPosY), 2) + Math.Pow((clientObjectAttributeA.CameraPosZ - clientObjectAttributeB.CameraPosZ), 2))); }
void SynchornizeDynamicObjects(ClientObjectAttribute clientObjAttribute) { Launcher.instance.sceneCamera.transform.position = new Vector3(clientObjAttribute.CameraPosX, clientObjAttribute.CameraPosY, clientObjAttribute.CameraPosZ); Launcher.instance.sceneCamera.transform.forward = new Vector3(clientObjAttribute.CameraRotX, clientObjAttribute.CameraRotY, clientObjAttribute.CameraRotZ); //Launcher.instance.sceneCamera.transform.rotation = Quaternion.Euler(new Vector3(clientObjAttribute.CameraRotX, clientObjAttribute.CameraRotY, clientObjAttribute.CameraRotZ)); switch (Launcher.instance.SceneName) { case "CornellBox": { if (Launcher.instance.dynLights.Count > 0) { Launcher.instance.dynLights[0].transform.position = new Vector3(clientObjAttribute.LightPosX, clientObjAttribute.LightPosY, clientObjAttribute.LightPosZ); Launcher.instance.dynLights[0].transform.forward = new Vector3(clientObjAttribute.LightRotX, clientObjAttribute.LightRotY, clientObjAttribute.LightRotZ) - Launcher.instance.dynLights[0].transform.position; } } break; case "OfficeInterior": { if (Launcher.instance.dynLights.Count > 1) { Launcher.instance.dynLights[0].gameObject.SetActive(clientObjAttribute.LightPosX > 0.0f); Launcher.instance.dynLights[1].gameObject.SetActive(clientObjAttribute.LightPosY > 0.0f);; } } break; } }
IEnumerator SyncClientAttribute() { while (true) { ClientObjectAttribute clientObjAttribute = new ClientObjectAttribute(); clientObjAttribute.CameraPosX = Launcher.instance.sceneCamera.transform.position.x; clientObjAttribute.CameraPosY = Launcher.instance.sceneCamera.transform.position.y; clientObjAttribute.CameraPosZ = Launcher.instance.sceneCamera.transform.position.z; clientObjAttribute.CameraRotX = Launcher.instance.sceneCamera.transform.rotation.eulerAngles.x; clientObjAttribute.CameraRotY = Launcher.instance.sceneCamera.transform.rotation.eulerAngles.y; clientObjAttribute.CameraRotZ = Launcher.instance.sceneCamera.transform.rotation.eulerAngles.z; //clientObjAttribute.LightPosX = Launcher.instance.dynLight.transform.position.x; //clientObjAttribute.LightPosY = Launcher.instance.dynLight.transform.position.y; //clientObjAttribute.LightPosZ = Launcher.instance.dynLight.transform.position.z; SendRawData(new XPacket((ushort)eMsgID.C2S_AttributeStream, 300, 300), MsgNoteUtils.StructToBytes(clientObjAttribute)); yield return(new WaitForSeconds(0.1f)); } yield return(new AsyncOperation()); }
Utils.int2 ExtractScreenSize(ClientObjectAttribute clientData) { int height = (int)clientData.Param % mWebClientExchangeCode; int weight = (int)clientData.Param / mWebClientExchangeCode; return(new Utils.int2(weight, height)); }
public virtual void Collect(int width, int height, ClientObjectAttribute clientObjAttribute) { SynchornizeDynamicObjects(clientObjAttribute); PrepareRenderTexture(width, height); Render(width, height); }
public void EnqueueAttributeData(ClientObjectAttribute clientObjectAttribute) { //if (mAttributeDataList.Count >= 3) { // mAttributeDataList.Dequeue(); //} mAttributeDataList.Push(clientObjectAttribute); Debug.Log("Update Viewpoint List"); }
public Record getPredict(string ctsMarker, ClientObjectAttribute cl) { Program dbscan = new Program(); //Debug.Log("!!!!!!!!!!!!!Start Dbscan!!!!!!!!!!!!!"); List <int> clusterIds; List <Cluster> clusterDes; HashSet <Record[]> _clusters = dbscan.Dbscan(out clusterIds, out clusterDes); Predict predict = new Predict(); List <Record> gazePoints = preGaze.getGazePoints(getAllBrowseRecord()); List <Record> predictedCluster = predict.GetPredictedCluster( new Vector3(cl.CameraPosX, cl.CameraPosY, cl.CameraPosZ), new Vector3(cl.CameraRotX, cl.CameraRotY, cl.CameraRotZ), _clusters, clusterDes ); Record posRange = getRangeRecord(predictedCluster); Vector3 tmpPos = pathHistory[ctsMarker].cameraPos; Vector3 rot; float x_sum = 0, y_sum = 0, z_sum = 0, x_rot = 0, y_rot = 0, z_rot = 0; foreach (var j in predictedCluster) { x_sum += (float)j.posX; y_sum += (float)j.posY; z_sum += (float)j.posZ; x_rot += (float)j.rotX; y_rot += (float)j.rotY; z_rot += (float)j.rotZ; } float x_ave = x_sum / predictedCluster.Count; float y_ave = y_sum / predictedCluster.Count; float z_ave = z_sum / predictedCluster.Count; float x_averot = x_rot / predictedCluster.Count; float y_averot = y_rot / predictedCluster.Count; float z_averot = z_rot / predictedCluster.Count; if (tmpPos.x <= posRange.posX && tmpPos.y <= posRange.posY && tmpPos.z <= posRange.posZ && tmpPos.x >= posRange.rotX && tmpPos.y >= posRange.rotY && tmpPos.z >= posRange.rotZ) { rot = new Vector3(x_averot, y_averot, z_averot); } else { rot = new Vector3(x_ave, y_ave, z_ave); rot = rot - tmpPos; } //------ /*if (predictedCluster != null) * { * //把块变成坐标系 * var exchangeAxis = new ExchangeAxis(); * Record pos = new Record(exchangeAxis.ModelIndex_to_unityPos(x_ave, y_ave, z_ave), new Vector3(x_averot, y_averot, z_averot)); * return pos; * * } * else { Debug.Log("No suggestion"); }*/ return(new Record(MoveForwardPredict(pathHistory[ctsMarker], rot), rot)); }
public virtual void Collect(int width, int height, ClientObjectAttribute clientObjAttribute) { SynchornizeDynamicObjects(clientObjAttribute); PrepareRenderTexture(width, height); Render(width, height); Debug.Log("Start Collecting Components"); }
public Record getPredict(string ctsMarker, ClientObjectAttribute cl) { Debug.Log("Start predict"); Predict predict = new Predict(); List <Record> gazePoints = preGaze.getGazePoints(getAllBrowseRecord()); Cluster predictedCluster = predict.GetPredictedCluster( new Vector3(cl.CameraPosX, cl.CameraPosY, cl.CameraPosZ), new Vector3(cl.CameraRotX, cl.CameraRotY, cl.CameraRotZ), clusterNet, gazePoints); //Record posRange = getRangeRecord(predictedCluster); Vector3 tmpPos = pathHistory[ctsMarker].cameraPos; //float x_sum = 0, y_sum = 0, z_sum = 0, x_rot = 0, y_rot = 0, z_rot = 0; //foreach (var j in predictedCluster) //{ // x_sum += (float)j.posX; // y_sum += (float)j.posY; // z_sum += (float)j.posZ; // x_rot += (float)j.rotX; // y_rot += (float)j.rotY; // z_rot += (float)j.rotZ; //} //float x_ave = x_sum / predictedCluster.Count; //float y_ave = y_sum / predictedCluster.Count; //float z_ave = z_sum / predictedCluster.Count; Vector3 cluterPos = predictedCluster.center; //float x_averot = x_rot / predictedCluster.Count; //float y_averot = y_rot / predictedCluster.Count; //float z_averot = z_rot / predictedCluster.Count; Vector3 rot = cluterPos - tmpPos; //if (tmpPos.x <= posRange.posX && tmpPos.y <= posRange.posY && tmpPos.z <= posRange.posZ // && tmpPos.x >= posRange.rotX && tmpPos.y >= posRange.rotY && tmpPos.z >= posRange.rotZ) //{ // rot = new Vector3(x_averot, y_averot, z_averot); //} //else //{ // rot = new Vector3(x_ave, y_ave, z_ave); // rot = rot - tmpPos; //} //------ /*if (predictedCluster != null) * { * //把块变成坐标系 * var exchangeAxis = new ExchangeAxis(); * Record pos = new Record(exchangeAxis.ModelIndex_to_unityPos(x_ave, y_ave, z_ave), new Vector3(x_averot, y_averot, z_averot)); * return pos; * * } * else { Debug.Log("No suggestion"); }*/ return(new Record(MoveForwardPredict(pathHistory[ctsMarker], rot), rot)); }
public void Update() { if (mRadianceCollector != null) { AttributeData attributeData = null; while ((attributeData = mCloudSocket.DequeueAttributeData()) != null) { var msgHeader = MsgNoteUtils.GetMessageHead(attributeData.RawData); LCRS.Log("msgHeader: " + msgHeader); if (msgHeader == eMsgID.C2S_DGI_Init) { Baker.Instance.Init(); Baker.Instance.SetLightMap(); //不需要传ST了:导出json的时候已经计算好了 //mCloudSocket.EnqueueJsonData(new LightmapSTJsonData(Object.FindObjectsOfType<MeshRenderer>(), eMsgID.S2C_Json_LightmapST)); mCloudSocket.EnqueueJsonData(new LightmapArrayJsonData(eMsgID.S2C_Json_LightmapArray)); } else if (msgHeader == eMsgID.C2D_DGI_RecalcLightmap) { Baker.Instance.Init(); Baker.Instance.SetLightMap(); mCloudSocket.EnqueueJsonData(new LightmapArrayJsonData(eMsgID.S2C_Json_LightmapArray)); } else if (msgHeader == eMsgID.C2S_Json_UpdateObjectPosition) { byte[] clientObjBytes = MsgNoteUtils.GetMessageBody(attributeData.RawData); string jsonStr = Encoding.UTF8.GetString(clientObjBytes); JsonMapper.RegisterExporter <float>((obj, writer) => writer.Write(Convert.ToDouble(obj))); JsonMapper.RegisterImporter <double, float>(input => Convert.ToSingle(input)); ClientSyncObjectData syncObject = JsonMapper.ToObject <ClientSyncObjectData>(jsonStr); Baker.Instance.SyncObjectPosition(syncObject); Baker.Instance.Init(); Baker.Instance.SetLightMap(); mCloudSocket.EnqueueJsonData(new LightmapArrayJsonData(eMsgID.S2C_Json_LightmapArray)); } else { ClientObjectAttribute clientObjAttribute = (ClientObjectAttribute)MsgNoteUtils.BytesToStruct(attributeData.RawData, typeof(ClientObjectAttribute)); int height = (int)clientObjAttribute.Param % mWebClientExchangeCode; int width = (int)clientObjAttribute.Param / mWebClientExchangeCode; LCRS.Log("===================================================== Log: " + width + "==324234234235^%$^%@#R@3: " + (ushort)clientObjAttribute.LightPosZ); // mRadianceCollector.Collect(width, height, clientObjAttribute); // mCloudSocket.EnqueueRadianceData(new RadianceData((ushort)clientObjAttribute.LightPosZ, (ushort)width, (ushort)height, mRadianceCollector.GetRadianceDataInPng())); } } } }
public ClientObjectAttribute PredictNextNode(ClientObjectAttribute clientObjectAttributeA, ClientObjectAttribute clientObjectAttributeB) { ClientObjectAttribute result = new ClientObjectAttribute(); result.Param = clientObjectAttributeA.Param; result.CameraPosX = 2 * clientObjectAttributeA.CameraPosX - clientObjectAttributeB.CameraPosX; result.CameraPosY = 2 * clientObjectAttributeA.CameraPosY - clientObjectAttributeB.CameraPosY; result.CameraPosZ = 2 * clientObjectAttributeA.CameraPosZ - clientObjectAttributeB.CameraPosZ; result.CameraRotX = clientObjectAttributeB.CameraRotX; result.CameraRotY = clientObjectAttributeB.CameraRotY; result.CameraRotZ = clientObjectAttributeB.CameraRotZ; return(result); }
private double Compare(ClientObjectAttribute clientObjectAttribute, ClientObjectAttribute predictObjectAttribute) { double score; double a = clientObjectAttribute.CameraPosX - predictObjectAttribute.CameraPosX; double b = clientObjectAttribute.CameraPosY - predictObjectAttribute.CameraPosY; double c = clientObjectAttribute.CameraPosZ - predictObjectAttribute.CameraPosZ; double d = clientObjectAttribute.CameraRotX - predictObjectAttribute.CameraRotX; double e = clientObjectAttribute.CameraRotY - predictObjectAttribute.CameraRotY; double f = clientObjectAttribute.CameraRotZ - predictObjectAttribute.CameraRotZ; score = a * a + b * b + c * c + d * d + e * e + f * f; return(score); }
public ClientObjectAttribute PredictNextNode(ClientObjectAttribute clientObjectAttributeA, ClientObjectAttribute clientObjectAttributeB) { ClientObjectAttribute result = new ClientObjectAttribute(); double distance = DistanceBtw(clientObjectAttributeA, clientObjectAttributeB); result.Param = clientObjectAttributeA.Param; result.CameraPosX = (float)(clientObjectAttributeA.CameraPosX + distance * clientObjectAttributeA.CameraRotX); result.CameraPosY = (float)(clientObjectAttributeA.CameraPosY + distance * clientObjectAttributeA.CameraRotY); result.CameraPosZ = (float)(clientObjectAttributeA.CameraPosZ + distance * clientObjectAttributeA.CameraRotZ); result.CameraRotX = clientObjectAttributeA.CameraRotX; result.CameraRotY = clientObjectAttributeA.CameraRotY; result.CameraRotZ = clientObjectAttributeA.CameraRotZ; return(result); }
public void UpdateCamera(ClientObjectAttribute clientObjectAttribute) { camera.posX = clientObjectAttribute.CameraPosX; camera.posY = clientObjectAttribute.CameraPosY; camera.posZ = clientObjectAttribute.CameraPosZ; camera.rotX = clientObjectAttribute.CameraRotX; camera.rotY = clientObjectAttribute.CameraRotY; camera.rotZ = clientObjectAttribute.CameraRotZ; Vector3 _cameraPos = new Vector3(clientObjectAttribute.CameraPosX, clientObjectAttribute.CameraPosY, clientObjectAttribute.CameraPosZ); if (lastPos != _cameraPos)//运动时更新速度以及预测开关 { speed = _cameraPos - lastPos; //Debug.Log(speed.ToString()); } }
public void Update() { if (mRadianceCollector != null) { if (mCloudSocket.AttributeDataListLength > 0) { Debug.Log("Start Syn View Point"); ClientObjectAttribute clientObjAttribute = mCloudSocket.DequeueAttributeData(); int height = (int)clientObjAttribute.Param % mWebClientExchangeCode; int width = (int)clientObjAttribute.Param / mWebClientExchangeCode; //Debug.Log("Param:" + (int)clientObjAttribute.Param + " ExchangeCode:" + mWebClientExchangeCode); //Debug.Log("Width:" + width +" Height:"+ height); if (times == 1 && File.Exists(firstLoadDataPath + index + ".bin")) { while (File.Exists(firstLoadDataPath + index + ".bin")) { byte[] data = File.ReadAllBytes(firstLoadDataPath + index + ".bin"); //mCloudSocket.EnqueueRadianceData(new RadianceData((ushort)clientObjAttribute.LightPosZ, (ushort)width, (ushort)height, data)); NetworkServer.SendRawData(mCTSMarker, new XPacket((ushort)eMsgID.S2C_RadianceStream, (ushort)width, (ushort)height), data); index++; } } else if (times == 1) { mRadianceCollector.Collect(width, height, clientObjAttribute); mRadianceCollector.SendRadianceData(mCTSMarker, (ushort)clientObjAttribute.LightPosZ, (ushort)width, (ushort)height, ComponentTransformittedSet, ReuseDataInfoObj, true); } else { mRadianceCollector.Collect(width, height, clientObjAttribute); mRadianceCollector.SendRadianceData(mCTSMarker, (ushort)clientObjAttribute.LightPosZ, (ushort)width, (ushort)height, ComponentTransformittedSet, ReuseDataInfoObj, false); } times++; } } }
//判断该路径中是否有注视行为 public bool isValidGaze(List <BrowseRecord> _record, out HashSet <string> gezeComponents) { int mWebClientExchangeCode = 4000; int Param = 3840451; //List<BrowseRecord> tmpList = getLastPoints(_record); HashSet <string> result = new HashSet <string>(); for (int i = 0; i < _record.Count; i++) { int height = Param % mWebClientExchangeCode; int width = Param / mWebClientExchangeCode; ClientObjectAttribute clientObject = new ClientObjectAttribute(); clientObject.CameraPosX = _record[i].pos.x; clientObject.CameraPosY = _record[i].pos.y; clientObject.CameraPosZ = _record[i].pos.z; clientObject.CameraRotX = _record[i].rot.x; clientObject.CameraRotY = _record[i].rot.y; clientObject.CameraRotZ = _record[i].rot.z; mRadianceCollector.Setup(); mRadianceCollector.Collect(width, height, clientObject); HashSet <string> components = mRadianceCollector.getCenterComponents(width, height, clientObject); if (result == new HashSet <string>()) { result = components; } else { result.IntersectWith(components); } //Debug.Log(components); } if (result.Count == 0) { gezeComponents = result; return(true); } gezeComponents = null; return(false); }
//1751578 public override HashSet <string> getCenterComponents(int width, int height, ClientObjectAttribute clientObjAttribute) { HashSet <string> result = new HashSet <string>(); if (Launcher.instance.radianceMgr.mIsPrepaed == false) { return(null); } RenderTexture.active = mRenderTexture; Texture2D png = new Texture2D(mRenderTexture.width, mRenderTexture.height, TextureFormat.RGB24, false); png.ReadPixels(new Rect(mRenderTexture.width * 0.33f, mRenderTexture.height * 0.33f, mRenderTexture.width * 0.33f, mRenderTexture.height * 0.33f), 0, 0); /* System.IO.File.WriteAllBytes(@"e:\test.png", png.EncodeToPNG()); * Texture2D png2 = new Texture2D(mRenderTexture.width, mRenderTexture.height, TextureFormat.RGB24, false); * png2.ReadPixels(new Rect(0, 0, mRenderTexture.width, mRenderTexture.height), 0, 0); * System.IO.File.WriteAllBytes(@"e:\test2.png", png2.EncodeToPNG());*/ Color32[] visiblePixels = png.GetPixels32(); for (int i = 0; i < visiblePixels.Length; i++) { string name = Launcher.instance.radianceMgr.mVisibleNames[visiblePixels[i].r, visiblePixels[i].g, visiblePixels[i].b]; if (name == null) { continue; } //替换重用构件名 string[] nameArr = name.Split('/'); if (!result.Contains(name)) { result.Add(name); } } Debug.Log("Saved"); return(result); }
//1751578 public virtual HashSet <string> getCenterComponents(int width, int height, ClientObjectAttribute clientObjAttribute) { return(null); }
public void UpdateCamera(string ctsMarker, ClientObjectAttribute clientObjectAttribute) { pathHistory[ctsMarker].UpdateCamera(clientObjectAttribute); }
public void UpdateList(ClientObjectAttribute clientObjectAttribute) { ConnectionMgr connectionMgr = Launcher.instance.connectionMgr; CTSMarker ctsMarker = connectionMgr.cloudToTcpSocketMap[this]; Launcher.instance.history.UpdateCamera(ctsMarker.sessionId, clientObjectAttribute); //clientObjectAttribute.LightPosZ = 66; if (mList.Count <= 0) { EnqueueAttributeData(clientObjectAttribute); mList.Add(clientObjectAttribute); _count = 0; } else { if (!IsEqual(clientObjectAttribute, mList[mList.Count - 1])) { EnqueueAttributeData(clientObjectAttribute); mList.Add(clientObjectAttribute); _count = 0; Debug.Log(clientObjectAttribute.CameraPosX + " " + clientObjectAttribute.CameraPosY + " " + clientObjectAttribute.CameraPosZ); Debug.Log(clientObjectAttribute.CameraRotX + " " + clientObjectAttribute.CameraRotY + " " + clientObjectAttribute.CameraRotZ); if (!_notPredicted) { //做预测的反馈 double score = Compare(clientObjectAttribute, predictObjectAttribute); // Debug.Log(clientObjectAttribute.CameraPosX+" "+clientObjectAttribute.CameraPosY+" "+ // clientObjectAttribute.CameraPosZ); // Debug.Log(clientObjectAttribute.CameraRotX+" "+clientObjectAttribute.CameraRotY+" "+ // clientObjectAttribute.CameraRotZ); // Debug.Log("偏差值: "+(score/128).ToString("0.00")); // Debug.Log(predictObjectAttribute.CameraPosX+" "+predictObjectAttribute.CameraPosY+" "+ // predictObjectAttribute.CameraPosZ); // Debug.Log(predictObjectAttribute.CameraRotX+" "+predictObjectAttribute.CameraRotY+" "+ // predictObjectAttribute.CameraRotZ); _notPredicted = true; } } //1751578 else { _count++; } if (_count > 5 && _notPredicted) { Debug.Log("!!!!!!!!!!!!!Predict!!!!!!!!!!!!!"); //Record a = Launcher.instance.history.getPredict(ctsMarker.sessionId,clientObjectAttribute); predictObjectAttribute.Param = clientObjectAttribute.Param; //predictObjectAttribute.CameraPosX = (float)a.posX; //predictObjectAttribute.CameraPosY = (float)a.posY; //predictObjectAttribute.CameraPosZ = (float)a.posZ; //predictObjectAttribute.CameraRotX = (float)a.rotX; //predictObjectAttribute.CameraRotY = (float)a.rotY; //predictObjectAttribute.CameraRotZ = (float)a.rotZ; //测试数据 predictObjectAttribute.CameraPosX = (float)-9.745914; predictObjectAttribute.CameraPosY = (float)13.74586; predictObjectAttribute.CameraPosZ = (float)6.888044; predictObjectAttribute.CameraRotX = (float)0.3567473; predictObjectAttribute.CameraRotY = (float)-0.7427009; predictObjectAttribute.CameraRotZ = (float)-0.5666805; //测试结束 predictObjectAttribute.LightPosZ = 66; EnqueueAttributeData(predictObjectAttribute); _notPredicted = false; Debug.Log("!!!!!!!!!!!!!Finish!!!!!!!!!!!!!"); } //1751578 } }
public void EnqueueAttributeData(ClientObjectAttribute clientObjectAttribute) { mAttributeDataList.Push(clientObjectAttribute); //Debug.Log("Update Viewpoint List"); }