Ejemplo n.º 1
0
    IEnumerator UploadJPGwithGPS(string filePath, string apiURL, float langitude, float latitude, Action <string> getJsonCameraObjects)
    {
        localizationStatus = LocalizationStatus.WaitForAPIAnswer;
        byte[] bytes = File.ReadAllBytes(filePath);
        Debug.Log("bytes = " + bytes.Length);
        List <IMultipartFormSection> form = new List <IMultipartFormSection>();
        string jsona = "{\"gps\":{\"latitude\":" + langitude + ",\"longitude\":" + latitude + "},\"rotation\": 0,\"mirrored\": false}";

        Debug.Log("" + jsona);
        form.Add(new MultipartFormFileSection("image", bytes, "test.jpg", "image/jpeg"));
        form.Add(new MultipartFormDataSection("description", jsona));
        byte[] boundary = UnityWebRequest.GenerateBoundary();
        var    request  = UnityWebRequest.Post(apiURL, form, boundary);

        request.SetRequestHeader("Accept-Encoding", "gzip, deflate, br");
        request.SetRequestHeader("Accept", "application/vnd.myplace.v2+json");
        Debug.Log("Uploading Screenshot started...");
        yield return(request.SendWebRequest());

        if (request.isNetworkError || request.isHttpError)
        {
            Debug.Log(request.error); localizationStatus = LocalizationStatus.ServerError;
        }
        else
        {
            Debug.Log("Finished Uploading Screenshot");
        }
        Debug.Log(request.downloadHandler.text);
        getJsonCameraObjects(request.downloadHandler.text);
    }
Ejemplo n.º 2
0
        private void SetLocalizationStatus(LocalizationStatus status)
        {
            if (status == statusToDisplay)
            {
                return;
            }

            statusToDisplay = status;
            FilterKeys();
        }
Ejemplo n.º 3
0
    IEnumerator Locate(Action <float, float, float, string, Action <string, Transform, StickerInfo[]> > getLocData)
    {
        Debug.Log("Started Locate GPS");
        localizationStatus = LocalizationStatus.GetGPSData;
        // First, check if user has location service enabled
        if (!Input.location.isEnabledByUser)
        {
            Debug.Log("geo not enabled"); PlayerPrefs.SetInt("LocLoaded", -1);
            yield break;
        }
        // Start service before querying location
        Input.location.Start();
        // Wait until service initializes
        int maxWait = 20;

        while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
        {
            yield return(new WaitForSeconds(1));

            maxWait--;
        }

        // Service didn't initialize in 20 seconds
        if (maxWait < 1)
        {
            Debug.Log("Timed out");
            localizationStatus = LocalizationStatus.NoGPSData;
            yield break;
        }

        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed)
        {
            Debug.Log("Unable to determine device location");
            PlayerPrefs.SetInt("LocLoaded", -2);
            localizationStatus = LocalizationStatus.NoGPSData;
            yield break;
        }
        else
        {
            // Access granted and location value could be retrieved
            Debug.Log("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
            getLocData(Input.location.lastData.latitude, Input.location.lastData.longitude, Input.location.lastData.horizontalAccuracy, null, null);
            GPSlocation = true;
            longitude   = Input.location.lastData.longitude;
            latitude    = Input.location.lastData.latitude;
            hdop        = Input.location.lastData.horizontalAccuracy;
        }

        // Stop service if there is no need to query location updates continuously
        //  Input.location.Stop();
    }
Ejemplo n.º 4
0
    IEnumerator prepareC(float langitude, float latitude, Action <bool, string> getServerAnswer)
    {
        Debug.Log(apiURL + "/api/localizer/prepare?lat=" + latitude + "f&lon=" + langitude + "f");
        var w = UnityWebRequest.Get(apiURL + "/api/localizer/prepare?lat=" + latitude + "f&lon=" + langitude + "f");

        w.SetRequestHeader("Accept-Encoding", "gzip, deflate, br");
        w.SetRequestHeader("Accept", "application/vnd.myplace.v2+json");
        yield return(w.SendWebRequest());

        if (w.isNetworkError || w.isHttpError)
        {
            Debug.Log(w.error); localizationStatus = LocalizationStatus.ServerError;
            getServerAnswer(false, w.downloadHandler.text);
        }
        else
        {
            Debug.Log("prepared API");
            Debug.Log(w.downloadHandler.text);
            getServerAnswer(true, w.downloadHandler.text);
        }
    }
