List of Poly models

Hello ,
I want to load list contains many models of Poly.Google , choose one of them and show it in Babylon scene.
Is that possible !!
Thanks for help :)))

As the model are accessible in GLTF if I remember correctly it should be. Now I wonder if the APIs are public on the poly side and authorize cross origin requests.

If yes it should be all good as it is what we do to load models in babylon, just points to the glb/gltf url.

1 Like

thanks for the reply , but how i can load many models of ploy.google into list !

you can use sceneLoader.append for each url stored in the list ?

1 Like

Hello!

I took a crack at creating a playground to answer your question. Google Poly is pretty cool! Thanks for showing me.

I downloaded a couple models (I just searched for “sword”) and added them to my github account for this example. But it looks like you can access the assets via an api. Or you can just add them to your project directly.

https://playground.babylonjs.com/#Y5HMAN

Hope this helps!

4 Likes

Hi. Yes, it is possible.
Here is an exmple:
https://www.babylonjs-playground.com/#TZCIM9#4
You have to change the id of 3d object, to get other.

Or if you want to search for something and display the results, the above functions should return you the path and the filename, like you need on ImportMesh function.

getResultsFromPolyGoogle (searchFor) {
  const key = 'yourkey';
  const url = 'https://poly.googleapis.com/v1/assets/?keywords=' + searchFor + '&key=' + key + '&format=GLTF2';

  let results = [];
  var request = new XMLHttpRequest();
  request.open( 'GET', url, true );
  request.addEventListener( 'load', ( event ) => {
    const response = JSON.parse(event.target.response);
    console.log(response);
    for (let i = 0; i < response.assets.length; i++) {
      const assetInfo = this.getAssetInfoPolyGoogle(response.assets[i].formats)
      results.push({
        id: response.assets[i].name,
        name: response.assets[i].displayName,
        link: assetInfo.link,
        filename: assetInfo.filename
      })
    }
    console.log(results);
  });
  request.send(null);
},
getAssetInfoPolyGoogle (formats) {
  let format;
  for (let i = 0; i < formats.length; i++) {
    if (formats[i].formatType === 'GLTF2') {
      format = formats[i];
      break;
    }
  }

  var uri = format.root.url;
  var fileIndex = uri.lastIndexOf("/");
  var link = uri.substring(0, fileIndex + 1);
  var filename = uri.substring(fileIndex + 1);
  
  return {
    link: link,
    filename: filename
  }
},

Cheers! :beers:

4 Likes

thanks a lot @MarianG @belfortk :))
about poly_id and API_Key ; what’s that !! and from where i can choose them !!

The api key is a credential you need to get from Google. You can sign up for one by following the directions here. It authorizes you to interact with the Google Poly API.

Poly id is the ID tag of the poly asset. You can find it at the end of the URL of the asset. For example, the ID for this asset is i7FXM8FPqgYd

1 Like

thanks a lot for ur explication :))

Sorry for the inconvenience , but when i want to change the the id of 3d object nothing is displayed just the loader of babylon

I think you have to make sure that the format of 3d object you want to import is right.
This works, but as you said, I found few which doesn’t work

https://www.babylonjs-playground.com/#TZCIM9#5

3 Likes

really thanks a lot for ur help and ur time :))))

2 Likes