void Start() { dropdown = destinationDropdown.GetComponent <TMP_Dropdown>(); dropdown.options.Clear(); dropdown.options.Add(new TMP_Dropdown.OptionData("Select Destination")); map_id = PlayerPrefs.GetString("MAP_ID"); Debug.Log("MapID >> " + map_id); filePath = $"{Application.persistentDataPath}/Files/test.glb"; navController = this.GetComponent <NavController>(); if (map_id.Length > 0) { m_Sdk = ArwaySDK.Instance; if (m_Sdk.developerToken != null && m_Sdk.developerToken.Length > 0) { StartCoroutine(GetMapData(map_id)); } else { Debug.Log("***********\tInvalid Developer Token!\t***********"); NotificationManager.Instance.GenerateError("Invalid Developer Token!!"); } } if (m_ARSpace == null) { m_ARSpace = new GameObject("ARSpace"); if (m_ARSpace == null) { Debug.Log("No AR Space found"); } } // Create WaypointsAndDestinations Group with an ARAnchor m_WaypointsAndDestinations = new GameObject("Waypoints & Destinations"); m_WaypointsAndDestinations.transform.parent = m_ARSpace.transform; // Create 3D Models Group with an ARAnchor m_3DModels = new GameObject("3D Models"); m_3DModels.transform.parent = m_ARSpace.transform; // Create Images Group with an ARAnchor m_Images = new GameObject("Images"); m_Images.transform.parent = m_ARSpace.transform; // Create Text Group with an ARAnchor m_Texts = new GameObject("Texts"); m_Texts.transform.parent = m_ARSpace.transform; // Get reference to AzureAnchorLocalizer script if (m_Sdk.GetComponent <AzureAnchorLocalizer>() != null) { azureAnchorLocalizer = m_Sdk.GetComponent <AzureAnchorLocalizer>(); } }
/// <summary> /// Requests the localization. /// </summary> public unsafe void RequestLocalization() { Debug.Log(" >>>>>> RequestLocalization <<<<<<<" + cloudMaps.Count); m_Sdk.GetComponent <MultiMapAssetImporter>().RemoveARAnchors(); 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); LocalizationRequest lr = new LocalizationRequest(); 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; Vector3 camPos = ARCamera.transform.position; Quaternion camRot = ARCamera.transform.rotation; string loc_request_data = JsonUtility.ToJson(lr); StartCoroutine(sendCameraImages(loc_request_data, camPos, camRot)); } }
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(); }