Ejemplo n.º 5
0
    IEnumerator UploadJPGwithGPS(byte[] bytes, string apiURL, float langitude, float latitude, float hdop, Action <string, bool> getJsonCameraObjects)
    {
        localizationStatus = LocalizationStatus.WaitForAPIAnswer;
        Debug.Log("bytes = " + bytes.Length);
        List <IMultipartFormSection> form = new List <IMultipartFormSection>();
        string rotationDevice             = "90";

        if (!editorTestMode)
        {
            if (Input.deviceOrientation == DeviceOrientation.Portrait)
            {
                rotationDevice = "0";
            }
            if (Input.deviceOrientation == DeviceOrientation.LandscapeRight)
            {
                rotationDevice = "90";
            }
            if (Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown)
            {
                rotationDevice = "180";
            }
            if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft)
            {
                rotationDevice = "270";
            }
        }

        string jsona = "{\"gps\":{\"latitude\":" + langitude + ",\"longitude\":" + latitude + ",\"hdop\":" + hdop + "},\"rotation\": " + rotationDevice + ",\"mirrored\": false}";

        uim.gpsDebug(langitude, latitude, hdop);
        Debug.Log("" + jsona);
        form.Add(new MultipartFormFileSection("image", bytes, "test.jpg", "image/jpeg"));
        form.Add(new MultipartFormDataSection("description", jsona));
        byte[] boundary = UnityWebRequest.GenerateBoundary();
        Debug.Log(apiURL + "/api/localizer/localize");
        var w = UnityWebRequest.Post(apiURL + "/api/localizer/localize", form, boundary);

        w.SetRequestHeader("Accept-Encoding", "gzip, deflate, br");
        w.SetRequestHeader("Accept", "application/vnd.myplace.v2+json");
        w.SetRequestHeader("user-agent", "Unity AC-viewer based app, name: " + Application.productName + ", Device: " + SystemInfo.deviceModel);

        Debug.Log("Uploading Screenshot started...");

        yield return(w.SendWebRequest());

        if (w.isNetworkError || w.isHttpError)
        {
            Debug.Log(w.error); localizationStatus = LocalizationStatus.ServerError;
        }
        else
        {
            Debug.Log("Finished Uploading Screenshot");
        }
        Debug.Log(w.downloadHandler.text);
        var    jsonParse = JSON.Parse(w.downloadHandler.text);
        string sid       = null;

        if (jsonParse["camera"] != null)
        {
            sid = jsonParse["reconstruction_id"];
        }
        tempScale3d = 1;

        getJsonCameraObjects(w.downloadHandler.text, false);
    }
Ejemplo n.º 6
0
    IEnumerator UploadJPGwithGPSOSCP(byte[] bytes, string apiURL, float langitude, float latitude, float hdop, Action <string, bool> getJsonCameraObjects)
    {
        localizationStatus = LocalizationStatus.WaitForAPIAnswer;
        //  byte[] bytes = File.ReadAllBytes(filePath);
        Debug.Log("bytes length = " + bytes.Length);
        string rotationDevice = "180";

        if (!editorTestMode)
        {
            if (Input.deviceOrientation == DeviceOrientation.Portrait)
            {
                rotationDevice = "0";
            }
            if (Input.deviceOrientation == DeviceOrientation.LandscapeRight)
            {
                rotationDevice = "90";
            }
            if (Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown)
            {
                rotationDevice = "180";
            }
            if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft)
            {
                rotationDevice = "270";
            }
        }

        //  string shot = System.Text.Encoding.UTF8.GetString(bytes);
        string shot = Convert.ToBase64String(bytes);
        // Debug.Log("Uploading Screenshot started...");

        string finalJson = "{\"id\":\"9089876676575754\",\"timestamp\":\"2020-11-11T11:56:21+00:00\",\"type\":\"geopose\",\"sensors\":[{\"id\":\"0\",\"type\":\"camera\"},{\"id\":\"1\",\"type\":\"geolocation\"}],\"sensorReadings\":[{\"timestamp\":\"2020-11-11T11:56:21+00:00\",\"sensorId\":\"0\",\"reading\":{\"sequenceNumber\":0,\"imageFormat\":\"JPG\",\"imageOrientation\":{\"mirrored\":false,\"rotation\":" + rotationDevice + "},\"imageBytes\":\"" + shot + "\"}},{\"timestamp\":\"2020-11-11T11:56:21+00:00\",\"sensorId\":\"1\",\"reading\":{\"latitude\":" + langitude + ",\"longitude\":" + latitude + ",\"altitude\":0}}]}";

        Debug.Log("finalJson OSCP = " + finalJson);
        Debug.Log(apiURL + "/scrs/geopose_objs_local");

        /*  string path = "request.json";
         * //  File.Create(path);
         * StreamWriter writer = new StreamWriter(path, true, Encoding.UTF8, 1000000);
         * writer.WriteLine(finalJson);
         * writer.Close();*/

        var request = new UnityWebRequest(apiURL + "/scrs/geopose_objs_local", "POST");

        byte[] bodyRaw = Encoding.UTF8.GetBytes(finalJson);
        request.uploadHandler   = (UploadHandler) new UploadHandlerRaw(bodyRaw);
        request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
        request.SetRequestHeader("Accept-Encoding", "gzip, deflate, br");
        request.SetRequestHeader("Accept", "application/vnd.myplace.v2+json");
        request.SetRequestHeader("Content-Type", "application/json");
        request.uploadHandler.contentType = "application/json";
        request.timeout = 50;
        yield return(request.SendWebRequest());

        if (request.isNetworkError || request.isHttpError)
        {
            Debug.Log(request.error); localizationStatus = LocalizationStatus.ServerError;
        }
        else
        {
            //  Debug.Log("Finished Uploading Screenshot");
        }
        Debug.Log(request.downloadHandler.text);
        var    jsonParse = JSON.Parse(request.downloadHandler.text);
        string sid       = null;

        if (jsonParse["camera"] != null)
        {
            sid = jsonParse["reconstruction_id"];
        }
        tempScale3d = 1;
        getJsonCameraObjects(request.downloadHandler.text, true);
    }
