Create thumbnail of 3d model for Mobile platform

Hi All,

My scenario is as follows:

I am working on an app targeted for mobile platforms like Android.
I host some 3d models as assets in a webserver. These models are fbx files.
I present a grid view of the available assets in webserver to the user, where each grid item represents a 3d model as a thumbnail image.

I can download the assets at runtime using UnityWebRequest and create thumbnails using the following code:

Texture2D texture = null;
texture = AssetPreview.GetAssetPreview(myModel);

The problem is that this code works only inside Unity editor.
As these APIs are not available for other platforms, the problem of creating thumbnails for 3d models looks hard to address.

On searching the forums, I found the following approach:

  1. Create a texture out of the 3d model
  2. Use the texture to display in the grid item

However, creating a texture out of 3d model looks tricky. I tried something on the lines of:

Renderer renderer = myModel.GetComponent<Renderer>();

if(renderer != null) {
    Material material = renderer.material;
    Debug.Log("material = " + material);
    Texture texture = material.GetTexture("_MainTex");

}

Renderer is null for the top level component of the 3d model.

As the 3d model is composed of several child components, the material exists only for those child components. Iterating through the child components and creating texture out of them doesn’t look right.

I would like to know:

  1. Is there any easy approach to create thumbnail image out of 3d model
  2. Is there any other way to solve this issue

The method you mention will get you the texture currently used by the 3D model, not a thumbnail of your model.

To create a thumbnail you will have to render the model to a texture. The easiest way to do this is to add your model to the scene, use a camera to look at it, and render what the camera sees to a render texture : Unity - Scripting API: RenderTexture

You can later on use this render texture on a quad or anything you want.

Also, I don’t know if your app is meant to dowload a lot of models, but a better approach would be to generate the thumbnails offline and store them on the webserver alongside the fbx.

Doing this you can fetch all the thumbnails first, and only download the full models when you want to display them.