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); } }
// 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); } }); }
void Start() { PolyToolkit.PolyApi.GetAsset("assets/6LSB0OZK8I7", // ← id result => { PolyApi.Import(result.Value, PolyImportOptions.Default()); }); }
static PolyGridAsset() { s_Options = PolyImportOptions.Default(); s_Options.rescalingMode = PolyImportOptions.RescalingMode.FIT; s_Options.desiredSize = 1.0f; s_Options.recenter = true; }
// 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); } }
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); }
// 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); }
//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()); } }); }
/// <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); }
/// <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); }
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); }
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); }); }
/// <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); }
public static void TestImportSelection() { var gltfAssets = Selection.objects .Select(o => AssetDatabase.GetAssetPath(o)) .Where(p => !string.IsNullOrEmpty(p)) .Where(p => p.Contains(".gltf")) .ToArray(); if (gltfAssets.Length == 0) { Debug.LogFormat("No selected .gltf assets"); return; } foreach (var asset in gltfAssets) { DoImport(asset, PolyImportOptions.Default(), true); } }
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>(); }); }
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); }
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); }
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); } }
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); }
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); }
void OnClickImportAsset(PolyAsset asset) { PolyApi.Import(asset, PolyImportOptions.Default(), ImportAssetCallback); }
public static void TestImportGltf2FromFbx() { DoImport(Path.Combine(RepoRoot, kShark), PolyImportOptions.Default()); }
public static void TestImportGltf2Transparent() { DoImport(Path.Combine(RepoRoot, kGoblets), PolyImportOptions.Default()); }
public static void TestImportGltf2() { DoImport(Path.Combine(RepoRoot, kComputer), PolyImportOptions.Default()); }
public static void TestImportGltf1() { DoImport(Path.Combine(RepoRoot, kAllBrush14), PolyImportOptions.Default()); }
public static void TestSaveAsSeparateWithMeshesInAsset() { IUriLoader binLoader = new BufferedStreamLoader(Path.GetDirectoryName(Path.Combine(RepoRoot, kAllBrush10))); ImportGltf.GltfImportResult result = null; using (TextReader reader = new StreamReader(Path.Combine(RepoRoot, kAllBrush10))) { result = ImportGltf.Import(GltfSchemaVersion.GLTF1, reader, binLoader, PolyImportOptions.Default()); } string assetPath = "Assets/Poly/TestData/separate_a.asset"; string prefabPath = "Assets/Poly/TestData/separate_p.prefab"; SaveAsSeparateWithMeshesInAsset(result, assetPath, prefabPath); GameObject.DestroyImmediate(result.root); }
public static void TestSaveAsSinglePrefab() { IUriLoader binLoader = new BufferedStreamLoader(Path.GetDirectoryName(Path.Combine(RepoRoot, kMoto))); ImportGltf.GltfImportResult result = null; using (TextReader reader = new StreamReader(Path.Combine(RepoRoot, kMoto))) { result = ImportGltf.Import(GltfSchemaVersion.GLTF1, reader, binLoader, PolyImportOptions.Default()); } string prefabPath = "Assets/Poly/TestData/single_p.prefab"; SaveAsSinglePrefab(result, prefabPath); GameObject.DestroyImmediate(result.root); }