[Solved] How to extract texCoord1 (the second uv suit) from fbx file correctly?

Hi~
I am working on a project which relays on Play Canvas Engine heavily.
I found that the second uv data (texCoord1) I read from fbx file (by FBX SDK) is different from the data converted by Play Canvas Editor. For simple models, the difference is just an mismatch of number order, but for complex model, they get different numbers.
Since the data is going to feed Play Canvas Engine, so I think it is necessary to get the same output as Play Canvas Editor.
So my I ask you that how can I get the same output as Play Canvas Editor?
Thank you in advance!

Could you provide simple example that replicates the problem?

1 Like

Hi max, thank you for your reply.

Actually I am not 100% sure that the difference between these two output is other than a mismatch of order, because some of the “different” numbers can be regard as the same number of a different precision.

I uploaded several files to google drive, but I can not post more than two links in one reply, so I will list them in the following replies.

The method I used to read UV data from FBX file is like the following code (which follows the sample code from FBX SDK official example):

# this function runs everytime we collect data of a control point
def collect_uv_data(fbx_mesh, polygon_index, control_point_index, vertex_index_in_polygon):
    uvs =[None, None]  # this list holds the two set of uv data of a control point

    # start to collect uv data
    for index in range(2):

        #  we skip the fbx layer if it does not exist or it does not have uv data
        fbx_layer = fbx_mesh.GetLayer(index)
        if fbx_layer is None:
            continue

        fbx_uvs = fbx_layer.GetUVs()
        if fbx_uvs is None:
            continue
        
        # the following block is the same as the FBX SDK official examples
        mapping_mode = fbx_uvs.GetMappingMode() 
        reference_mode = fbx_uvs.GetReferenceMode()
        if mapping_mode == FbxLayerElement.eByControlPoint:
            if reference_mode == FbxLayerElement.eDirect:
                fbx_uv = fbx_uvs.GetDirectArray().GetAt(control_point_index)
            elif reference_mode == FbxLayerElement.eIndexToDirect:
                fbx_uv_index = fbx_uvs.GetIndexArray().GetAt(control_point_index)
                fbx_uv = fbx_uvs.GetDirectArray().GetAt(fbx_uv_index)
        elif mapping_mode == FbxLayerElement.eByPolygonVertex:
            fbx_texture_uv_index = fbx_mesh.GetTextureUVIndex(polygon_index, vertex_index_in_polygon)
            if reference_mode in [FbxLayerElement.eDirect, FbxLayerElement.eIndexToDirect]:
                fbx_uv = fbx_uvs.GetDirectArray().GetAt(fbx_texture_uv_index)
        uvs[index] = append([fbx_uv[0], fbx_uv[1]])

    return uvs

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

and here are the fbx model files:
the chair.
the cube.

The first pair of sample data is of a chair model:
The output I got from FBX SDK is here.
The json output I got from Play Canvas Engine is here.

Please don’t flag this as spam, I need to upload to google drive because fbx file and json file are not permitted to be upload here…

the second pair of sample data is of a simple cube:

The output from Play Canvas Editor is here.
And my output file is here.

Please don’t flag this as spam, I need to upload to google drive because fbx file and json file are not permitted to be upload here…

I figure it out by myself.
The problem is related to the method I read uv from FBX file.

The method to read UV correctly looks like this:

...
fbx_uv = FbxVector2()
fbx_mesh.GetPolygonVertexUV(polygon_index, vertex_index_in_polygon, fbx_uvs_name, fbx_uv)
...
1 Like