Esempio n. 1
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);
                }
            });
        }
    // 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);
        }
    }
Esempio n. 3
0
 void Start()
 {
     PolyToolkit.PolyApi.GetAsset("assets/6LSB0OZK8I7", // ← id
                                  result => {
         PolyApi.Import(result.Value, PolyImportOptions.Default());
     });
 }
    // 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);
    }
Esempio n. 5
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);
        }
    }
Esempio n. 6
0
    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);
    }
    //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);
    }
 public void TestImport(string id)
 {
     PolyApi.GetAsset(id, result => {
         if (result.Ok)
         {
             PolyApi.Import(result.Value, PolyImportOptions.Default());
         }
     });
 }
Esempio n. 9
0
        public void ImportModel()
        {
#if INCLUDE_POLY_TOOLKIT
            if (m_Prefab == null && !m_Importing)
            {
                PolyApi.Import(asset, s_Options, ImportAssetCallback);
            }

            m_Importing = true;
#endif
        }
Esempio n. 10
0
    /// <summary>
    /// Import asset from clicked thumbnail button
    /// </summary>
    /// <param name="asset">The asset to be imported</param>
    public static void ImportAsset(PolyAsset asset)
    {
        PolyImportOptions options = PolyImportOptions.Default();

        options.rescalingMode = PolyImportOptions.RescalingMode.CONVERT;
        options.desiredSize   = 0.2f;
        options.recenter      = true;

        PolyApi.Import(asset, options, ImportAssetCallback);
        Instance.scrollPanel.SetActive(false);
        Instance.loadingPanel.SetActive(true);
    }
Esempio n. 11
0
    private void GetAssetCallback(PolyStatusOr <PolyAsset> result)
    {
        if (!result.Ok)
        {
            Debug.LogError("Failed to get assets. Reason: " + result.Status);
            //statusText.text = "ERROR: " + result.Status;
            return;
        }
        Debug.Log("Successfully got asset!");
        PolyImportOptions options = PolyImportOptions.Default();

        options.rescalingMode = PolyImportOptions.RescalingMode.FIT;
        options.desiredSize   = 0.5f;
        PolyApi.Import(result.Value, options, ImportAssetCallback);
    }
Esempio n. 12
0
    /// <summary>
    /// Callback for Poly asset GET call.
    /// </summary>
    /// <param name="result">Result of the GET call</param>
    private void GetAssetCallback(PolyStatusOr <PolyAsset> result)
    {
        if (!result.Ok)
        {
            return;
        }

        PolyImportOptions options = PolyImportOptions.Default();

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

        PolyApi.Import(result.Value, options, ImportAssetCallback);
    }
Esempio n. 13
0
    private static void GetAssetCallback(PolyStatusOr <PolyAsset> getAssetResult, GetPolyResultCallback callback)
    {
        if (!getAssetResult.Ok)
        {
            Debug.LogError("<color=red> Failed to get assets. Reason: " + getAssetResult.Status + "</color>");
            return;
        }

        PolyImportOptions options = PolyImportOptions.Default();

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

        PolyApi.Import(getAssetResult.Value, options, (asset, importResult) => ImportAssetCallback(asset, importResult, callback));
    }
        ////////////////////////////////////////
        //
        // Import Asset

        public void ImportAsset(PolyAsset asset, Action <GameObject> callback)
        {
            // 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 = .1f;
            // We want the imported assets to be recentered such that their centroid coincides with the origin.
            options.recenter = true;

            PolyApi.Import(asset, options, (importedAsset, result) =>
            {
                OnAssetImported(importedAsset, result, callback);
            });
        }
Esempio n. 15
0
    /// <summary>
    /// Specified callback on GET Asset.
    /// </summary>
    /// <param name="result">Result of the GET method</param>
    public void GetAssetCallback(PolyStatusOr <PolyAsset> result)
    {
        if (!result.Ok)
        {
            StatusField.text = "ERROR: " + result.Status;
            isRunning        = false;
            return;
        }

        PolyImportOptions options = PolyImportOptions.Default();

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

        StatusField.text = "Importing...";
        PolyApi.Import(result.Value, options, ImportAssetCallback);
    }
Esempio n. 16
0
    public void AddFromPoly(PolyAsset asset)
    {
        PolyApi.Import(
            asset,
            PolyImportOptions.Default(),
            (_, res) =>
        {
            Debug.Log("Best asset: " + _.displayName + " by: " + _.authorName);

            if (!res.Ok)
            {
                Debug.LogError("Failed to import asset. :( Reason: " + res.Status);
                return;
            }

            res.Value.gameObject.AddComponent <Rotate>();
        });
    }
