A very basic question on Diffuse UV coordinates... It is the final blocker for me it seems


I have designed a model like this. I have NOT created any UV map.
I want to export it as FBX. When I do so, as I don’t have UVs, the Base Color texture (Diffuse Texture) is not displayed. So, I want to generate the UV map for base color texture. I can create a new UV Map, do UV Unwrap and bake a DIFFUSE texture but, my requirement is,

This FBX will be imported into an online viewer. In that viewer, a user can upload his own image and that image should be applied and shown. So, If my UV Map is a atlas-packed, it won’t work.

So, basically, I need to figure-out how the Blender/Cycles calculate UV from the GENERATED attribute. Where is this logic/code located?

Thanks in advance

Implemented like this but the quality is not good. Do I need to do anything?

const char *attrib_name = uv_attribute_name ? uv_attribute_name : "_dnt_generated_diffuse_uv_";
    ustring attribute_name(attrib_name);
    Attribute *uvs_attribute = mesh.attributes.find(attribute_name);
    if (!uvs_attribute) {
      uvs_attribute = mesh.attributes.add(AttributeStandard::ATTR_STD_UV, attribute_name);
    float2 *uv_data = uvs_attribute->data_float2();

    int vertices_count = mesh.verts.size();
    MinAndMax3 minmax;
    for (int i = 0; i < vertices_count; i++) {

    float3 &loc = minmax.GetCenter();
    float3 &size = minmax.GetSize();

    if (size.x != 0.0f)
      size.x = 0.5f / size.x;
    if (size.y != 0.0f)
      size.y = 0.5f / size.y;
    if (size.z != 0.0f)
      size.z = 0.5f / size.z;

    loc = loc * size - make_float3(0.5f, 0.5f, 0.5f);

    float3 *generated_data = new float3[vertices_count];
    for (int i = 0; i < vertices_count; i++) {
      float3 &vertex = mesh.verts[i];
      generated_data[i] = (vertex * size) - loc;
    int indices_count = mesh.triangles.size();

    for (int i = 0; i < indices_count; i++) {
      int vertex_index = mesh.triangles[i];

      const float3 orco = (generated_data[vertex_index] + loc) / size;
      // const float2 tmp = map_to_sphere(orco);
      uv_data[i] = map_to_sphere(orco);
    delete[] generated_data;