Esempio n. 1
0
    void handleListAssetsCallback(PolyStatusOr <PolyListAssetsResult> result)
    {
        if (!result.Ok)
        {
            Debug.Log("Error occured while getting asset list");
        }
        Debug.Log("Displaying thumbnails of assets retrieved");

        for (int i = 0; i < 1; i++)
        {
            PolyAsset res = result.Value.assets[0];
            PolyApi.FetchThumbnail(res, CallFetchThumbnailEvent);
        }

        //foreach (PolyAsset asset in result.Value.assets) {
        //	Debug.Log (asset.thumbnail); //png
        //          Debug.Log(asset.thumbnailTexture);
        //          // t = asset.thumbnailTexture;
        //          // thumbnail.GetComponent<RawImage>().texture = t;
        //          Debug.Log(asset.description);
        //          Debug.Log(asset.authorName);
        //          Debug.Log(asset.displayName);
        //          Debug.Log(asset.formats);
        //          Debug.Log(asset.name); // asset ID
        //          Debug.Log(asset.license);
        //          Debug.Log(asset.visibility);

        //          PolyApi.FetchThumbnail(asset, CallFetchThumbnailEvent);
        //      }
    }
Esempio n. 2
0
        private void CmdThumb(string[] args)
        {
            int index;

            if (args.Length == 0 || !int.TryParse(args[0], out index) || index < 0 || index >= currentResults.Count)
            {
                PrintLn("*** Invalid index. Please specify the index of the asset whose thumbnail " +
                        "you wish to load (use the 'show' command to show the results).");
                return;
            }
            PolyAsset assetToUse = currentResults[index];

            PrintLn("Fetching thumbnail... Please wait.");
            PolyApi.FetchThumbnail(assetToUse, (PolyAsset asset, PolyStatus status) => {
                if (status.ok)
                {
                    PrintLn("Successfully fetched thumbnail for asset '{0}'", asset.name);
                    imageDisplay.sprite = Sprite.Create(asset.thumbnailTexture,
                                                        new Rect(0, 0, asset.thumbnailTexture.width, asset.thumbnailTexture.height),
                                                        Vector2.zero);
                    imageDisplay.gameObject.SetActive(true);
                }
                else
                {
                    PrintLn("*** Error loading thumbnail for asset '{0}': {1}", asset.name, status);
                }
            });
        }
Esempio n. 3
0
    void FeaturedAssetListCallback(PolyStatusOr <PolyListAssetsResult> result)
    {
        if (!result.Ok)
        {
            // Handle error.
            Debug.LogError("Failed to import featured list. :( Reason: " + result.Status);
            return;
        }
        // Success. result.Value is a PolyListAssetsResult and
        // result.Value.assets is a list of PolyAssets.
        foreach (PolyAsset asset in result.Value.assets)
        {
            if (asset_id_name_list.Count < resultCount)
            {
                // Do something with the asset here.
                //Debug.Log(asset);
                Debug.Log(asset.displayName);
                // add name and ID KeyValuePair to List
                asset_id_name_list.Add(new KeyValuePair <string, string>(asset.name, asset.displayName));
                // request thumbnail of each asset
                PolyApi.FetchThumbnail(asset, GetThumbnailCallback);
            }
        }

        asset_id_name_list.Sort((x, y) => string.Compare(x.Key, y.Key, StringComparison.Ordinal));
        //      uI.InstatiatePolyAssetMenu(asset_id_name_list);
        //uI.SetPolyMenuInfo(assetNames, assetID);
        //uI.enabled = true;
        if (onPolyAssetsLoaded != null)
        {
            onPolyAssetsLoaded.Invoke();
        }
    }
Esempio n. 4
0
        private void FetchThumbnail(PolyAsset asset)
        {
            PolyFetchThumbnailOptions options = new PolyFetchThumbnailOptions();

            options.SetRequestedImageSize(THUMBNAIL_REQUESTED_SIZE);
            PolyApi.FetchThumbnail(asset, options, OnThumbnailFetched);
        }
    void FeaturedAssetListCallback(PolyStatusOr <PolyListAssetsResult> result)
    {
        if (!result.Ok)
        {
            // Handle error.
            Debug.LogError("Failed to import featured list. :( Reason: " + result.Status);
            return;
        }
        // Success. result.Value is a PolyListAssetsResult and
        // result.Value.assets is a list of PolyAssets.
        // asset_id_name_list
        asset_id_name_list.AddRange(
            result.Value.assets.Take(resultCount).Select((asset) =>
        {
            Debug.Log(asset.displayName);
            PolyApi.FetchThumbnail(asset, GetThumbnailCallback);
            return(new KeyValuePair <string, string>(asset.name, asset.displayName));
        }).AsParallel()
            );

        asset_id_name_list.Sort((x, y) => string.Compare(x.Key, y.Key, StringComparison.Ordinal));

        if (onPolyAssetsLoaded != null)
        {
            onPolyAssetsLoaded.Invoke();
        }
    }
