Adding/exporting VertexColor issues

Adding/exporting VertexColor issues

Anonymous
Not applicable
985 Views
1 Reply
Message 1 of 2

Adding/exporting VertexColor issues

Anonymous
Not applicable

When I export an FBX it has an extra VertexColor layer in it that I can not get rid of.

 

I am writing a tool that takes an FBX as input, bakes a bunch of data into textures, and exports a new version of the model with important information added to the vertex colors. When I send the result to the program we need it to work in it doesn't see any vertex colors. I export the file as ASCII and when I manually check it it's got this little sucker sitting right above my data:

 

LayerElementColor: 0 {
                        Version: 101
                        Name: ""
                        MappingInformationType: "NoMappingInformation"
                        ReferenceInformationType: "Direct"
}

So when I add my data in it gets put in as LayerElementColor: 1, which nothing checks. When I manually remove that section and renumber my data to LayerElementColor: 0 it works how I need it to.

 

The thing is, I can't find that layer element when I am running my program.

Here are the remnants of my latest attempts at finding it:

 

printf("DEBUG: %i existing vertex color elements.\n", pMesh->GetElementVertexColorCount()); //Says there are 0
printf("DEBUG: index: %i\n", pMesh->GetLayerIndex(0, FbxLayerElement::EType::eVertexColor)); //This returns -1
printf("DEBUG: %i layers\n", pMesh->GetLayerCount()); //There are two layers, neither apparently has a vertex color element
for (int i = 0; i < pMesh->GetLayerCount(); i++)
{
	const FbxLayer* pLayer = pMesh->GetLayer(i);
	const FbxLayerElement* pLayerElement = pLayer->GetLayerElementOfType(FbxLayerElement::EType::eVertexColor);
	if (pLayerElement != nullptr)
	{
		printf("DEBUG: Found the stupid thing.\n");
	}
	else
	{
		printf("DEBUG: Layer %i does not contain vertex color data.\n", i);
	}
}
FbxGeometryElementVertexColor* pVertColor = pMesh->GetElementVertexColor(); if (pVertColor == nullptr) { printf("Could not find preexisting vertex color element layer.\n"); pVertColor = pMesh->CreateElementVertexColor(); //The thought being at this point I should be fine to add a vertex color element since I can't find any existing ones }

But yea, after this runs it saves with two vertex color elements, an empty useless one sitting at 0, the only spot anything checks, and my actual data sitting at 1.

 

I have to be misunderstanding how something works here. I am new to the FBX SDK and this file structure seems very complicated, I am sure I am misunderstanding something about how it works.

 

Can anyone help me out here?

 

I am using FBX SDK 2017 for MSVS2015.

 

---

 

Ok what gives? Using GetElementVertexColorCount I have discovered CreateElementVertexColor is creating both and giving me the pointer to the second one. Why is this happening like this? What am I missing here?
I can bypass the issue by calling GetElementVertexColor(0) after calling CreateElementVertexColor, but I am clearly very much misunderstanding how this is supposed to work, which is going to make things more difficult in the future.

 

0 Likes
Accepted solutions (1)
986 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

Ok, well, for some reason this forum doesn't allow you to delete your own threads.

I found out that there were two layers in the mesh and if I told the mesh to create vertex color elements it created them for all of its layers and returned the pointer to the last one made.

So the solution was to go in and grab the first layer and tell it specifically to create a vertex color element. Then it is the only layer with a vertex color element and everything works as would be expected.

 

Is there a document somewhere that explains the paradigm this structure was designed with?

0 Likes