Ejemplo n.º 7
0
    public void camLocalize(string jsonanswer, bool geopose)
    {
        var   jsonParse = JSON.Parse(jsonanswer);
        float px, py, pz, ox, oy, oz, ow;
        int   objectsAmount = -1; string js, sessionId;

        if (!geopose)
        {
            if (jsonParse["camera"] != null)
            {
                sessionId = jsonParse["reconstruction_id"];

                do
                {
                    objectsAmount++;
                    js = jsonParse["placeholders"][objectsAmount]["placeholder_id"];
                } while (js != null);

                Debug.Log("nodeAmount =   " + objectsAmount + ", RecoArray Length = " + recoList.Count);

                px = jsonParse["camera"]["pose"]["position"]["x"].AsFloat;
                py = jsonParse["camera"]["pose"]["position"]["y"].AsFloat;
                pz = jsonParse["camera"]["pose"]["position"]["z"].AsFloat;
                ox = jsonParse["camera"]["pose"]["orientation"]["x"].AsFloat;
                oy = jsonParse["camera"]["pose"]["orientation"]["y"].AsFloat;
                oz = jsonParse["camera"]["pose"]["orientation"]["z"].AsFloat;
                ow = jsonParse["camera"]["pose"]["orientation"]["w"].AsFloat;
                uim.setDebugPose(px, py, pz, ox, oy, oz, ow, sessionId);
                GameObject newCam = new GameObject("tempCam");
                newCam.transform.localPosition = new Vector3(px, py, pz);
                newCam.transform.localRotation = new Quaternion(ox, oy, oz, ow);
                newCam.transform.localPosition = new Vector3(px, -newCam.transform.localPosition.y, pz);
                //   Debug.Log("Camera new: " + newCam.transform.localPosition.x + ", " + newCam.transform.localPosition.y + ", " + newCam.transform.localPosition.z);
                newCam.transform.localRotation = Quaternion.Euler(-newCam.transform.localRotation.eulerAngles.x, newCam.transform.localRotation.eulerAngles.y, -newCam.transform.localRotation.eulerAngles.z);
                GameObject zeroCoord = new GameObject("Zero");
                zeroCoord.transform.SetParent(newCam.transform);
                RecoInfo      currentRi = checkRecoID(sessionId);
                StickerInfo[] stickers;
                stickers = null;
                if (currentRi == null)
                {
                    currentRi    = new RecoInfo();
                    currentRi.id = sessionId;
                    if (objectsAmount > 0)
                    {
                        currentRi.scale3dcloud = tempScale3d;
                        stickers = new StickerInfo[objectsAmount];
                        currentRi.stickerArray     = new StickerInfo[objectsAmount];
                        GameObject[,] placeHolders = new GameObject[objectsAmount, 4];
                        for (int j = 0; j < objectsAmount; j++)
                        {
                            currentRi.stickerArray[j] = new StickerInfo();
                            stickers[j] = new StickerInfo();
                            currentRi.stickerArray[j].positions = new Vector3[4];
                            float positionObjX = jsonParse["placeholders"][j]["pose"]["position"]["x"].AsFloat;
                            float positionObjY = jsonParse["placeholders"][j]["pose"]["position"]["y"].AsFloat;
                            float positionObjZ = jsonParse["placeholders"][j]["pose"]["position"]["z"].AsFloat;
                            currentRi.stickerArray[j].mainPositions = new Vector3(positionObjX, -positionObjY, positionObjZ);
                            //    Debug.Log("currentRi.stickerArray[j].mainPositions = " + currentRi.stickerArray[j].mainPositions);
                            stickers[j].mainPositions = new Vector3(positionObjX, -positionObjY, positionObjZ);
                            currentRi.stickerArray[j].orientations = new Vector4(jsonParse["placeholders"][j]["pose"]["orientation"]["x"].AsFloat, jsonParse["placeholders"][j]["pose"]["orientation"]["y"].AsFloat, jsonParse["placeholders"][j]["pose"]["orientation"]["z"].AsFloat, jsonParse["placeholders"][j]["pose"]["orientation"]["w"].AsFloat);
                            stickers[j].orientations = currentRi.stickerArray[j].orientations;
                            //   Debug.Log("!!!!! currentRi.stickerArray[" + j + "].orientations" + currentRi.stickerArray[j].orientations);
                            for (int i = 0; i < 4; i++)
                            {
                                px = jsonParse["placeholders"][j]["frame"][i]["x"].AsFloat + positionObjX;
                                py = jsonParse["placeholders"][j]["frame"][i]["y"].AsFloat + positionObjY;
                                pz = jsonParse["placeholders"][j]["frame"][i]["z"].AsFloat + positionObjZ;
                                placeHolders[j, i] = new GameObject("Placeholder" + j + " " + i);
                                placeHolders[j, i].transform.SetParent(newCam.transform);
                                py = -py;
                                placeHolders[j, i].transform.position  = new Vector3(px, py, pz);
                                currentRi.stickerArray[j].positions[i] = new Vector3(px, py, pz);
                            }

                            string idnode = "" + jsonParse["placeholders"][j]["placeholder_id"];

                            for (int x = 0; x < objectsAmount; x++)
                            {
                                string idobj = "" + jsonParse["objects"][x]["sticker"]["sticker_id"];

                                if (idobj.Contains(idnode))
                                {
                                    stickers[j].sPath             = "" + jsonParse["objects"][x]["sticker"]["path"];
                                    stickers[j].sText             = "" + jsonParse["objects"][x]["sticker"]["sticker_text"];
                                    stickers[j].sType             = "" + jsonParse["objects"][x]["sticker"]["sticker_type"];
                                    stickers[j].sSubType          = "" + jsonParse["objects"][x]["sticker"]["sticker_subtype"];
                                    stickers[j].sDescription      = "" + jsonParse["objects"][x]["sticker"]["description"];
                                    stickers[j].SModel_scale      = "" + jsonParse["objects"][x]["sticker"]["model_scale"];
                                    stickers[j].sId               = "" + jsonParse["objects"][x]["sticker"]["sticker_id"];
                                    stickers[j].objectId          = "" + jsonParse["objects"][x]["placeholder"]["placeholder_id"];
                                    stickers[j].sImage            = "" + jsonParse["objects"][x]["sticker"]["Image"];
                                    stickers[j].sAddress          = "" + jsonParse["objects"][x]["sticker"]["Address"];
                                    stickers[j].sFeedbackAmount   = "" + jsonParse["objects"][x]["sticker"]["Feedback amount"];
                                    stickers[j].sRating           = "" + jsonParse["objects"][x]["sticker"]["Rating"];
                                    stickers[j].sUrl_ta           = "" + jsonParse["objects"][x]["sticker"]["url_ta"];
                                    stickers[j].sTrajectoryPath   = "" + jsonParse["objects"][x]["sticker"]["trajectory_path"];
                                    stickers[j].sTrajectoryOffset = "" + jsonParse["objects"][x]["sticker"]["trajectory_time_offset"];
                                    stickers[j].sTrajectoryPeriod = "" + jsonParse["objects"][x]["sticker"]["trajectory_time_period"];

                                    currentRi.stickerArray[j].sPath             = stickers[j].sPath;
                                    currentRi.stickerArray[j].sText             = stickers[j].sText;
                                    currentRi.stickerArray[j].sType             = stickers[j].sType;
                                    currentRi.stickerArray[j].sSubType          = stickers[j].sSubType;
                                    currentRi.stickerArray[j].sDescription      = stickers[j].sDescription;
                                    currentRi.stickerArray[j].SModel_scale      = stickers[j].SModel_scale;
                                    currentRi.stickerArray[j].sId               = stickers[j].sId;
                                    currentRi.stickerArray[j].sImage            = stickers[j].sImage;
                                    currentRi.stickerArray[j].sAddress          = stickers[j].sAddress;
                                    currentRi.stickerArray[j].sRating           = stickers[j].sRating;
                                    currentRi.stickerArray[j].sUrl_ta           = stickers[j].sUrl_ta;
                                    currentRi.stickerArray[j].sTrajectoryPath   = stickers[j].sTrajectoryPath;
                                    currentRi.stickerArray[j].sTrajectoryOffset = stickers[j].sTrajectoryOffset;
                                    currentRi.stickerArray[j].sTrajectoryPeriod = stickers[j].sTrajectoryPeriod;
                                }
                            }
                        }
                        recoList.Add(currentRi);
                        newCam.transform.position    = cameraPositionInLocalization;
                        newCam.transform.eulerAngles = cameraRotationInLocalization;
                        newCam.transform.RotateAround(newCam.transform.position, newCam.transform.forward, 90);
                        for (int j = 0; j < objectsAmount; j++)
                        {
                            stickers[j].positions = new Vector3[4];
                            for (int i = 0; i < 4; i++)
                            {
                                stickers[j].positions[i] = placeHolders[j, i].transform.position;
                            }
                        }
                    }
                }
                else if (currentRi != null)
                {
                    cameraDistance = Vector3.Magnitude(currentRi.lastCamCoordinate - new Vector3(px, py, pz));
                    tempScale3d    = currentRi.scale3dcloud;
                    int savedNodeLentgh = currentRi.stickerArray.Length;
                    stickers = new StickerInfo[savedNodeLentgh];
                    GameObject[,] placeHolders = new GameObject[savedNodeLentgh, 4];

                    for (int j = 0; j < savedNodeLentgh; j++)
                    {
                        stickers[j] = new StickerInfo();
                        for (int i = 0; i < 4; i++)
                        {
                            placeHolders[j, i] = new GameObject("Placeholder" + j + " " + i);
                            placeHolders[j, i].transform.SetParent(newCam.transform);
                            placeHolders[j, i].transform.position = currentRi.stickerArray[j].positions[i];
                        }
                        stickers[j].sPath        = currentRi.stickerArray[j].sPath;
                        stickers[j].sText        = currentRi.stickerArray[j].sText;
                        stickers[j].sType        = currentRi.stickerArray[j].sType;
                        stickers[j].sSubType     = currentRi.stickerArray[j].sSubType;
                        stickers[j].sDescription = currentRi.stickerArray[j].sDescription;

                        stickers[j].sId    = currentRi.stickerArray[j].sId;
                        stickers[j].sImage = currentRi.stickerArray[j].sImage;
                        currentRi.stickerArray[j].sAddress = stickers[j].sAddress;
                        currentRi.stickerArray[j].sRating  = stickers[j].sRating;
                        currentRi.stickerArray[j].sUrl_ta  = stickers[j].sUrl_ta;
                    }
                    newCam.transform.position    = cameraPositionInLocalization;
                    newCam.transform.eulerAngles = cameraRotationInLocalization;
                    newCam.transform.RotateAround(newCam.transform.position, newCam.transform.forward, 90);

                    for (int j = 0; j < savedNodeLentgh; j++)
                    {
                        stickers[j].positions = new Vector3[4];
                        for (int i = 0; i < 4; i++)
                        {
                            stickers[j].positions[i] = placeHolders[j, i].transform.position;
                        }
                    }
                }

                if (zeroCoord.transform.eulerAngles == Vector3.zero)
                {
                    newCam.transform.position    = cameraPositionInLocalization;
                    newCam.transform.eulerAngles = cameraRotationInLocalization;
                    newCam.transform.RotateAround(newCam.transform.position, newCam.transform.forward, 90);
                }
                currentRi.lastCamCoordinate = new Vector3(px, py, pz);
                localizationStatus          = LocalizationStatus.Ready;
                getStickersAction(currentRi.id, zeroCoord.transform, stickers);
                Destroy(newCam);
            }
            else
            {
                Debug.Log("Cant localize");

                localizationStatus = LocalizationStatus.CantLocalize;
                uim.setDebugPose(0, 0, 0, 0, 0, 0, 0, "cant loc");
                getStickersAction(null, null, null);
            }
        }
        // -- if -- GEOPOSE
        else
        {
            if (jsonParse["geopose"] != null)
            {
                sessionId = jsonParse["geopose"]["reconstruction_id"];

                Debug.Log("sessioID: " + sessionId);
                do
                {
                    objectsAmount++;
                    js = jsonParse["scrs"][objectsAmount]["type"];
                    // Debug.Log("js node [" + objectsAmount + "]  - " + js);
                } while (js != null);

                Debug.Log("nodeAmount =   " + objectsAmount + ", RecoArray Length = " + recoList.Count);

                px = jsonParse["geopose"]["local"]["position"]["x"].AsFloat;
                py = jsonParse["geopose"]["local"]["position"]["y"].AsFloat;
                pz = jsonParse["geopose"]["local"]["position"]["z"].AsFloat;
                ox = jsonParse["geopose"]["local"]["orientation"]["x"].AsFloat;
                oy = jsonParse["geopose"]["local"]["orientation"]["y"].AsFloat;
                oz = jsonParse["geopose"]["local"]["orientation"]["z"].AsFloat;
                ow = jsonParse["geopose"]["local"]["orientation"]["w"].AsFloat;
                uim.setDebugPose(px, py, pz, ox, oy, oz, ow, sessionId);
                GameObject newCam = new GameObject("tempCam");
                newCam.transform.localPosition = new Vector3(px, py, pz);
                newCam.transform.localRotation = new Quaternion(ox, oy, oz, ow);
                newCam.transform.localPosition = new Vector3(px, -newCam.transform.localPosition.y, pz);
                // Debug.Log("Camera new: " + newCam.transform.localPosition.x + ", " + newCam.transform.localPosition.y + ", " + newCam.transform.localPosition.z);



                newCam.transform.localRotation = Quaternion.Euler(-newCam.transform.localRotation.eulerAngles.x, newCam.transform.localRotation.eulerAngles.y, -newCam.transform.localRotation.eulerAngles.z);
                GameObject zeroCoord = new GameObject("Zero");
                zeroCoord.transform.SetParent(newCam.transform);
                RecoInfo      currentRi = checkRecoID(sessionId);
                StickerInfo[] stickers;
                stickers = null;
                if (currentRi == null)
                {
                    currentRi    = new RecoInfo();
                    currentRi.id = sessionId;
                    if (objectsAmount > 0)
                    {
                        currentRi.scale3dcloud = tempScale3d;
                        stickers = new StickerInfo[objectsAmount];
                        currentRi.stickerArray     = new StickerInfo[objectsAmount];
                        GameObject[,] placeHolders = new GameObject[objectsAmount, 4];
                        for (int j = 0; j < objectsAmount; j++)
                        {
                            currentRi.stickerArray[j] = new StickerInfo();
                            stickers[j] = new StickerInfo();
                            currentRi.stickerArray[j].positions = new Vector3[4];
                            float positionObjX = jsonParse["scrs"][j]["content"]["geopose"]["local"]["position"]["x"].AsFloat;
                            float positionObjY = jsonParse["scrs"][j]["content"]["geopose"]["local"]["position"]["y"].AsFloat;
                            float positionObjZ = jsonParse["scrs"][j]["content"]["geopose"]["local"]["position"]["z"].AsFloat;
                            currentRi.stickerArray[j].mainPositions = new Vector3(positionObjX, -positionObjY, positionObjZ);
                            //  Debug.Log("currentRi.stickerArray[j].mainPositions = " + currentRi.stickerArray[j].mainPositions);
                            stickers[j].mainPositions = new Vector3(positionObjX, -positionObjY, positionObjZ);
                            currentRi.stickerArray[j].orientations = new Vector4(jsonParse["scrs"][j]["content"]["geopose"]["local"]["orientation"]["x"].AsFloat, jsonParse["scrs"][j]["content"]["geopose"]["local"]["orientation"]["y"].AsFloat, jsonParse["scrs"][j]["content"]["geopose"]["local"]["orientation"]["z"].AsFloat, jsonParse["scrs"][j]["content"]["geopose"]["local"]["orientation"]["w"].AsFloat);
                            stickers[j].orientations = currentRi.stickerArray[j].orientations;
                            Debug.Log("!!!!! currentRi.stickerArray[" + j + "].orientations x" + currentRi.stickerArray[j].orientations.x + "   " + stickers[j].orientations.x);
                            Debug.Log("!!!!! currentRi.stickerArray[" + j + "].orientations y" + currentRi.stickerArray[j].orientations.y + "   " + stickers[j].orientations.y);
                            Debug.Log("!!!!! currentRi.stickerArray[" + j + "].orientations z" + currentRi.stickerArray[j].orientations.z + "   " + stickers[j].orientations.z);
                            Debug.Log("!!!!! currentRi.stickerArray[" + j + "].orientations w" + currentRi.stickerArray[j].orientations.w + "   " + stickers[j].orientations.w);

                            for (int i = 0; i < 4; i++)
                            {
                                px = jsonParse["scrs"][j]["content"]["geopose"]["local"]["frame"][i]["x"].AsFloat + positionObjX;
                                py = jsonParse["scrs"][j]["content"]["geopose"]["local"]["frame"][i]["y"].AsFloat + positionObjY;
                                pz = jsonParse["scrs"][j]["content"]["geopose"]["local"]["frame"][i]["z"].AsFloat + positionObjZ;
                                placeHolders[j, i] = new GameObject("Placeholder" + j + " " + i);
                                placeHolders[j, i].transform.SetParent(newCam.transform);
                                py = -py;
                                placeHolders[j, i].transform.position  = new Vector3(px, py, pz);
                                currentRi.stickerArray[j].positions[i] = new Vector3(px, py, pz);
                            }

                            stickers[j].sPath             = "" + jsonParse["scrs"][j]["content"]["custom_data"]["path"];
                            stickers[j].sText             = "" + jsonParse["scrs"][j]["content"]["custom_data"]["sticker_text"];
                            stickers[j].sType             = "" + jsonParse["scrs"][j]["content"]["custom_data"]["sticker_type"];
                            stickers[j].sSubType          = "" + jsonParse["scrs"][j]["content"]["custom_data"]["sticker_subtype"];
                            stickers[j].sDescription      = "" + jsonParse["scrs"][j]["content"]["custom_data"]["description"];
                            stickers[j].SModel_scale      = "" + jsonParse["scrs"][j]["content"]["custom_data"]["model_scale"];
                            stickers[j].sId               = "" + jsonParse["scrs"][j]["content"]["custom_data"]["sticker_id"];
                            stickers[j].objectId          = "" + jsonParse["scrs"][j]["content"]["custom_data"]["placeholder_id"];
                            stickers[j].sImage            = "" + jsonParse["scrs"][j]["content"]["custom_data"]["Image"];
                            stickers[j].sAddress          = "" + jsonParse["scrs"][j]["content"]["custom_data"]["Address"];
                            stickers[j].sFeedbackAmount   = "" + jsonParse["scrs"][j]["content"]["custom_data"]["Feedback amount"];
                            stickers[j].sRating           = "" + jsonParse["scrs"][j]["content"]["custom_data"]["Rating"];
                            stickers[j].sUrl_ta           = "" + jsonParse["scrs"][j]["content"]["custom_data"]["url_ta"];
                            stickers[j].sTrajectoryPath   = "" + jsonParse["scrs"][j]["content"]["custom_data"]["trajectory_path"];
                            stickers[j].sTrajectoryOffset = "" + jsonParse["scrs"][j]["content"]["custom_data"]["trajectory_time_offset"];
                            stickers[j].sTrajectoryPeriod = "" + jsonParse["scrs"][j]["content"]["custom_data"]["trajectory_time_period"];

                            currentRi.stickerArray[j].sPath             = stickers[j].sPath;
                            currentRi.stickerArray[j].sText             = stickers[j].sText;
                            currentRi.stickerArray[j].sType             = stickers[j].sType;
                            currentRi.stickerArray[j].sSubType          = stickers[j].sSubType;
                            currentRi.stickerArray[j].sDescription      = stickers[j].sDescription;
                            currentRi.stickerArray[j].SModel_scale      = stickers[j].SModel_scale;
                            currentRi.stickerArray[j].sId               = stickers[j].sId;
                            currentRi.stickerArray[j].sImage            = stickers[j].sImage;
                            currentRi.stickerArray[j].sAddress          = stickers[j].sAddress;
                            currentRi.stickerArray[j].sRating           = stickers[j].sRating;
                            currentRi.stickerArray[j].sUrl_ta           = stickers[j].sUrl_ta;
                            currentRi.stickerArray[j].sTrajectoryPath   = stickers[j].sTrajectoryPath;
                            currentRi.stickerArray[j].sTrajectoryOffset = stickers[j].sTrajectoryOffset;
                            currentRi.stickerArray[j].sTrajectoryPeriod = stickers[j].sTrajectoryPeriod;
                        }
                        recoList.Add(currentRi);
                        newCam.transform.position    = cameraPositionInLocalization;
                        newCam.transform.eulerAngles = cameraRotationInLocalization;
                        newCam.transform.RotateAround(newCam.transform.position, newCam.transform.forward, 90);
                        for (int j = 0; j < objectsAmount; j++)
                        {
                            stickers[j].positions = new Vector3[4];
                            for (int i = 0; i < 4; i++)
                            {
                                stickers[j].positions[i] = placeHolders[j, i].transform.position;
                            }
                        }
                    }
                }
                else if (currentRi != null)
                {
                    cameraDistance = Vector3.Magnitude(currentRi.lastCamCoordinate - new Vector3(px, py, pz));
                    tempScale3d    = currentRi.scale3dcloud;
                    int savedNodeLentgh = currentRi.stickerArray.Length;
                    stickers = new StickerInfo[savedNodeLentgh];
                    GameObject[,] placeHolders = new GameObject[savedNodeLentgh, 4];

                    for (int j = 0; j < savedNodeLentgh; j++)
                    {
                        stickers[j] = new StickerInfo();
                        for (int i = 0; i < 4; i++)
                        {
                            placeHolders[j, i] = new GameObject("Placeholder" + j + " " + i);
                            placeHolders[j, i].transform.SetParent(newCam.transform);
                            placeHolders[j, i].transform.position = currentRi.stickerArray[j].positions[i];
                        }
                        stickers[j].sPath        = currentRi.stickerArray[j].sPath;
                        stickers[j].sText        = currentRi.stickerArray[j].sText;
                        stickers[j].sType        = currentRi.stickerArray[j].sType;
                        stickers[j].sSubType     = currentRi.stickerArray[j].sSubType;
                        stickers[j].sDescription = currentRi.stickerArray[j].sDescription;

                        stickers[j].sId    = currentRi.stickerArray[j].sId;
                        stickers[j].sImage = currentRi.stickerArray[j].sImage;
                        currentRi.stickerArray[j].sAddress = stickers[j].sAddress;
                        currentRi.stickerArray[j].sRating  = stickers[j].sRating;
                        currentRi.stickerArray[j].sUrl_ta  = stickers[j].sUrl_ta;
                    }
                    newCam.transform.position    = cameraPositionInLocalization;
                    newCam.transform.eulerAngles = cameraRotationInLocalization;
                    newCam.transform.RotateAround(newCam.transform.position, newCam.transform.forward, 90);

                    for (int j = 0; j < savedNodeLentgh; j++)
                    {
                        stickers[j].positions = new Vector3[4];
                        for (int i = 0; i < 4; i++)
                        {
                            stickers[j].positions[i] = placeHolders[j, i].transform.position;
                        }
                    }
                }

                if (zeroCoord.transform.eulerAngles == Vector3.zero)
                {
                    newCam.transform.position    = cameraPositionInLocalization;
                    newCam.transform.eulerAngles = cameraRotationInLocalization;
                    newCam.transform.RotateAround(newCam.transform.position, newCam.transform.forward, 90);
                }
                currentRi.lastCamCoordinate = new Vector3(px, py, pz);
                localizationStatus          = LocalizationStatus.Ready;
                getStickersAction(currentRi.id, zeroCoord.transform, stickers);
                Destroy(newCam);
            }
            else
            {
                Debug.Log("Cant localize");

                localizationStatus = LocalizationStatus.CantLocalize;
                uim.setDebugPose(0, 0, 0, 0, 0, 0, 0, "cant loc");
                getStickersAction(null, null, null);
            }
        }
    }