Esempio n. 6
0
 void InitialiseUIContent(PolyStatusOr <PolyListAssetsResult> result)
 {
     foreach (PolyAsset asset in result.Value.assets)
     {
         PolyApi.FetchThumbnail(asset, callback);
     }
 }
 protected void FetchThumbnail(PolyAsset assetToFetch, Action <bool> callback)
 {
     PolyApi.FetchThumbnail(assetToFetch, (PolyAsset fetchedAsset, PolyStatus status) =>
     {
         callback(status.ok);
     });
 }
Esempio n. 8
0
    private void CallListAssetsCallbackEvent(PolyStatusOr<PolyListAssetsResult> result)
    {
        foreach (PolyAsset asset in result.Value.assets)
        {
            PolyApi.FetchThumbnail(asset, callback);

        }
    }
Esempio n. 9
0
 void PolyAssetCallback(PolyStatusOr <PolyAsset> result, OnActorableSearchResult resultCallback)
 {
     if (!result.Ok)
     {
         Debug.LogError("There is a problem with poly poly stuff" + result.Status.errorMessage);
         return;
     }
     PolyApi.FetchThumbnail(result.Value, (newasset, status) => PolyThumbnailCallback(newasset, status, resultCallback));
 }
    public void SetPolyModel(PolyAsset polyAsset)
    {
        // Set the text and gather the information that is to be displayed
        this.polyAsset = polyAsset;
        modelName.SetText(polyAsset.displayName);
        modelAuthor.SetText(polyAsset.authorName);
        PolyApi.FetchThumbnail(polyAsset, SetThumbnail);

        SetFilled();
    }
Esempio n. 11
0
    private void CallListAssetsCallbackEvent(PolyStatusOr <PolyListAssetsResult> result)
    {
        foreach (PolyAsset asset in result.Value.assets)
        {
            PolyApi.FetchThumbnail(asset, callback);
        }

        currentpanel.SetActive(false);
        panel.SetActive(true);
        // SceneManager.LoadScene("2");
    }
Esempio n. 12
0
    public void Initialize(PolyAsset pa)
    {
        // Display all information about the model
        polyModel = pa;
        modelName.SetText(pa.displayName);
        author.SetText(pa.authorName);
        complexity.SetText("Tris: " + pa.formats[0].formatComplexity.triangleCount.ToString());
        dateAdded.SetText("Created at: " + pa.createTime.ToShortDateString());
        lastEdit.SetText("Last edited: " + pa.updateTime.ToShortDateString());

        PolyApi.FetchThumbnail(pa, SetThumbnail);
    }
    void handleListAssetsCallback(PolyStatusOr <PolyListAssetsResult> result)
    {
        if (!result.Ok)
        {
            Debug.Log("Error occured while getting asset list");
        }
        Debug.Log("Displaying thumbnails of assets retrieved");

        //for (int i = 0; i < 1; i++)
        foreach (PolyAsset asset in result.Value.assets)
        {
            //PolyAsset res = result.Value.assets[1];
            PolyApi.FetchThumbnail(asset, CallFetchThumbnailEvent);
        }
    }
 void LoadAssetsCallback(PolyStatusOr <PolyListAssetsResult> result)
 {
     thumbnailCount = 0;
     if (!result.Ok)
     {
         Debug.LogError("Failed to get assets. Reason: " + result.Status);
         statusText.text = "ERROR: " + result.Status;
         return;
     }
     foreach (var item in result.Value.assets)
     {
         PolyApi.FetchThumbnail(item, FetchThumbnailCallback);
     }
     pageination = result.Value.nextPageToken;
 }
