public Entry ParseEntry(JSONNode entry)
    {
        // Create entry
        Entry entryObject = new Entry();

        entryObject.setId(entry["id"]);

        // Create target
        Target targetObject;
        var    target     = entry["target"];
        string targetType = target["type"];

        switch (targetType)
        {
        case "IMAGE_TARGET":
            ImageTarget imageTargetObject = new ImageTarget();
            imageTargetObject.setFilename(target["filename"]);
            imageTargetObject.setStorageID(target["storageID"]);
            imageTargetObject.setId(target["id"]);
            imageTargetObject.setType(Target.targetType.IMAGE_TARGET);
            targetObject = imageTargetObject;
            break;

        case "GEOLOCATION_TARGET":
            GeolocationTarget geolocationTargetObject = new GeolocationTarget();
            geolocationTargetObject.setCity(target["city"]);
            geolocationTargetObject.setContinent(target["continent"]);
            geolocationTargetObject.setCountry(target["country"]);
            geolocationTargetObject.setId(target["id"]);
            geolocationTargetObject.setLatitude(target["latitude"]);
            geolocationTargetObject.setLongitude(target["longitude"]);
            geolocationTargetObject.setPlace(target["place"]);
            geolocationTargetObject.setType(Target.targetType.GEOLOCATION_TARGET);
            targetObject = geolocationTargetObject;
            break;

        case "BRICK_TARGET":
            BrickTarget brickTargetObject = new BrickTarget();
            brickTargetObject.setId(target["id"]);
            brickTargetObject.setType(Target.targetType.BRICK_TARGET);
            targetObject = brickTargetObject;
            break;

        default:
            targetObject = new Target();
            break;
        }
        List <string> hologramsListObject = new List <string>();
        int           j          = 0;
        var           hologramID = target["holograms"][j];

        while (hologramID != null)
        {
            hologramsListObject.Add(hologramID);
            hologramID = target["holograms"][++j];
        }
        targetObject.setHolograms(hologramsListObject);
        entryObject.setTarget(targetObject);

        // Create Hologram
        Hologram hologramObject;
        var      hologram     = entry["hologram"];
        string   hologramType = hologram["type"];

        switch (hologramType)
        {
        case "IMAGE_HOLOGRAM":
            ImageHologram imageHologramObject = new ImageHologram();
            imageHologramObject.setFilename(hologram["filename"]);
            imageHologramObject.setId(hologram["id"]);
            imageHologramObject.setStorageID(hologram["storageID"]);
            imageHologramObject.setTargetID(hologram["targetID"]);
            imageHologramObject.setType(Hologram.hologramType.IMAGE_HOLOGRAM);
            imageHologramObject.setTarget(targetObject);
            hologramObject = imageHologramObject;
            break;

        case "VIDEO_HOLOGRAM":
            VideoHologram videoHologramObject = new VideoHologram();
            videoHologramObject.setFilename(hologram["filename"]);
            videoHologramObject.setId(hologram["id"]);
            videoHologramObject.setStorageID(hologram["storageID"]);
            videoHologramObject.setTargetID(hologram["targetID"]);
            videoHologramObject.setType(Hologram.hologramType.VIDEO_HOLOGRAM);
            videoHologramObject.setTarget(targetObject);
            hologramObject = videoHologramObject;
            break;

        case "ECHO_HOLOGRAM":
            EchoHologram echoHologramObject = new EchoHologram();
            echoHologramObject.setFilename(hologram["filename"]);
            echoHologramObject.setId(hologram["id"]);
            echoHologramObject.setEncodedEcho(hologram["encodedEcho"]);
            echoHologramObject.setTextureFilename(hologram["textureFilename"]);
            echoHologramObject.setTargetID(hologram["targetID"]);
            echoHologramObject.setType(Hologram.hologramType.ECHO_HOLOGRAM);
            echoHologramObject.setTarget(targetObject);
            List <string> videosListObject = new List <string>();

            j = 0;
            var videoID = hologram["vidoes"][j];
            while (videoID != null)
            {
                videosListObject.Add(videoID);
                hologramID = hologram["vidoes"][++j];
            }
            echoHologramObject.setVidoes(videosListObject);

            hologramObject = echoHologramObject;
            break;

        case "MODEL_HOLOGRAM":
            ModelHologram modelHologramObject = new ModelHologram();
            modelHologramObject.setEncodedFile(hologram["encodedFile"]);
            modelHologramObject.setFilename(hologram["filename"]);
            modelHologramObject.setId(hologram["id"]);
            modelHologramObject.setMaterialFilename(hologram["materialFilename"]);
            modelHologramObject.setMaterialStorageID(hologram["materialStorageID"]);
            modelHologramObject.setStorageID(hologram["storageID"]);
            modelHologramObject.setTargetID(hologram["targetID"]);
            var textureFilenames  = hologram["textureFilenames"].AsArray;
            var textureStorageIDs = hologram["textureStorageIDs"].AsArray;
            for (j = 0; j < textureFilenames.Count; j++)
            {
                modelHologramObject.addTexture(textureFilenames[j], textureStorageIDs[j]);
            }
            modelHologramObject.setType(Hologram.hologramType.MODEL_HOLOGRAM);
            modelHologramObject.setTarget(targetObject);
            // If applicable, update model hologram with .glb version
            if (entry["additionalData"]["glbHologramStorageID"] != null)
            {
                modelHologramObject.setFilename(entry["additionalData"]["glbHologramStorageFilename"]);
                modelHologramObject.setStorageID(entry["additionalData"]["glbHologramStorageID"]);
            }
            hologramObject = modelHologramObject;
            break;

        default:
            hologramObject = new Hologram();
            break;
        }
        entryObject.setHologram(hologramObject);

        // Create SDKs array
        bool[] sdksObject = new bool[9];
        var    sdks       = entry["sdks"].AsArray;

        for (j = 0; j < 9; j++)
        {
            sdksObject[j] = sdks[j];
        }
        entryObject.setSupportedSDKs(sdksObject);

        // Create Additional Data
        var additionalData = entry["additionalData"];

        foreach (var data in additionalData)
        {
            entryObject.addAdditionalData(data.Key, data.Value);
        }

        // Add entry to database
        dbObject.addEntry(entryObject);

        // Return
        return(entryObject);
    }
    public void DownloadEntryAssets(Entry entry, string serverURL)
    {
        // Check if Unity is supported
        //if (entry.getSupportedSDKs()[Entry.SDKs.UNITY.ordinal()])
        if (true)
        {
            // Get hologram type
            Hologram.hologramType hologramType = entry.getHologram().getType();
            // Handle model hologram
            if (hologramType.Equals(Hologram.hologramType.MODEL_HOLOGRAM))
            {
                // Get model names and ID
                ModelHologram modelHologram = (ModelHologram)entry.getHologram();

                List <string> filenames = new List <string>();
                filenames.Add(modelHologram.getFilename());
                if (modelHologram.getMaterialFilename() != null)
                {
                    filenames.Add(modelHologram.getMaterialFilename());
                }
                if (modelHologram.getTextureFilenames() != null)
                {
                    filenames.AddRange(modelHologram.getTextureFilenames());
                }

                List <string> fileStorageIDs = new List <string>();
                fileStorageIDs.Add(modelHologram.getStorageID());
                if (modelHologram.getMaterialStorageID() != null)
                {
                    fileStorageIDs.Add(modelHologram.getMaterialStorageID());
                }
                if (modelHologram.getTextureStorageIDs() != null)
                {
                    fileStorageIDs.AddRange(modelHologram.getTextureStorageIDs());
                }

                // Import Options
                ImportOptions importOptions = ParseAdditionalData(entry.getAdditionalData());

                // Instantiate model based on type
                if (modelHologram.getFilename().EndsWith(".glb"))
                {
                    // Instantiate model without downloading it
                    StartCoroutine(InstantiateModel(entry, filenames, importOptions));
                }
                else
                {
                    // Download model files and then instantiate
                    StartCoroutine(DownloadFiles(entry, serverURL, filenames, fileStorageIDs, importOptions));
                }
                // Handle video hologram
            }
            else if (hologramType.Equals(Hologram.hologramType.VIDEO_HOLOGRAM))
            {
                // Get video
                VideoHologram videoHologram = (VideoHologram)entry.getHologram();

                // Create primitive plane for the video to appear on
                GameObject videoPlane = GameObject.CreatePrimitive(PrimitiveType.Plane);

                // Set video plane position
                videoPlane.transform.parent   = this.gameObject.transform;
                videoPlane.transform.position = this.gameObject.transform.position;

                // Set video plane size
                string value  = "";
                float  height = (entry.getAdditionalData() != null && entry.getAdditionalData().TryGetValue("height", out value)) ? float.Parse(value) * 0.01f : 1;
                float  width  = (entry.getAdditionalData() != null && entry.getAdditionalData().TryGetValue("width", out value)) ? float.Parse(value) * 0.01f : 2;

                // Scale video plane
                videoPlane.transform.localScale = new Vector3(width, height, height);

                // Attach VideoPlayer to video plane
                var videoPlayer = videoPlane.AddComponent <VideoPlayer>();
                videoPlayer.playOnAwake = false;

                // Attach a CustomBehaviour Component
                videoPlane.AddComponent <CustomBehaviour>().entry = entry;

                // Set gameobject name to video name
                videoPlane.name = videoHologram.getFilename();

                // Set video URL
                videoPlayer.url = serverURL + "&file=" + videoHologram.getStorageID();

                // Play video
                videoPlayer.Play();

                // Mute
                if (entry.getAdditionalData() != null && entry.getAdditionalData().TryGetValue("mute", out value) && value.Equals("true"))
                {
                    for (ushort i = 0; i < videoPlayer.controlledAudioTrackCount; ++i)
                    {
                        videoPlayer.SetDirectAudioMute(i, true);
                    }
                }
                // Handle image hologram
            }
            else if (hologramType.Equals(Hologram.hologramType.IMAGE_HOLOGRAM))
            {
                // Get image
                ImageHologram imageHologram = (ImageHologram)entry.getHologram();

                // Create primitive plane for the image to appear on
                GameObject imagePlane = GameObject.CreatePrimitive(PrimitiveType.Plane);

                // Set image plane position
                imagePlane.transform.parent   = this.gameObject.transform;
                imagePlane.transform.position = this.gameObject.transform.position;

                // Set image plane size
                string value  = "";
                float  height = (entry.getAdditionalData() != null && entry.getAdditionalData().TryGetValue("height", out value)) ? float.Parse(value) * 0.01f : 1;
                float  width  = (entry.getAdditionalData() != null && entry.getAdditionalData().TryGetValue("width", out value)) ? float.Parse(value) * 0.01f : 1;

                // Scale image plane
                imagePlane.transform.localScale = new Vector3(width, height, height);

                // Set gameobject name to image name
                imagePlane.name = imageHologram.getFilename();

                // Set image URL
                string imageURL = (entry.getAdditionalData() != null && entry.getAdditionalData().TryGetValue("compressedImageStorageID", out value)) ?
                                  serverURL + "&file=" + value :
                                  serverURL + "&file=" + imageHologram.getStorageID();

                // Download image file and then instantiate
                StartCoroutine(DownloadandInitiateImage(entry, imageURL, imagePlane));
            }
        }
    }