Esempio n. 17
0
    private void MenuItemClicked(PolyAsset asset)
    {
        if (selectedAsset == asset)
        {
            return;
        }

        ui.AddMessageToBox(asset.displayName + " selected");
        selectedAsset = asset;

        // Set options for import so the assets aren't crazy sizes
        PolyImportOptions options = PolyImportOptions.Default();

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

        PolyApi.Import(asset, options, ParseToGameObject);
    }
    // Callback invoked when the featured assets results are returned.
    private void GetAssetCallback2(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 = 1.0f;
        // We want the imported assets to be recentered such that their centroid coincides with the origin:
        options.recenter = true;

        PolyApi.Import(result.Value, options, ImportAssetCallback);
    }
Esempio n. 19
0
    private void GetDonuts(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   = 2.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(3, result.Value.assets.Count); i++)
        {
            // Import our assets into the scene with the ImportDonuts function
            PolyApi.Import(result.Value.assets[i], options, ImportDonuts);
            assetsInUse.Add(result.Value.assets[i]);

            // Attributions Text
            // attributionsText.text = PolyApi.GenerateAttributions(includeStatic: false, runtimeAssets: assetsInUse);
        }
    }
Esempio n. 20
0
    void ImportAsset(int idx)
    {
        Debug.Log("button clicked)");
        List <PolyAsset> assetsInUse = new List <PolyAsset>();

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

        Debug.Log("import asset " + idx);
        PolyApi.Import(assetsInPalette[idx], options, ImportAssetCallback);
        assetsInUse.Add(assetsInPalette[idx]);

        // Show attributions for the assets we display.
        //attributionsText.text = PolyApi.GenerateAttributions(includeStatic: true, runtimeAssets: assetsInUse);
    }
Esempio n. 21
0
        private void CmdImp(string[] args)
        {
            int index;

            if (args.Length == 0 || !int.TryParse(args[0], out index))
            {
                PrintLn("*** Specify the index of the asset to import (as given by the 'show' command).");
                return;
            }
            if (index < 0 || index >= currentResults.Count)
            {
                PrintLn("*** Invalid index. Use the 'show' command to see the valid assets.");
                return;
            }
            PolyAsset         assetToImport = currentResults[index];
            PolyImportOptions options       = new PolyImportOptions();

            options.rescalingMode = GetEnumOpt(args, "-m", PolyImportOptions.RescalingMode.FIT);
            options.recenter      = !HasOpt(args, "--no-center");
            options.desiredSize   = GetFloatOpt(args, "--ds", 5.0f);
            options.scaleFactor   = GetFloatOpt(args, "--sf", 1.0f);
            PrintLn("Importing asset... May take a while. Please wait!");
            PolyApi.Import(assetToImport, options, (PolyAsset asset, PolyStatusOr <PolyImportResult> result) => {
                if (!result.Ok)
                {
                    PrintLn("ERROR: failed to import {0}: {1}", asset.name, result.Status);
                    return;
                }
                PrintLn("Successfully imported asset '{0}' ({1})", asset.name, asset.displayName);

                if (currentAsset != null)
                {
                    Destroy(currentAsset);
                    currentAsset = null;
                }

                currentAsset = result.Value.gameObject;
            });
        }
Esempio n. 22
0
        private void AlreadyGotAssetList()
        {
            if (_statusText == null)
            {
                return;
            }

            _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 = 5.0f;
            // We want the imported assets to be recentered such that their centroid coincides with the origin:
            options.recenter = true;

            int i = Random.Range(0, results.Value.assets.Count - 1);

            PolyApi.Import(results.Value.assets[i], options, ImportAssetCallback);
        }
 void OnClickImportAsset(PolyAsset asset)
 {
     PolyApi.Import(asset, PolyImportOptions.Default(), ImportAssetCallback);
 }
Esempio n. 24
0
    // Buttons

    public void _OnAddModelToScene()
    {
        PolyApi.Import(polyModel, PolyImportOptions.Default(), AddModel);
    }
Esempio n. 25
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. 26
0
 public void OnClick()
 {
     PolyApi.Import(asset, PolyImportOptions.Default(), ImportCallback);
 }
Esempio n. 27
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);
    }