Esempio n. 15
0
    void PolySearchCallback(PolyStatusOr <PolyListAssetsResult> result, OnActorableSearchResult resultCallback, System.Action <bool> onComplete)
    {
        if (!result.Ok)
        {
            Debug.Log(result.Status);
            return;
        }

        onComplete?.Invoke(result.Value.assets.Count != 0);

        foreach (PolyAsset asset in result.Value.assets)
        {
            PolyApi.FetchThumbnail(asset, (newasset, status) => PolyThumbnailCallback(newasset, status, resultCallback));
        }
    }
Esempio n. 16
0
    //Looping over the assets that matches your search
    public void createAssest(PolyStatusOr <PolyListAssetsResult> result)
    {
        if (!result.Ok)
        {
            Debug.LogError("Failed to get featured assets. :( Reason: " + result.Status);
            return;
        }
        numberOfAssetsFoundFromPoly = result.Value.assets.ToArray().Length.ToString();
        creatingAssestsMessageFlag  = true;

        foreach (PolyAsset asset in result.Value.assets)
        {
            PolyApi.FetchThumbnail(asset, createAssetsThumbnail);
        }
    }
Esempio n. 17
0
 /// <summary>
 /// Called when Asset is listed
 /// </summary>
 /// <param name="result">result of the request to list poly toolkit asset</param>
 private void ListAssetCallback(PolyStatusOr <PolyListAssetsResult> result)
 {
     loadingPanel.SetActive(false);
     if (!result.Ok)
     {
         Toaster.showToast("Failed to load asset : " + result.Status, 2);
         return;
     }
     for (int i = 0; i < result.Value.assets.Count; i++)
     {
         // Fetch thumbnails for assets listed by the request
         PolyApi.FetchThumbnail(result.Value.assets[i], FetchThumbnailCallback);
     }
     assetsPanel.gameObject.SetActive(true);
 }
Esempio n. 18
0
 /// <summary>
 /// Fetches thumbnails that do not yet exist in the cache.
 /// </summary>
 private void FinishFetchingThumbnails(PolyStatusOr <PolyListAssetsResult> result)
 {
     if (result.Ok)
     {
         List <PolyAsset> assetsMissingThumbnails = new List <PolyAsset>();
         foreach (PolyAsset asset in listAssetsResult.Value.assets)
         {
             if (!thumbnailCache.TryGet(asset.name, out asset.thumbnailTexture))
             {
                 assetsMissingThumbnails.Add(asset);
             }
         }
         foreach (PolyAsset asset in assetsMissingThumbnails)
         {
             PolyApi.FetchThumbnail(asset, OnThumbnailFetched);
         }
     }
 }
Esempio n. 19
0
    private void HandleResults(PolyStatusOr <PolyListAssetsResult> result)
    {
        // Handle error.
        if (!result.Ok)
        {
            InterfaceManager.GetInstance().AddMessageToBox("Error fetching asset thumbnail from Poly API :(");
            return;
        }

        assetMenu.GetComponent <PolyMenu>().ClearMenu();
        fetchedAssets.Clear();
        resultSetSize = result.Value.assets.Count;

        foreach (PolyAsset asset in result.Value.assets)
        {
            fetchedAssets.Add(asset);
            PolyApi.FetchThumbnail(asset, AddToMenu);
        }
    }
Esempio n. 20
0
    // Callback invoked when the featured assets results are returned.
    private void ListAssetsCallback(PolyStatusOr <PolyListAssetsResult> result)
    {
        if (!result.Ok)
        {
            Debug.LogError("Failed to get featured assets. :( Reason: " + result.Status);
            statusText.text = "ERROR: " + result.Status;
            return;
        }

        Debug.Log("Successfully got featured assets!");
        statusText.text = "Importing thumbnails...";

        // Now let's get the first 4 featured assets and show their thumbnails
        for (int i = 0; i < Mathf.Min(4, result.Value.assets.Count); i++)
        {
            // fetch this asset's thumbnail
            PolyApi.FetchThumbnail(result.Value.assets[i], FetchThumbnailCallback);
            assetsInPalette.Add(result.Value.assets[i]);
        }
    }