Beispiel #3
0
    public void DownloadEntryAssets(Entry entry, string serverURL)
    {
        Debug.Log("Download started");
        try
        {
            Debug.Log("tried");
            // StartCoroutine(FindLocation());
        }
        catch (System.Exception e)
        {
            Debug.Log("failed");
        }
        FoundXPos = (float)LocationScript.XPosition;
        FoundYPos = (float)LocationScript.YPosition;
        Debug.Log(levelReached);
        echolocation.text = FoundXPos + ",  " + FoundYPos;

        // Check if Unity is supported
        //if (entry.getSupportedSDKs()[Entry.SDKs.UNITY.ordinal()])
        Debug.Log("Download entry assets " + Latitude);
        //geolocationTargetObject.getLongitude();
        Target.targetType targetType = entry.getTarget().getType();
        if (targetType.Equals(Target.targetType.GEOLOCATION_TARGET))
        {
            GeolocationTarget geolocationTarget = (GeolocationTarget)entry.getTarget();
            Debug.Log("float" + geolocationTarget.getLatitude());
            // Switch find location to a fixed update to every second or so
            if (Mathf.Sqrt((geolocationTarget.getLatitude() - FoundXPos) * (geolocationTarget.getLatitude() - FoundXPos) + (geolocationTarget.getLongitude() - FoundYPos) * (geolocationTarget.getLongitude() - FoundYPos)) < .001)
            {
                /*  if ((42.335 < geolocationTarget.getLatitude() && geolocationTarget.getLatitude() < 42.337) &&
                 * (-71.089 > geolocationTarget.getLongitude() && geolocationTarget.getLongitude() > -71.091))
                 * {*/
                Debug.Log("passed if loop");
                echolocation.text = levelReached + ",  " + FoundXPos.ToString();
                location.text     = Input.location.lastData.timestamp.ToString();



                if (true)
                {
                    // Get hologram type
                    Hologram.hologramType hologramType = entry.getHologram().getType();
                    // Handle model hologram
                    if (hologramType.Equals(Hologram.hologramType.MODEL_HOLOGRAM))
                    {
                        // Get model names and ID
                        ModelHologram modelHologram = (ModelHologram)entry.getHologram();

                        List <string> filenames = new List <string>();
                        filenames.Add(modelHologram.getFilename());
                        if (modelHologram.getMaterialFilename() != null)
                        {
                            filenames.Add(modelHologram.getMaterialFilename());
                        }
                        if (modelHologram.getTextureFilenames() != null)
                        {
                            filenames.AddRange(modelHologram.getTextureFilenames());
                        }

                        List <string> fileStorageIDs = new List <string>();
                        fileStorageIDs.Add(modelHologram.getStorageID());
                        if (modelHologram.getMaterialStorageID() != null)
                        {
                            fileStorageIDs.Add(modelHologram.getMaterialStorageID());
                        }
                        if (modelHologram.getTextureStorageIDs() != null)
                        {
                            fileStorageIDs.AddRange(modelHologram.getTextureStorageIDs());
                        }

                        // Import Options
                        ImportOptions importOptions = ParseAdditionalData(entry.getAdditionalData());


                        // Instantiate model based on type
                        if (modelHologram.getFilename().EndsWith(".glb"))
                        {
                            // Instantiate model without downloading it
                            // LocationScript.FindLocation();
                            //if ((42.3388 < Input.location.lastData.latitude && Input.location.lastData.latitude < 42.3590) &&
                            //  (-71.0870 > Input.location.lastData.longitude && Input.location.lastData.longitude > -71.0875))
                            StartCoroutine(InstantiateModel(entry, filenames, importOptions));
                        }
                        else
                        {
                            // Download model files and then instantiate
                            StartCoroutine(DownloadFiles(entry, serverURL, filenames, fileStorageIDs, importOptions));
                        }
                        // Handle video hologram
                    }
                    else if (hologramType.Equals(Hologram.hologramType.VIDEO_HOLOGRAM))
                    {
                        // Get video
                        VideoHologram videoHologram = (VideoHologram)entry.getHologram();

                        // Create primitive plane for the video to appear on
                        GameObject videoPlane = GameObject.CreatePrimitive(PrimitiveType.Plane);

                        // Set video plane position
                        videoPlane.transform.parent   = this.gameObject.transform;
                        videoPlane.transform.position = this.gameObject.transform.position;

                        // Set video plane size
                        string value  = "";
                        float  height = (entry.getAdditionalData() != null && entry.getAdditionalData().TryGetValue("height", out value)) ? float.Parse(value) * 0.01f : 1;
                        float  width  = (entry.getAdditionalData() != null && entry.getAdditionalData().TryGetValue("width", out value)) ? float.Parse(value) * 0.01f : 2;

                        // Scale video plane
                        videoPlane.transform.localScale = new Vector3(width, height, height);

                        // Attach VideoPlayer to video plane
                        var videoPlayer = videoPlane.AddComponent <VideoPlayer>();
                        videoPlayer.playOnAwake = false;

                        // Attach a CustomBehaviour Component
                        videoPlane.AddComponent <CustomBehaviour>().entry = entry;

                        // Set gameobject name to video name
                        videoPlane.name = videoHologram.getFilename();

                        // Set video URL
                        videoPlayer.url = serverURL + "&file=" + videoHologram.getStorageID();

                        // Play video
                        videoPlayer.Play();

                        // Mute
                        if (entry.getAdditionalData() != null && entry.getAdditionalData().TryGetValue("mute", out value) && value.Equals("true"))
                        {
                            for (ushort i = 0; i < videoPlayer.controlledAudioTrackCount; ++i)
                            {
                                videoPlayer.SetDirectAudioMute(i, true);
                            }
                        }
                        // Handle image hologram
                    }
                    else if (hologramType.Equals(Hologram.hologramType.IMAGE_HOLOGRAM))
                    {
                        // Get image
                        ImageHologram imageHologram = (ImageHologram)entry.getHologram();

                        // Create primitive plane for the image to appear on
                        GameObject imagePlane = GameObject.CreatePrimitive(PrimitiveType.Plane);

                        // Set image plane position
                        imagePlane.transform.parent   = this.gameObject.transform;
                        imagePlane.transform.position = this.gameObject.transform.position;

                        // Set image plane size
                        string value  = "";
                        float  height = (entry.getAdditionalData() != null && entry.getAdditionalData().TryGetValue("height", out value)) ? float.Parse(value) * 0.01f : 1;
                        float  width  = (entry.getAdditionalData() != null && entry.getAdditionalData().TryGetValue("width", out value)) ? float.Parse(value) * 0.01f : 1;

                        // Scale image plane
                        imagePlane.transform.localScale = new Vector3(width, height, height);

                        // Set gameobject name to image name
                        imagePlane.name = imageHologram.getFilename();

                        // Set image URL
                        string imageURL = (entry.getAdditionalData() != null && entry.getAdditionalData().TryGetValue("compressedImageStorageID", out value)) ?
                                          serverURL + "&file=" + value :
                                          serverURL + "&file=" + imageHologram.getStorageID();

                        // Download image file and then instantiate
                        StartCoroutine(DownloadandInitiateImage(entry, imageURL, imagePlane));
                    }
                }
            }
        }
    }