Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fbx mesh export #285

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions examples/Prototype/ProgressiveMesh/GenericToPMToFbx/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ int main(int argc, char** argv)
}

// Processing
std::map<cd::MeshID, cd::NodeID> mapMeshToNodeId;
for (uint32_t nodeIndex = 0U; nodeIndex < pSceneDatabase->GetNodeCount(); ++nodeIndex)
{
const auto& node = pSceneDatabase->GetNode(nodeIndex);
for (uint32_t meshIndex = 0U; meshIndex < node.GetMeshIDCount(); ++meshIndex)
{
mapMeshToNodeId[node.GetMeshID(meshIndex)] = nodeIndex;
}
}

uint32_t meshCount = pSceneDatabase->GetMeshCount();
for (uint32_t meshIndex = 0U; meshIndex < meshCount; ++meshIndex)
{
Expand Down Expand Up @@ -71,9 +81,15 @@ int main(int argc, char** argv)
pm.InitBoundary(intersection);
}

auto lodMesh = pm.GenerateLodMesh(0.1f, 2000, &mesh);
auto lodMesh = pm.GenerateLodMesh(0.5f, 3000, &mesh);
lodMesh.SetName(std::format("{}_reduced", mesh.GetName()).c_str());
lodMesh.SetID(pSceneDatabase->GetMeshCount());
cd::MeshID lodMeshID(pSceneDatabase->GetMeshCount());
lodMesh.SetID(lodMeshID);
lodMesh.AddMaterialID(cd::MaterialID::InvalidID);

cd::NodeID nodeID = mapMeshToNodeId[mesh.GetID()];
pSceneDatabase->GetNode(nodeID.Data()).AddMeshID(lodMeshID);

pSceneDatabase->AddMesh(cd::MoveTemp(lodMesh));
}

Expand Down
47 changes: 22 additions & 25 deletions private/Consumers/FbxConsumer/FbxConsumerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,36 +290,33 @@ void FbxConsumerImpl::ExportMesh(fbxsdk::FbxScene* pScene, fbxsdk::FbxNode* pNod
}
}

if (mappingSurfaceAttributes)
// If using vertex instance, then init vertex index to attribute index.
for (const auto& polygonGroup : mesh.GetPolygonGroups())
{
// If using vertex instance, then init vertex index to attribute index.
for (const auto& polygonGroup : mesh.GetPolygonGroups())
for (const auto& polygon : polygonGroup)
{
for (const auto& polygon : polygonGroup)
for (cd::VertexID instanceID : polygon)
{
for (cd::VertexID instanceID : polygon)
{
cd::VertexID vertexID = mesh.GetVertexInstanceToID(instanceID.Data());
cd::VertexID vertexID = mappingSurfaceAttributes ? mesh.GetVertexInstanceToID(instanceID.Data()) : instanceID;

if (pNormalElement)
{
pNormalElement->GetIndexArray().SetAt(vertexID.Data(), instanceID.Data());
}
if (pNormalElement)
{
pNormalElement->GetIndexArray().SetAt(vertexID.Data(), instanceID.Data());
}

if (pBinormalElement)
{
pBinormalElement->GetIndexArray().SetAt(vertexID.Data(), instanceID.Data());
}

if (pTangentElement)
{
pTangentElement->GetIndexArray().SetAt(vertexID.Data(), instanceID.Data());
}

if (pAlbedoUVElement)
{
pAlbedoUVElement->GetIndexArray().SetAt(vertexID.Data(), instanceID.Data());
}
if (pBinormalElement)
{
pBinormalElement->GetIndexArray().SetAt(vertexID.Data(), instanceID.Data());
}

if (pTangentElement)
{
pTangentElement->GetIndexArray().SetAt(vertexID.Data(), instanceID.Data());
}

if (pAlbedoUVElement)
{
pAlbedoUVElement->GetIndexArray().SetAt(vertexID.Data(), instanceID.Data());
}
}
}
Expand Down
Loading