// 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...";

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

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

        // Now let's get the first 5 featured assets and put them on the scene.
        List <PolyAsset> assetsInUse = new List <PolyAsset>();

        for (int i = 0; i < Mathf.Min(5, result.Value.assets.Count); i++)
        {
            // Import this asset.
            PolyApi.Import(result.Value.assets[i], options, ImportAssetCallback);
            assetsInUse.Add(result.Value.assets[i]);
        }

        // Show attributions for the assets we display.
        attributionsText.text = PolyApi.GenerateAttributions(includeStatic: true, runtimeAssets: assetsInUse);
    }
Exemple #2
0
        private void Start()
        {
            inputField      = ComponentById <InputField>("ID_Input");
            outputText      = ComponentById <Text>("ID_Output");
            outputText.text = "Poly Toolkit v" + PtSettings.Version.ToString() + "\n" +
                              "Type 'help' for a list of commands.\n\n";

            ComponentById <Button>("ID_ClearButton").onClick.AddListener(() => { outputText.text = ""; });
            ComponentById <Button>("ID_RunButton").onClick.AddListener(SubmitCurrentCommand);
            ComponentById <Button>("ID_CopyButton").onClick.AddListener(() => {
                GUIUtility.systemCopyBuffer = outputText.text;
            });
            ComponentById <Button>("ID_ToggleTransparencyButton").onClick.AddListener(ToggleTransparency);
            userProfileImage = ComponentById <Image>("ID_UserProfileImage");
            userProfileImage.gameObject.SetActive(false);
            imageDisplay = ComponentById <Image>("ID_ImageDisplay");
            imageDisplay.gameObject.SetActive(false);

            // Subscribe to Unity log messages so we can show them.
            Application.logMessageReceivedThreaded += HandleLogThreaded;

            // Initialize Poly. We do this explicit initialization rather than have a PolyToolkitManager on the
            // scene because we want to use a specific API key that's not the one that's configured in PtSettings
            // (since we want to keep PtSettings uninitialized for the user to fill in).
            PolyApi.Init(new PolyAuthConfig(API_KEY, CLIENT_ID, CLIENT_SECRET));
        }
Exemple #3
0
    void HandleRequest(PolyStatusOr <PolyListAssetsResult> result)
    {
        if (!result.Ok)
        {
            // Handle error.
            Debug.LogError("Failed to get assets. Reason: " + result.Status);
            currCount++;
            return;
        }
        // Success. result.Value is a PolyListAssetsResult and
        // result.Value.assets is a list of PolyAssets.
        if (result.Value.assets.Count == 0)
        {
            Debug.Log("No asset found");
            currCount++;
            return;
        }

        foreach (PolyAsset asset in result.Value.assets)
        {
            // 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:
            options.desiredSize = 0.05f;
            // We want the imported assets to be recentered such that their centroid coincides with the origin:
            options.recenter = true;

            PolyApi.Import(asset, options, ImportAssetCallback);
        }
    }
    // Use this for initialization
    void Start()
    {
        // Custom List Asset
        PolyListAssetsRequest req = new PolyListAssetsRequest();

        // Search by keyword:
        req.keywords = "furniture";
        // Only curated assets:
        req.curated = true;
        // Limit complexity to medium.
        req.maxComplexity = PolyMaxComplexityFilter.MEDIUM;
        // Only Blocks objects.
        req.formatFilter = PolyFormatFilter.BLOCKS;
        // Order from best to worst.
        req.orderBy = PolyOrderBy.BEST;
        // Up to 20 results per page.
        req.pageSize = 100;
        ///////////////////////////////////////////////////
        //////////////////////////////////////////////////
        // Send the request.
        PolyApi.ListAssets(req, MyCallback);
        ///////////////////////////////////////////////////////////////////

        //foreach (var prefab in Prefabs)
        //{
        //    var buttonObj = Instantiate(ButtonPrefab);
        //    buttonObj.transform.SetParent(UiPanel, false);

        //    buttonObj.GetComponentInChildren<Text>().text = prefab.name;
        //    buttonObj.GetComponent<Button>().onClick.AddListener(
        //        () => buttonPressed(prefab));
        //}
    }
Exemple #5
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();
        }
    }
    // Use this for initialization
    void Start()
    {
        // Buildin List Asset
        // PolyApi.ListAssets(PolyListAssetsRequest.Featured(), MyCallback);


        // Custom List Asset
        PolyListAssetsRequest req = new PolyListAssetsRequest();

        // Search by keyword:
        req.keywords = "table";
        // Only curated assets:
        req.curated = true;
        // Limit complexity to medium.
        req.maxComplexity = PolyMaxComplexityFilter.MEDIUM;
        // Only Blocks objects.
        req.formatFilter = PolyFormatFilter.BLOCKS;
        // Order from best to worst.
        req.orderBy = PolyOrderBy.BEST;
        // Up to 20 results per page.
        req.pageSize = 20;
        ///////////////////////////////////////////////////
        req.category = PolyCategory.OBJECTS;
        //////////////////////////////////////////////////
        // Send the request.
        PolyApi.ListAssets(req, MyCallback);
    }
