About writing vertexcolor to FBX

Hey! I’m currently using Unity’s FBX SDK to do some things, but I’m currently having some issues and need your help! I created a color array of VertexColor with the help of the object’s Mesh, which corresponds to the Mesh vertex, and I need to write this VertexColor to the source Fbx file, but the Fbx PolygonVertex does not correspond to the number of Mesh Vertex, which is very tricky! I tried to use FBX’s ControlPoint and it doesn’t correspond to the number of Vertex for Mesh, what should I do?

I looked at the example of the Untiy fbx import and saw code like this, so the number of vertex in the Unity mesh should correspond to the eByControlPoint in the Fbx file, why don’t I get them in the code when they are not the same!

I looked at the number of mesh vertices in the fbx file in my modeling software, and it did match the number of ControlPoints, but it showed up a few more vertices in Unity!

When you say “FBX SDK”, which piece of software are you talking about exactly? Is it this, com.autodesk.fbx? About Autodesk® FBX® SDK for Unity | Autodesk FBX SDK for Unity | 4.0.1

Yes, using an FBX SDK provided by Unity, installed via the package manager

Hi @AlanParrick !

Can you first confirm which version of com.autodesk.fbx (and confirm you are on Unity 21.3 LTS ?

Also could you provide a minimalist set-up that repro the issue ? (or share your current work)
That would help investigate the issue.

Thanks

I’ll give you examples during the day tomorrow, and now it’s night on my side, thank you

Currently, the version I am using is 2021.3.23, where the version of the FBX SDK is 4.1.2。
In the editor, I used the code to get the Mesh Filter component of the currently mounted object, and got the information of the currently rendered Mesh, and I used the number of vertices of the Mesh to generate an array of vertex colors with some rules, and wrote it into the vertex colors of the Mesh.

After that, I got the location of the FBX file where the mesh was located, and used the SDK to try to write the vertex color information to this fbx file.


I use eByControlPoint as well as eDirect to map vertex color information because I see some code and eByControlPoint definitions! I feel that the number of ControlPoints should be the same as the number of vertices in the Unity mesh! In the actual code run, I print out the number of ControlPoints as 176, but in Unity it shows that the number of mesh vertices is 187, I open the fbx file with 3dmax and see that the number of vertices is 176. This made me wonder why the numbers were inconsistent, which made the vertex color data I created with Unity mesh not correspond to ControlPoint and therefore not map the information.

g.GetControlPointsCount() : 176
g.GetPolygonVertexCount() :600
l.GetUVs().GetDirectArray() : 187
l.GetUVs().GetIndexArray() : 600

mesh.vertexCount : 187
That’s some of the information I’m trying to get, and now I have an array of 187 vertex color information and don’t know how to write it into fbx

I executed for (int i = 0; i < mesh.vertexCount; i++) to vertexColorElement.GetDirectArray(). Add(), since the mesh.vertexCount does not correspond to the number of ControlPoints of the mesh in the source fbx file, the fbx file will report an error and the vertex color will not be written.I executed for (int i = 0; i < mesh.vertexCount; i++) to vertexColorElement.GetDirectArray(). Add(), since the mesh.vertexCount does not correspond to the number of ControlPoints of the mesh in the source fbx file, the fbx file will report an error and the vertex color will not be written. The error log is: ImportFBX Errors:
The mesh LT_Wall1 has invalid vertex Colors. Try cleaning and triangulating LT_Wall1 in your 3D modeller before importing it in unity.
This is a failure in the fbx exporter of the tool which exported the fbx file.

Hi @AlanParrick !

So several things to unpack here.

First, I would suggest you upgrade to the last version of the SDK (5.1.1), it’s compatible with 2021.3 and the Autodesk SDK has been updated several times between 4.1.3 and 5.1.1. So definitely can’t hurt.

Then answering this:

I feel that the number of ControlPoints should be the same as the number of vertices in the Unity mesh!

Not sure what you mean here, control points and vertices are 2 different concepts so they don’t necessarily match. It is common for the number of vertices to exceed the number of control points.

Then I see you are using the SDK to import: we don’t recommend this, the support for import is very very limited, we plan to remove documentation and sample that refers to this as a possibility. com.autodesk.sdk has been created for the export use case, so it should exclusively be used for that.

And finally, that would be really helpful if you can provide a tiny project sample that demonstrate your problem, there are still unknowns with what you provided.

Thanks !

So, in another direction, what I actually need is to rewrite the vertex colors created with the Unity Mesh back to the fbx file that provided the mesh, what should I do? I’ve also tried saving it directly as a new Unity Asset asset, but I’ve found that it takes up much more space on disk than fbx files, and I packaged them as AssetBundle packages, and as AssetBundle packages, they look like the memory footprint size is the same if used
Does the Resources.load disk footprint have an impact?

That’s why I’m trying to export FBX

Maybe I’m sorry that some of my statements confuse you because I’m using translation software