Ejemplo n.º 8
0
        private static void CheckForValidFiles()
        {
            string registryPath = Path.Combine(Application.streamingAssetsPath, LOCALIZATION_REGISTRY_FILE_NAME + ".json");

            if (File.Exists(registryPath))
            {
                string dataAsJson = File.ReadAllText(registryPath);
                try
                {
                    m_FileRegistry = JsonUtility.FromJson <LocalizationFileRegistry>(dataAsJson);
                    Debug.Log("Registry File exists and is readable");

                    LocalizationFileRegistry tempRegist = new LocalizationFileRegistry(new List <LocalizationFileEntry>());
                    for (int i = 0; i < m_FileRegistry.fileEntries.Count; i++)
                    {
                        string filePath = Path.Combine(Application.streamingAssetsPath, m_FileRegistry.fileEntries[i].fileName + ".json");
                        if (File.Exists(filePath))
                        {
                            try
                            {
                                string           langDataAsJson = File.ReadAllText(filePath);
                                LocalizationData loadedData     = JsonUtility.FromJson <LocalizationData>(langDataAsJson);

                                localizedTextList.Add(new Dictionary <string, string>());

                                if (loadedData.font != null)
                                {
                                    fontList.Add(loadedData.font);
                                }
                                else
                                {
                                    fontList.Add(instance.defaultFont);
                                }


                                for (int j = 0; j < loadedData.items.Length; j++)
                                {
                                    localizedTextList[localizedTextList.Count - 1].Add(loadedData.items[j].key, loadedData.items[j].value);
                                }
                                //Check to make sure that all other entries after the initial English file have the correct Count as well as the exact same keys.
                                if (i > 0)
                                {
                                    if (!FilesAreEqual(localizedTextList[0], localizedTextList[localizedTextList.Count - 1]))
                                    {
                                        Debug.Log("Error: Localization File " + filePath + " can not be used due to inconsistencies with the base Localization File.");
                                    }
                                    else
                                    {
                                        tempRegist.fileEntries.Add(m_FileRegistry.fileEntries[i]);
                                    }
                                }
                                else if (i == 0)
                                {
                                    tempRegist.fileEntries.Add(m_FileRegistry.fileEntries[i]);
                                }

                                Debug.Log(filePath + " successfully loaded for localization. -- " + localizedTextList[localizedTextList.Count - 1].Count + " entries.");
                            }
                            catch
                            {
                                Debug.Log("Error: Localization File " + filePath + " found, but can not be read.");
                                m_Status = LocalizationStatus.fail;
                            }
                        }
                        else
                        {
                            Debug.Log("Error: Localization File " + filePath + " Not found");
                        }
                    }
                    if (localizedTextListCount == 0)
                    {
                        Debug.Log("Error: No localization text files could be found. Localization has failed");
                        m_Status = LocalizationStatus.fail;
                        return;
                    }
                    //modify the registy with the correct list of valid localization options.
                    m_FileRegistry = tempRegist;

                    m_Status = LocalizationStatus.success;
                }
                catch
                {
                    Debug.Log("Error: Registry File exists, but can not be read properly Localization has failed.");
                    m_Status = LocalizationStatus.fail;
                }
            }
            else
            {
                Debug.Log("Error: No Registry File exists. Localization has failed");
                m_Status = LocalizationStatus.fail;
            }
        }