Exemple #7
0
 private void Start()
 {
     // Request the asset.
     Debug.Log("Requesting asset...");
     PolyApi.GetAsset("assets/" + assetKey, GetAssetCallback);
     statusText.text = "Requesting...";
 }
 protected void FetchThumbnail(PolyAsset assetToFetch, Action <bool> callback)
 {
     PolyApi.FetchThumbnail(assetToFetch, (PolyAsset fetchedAsset, PolyStatus status) =>
     {
         callback(status.ok);
     });
 }
Exemple #9
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);
                }
            });
        }
Exemple #10
0
        // Callback invoked when the featured assets results are returned.
        private static void GetAssetCallback(PolyStatusOr <PolyToolkit.PolyAsset> result, Action <GameObject> onImport)
        {
            if (!result.Ok)
            {
                Debug.LogError("Failed to get assets. Reason: " + result.Status);
                //statusText.text = "ERROR: " + 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.CONVERT;
            // The specific size we want assets rescaled to (fit in a 5x5x5 box):
            options.desiredSize = 5.0f;
            // We want the imported assets to be recentered such that their centroid coincides with the origin:
            options.recenter = true;

            //statusText.text = "Importing...";
            PolyApi.Import(result.Value, options, (asset, importResult) =>
            {
                if (result.Ok)
                {
                    onImport(importResult.Value.gameObject);
                }
            });
        }
    private void ImportResults(PolyStatusOr <PolyListAssetsResult> result)
    {
        // Set options for import so the assets aren't crazy sizes
        PolyImportOptions options = PolyImportOptions.Default();

        options.rescalingMode = PolyImportOptions.RescalingMode.FIT;
        options.desiredSize   = 5.0f;
        options.recenter      = true;

        // List our assets
        List <PolyAsset> assetsInUse = new List <PolyAsset>();

        // Loop through the list and display the first 3
        for (int i = 0; i < Mathf.Min(5, result.Value.assets.Count); i++)
        {
            // Import our assets into the scene with the ImportAsset function
            PolyApi.Import(result.Value.assets[i], options, ImportAsset);
            PolyAsset asset = result.Value.assets[i];
            assetsInUse.Add(asset);

            //attributionsText.text = PolyApi.GenerateAttributions(includeStatic: false, runtimeAssets: assetsInUse);
        }

        string attribution = PolyApi.GenerateAttributions(includeStatic: false, runtimeAssets: assetsInUse);

        InterfaceManager.GetInstance().AddMessageToBox(attribution);
    }
    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();
        }
    }
Exemple #13
0
 public static void LoadAsset(PolyAsset asset, Action <GameObject> onLoad)
 {
     PolyApi.GetAsset("assets/" + asset.AssetId, (result) =>
     {
         GetAssetCallback(result, onLoad);
     });
 }
Exemple #14
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);
        //      }
    }
Exemple #15
0
        private void FetchThumbnail(PolyAsset asset)
        {
            PolyFetchThumbnailOptions options = new PolyFetchThumbnailOptions();

            options.SetRequestedImageSize(THUMBNAIL_REQUESTED_SIZE);
            PolyApi.FetchThumbnail(asset, options, OnThumbnailFetched);
        }
    public void RequestAssets(string label)
    {
        // Request the asset.
        Debug.Log("Requesting asset...");
        //PolyApi.GetAsset("assets/5vbJ5vildOq", GetAssetCallback);
        PolyListAssetsRequest req = new PolyListAssetsRequest();

        // Search by keyword:
        req.keywords = label;
        // Only curated assets:
        req.curated = true;
        // Limit complexity to medium.
        req.maxComplexity = PolyMaxComplexityFilter.SIMPLE;
        // Only Blocks objects.
        req.formatFilter = null;

        req.category = PolyCategory.UNSPECIFIED;
        // Order from best to worst.
        req.orderBy = PolyOrderBy.BEST;
        // Up to 20 results per page.
        req.pageSize = 1;
        // Send the request.
        PolyApi.ListAssets(req, GetAssetCallback);
        statusText.text = "Requesting...";
        labelText.text  = label;
    }
    // Callback invoked when the featured assets results are returned.
    private void GetAssetCallback(PolyStatusOr <PolyListAssetsResult> result)
    {
        if (!result.Ok)
        {
            Debug.LogError("Failed to get assets. Reason: " + result.Status);

            statusText.text = "ERROR: " + result.Status;

            return;
        }
        Debug.Log("Successfully got asset!");

        foreach (PolyAsset asset in result.Value.assets)
        {
            // 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.4f;
            // We want the imported assets to be recentered such that their centroid coincides with the origin:
            options.recenter = true;

            statusText.text = "Importing...";
            PolyApi.Import(asset, options, ImportAssetCallback);
        }
    }
Exemple #18
0
 void InitialiseUIContent(PolyStatusOr <PolyListAssetsResult> result)
 {
     foreach (PolyAsset asset in result.Value.assets)
     {
         PolyApi.FetchThumbnail(asset, callback);
     }
 }
