Exemple #1
0
 private void Start()
 {
     // Request the asset.
     Debug.Log("Requesting asset...");
     PolyApi.GetAsset("assets/" + assetKey, GetAssetCallback);
     statusText.text = "Requesting...";
 }
Exemple #2
0
 public static void LoadAsset(PolyAsset asset, Action <GameObject> onLoad)
 {
     PolyApi.GetAsset("assets/" + asset.AssetId, (result) =>
     {
         GetAssetCallback(result, onLoad);
     });
 }
    void OnAssetListReturned(PolyStatusOr <PolyListAssetsResult> result)
    {
        if (!result.Ok)
        {
            // Handle error.
            return;
        }

        PolyAsset bestResult = null;

        // Success. result.Value is a PolyListAssetsResult and
        // result.Value.assets is a list of PolyAssets.
        foreach (PolyAsset asset in result.Value.assets)
        {
            if (bestResult == null)
            {
                bestResult = asset;
            }
            // Do something with the asset here.
            if (!findBestMatchRequested || asset.displayName == lastRequestedAsset)
            {
                bestResult = asset;
            }
        }

        Debug.Log("Loading asset " + bestResult.displayName + " ...");
        PolyApi.GetAsset(bestResult.name, GetAssetCallback);
    }
 public void TestImport(string id)
 {
     PolyApi.GetAsset(id, result => {
         if (result.Ok)
         {
             PolyApi.Import(result.Value, PolyImportOptions.Default());
         }
     });
 }
Exemple #5
0
 private void Start()
 {
     penobject.SetActive(false);
     // Request the asset.
     Debug.Log("Requesting asset...");
     PolyApi.GetAsset("assets/5vbJ5vildOq", GetAssetCallback);
     statusText.text = "Requesting...";
     // PolyApi.ListAssets(PolyListAssetsRequest.Featured(), MyCallback);
 }
Exemple #6
0
        /// <summary>
        /// Starts a new request for a specific asset. If there is already an existing
        /// request in progress, it will be cancelled.
        /// </summary>
        /// <param name="assetId">Id of the asset to get.</param>
        public void StartRequestForSpecificAsset(string assetId)
        {
            int thisQueryId = PrepareForNewQuery();

            PolyApi.GetAsset(assetId, (PolyStatusOr <PolyAsset> result) => {
                if (thisQueryId == queryId)
                {
                    OnRequestForSpecificAssetResult(result);
                }
            });
        }
Exemple #7
0
    public void GetAsset()
    {
        // Request the asset.
        Debug.Log("Requesting asset...");

        // id working: 5vbJ5vildOq
        // id failing: 97yTneQB9uc (link: https://poly.google.com/view/97yTneQB9uc)
        // 8gY8SLQBM1O

        PolyApi.GetAsset("assets/0ptVcFhHelE", GetAssetCallback);
        statusText.text = "Requesting...";
    }
Exemple #8
0
    /// <summary>
    /// Load asset from a specific key string.
    /// </summary>
    /// <param name="key">Specific key (string)</param>
    public static void Load(string key)
    {
        if (instance.isRunning)
        {
            return;
        }

        instance.StatusField.gameObject.SetActive(true);
        instance.isRunning = true;

        latestKey = key;

        PolyApi.GetAsset("assets/" + key, instance.GetAssetCallback);
        instance.StatusField.text = "Requesting...";
    }
Exemple #9
0
 void MyCallback(PolyStatusOr <PolyListAssetsResult> result)
 {
     if (!result.Ok)
     {
         // Handle error.
         return;
     }
     // Success. result.Value is a PolyListAssetsResult and
     // result.Value.assets is a list of PolyAssets.
     foreach (PolyAsset asset in result.Value.assets)
     {
         PolyApi.GetAsset(asset.name, GetAssetCallback);
         break;
         // print();
         // Do something with the asset here.
     }
 }