Esempio n. 21
0
        /// <summary>
        /// Callback invoked when we receive the result of a request for a specific asset.
        /// </summary>
        private void OnRequestForSpecificAssetResult(PolyStatusOr <PolyAsset> result)
        {
            if (result.Ok)
            {
                PtDebug.Log("ABM: get asset request received result.");
                assetResult = result.Value;

                if (!thumbnailCache.TryGet(assetResult.name, out assetResult.thumbnailTexture))
                {
                    PolyApi.FetchThumbnail(assetResult, OnThumbnailFetched);
                }
            }
            else
            {
                Debug.LogError("Error: " + result.Status.errorMessage);
            }
            querying = false;
            if (null != refreshCallback)
            {
                refreshCallback();
            }
        }
    void MyCallback(PolyStatusOr <PolyListAssetsResult> result)
    {
        if (!result.Ok)
        {
            // Handle error.
            Debug.Log("Resault not found shiiiiiiiiiiiiiiiit");
            return;
        }
        // Success. result.Value is a PolyListAssetsResult and
        // result.Value.assets is a list of PolyAssets.
        foreach (PolyAsset asset in result.Value.assets)
        {
            Debug.Log("Count >>>>>>  " + result.Value.assets.Count);

            // Do something with the asset here.
            Debug.Log("Asset DisplayName ya Ahmed " + asset.displayName);
            Debug.Log("Asset URL ya Ahmed " + asset.Url);
            Debug.Log("Asset Name ya Ahmed " + asset.name);

            // Fetch Thumbnail
            PolyApi.FetchThumbnail(asset, MyCallback_FetchThumbnail);

            //// get the asset
            //// Request the asset.

            //var buttonObj = Instantiate(ButtonPrefab);
            //buttonObj.transform.SetParent(UiPanel, false);

            //buttonObj.GetComponentInChildren<Text>().text = asset.displayName;

            //Sprite s = Sprite.Create(img,
            //    new Rect(0.0f, 0.0f, img.width, img.height), new Vector2(0.5f, 0.5f), 100.0f);
            //buttonObj.GetComponentInChildren<Image>().sprite = s;

            //buttonObj.GetComponent<Button>().onClick.AddListener(
            //    () => buttonPressed(asset));
        }
    }
Esempio n. 23
0
    void FeaturedAssetCallback(PolyStatusOr <PolyAsset> result)
    {
        if (!result.Ok)
        {
            // Handle error.
            Debug.LogError("Failed to import featured list. :( Reason: " + result.Status);
            loadingCircle.SetActive(false);
            return;
        }
        // Success. result.Value is a PolyAssets
        PolyApi.FetchThumbnail(result.Value, GetThumbnailCallback);
        Debug.Log(result.Value.displayName);
        asset_id_name_list.Add(new KeyValuePair <string, string>(result.Value.name, result.Value.displayName));

        asset_id_name_list.Sort((x, y) => string.Compare(x.Key, y.Key, StringComparison.Ordinal));

        if (onPolyAssetsLoaded != null)
        {
            onPolyAssetsLoaded.Invoke();
        }

        loadingCircle.SetActive(false);
    }
