public unsafe void RequestLocalization() { if (sentrequestCount < maximumRequestinSession) { Debug.Log(" >>>>>> RequestLocalization <<<<<<< " + cloudMaps.Count); m_Sdk.GetComponent <MultiMapAssetImporter>().RemoveARAnchors(); loaderText.text = "Localizing..."; XRCameraIntrinsics intr; ARCameraManager cameraManager = m_Sdk.cameraManager; var cameraSubsystem = cameraManager.subsystem; if (cameraSubsystem != null && cameraSubsystem.TryGetIntrinsics(out intr) && cameraManager.TryAcquireLatestCpuImage(out XRCpuImage image)) { //Debug.Log("Cloud ID >>>>>>>>>>>>>>> : " + cloud_id); var format = TextureFormat.RGB24; if (m_Texture == null || m_Texture.width != image.width || m_Texture.height != image.height) { m_Texture = new Texture2D(image.width, image.height, format, false); } // Convert the image to format, flipping the image across the Y axis. // We can also get a sub rectangle, but we'll get the full image here. var conversionParams = new XRCpuImage.ConversionParams(image, format, XRCpuImage.Transformation.MirrorX); // Texture2D allows us write directly to the raw texture data // This allows us to do the conversion in-place without making any copies. var rawTextureData = m_Texture.GetRawTextureData <byte>(); try { image.Convert(conversionParams, new IntPtr(rawTextureData.GetUnsafePtr()), rawTextureData.Length); } finally { // We must dispose of the XRCameraImage after we're finished // with it to avoid leaking native resources. image.Dispose(); } // Apply the updated texture data to our texture m_Texture.Apply(); //show requeset counts.. loc_attempts_txt.GetComponent <TMP_Text>().enabled = true; loc_map_txt.GetComponent <TMP_Text>().enabled = true; byte[] _bytesjpg = m_Texture.EncodeToJPG(); loc_map_txt.text = ""; Debug.Log("TotalMaps: " + cloudMaps.Count); LocalizationRequestwithToken lr = new LocalizationRequestwithToken(); lr.developer_token = m_Sdk.developerToken; lr.cloud_Ids = cloudMaps; lr.width = image.width; lr.height = image.height; lr.channel = 3; lr.Camera_fx = intr.focalLength.x; lr.Camera_fy = intr.focalLength.y; lr.Camera_px = intr.principalPoint.x; lr.Camera_py = intr.principalPoint.y; lr.version = m_Sdk.arwaysdkversion; lr.image = Convert.ToBase64String(_bytesjpg); lr.timestamp = image.timestamp; ArCameraOffset arCameraOffset = new ArCameraOffset { position = ARCamera.transform.position, rotation = ARCamera.transform.rotation }; ArCameraPoseQueue.Enqueue(arCameraOffset); string loc_request_data = JsonUtility.ToJson(lr); SendCameraImages(loc_request_data); sentrequestCount++; } } else { CancelInvoke("RequestLocalization"); } }
public async void ConnectWS() { websocket.OnOpen += () => { Debug.Log("Connection open!"); Invoke("RequestLocalization", 1f); if (isFirstRequest) { connectionLoaderPanel.SetActive(true); } }; websocket.OnError += (e) => { Debug.Log("Error! " + e); //hide loader panel.. loaderPanel.SetActive(false); if (isFirstRequest) { connectionLoaderPanel.SetActive(false); } }; websocket.OnClose += (e) => { Debug.Log("Connection closed!"); //hide loader panel.. loaderPanel.SetActive(false); if (isFirstRequest) { connectionLoaderPanel.SetActive(false); } }; websocket.OnMessage += (bytes) => { Debug.Log("OnMessage!"); Vector3 camPos; Quaternion camRot; if (isFirstRequest) { connectionLoaderPanel.SetActive(false); isFirstRequest = false; InvokeRepeating("RequestLocalization", 1f, localizationFrequency); StartCoroutine(showInstructions()); } if (ArCameraPoseQueue.Count > 0) { ArCameraOffset arCameraOffset = new ArCameraOffset(); arCameraOffset = ArCameraPoseQueue.Dequeue(); camPos = arCameraOffset.position; camRot = arCameraOffset.rotation; //hide loader panel.. loaderPanel.SetActive(false); // getting the message as a string var Response = System.Text.Encoding.UTF8.GetString(bytes); requestCount++; LocalizationResponse localization = JsonUtility.FromJson <LocalizationResponse>(Response); Debug.Log(localization); if (localization.poseAvailable == true) { counts += 1; poseSetterGO.GetComponent <PoseSetter>().poseHandlerMultiMap(localization, camPos, camRot); if (vibrateOnLocalize) { Handheld.Vibrate(); } CancelInvoke("RequestLocalization"); m_Sdk.GetComponent <MultiMapAssetImporter>().AddARAnchors(); } loc_attempts_txt.text = "Localization attempts: " + counts + " / " + requestCount; // show ARSpace GameObject if counts > 0 if (counts > 0) { ArSpace.SetActive(true); destinationDropdown.SetActive(true); } } }; // waiting for messages await websocket.Connect(); }