Exemple #10
0
    /// <summary>
    /// Load the next object stored in data.
    /// If every object has been loaded, instantiate Player.
    /// </summary>
    private void LoadNext()
    {
        // Create Objects
        if (counter < data.models.Count)
        {
            currentlyLoading = data.models[counter];
            PolyApi.GetAsset("assets/" + data.models[counter].key, GetAssetCallback);
            counter++;
        }

        // Create Player
        else
        {
            Instantiate(playerPrefab, data.PlayerPosition.get(),
                        Quaternion.Euler(0, data.PlayerEulerRotation.y, 0), playerParent.transform);
            counter = 0;

            onSuccessfulLoad();
        }
    }
    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)
        {
            // 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);

            // get the asset
            // Request the asset.
            Debug.Log("Requesting asset...");
            PolyApi.GetAsset(asset.name, GetAssetCallback2);
        }
    }
Exemple #12
0
    // Searches directly by Poly URL.
    private void SearchByPolyUrl(string polyUrl, OnActorableSearchResult resultCallback, System.Action <bool> onComplete)
    {
        string[] parts   = polyUrl.Split('/');
        string   assetId = parts[parts.Length - 1];

        PolyApi.GetAsset(assetId, result =>
        {
            PolyListAssetsResult assetsResult;
            List <PolyAsset> assetList = new List <PolyAsset>();
            if (result.Ok)
            {
                // Successfully got the asset. This is good.
                // Is it acceptably licensed?
                if (result.Value.license == PolyAssetLicense.CREATIVE_COMMONS_BY)
                {
                    // Good license. We can use it.
                    assetList.Add(result.Value);
                    assetsResult = new PolyListAssetsResult(PolyStatus.Success(), 1, assetList);
                }
                else
                {
                    // Not CC-By. Can't use it.
                    Debug.LogError("This asset (" + assetId + ") is not licensed by CC-By. Try another asset.");
                    assetsResult = new PolyListAssetsResult(PolyStatus.Error("Asset " + assetId + " is not licensed as CC-By."), 0, assetList);
                }
            }
            else
            {
                // Failed to get the asset. This is bad.
                assetsResult = new PolyListAssetsResult(PolyStatus.Error("Failed to get asset " + assetId), 0, assetList);
            }
            PolySearchCallback(
                new PolyStatusOr <PolyListAssetsResult>(assetsResult), resultCallback, onComplete);
        });
        return;
    }
 public void getAssetByID(string name)
 {
     Debug.Log("BUTOON CLICKED ::::::" + name);
     PolyApi.GetAsset("assets/5vbJ5vildOq", GetAssetCallback);
 }
Exemple #14
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);
                    });
                }
            });
        }
 public void getAssetByID(string name)
 {
     Debug.Log("Getting asset ::::" + name);
     // PolyApi.GetAsset("assets/5vbJ5vildOq", GetAssetCallback);
     PolyApi.GetAsset(name, GetAssetCallback);
 }
 private void buttonPressed(PolyAsset asset)
 {
     Debug.Log("Requesting asset...");
     PolyApi.GetAsset(asset.name, GetAssetCallback2);
 }
Exemple #17
0
 public void RequestResultByID(string polyID, OnActorableSearchResult resultCallback)
 {
     PolyApi.GetAsset($"assets/{polyID}", (result) => PolyAssetCallback(result, resultCallback));
 }
 // get single asset w/ ID
 public void GetSingleAssetWithID(string modelId)
 {
     PolyApi.GetAsset(modelId, GetAssetCallback);
 }
Exemple #19
0
 public void onGetAssetByIDClicked()
 {
     PolyApi.GetAsset("assets/8nMC2GZProF", CallAssetCallbackEvent);
 }
 public void GetSingleThumbnailWithID(string modelId)
 {
     PolyApi.GetAsset(modelId, FeaturedAssetCallback);
 }
 public static void GetPolyResult(string assetId, GetPolyResultCallback callback)
 {
     PolyApi.GetAsset("assets/" + assetId, (getAssetResult) => GetAssetCallback(getAssetResult, callback));
 }