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:
- Create a texture out of the 3d model
- 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:
- Is there any easy approach to create thumbnail image out of 3d model
- Is there any other way to solve this issue