Ejemplo n.º 9
0
    public void camLocalize(string jsonanswer)
    {
        var   jsonParse = JSON.Parse(jsonanswer);
        float px, py, pz, ox, oy, oz, ow;
        int   objectsAmount = -1; string js;

        if (jsonParse["camera"] != null)
        {
            do
            {
                objectsAmount++;
                js = jsonParse["placeholders"][objectsAmount]["placeholder_id"];
                Debug.Log("js node [" + objectsAmount + "]  - " + js);
            } while (js != null);

            Debug.Log("Objects amount =   " + objectsAmount);
            px = jsonParse["camera"]["pose"]["position"]["x"].AsFloat;
            py = jsonParse["camera"]["pose"]["position"]["y"].AsFloat;
            pz = jsonParse["camera"]["pose"]["position"]["z"].AsFloat;
            ox = jsonParse["camera"]["pose"]["orientation"]["x"].AsFloat;
            oy = jsonParse["camera"]["pose"]["orientation"]["y"].AsFloat;
            oz = jsonParse["camera"]["pose"]["orientation"]["z"].AsFloat;
            ow = jsonParse["camera"]["pose"]["orientation"]["w"].AsFloat;
            GameObject newCam = new GameObject("tempCam");
            newCam.transform.localPosition = new Vector3(px, py, pz);
            newCam.transform.localRotation = new Quaternion(ox, oy, oz, ow);
            newCam.transform.localPosition = new Vector3(px, -newCam.transform.localPosition.y, pz);
            Debug.Log("Camera new: " + newCam.transform.localPosition.x + ", " + newCam.transform.localPosition.y + ", " + newCam.transform.localPosition.z);
            newCam.transform.localRotation = Quaternion.Euler(-newCam.transform.localRotation.eulerAngles.x, newCam.transform.localRotation.eulerAngles.y, -newCam.transform.localRotation.eulerAngles.z);


            GameObject[,] placeHolders = new GameObject[objectsAmount, 4];
            StickerInfo[] stickers = new StickerInfo[objectsAmount];

            for (int j = 0; j < objectsAmount; j++)
            {
                stickers[j] = new StickerInfo();
                float positionObjX = jsonParse["placeholders"][j]["pose"]["position"]["x"].AsFloat;
                float positionObjY = jsonParse["placeholders"][j]["pose"]["position"]["y"].AsFloat;
                float positionObjZ = jsonParse["placeholders"][j]["pose"]["position"]["z"].AsFloat;

                for (int i = 0; i < 4; i++)
                {
                    px = jsonParse["placeholders"][j]["frame"][i]["x"].AsFloat + positionObjX;
                    py = jsonParse["placeholders"][j]["frame"][i]["y"].AsFloat + positionObjY;
                    pz = jsonParse["placeholders"][j]["frame"][i]["z"].AsFloat + positionObjZ;
                    placeHolders[j, i] = new GameObject("Placeholder" + j + " " + i);
                    placeHolders[j, i].transform.SetParent(newCam.transform);
                    py = -py;
                    placeHolders[j, i].transform.position = new Vector3(px, py, pz);
                }
                string idnode = "" + jsonParse["placeholders"][j]["placeholder_id"];
                for (int x = 0; x < objectsAmount; x++)
                {
                    string idobj = "" + jsonParse["objects"][x]["sticker"]["sticker_id"];
                    if (idobj.Contains(idnode))
                    {
                        stickers[j].sPath = "" + jsonParse["objects"][x]["sticker"]["path"];
                        stickers[j].sText = "" + jsonParse["objects"][x]["sticker"]["sticker_text"];
                    }
                }
            }
            newCam.transform.position    = cameraPositionInLocalization;
            newCam.transform.eulerAngles = cameraRotationInLocalization;

            for (int j = 0; j < objectsAmount; j++)
            {
                stickers[j].positions = new Vector3[4];

                for (int i = 0; i < 4; i++)
                {
                    stickers[j].positions[i] = placeHolders[j, i].transform.position;
                }
            }
            localizationStatus = LocalizationStatus.Ready;
            Destroy(newCam);
            getStickersAction(stickers);
        }
        else
        {
            Debug.Log("Cant localize");
            localizationStatus = LocalizationStatus.CantLocalize;
            getStickersAction(null);
        }
    }