Exemple #19
0
 void Start()
 {
     PolyToolkit.PolyApi.GetAsset("assets/6LSB0OZK8I7", // ← id
                                  result => {
         PolyApi.Import(result.Value, PolyImportOptions.Default());
     });
 }
    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 LoadAsset(string desiredName, bool findBestMatch = false)
    {
        Debug.Log("Requesting asset list using keyword: " + desiredName + " ...");
        //        PolyApi.ListAssets(PolyListAssetsRequest.Featured(), OnAssetListReturned);
        //        PolyApi.GetAsset("assets/5vbJ5vildOq", GetAssetCallback);
        //    statusText.text = "Requesting...";

        PolyListAssetsRequest req = new PolyListAssetsRequest();

        // Search by keyword:
        req.keywords = desiredName;
        // Only curated assets:
        req.curated = true;
        // Limit complexity to medium.
        req.maxComplexity = PolyMaxComplexityFilter.MEDIUM;
        // Only Blocks objects.
        req.formatFilter = PolyFormatFilter.BLOCKS;
        // Order from best to worst.
        req.orderBy = PolyOrderBy.BEST;
        // Up to 20 results per page.
        req.pageSize = 20;

        // Cache the request info because google doesn't track what you asked for
        lastRequestedAsset     = desiredName;
        findBestMatchRequested = findBestMatch;

        // Send the request.
        PolyApi.ListAssets(req, OnAssetListReturned);
    }
    private void CallListAssetsCallbackEvent(PolyStatusOr<PolyListAssetsResult> result)
    {
        foreach (PolyAsset asset in result.Value.assets)
        {
            PolyApi.FetchThumbnail(asset, callback);

        }
    }
    public void LoadAsset()
    {
        Debug.Log("Requesting asset...");
        //        PolyApi.GetAsset("assets/5vbJ5vildOq", GetAssetCallback);
        PolyApi.ListAssets(PolyListAssetsRequest.Featured(), OnAssetListReturned);

        //    statusText.text = "Requesting...";
    }
    //When user choose an assest, this method is called.
    public void ChooseAssest()
    {
        PolyImportOptions options = PolyImportOptions.Default();

        options.rescalingMode = PolyImportOptions.RescalingMode.FIT;
        options.desiredSize   = .5f;
        options.recenter      = true;
        PolyApi.Import(objectAsset, options, generatingAsset);
    }
Exemple #25
0
    public void LoadThumbnails()
    {
        //Make a request to Poly to list asset
        //TODO : add request configuration
        PolyListAssetsRequest request = new PolyListAssetsRequest();

        request.category = PolyCategory.UNSPECIFIED;
        PolyApi.ListAssets(request, ListAssetCallback);
    }
Exemple #26
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);
 }
 public void TestImport(string id)
 {
     PolyApi.GetAsset(id, result => {
         if (result.Ok)
         {
             PolyApi.Import(result.Value, PolyImportOptions.Default());
         }
     });
 }
Exemple #28
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));
 }
Exemple #29
0
    //Making a request Poly method
    private void requestPolyAssets()
    {
        PolyListAssetsRequest req = new PolyListAssetsRequest();

        req.keywords = nluResults;
        req.curated  = true;
        req.orderBy  = PolyOrderBy.BEST;
        PolyApi.ListAssets(req, ListAssetsCallback);
    }
Exemple #30
0
        private void CmdAuth(string[] args)
        {
            if (args.Length < 1)
            {
                PrintCommandHelp("auth");
                return;
            }
            switch (args[0])
            {
            case "signin":
                bool   interactive        = !HasOpt(args, "-n");
                string manualAccessToken  = GetOpt(args, "--at", null);
                string manualRefreshToken = GetOpt(args, "--rt", null);

                // Both --at and --rt should be present, or neither.
                if ((manualAccessToken == null) ^ (manualRefreshToken == null))
                {
                    // One is present, the other isn't: error.
                    PrintLn("*** The --at and --rt options must be both present, or both absent.");
                    return;
                }

                if (manualAccessToken != null)
                {
                    PrintLn("Attempting auth with given tokens...");
                    PolyApi.Authenticate(manualAccessToken, manualRefreshToken, AuthCallback);
                }
                else
                {
                    PrintLn("Attempting {0} auth...", interactive ? "interactive" : "non-interactive");
                    PolyApi.Authenticate(interactive, AuthCallback);
                }
                break;

            case "signout":
                PolyApi.SignOut();
                userProfileImage.sprite = null;
                userProfileImage.gameObject.SetActive(false);
                PrintLn("Requested sign out.");
                break;

            case "cancel":
                PrintLn("Requesting to cancel auth.");
                PolyApi.CancelAuthentication();
                break;

            case "status":
                PrintLn("authenticated: {0}\nauthenticating: {1}\naccess token: {2}\nrefresh token: {3}",
                        PolyApi.IsAuthenticated, PolyApi.IsAuthenticating, PolyApi.AccessToken, PolyApi.RefreshToken);
                break;

            default:
                PrintCommandHelp("auth");
                break;
            }
        }