Skip to content

Commit

Permalink
FBX exporter - handle multiple vertex color channels (assimp#5695)
Browse files Browse the repository at this point in the history
Co-authored-by: Kim Kulling <kimkulling@users.noreply.github.com>
  • Loading branch information
Kimbatt and kimkulling authored Aug 7, 2024
1 parent a37d748 commit 48c3a0e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions code/AssetLib/FBX/FBXExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,10 +1217,8 @@ void FBXExporter::WriteObjects ()
}

// colors, if any
// TODO only one color channel currently
const int32_t colorChannelIndex = 0;
if (m->HasVertexColors(colorChannelIndex)) {
FBX::Node vertexcolors("LayerElementColor", int32_t(colorChannelIndex));
for (size_t ci = 0; ci < m->GetNumColorChannels(); ++ci) {
FBX::Node vertexcolors("LayerElementColor", int32_t(ci));
vertexcolors.Begin(outstream, binary, indent);
vertexcolors.DumpProperties(outstream, binary, indent);
vertexcolors.EndProperties(outstream, binary, indent);
Expand All @@ -1230,7 +1228,7 @@ void FBXExporter::WriteObjects ()
"Version", int32_t(101), outstream, binary, indent
);
char layerName[8];
snprintf(layerName, sizeof(layerName), "COLOR_%d", colorChannelIndex);
snprintf(layerName, sizeof(layerName), "COLOR_%d", int32_t(ci));
FBX::Node::WritePropertyNode(
"Name", (const char*)layerName, outstream, binary, indent
);
Expand All @@ -1247,7 +1245,7 @@ void FBXExporter::WriteObjects ()
for (size_t fi = 0; fi < m->mNumFaces; ++fi) {
const aiFace &f = m->mFaces[fi];
for (size_t pvi = 0; pvi < f.mNumIndices; ++pvi) {
const aiColor4D &c = m->mColors[colorChannelIndex][f.mIndices[pvi]];
const aiColor4D &c = m->mColors[ci][f.mIndices[pvi]];
color_data.push_back(c.r);
color_data.push_back(c.g);
color_data.push_back(c.b);
Expand Down Expand Up @@ -1354,11 +1352,14 @@ void FBXExporter::WriteObjects ()
le.AddChild("Type", "LayerElementNormal");
le.AddChild("TypedIndex", int32_t(0));
layer.AddChild(le);
// TODO only 1 color channel currently
le = FBX::Node("LayerElement");
le.AddChild("Type", "LayerElementColor");
le.AddChild("TypedIndex", int32_t(0));
layer.AddChild(le);

for (size_t ci = 0; ci < m->GetNumColorChannels(); ++ci) {
le = FBX::Node("LayerElement");
le.AddChild("Type", "LayerElementColor");
le.AddChild("TypedIndex", int32_t(ci));
layer.AddChild(le);
}

le = FBX::Node("LayerElement");
le.AddChild("Type", "LayerElementMaterial");
le.AddChild("TypedIndex", int32_t(0));
Expand Down

0 comments on commit 48c3a0e

Please sign in to comment.