Esempio n. 24
0
        public void Visit(PolyVoosAsset asset)
        {
            string assetName = asset.assetId;
            string uri       = asset.GetUri();

            PolyApi.GetAsset(assetName, maybeAsset =>
            {
                if (MaybeLogError(assetName, maybeAsset))
                {
                    cache.CreateCacheEntry(uri, GameObject.CreatePrimitive(PrimitiveType.Cube), null);
                    return;
                }

                PolyAsset polyAsset = maybeAsset.Value;

                // We need both the asset and the thumbnail to consider it "downloaded".
                // We'll download them in parallel, and whichever one finishes second
                // will call SetCacheEntry.
                GameObject assetObject = null;
                Texture2D thumbnail    = null;

                PolyApi.FetchThumbnail(polyAsset, (_, maybeImported) =>
                {
                    if (MaybeLogError(assetName, maybeImported))
                    {
                        return;
                    }
                    thumbnail = polyAsset.thumbnailTexture;

                    // If we finished first, don't SetCacheEntry yet.
                    if (assetObject != null)
                    {
                        // Ok, both resources are done. Report completion!
                        // Set the cache (and flush the wait list)
                        cache.CreateCacheEntry(uri, assetObject, thumbnail);
                    }
                });

                System.Action <GameObject> onAssetImported = importedGameObject =>
                {
                    cache.downloadedPolyAssets.Add(polyAsset);

                    assetObject      = importedGameObject;
                    assetObject.name = assetName;
                    PrepareImportedModel(assetObject, polyAsset.description);

                    // If we finished first, don't SetCacheEntry yet.
                    if (thumbnail != null)
                    {
                        // Ok, both resources are done. Report completion!
                        // Set the cache (and flush the wait list)
                        cache.CreateCacheEntry(uri, assetObject, thumbnail);
                    }
                };

                var objFormat = polyAsset.GetFormatIfExists(PolyFormatType.OBJ);
                var fbx       = polyAsset.GetFormatIfExists(PolyFormatType.FBX);

#if USE_TRILIB
                // Blocks models, like the pug, have both GLTFs and FBX's. But, TRILIB
                // doesn't seem to load Blocks FBX well, so don't do it. However, it's
                // not trivial to detect Blocks models. So our current heuristic is
                // going to simply be, only load the FBX if it has FBX but NOT OBJ. At
                // least as of 20190325, actual FBX uploads don't have OBJs. In the
                // future, we can even peek at the GLTF and see if it was generated by
                // Blocks.
                if (objFormat == null && fbx != null)
                {
                    string tempDir = Util.CreateTempDirectory();

                    Dictionary <string, string> url2path = new Dictionary <string, string>();
                    foreach (var file in fbx.resources)
                    {
                        string localPath   = System.IO.Path.Combine(tempDir, file.relativePath);
                        url2path[file.url] = localPath;
                    }

                    // The root
                    string rootPath        = System.IO.Path.Combine(tempDir, fbx.root.relativePath);
                    url2path[fbx.root.url] = rootPath;

                    Util.DownloadFilesToDisk(url2path,
                                             () =>
                    {
                        // All done!
                        using (var loader = new TriLib.AssetLoaderAsync())
                        {
                            TriLib.AssetLoaderOptions opts = GetTriLibOpts();
                            loader.LoadFromFileWithTextures(rootPath, opts, null,
                                                            obj =>
                            {
                                System.IO.Directory.Delete(tempDir, true);
                                onAssetImported(obj);
                            });
                        }
                    },
                                             errors =>
                    {
                        System.IO.Directory.Delete(tempDir, true);
                        Debug.LogError($"Could not download Poly FBX for asset ID {assetName}. Errors: {string.Join("\n", errors)}");
                        return;
                    });
                }
                else
#endif
                {
                    PolyApi.Import(polyAsset, cache.polyImportOptions, (_, maybeImported) =>
                    {
                        if (MaybeLogError(assetName, maybeImported))
                        {
                            return;
                        }
                        onAssetImported(maybeImported.Value.gameObject);
                    });
                }
            });
        }
Esempio n. 25
0
    private void GetAssetCallback(PolyStatusOr <PolyAsset> result)
    {
        if (!result.Ok)
        {
            Debug.LogError("Failed to get assets. Reason: " + result.Status);
            return;
        }
        Debug.Log("Successfully got asset!");

        // Set the import options.
        PolyImportOptions options = PolyImportOptions.Default();

        // We want to rescale the imported mesh to a specific size.
        options.rescalingMode = PolyImportOptions.RescalingMode.FIT;
        // The specific size we want assets rescaled to (fit in a 5x5x5 box):
        options.desiredSize = 0.5f;
        // We want the imported assets to be recentered such that their centroid coincides with the origin:
        options.recenter = true;

        Debug.Log("passa aqui?");

        PolyApi.FetchThumbnail(result.Value, GetThumbCallback);

        if (polyDescription)
        {
            Title.text = result.Value.displayName;
            Debug.Log("ate aqui dibas");
            Debug.Log(result.Value);
            if (result.Value.description != null && result.Value.description.Length > 0)
            {
                Debug.Log("deu ruim?");
                description.text = result.Value.description;
            }
            else
            {
                description.text = "Este objeto ainda não possui descrição disponível";
            }
        }
        else
        {
            Debug.Log("e aqui?");
            var obj = firebaseObjects.SingleOrDefault(firebaseObject => {
                Debug.Log(firebaseObject.id);
                Debug.Log(result.Value.name);
                var objId = firebaseObject.id;
                return($"assets/{objId}" == result.Value.name && searchTerm.text == firebaseObject.hashtags[0]);
            });
            Debug.Log("obj:");
            Debug.Log(obj);
            if (obj != null)
            {
                Debug.Log("aqui tbm??");
                Title.text           = obj.name;
                options.desiredSize *= obj.scale;
                description.text     = obj.description;
            }
        }

        //statusText.text = "Importing...";
        PolyApi.Import(result.Value, options, ImportAssetCallback);
    }