/// <summary> /// Imports the given format of the given asset, asynchronously in a background thread. /// Calls the supplied callback when done. /// </summary> public void ImportAsync(PolyAsset asset, PolyFormat format, PolyImportOptions options, AsyncImportCallback callback = null) { ImportOperation operation = new ImportOperation(); operation.instance = this; operation.asset = asset; operation.format = format; operation.options = options; operation.callback = callback; operation.status = PolyStatus.Success(); operation.loader = new FormatLoader(format); if (Application.isPlaying) { Task.Run(() => BackgroundThreadProc(operation)); //ThreadPool.QueueUserWorkItem(new WaitCallback(BackgroundThreadProc), operation); } else { // If we are in the editor, don't do this in a background thread. Do it directly // here on the main thread. BackgroundThreadProc(operation); Update(); } }
void handleFetchThumbnailCallback(PolyAsset asset, PolyStatus status) { if (status.ok) { Debug.Log("handleFetchThumbnailCallback handled"); Debug.Log(asset.thumbnail); GameObject newThumbnail = (GameObject)Instantiate(buttonPrefab, transform); //newThumbnail.tag = ""; Button[] buttonComponents = newThumbnail.GetComponentsInChildren <Button>(); Text[] textComponents = newThumbnail.GetComponentsInChildren <Text>(); Image[] imgComponents = newThumbnail.GetComponentsInChildren <Image>(); RawImage[] rawImgcomponent = newThumbnail.GetComponentsInChildren <RawImage>(); Debug.Log("Button components::::" + buttonComponents[0]); // shrink // Debug.Log("Text Components::::" + textComponents[0] + textComponents[1]); //expandtext, itemContentText Debug.Log("Text Components::::" + textComponents[0]); Debug.Log("Image Components::::" + imgComponents[0] + imgComponents[1] + imgComponents[2]); // Debug.Log("Image Components::::" + imgComponents[0] + imgComponents[1]+ imgComponents[2]+imgComponents[3]); // ListItem, Header, Shrink, ItemContent Debug.Log("Raw Image Components::::" + rawImgcomponent[0]); textComponents[0].text = asset.displayName; // textComponents[1].text = null; rawImgcomponent[0].material.mainTexture = asset.thumbnailTexture; rawImgcomponent[0].name = asset.name; rawImgcomponent[0].gameObject.AddComponent <ThumbnailMenuPerCategory>(); rawImgcomponent[0].gameObject.AddComponent <ClickImg>().thumbnailMenuBackgroundImg = this.thumbnailMenuBackgroundImage; rawImgcomponent[0].gameObject.AddComponent <ClickImg>().modelbackGroundImg = this.modelbackGroundImg; newThumbnail.gameObject.SetActive(true); } }
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); } }); }
void handleFetchThumbnailCallback(PolyAsset asset, PolyStatus status) { if (status.ok) { Debug.Log("handleFetchThumbnailCallback handled"); Debug.Log(asset.thumbnail); //RawImage newObj = (RawImage)Instantiate(img1,transform); //// newObj.SetActive(false); //Debug.Log(asset.name); //newObj.material.mainTexture = asset.thumbnailTexture; ////newObj.SetNativeSize(); Button newObj; newObj = (Button)Instantiate(b, transform); // newObj.AddComponent<ObjectClick>()=newObj; newObj.GetComponentInChildren <RawImage>().material.mainTexture = asset.thumbnailTexture; newObj.GetComponentInChildren <Text>().text = asset.displayName; newObj.name = asset.name; newObj.onClick.AddListener(() => getAssetByID(newObj.name)); newObj.gameObject.SetActive(true); } }
// Callback invoked when an asset has just been imported. private void ImportAssetCallback(PolyAsset asset, PolyStatusOr <PolyImportResult> result) { if (!result.Ok) { Debug.LogError("Failed to import asset. :( Reason: " + result.Status); statusText.text = "ERROR: Import failed: " + result.Status; return; } Debug.Log("Successfully imported asset!"); // Show attribution (asset title and author). statusText.text = asset.displayName + "\nby " + asset.authorName; // Here, you would place your object where you want it in your scene, and add any // behaviors to it as needed by your app. As an example, let's just make it // slowly rotate: // result.Value.gameObject.AddComponent<Rotate>(); var object1 = result.Value.gameObject.transform.GetChild(0).gameObject.AddComponent <BoxCollider>(); if (curr != null) { Destroy(curr); } var pz = Instantiate(PrefabZone, result.Value.gameObject.transform); curr = pz; object1.transform.parent = pz.transform; BoxCollider colli = pz.GetComponent <BoxCollider>(); newbound = object1.GetComponent <BoxCollider>().bounds; colli.size = new Vector3((newbound.size.x / object1.transform.localScale.x) + 0.1f, (newbound.size.y / object1.transform.localScale.y) + 0.1f, (newbound.size.z / object1.transform.localScale.z) + 0.1f); colli.center = pz.transform.localPosition; /// var transl=result.Value.gameObject.AddComponent<Lean.Touch.LeanDragTranslate>(); // var selec = result.Value.gameObject.AddComponent<Lean.Touch.LeanSelectable>(); }
// Callback invoked when a thumbnail has just been fetched. private void FetchThumbnailCallback(PolyAsset asset, PolyStatus result) { if (!result.ok) { Debug.LogError("Failed to import thumbnail. :( Reason: " + result.errorMessage); return; } switch (thumbnailCount) // grab thumbnails of assets, assign as the UISprites to the buttons { case 0: Texture2D tex2D1 = assetsInPalette[0].thumbnailTexture; button1.image.sprite = Sprite.Create(tex2D1, new Rect(0.0f, 0.0f, tex2D1.width, tex2D1.height), new Vector2(0.5f, 0.5f)); break; case 1: Texture2D tex2D2 = assetsInPalette[1].thumbnailTexture; button2.image.sprite = Sprite.Create(tex2D2, new Rect(0.0f, 0.0f, tex2D2.width, tex2D2.height), new Vector2(0.5f, 0.5f)); break; case 2: Texture2D tex2D3 = assetsInPalette[2].thumbnailTexture; button3.image.sprite = Sprite.Create(tex2D3, new Rect(0.0f, 0.0f, tex2D3.width, tex2D3.height), new Vector2(0.5f, 0.5f)); break; case 3: Texture2D tex2D4 = assetsInPalette[3].thumbnailTexture; button4.image.sprite = Sprite.Create(tex2D4, new Rect(0.0f, 0.0f, tex2D4.width, tex2D4.height), new Vector2(0.5f, 0.5f)); break; } thumbnailCount++; statusText.text = "pick an asset to import"; }
protected void FetchThumbnail(PolyAsset assetToFetch, Action <bool> callback) { PolyApi.FetchThumbnail(assetToFetch, (PolyAsset fetchedAsset, PolyStatus status) => { callback(status.ok); }); }
public static string GetPtAssetBaseName(PolyAsset asset) { return(string.Format("{0}_{1}_{2}", SanitizeToUseAsFileName(asset.displayName), SanitizeToUseAsFileName(asset.authorName), SanitizeToUseAsFileName(asset.name).Replace("assets_", ""))); }
void PolyThumbnailCallback(PolyAsset asset, PolyStatus status, OnActorableSearchResult resultCallback) { if (!status.ok) { Debug.Log("There is a problem with poly stuff"); return; } ActorableSearchResult _newresult = new ActorableSearchResult(); _newresult.forceConcave = true; // Do this for Poly models, for now. _newresult.preferredRotation = Quaternion.identity; // Don't do any actor-level scaling for any of these hash tags if (asset.description.Contains(TerrainBlockHashtag) || asset.description.Contains(NoAutoFitHashtag)) { _newresult.preferredScaleFunction = _ => new Vector3(1f, 1f, 1f); } else { // Do some custom tuned actor scale. _newresult.preferredScaleFunction = CalculatePreferredScale; } _newresult.renderableReference.assetType = AssetType.Poly; _newresult.name = asset.displayName; _newresult.renderableReference.uri = new PolyVoosAsset(asset.name).GetUri(); _newresult.thumbnail = asset.thumbnailTexture; resultCallback(_newresult); }
// Callback invoked when an asset has just been imported. private void ImportAssetCallback(PolyAsset asset, PolyStatusOr <PolyImportResult> result) { if (!result.Ok) { Debug.LogError("Failed to import asset. :( Reason: " + result.Status); _statusText.text = "ERROR: Import failed: " + result.Status; return; } Debug.Log("Successfully imported asset!"); // need to make sure that the scene hasn't been destroyed by the time this callback comes in, so we just check // the validity of the status text object and if it's null, drop out if (_statusText == null) { Debug.Log("PolyImageManager>Dropping out because scene appears to have been unloaded!!"); return; } _statusText.text = ""; // Show attribution (asset title and author). _attributionsText.text = asset.displayName + "\nby " + asset.authorName; // Here, you would place your object where you want it in your scene, and add any // behaviors to it as needed by your app. As an example, let's just make it // slowly rotate: result.Value.gameObject.AddComponent <Rotate>(); // make the new object a child of this gameobject result.Value.gameObject.transform.parent = transform; result.Value.gameObject.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f); result.Value.gameObject.transform.localRotation = FPCAMERA.transform.localRotation; result.Value.gameObject.transform.Translate(result.Value.gameObject.transform.forward * 10000f); }
void MyCallback_FetchThumbnail(PolyAsset asset, PolyStatus status) { if (!status.ok) { // Handle error; return; } Debug.Log("Hiiiiiiiiiiiiiiiiiiiiiiiiiiiii"); // Display the asset.thumbnailTexture. img = asset.thumbnailTexture; // get the asset // Request the asset. var buttonObj = Instantiate(ButtonPrefab); // buttonObj.gameObject.AddComponent<Collider>(); 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.transform.GetChild(1).GetComponent <Image>().sprite = s; buttonObj.GetComponent <Button>().onClick.AddListener( () => buttonPressed(asset)); }
/// <summary> /// Builds a ThumbnailFetcher that will fetch the thumbnail for the given asset /// and call the given callback when done. Building this object doesn't immediately /// start the fetch. To start, call Fetch(). /// </summary> /// <param name="asset">The asset to fetch the thumbnail for.</param> /// <param name="callback">The callback to call when done. Can be null.</param> public ThumbnailFetcher(PolyAsset asset, PolyFetchThumbnailOptions options, PolyApi.FetchThumbnailCallback callback) { this.asset = asset; this.options = options ?? new PolyFetchThumbnailOptions(); this.callback = callback; }
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); }
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 callback(PolyAsset asset, PolyStatus status) { if (status.ok) { CreateItems(asset); } }
void CreateItems(PolyAsset asset) { GameObject newItem = Instantiate(itemPrefab) as GameObject; newItem.GetComponent <Item>().CreateEachItem(asset); newItem.transform.SetParent(scrollContainer.transform, false); }
public void AddToMenu(PolyAsset asset) { if (asset.thumbnailTexture != null) { //Add asset to menu list. assetsInMenu.Add(asset); //Instantiate a "card" to represent the asset in the menu GameObject newItem = Instantiate(menuItemTemplate) as GameObject; newItem.name = "MenuItem - " + asset.displayName; newItem.SetActive(true); //Get the asset thumbnail Texture2D tex = asset.thumbnailTexture; Sprite sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f); //Set the cards elements Transform assetTransform = newItem.transform; Image itemImage = assetTransform.Find("Thumbnail").gameObject.GetComponent <Image>(); itemImage.sprite = sprite; Text itemName = assetTransform.Find("Name").gameObject.GetComponent <Text>(); itemName.text = asset.displayName; Text itemAuthor = assetTransform.Find("Author").gameObject.GetComponent <Text>(); itemAuthor.text = asset.authorName; //Set the OnClick function newItem.GetComponent <Button>().onClick.AddListener(() => MenuItemClicked(asset)); //Set "content" as parent. assetTransform.SetParent(content.transform, false); } }
private void ImportAssetCallback(PolyAsset asset, PolyStatusOr <PolyImportResult> result) { if (!result.Ok) { Debug.LogError("Failed to import asset. :( Reason: " + result.Status); currCount++; return; } Debug.Log("Successfully imported asset: " + asset.name); // Here, you would place your object where you want it in your scene, and add any // behaviors to it as needed by your app. As an example, let's just make it // slowly rotate: result.Value.gameObject.AddComponent <Rotate>(); result.Value.gameObject.SetActive(false); result.Value.gameObject.transform.parent = this.transform; currentGameObjects.Add(result.Value.gameObject); if (currItemTotalCount == currCount + 1) { for (int i = 0; i < currentGameObjects.Count; i++) { currentGameObjects[i].transform.localPosition = GetPositionInCircle(i, currentGameObjects.Count, 0.1f); currentGameObjects[i].SetActive(true); } loadingSphere.SetActive(false); } else { currCount++; } }
public ImportRequest(string gltfLocalPath, string ptAssetLocalPath, EditTimeImportOptions options, PolyAsset polyAsset) { this.gltfLocalPath = gltfLocalPath; this.ptAssetLocalPath = ptAssetLocalPath; this.options = options; this.polyAsset = polyAsset; }
/// <summary> /// As documented in PolyApi.FetchThumbnails. /// </summary> public void FetchThumbnail(PolyAsset asset, PolyApi.FetchThumbnailCallback callback) { ThumbnailFetcher fetcher = new ThumbnailFetcher(asset, callback); // ThumbnailFetcher will handle fetching, converting and calling the callback. fetcher.Fetch(); }
/// <summary> /// Checks if the asset has the contents of the format to import, fetching them if need be; then imports /// the asset. /// </summary> /// <param name="asset">The asset who's format is being imported.</param> /// <param name="format">The format to import.</param> /// <param name="options">The import options for this asset.</param> /// <param name="callback">The callback to call when this is finished.</param> private void FetchAndImportFormat(PolyAsset asset, PolyFormat format, PolyImportOptions options, PolyApi.ImportCallback callback = null) { if (format.root.contents != null) { // If asset already has the gltf package, proceed directly to importing it. ImportFormat(asset, format, options, callback); } else { // Otherwise, first fetch the package and then import the model. FetchFormatFiles(asset, format.formatType, (PolyAsset resultAsset, PolyStatus status) => { PolyFormat fetchedFormat = resultAsset.GetFormatIfExists(format.formatType); if (fetchedFormat != null) { ImportFormat(asset, fetchedFormat, options, callback); } else { if (callback != null) { callback(asset, new PolyStatusOr <PolyImportResult>( PolyStatus.Error("Could not fetch format files for asset"))); } } }); } }
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); // } }
private void FetchThumbnail(PolyAsset asset) { PolyFetchThumbnailOptions options = new PolyFetchThumbnailOptions(); options.SetRequestedImageSize(THUMBNAIL_REQUESTED_SIZE); PolyApi.FetchThumbnail(asset, options, OnThumbnailFetched); }
//This method is importing the poly assest void generatingAsset(PolyAsset asset, PolyStatusOr <PolyImportResult> result) { if (!result.Ok) { Debug.LogError("Failed to import asset. :( Reason: " + result.Status); return; } assetAppeared = true; assetGenerate = true; assetName = "Creating: " + asset.displayName; result.Value.gameObject.gameObject.transform.position = Camera.main.transform.position + Camera.main.transform.forward; result.Value.gameObject.gameObject.transform.rotation = Camera.main.transform.rotation; result.Value.gameObject.AddComponent <BoxCollider>(); result.Value.gameObject.AddComponent <Rigidbody>(); boxCol = result.Value.gameObject.GetComponent <BoxCollider>(); boxCol.size = new Vector3(0.5f, 0.5f, 0.5f); var rb = result.Value.gameObject.GetComponent <Rigidbody>(); rb.useGravity = false; result.Value.gameObject.AddComponent <MiraPhysicsGrabExample>(); result.Value.gameObject.AddComponent <MiraPhysicsRaycast>(); var MiraGrab = result.Value.gameObject.GetComponent <MiraPhysicsRaycast>(); MiraGrab.raycastStyle = MiraBaseRaycaster.RaycastStyle.World; }
private void GetThumbnailCallback(PolyAsset asset, PolyStatus status) { if (!status.ok) { Debug.LogError("Failed to import thumbnail. :( Reason: " + status); return; } //Debug.Log("Successfully imported thumbnail!"); // add thumbnail textures to list asset_thumbnail_list.Add(new KeyValuePair <string, Texture2D>(asset.name, asset.thumbnailTexture)); //Debug.Log("thumb list size " + asset_thumbnail_list.Count + " result count " + resultCount); if (asset_thumbnail_list.Count == resultCount) { //Debug.Log("THIS IS GETTING CALLED EACH SEARCH"); asset_thumbnail_list.Sort((x, y) => string.Compare(x.Key, y.Key, StringComparison.Ordinal)); if (onPolyThumbLoaded != null) { onPolyThumbLoaded.Invoke(); } } }
/// <summary> /// Helper method to prepare the manager for starting a new query. /// </summary> private int PrepareForNewQuery() { querying = true; queryId++; assetResult = null; return(queryId); }
private void GetThumbCallback(PolyAsset asset, PolyStatus status) { Texture2D t = asset.thumbnailTexture; Sprite mySprite = Sprite.Create(t, new Rect(0.0f, 0.0f, t.width, t.height), new Vector2(0.5f, 0.5f), 100.0f); thumb.sprite = mySprite; thumb.preserveAspect = true; }
void CreateItems(PolyAsset asset) { GameObject newItem = Instantiate <GameObject>(assetPrefab, assetPrefab.transform); newItem.AddComponent <Item>().CreateEachItem(asset); //newItem.GetComponent<Item>().CreateEachItem(asset); // newItem.transform.SetParent(scrollContainer.transform, false); }
private void ImportAsset(PolyAsset asset, PolyStatusOr <PolyImportResult> result) { // Line the assets up so they don't overlap GameObject go = result.Value.gameObject; go.transform.position = new Vector3(Random.Range(-10.0f, 10.0f), 2f, Random.Range(-10.0f, 10.0f)); go.AddComponent <MouseDrag>(); assetCount++; }
public ScoredSearchResult(PolyAsset polyAsset, double score) { searchType = SearchType.POLY; this.polyAsset = polyAsset; this.score = score; this.tailoredAsset = null; this.name = polyAsset.displayName; }