c++ - 在 FBX 中,如何知道哪些顶点索引对应于哪些控制点索引?
问题描述
我目前正在尝试加载用于 DirectX 的 FBX 网格,但我的 FBX 文件的 UV 由顶点索引存储,法线由控制点索引存储。我如何知道哪些顶点具有哪些控制点的值?
我的加载位置、uvs 和法线的代码是直接从 fbx 示例代码中提取的,但如果需要,我可以发布它。
编辑:根据要求,这是我正在谈论的代码部分。
UV 代码将通过 vert index 进入 if 语句进行映射模式,而普通代码通过 ctrl 点设置为映射模式
//load uvs
if (lUVElement->GetMappingMode() == FbxGeometryElement::eByControlPoint)
{
for (int lPolyIndex = 0; lPolyIndex < lPolyCount; ++lPolyIndex)
{
// build the max index array that we need to pass into MakePoly
const int lPolySize = mesh->GetPolygonSize(lPolyIndex);
for (int lVertIndex = 0; lVertIndex < lPolySize; ++lVertIndex)
{
//get the index of the current vertex in control points array
int lPolyVertIndex = mesh->GetPolygonVertex(lPolyIndex, lVertIndex);
//the UV index depends on the reference mode
int lUVIndex = lUseIndex ? lUVElement->GetIndexArray().GetAt(lPolyVertIndex) : lPolyVertIndex;
lUVValue = lUVElement->GetDirectArray().GetAt(lUVIndex);
_floatVec->push_back((float)lUVValue.mData[0]);
_floatVec->push_back((float)lUVValue.mData[1]);
}
}
}
else if (lUVElement->GetMappingMode() == FbxGeometryElement::eByPolygonVertex)
{
int lPolyIndexCounter = 0;
for (int lPolyIndex = 0; lPolyIndex < lPolyCount; ++lPolyIndex)
{
// build the max index array that we need to pass into MakePoly
const int lPolySize = mesh->GetPolygonSize(lPolyIndex);
for (int lVertIndex = 0; lVertIndex < lPolySize; ++lVertIndex)
{
if (lPolyIndexCounter < lIndexCount)
{
//the UV index depends on the reference mode
int lUVIndex = lUseIndex ? lUVElement->GetIndexArray().GetAt(lPolyIndexCounter) : lPolyIndexCounter;
lUVValue = lUVElement->GetDirectArray().GetAt(lUVIndex);
_floatVec->push_back((float)lUVValue.mData[0]);
_floatVec->push_back((float)lUVValue.mData[1]);
lPolyIndexCounter++;
}
}
}
}
//and now normals
if (lNormalElement->GetMappingMode() == FbxGeometryElement::eByControlPoint)
{
//Let's get normals of each vertex, since the mapping mode of normal element is by control point
for (int lVertexIndex = 0; lVertexIndex < mesh->GetControlPointsCount(); lVertexIndex++)
{
int test = mesh->GetControlPointsCount();
int lNormalIndex = 0;
//reference mode is direct, the normal index is same as vertex index.
//get normals by the index of control vertex
if (lNormalElement->GetReferenceMode() == FbxGeometryElement::eDirect)
lNormalIndex = lVertexIndex;
//reference mode is index-to-direct, get normals by the index-to-direct
if (lNormalElement->GetReferenceMode() == FbxGeometryElement::eIndexToDirect)
lNormalIndex = lNormalElement->GetIndexArray().GetAt(lVertexIndex);
//Got normals of each vertex.
FbxVector4 lNormal = lNormalElement->GetDirectArray().GetAt(lNormalIndex);
_floatVec->push_back((float)lNormal[0]);
_floatVec->push_back((float)lNormal[1]);
_floatVec->push_back((float)lNormal[2]);
}
}
else if (lNormalElement->GetMappingMode() == FbxGeometryElement::eByPolygonVertex)
{
//etc... code wont go here
}
}
}
}
那么我怎么知道哪些顶点会有哪些法线呢?
解决方案
推荐阅读
- konvajs - 在 Konva 中围绕指针缩放图像
- python - 用段落中的常用词制作字典
- angular - 错误:由模块“DynamicTestModule”导入的意外值“BrowserDynamicTestingModule”。请添加@NgModule 注释
- python - 如何在不清除屏幕的情况下每 5 秒重复一次代码?
- php - 重复错误:“不再支持带有花括号的数组和字符串偏移访问语法”与 phpmyadmin
- swiftui - 当在列表中将项目显示为 GridItem 时,NavigationLink 上的 SwiftUI 错误
- java - 你可以在 for 循环中更改 i 的值吗(java)
- sql - Databrick SQL - 将数据插入分区表
- aem - AEM 6 在 Touch UI 对话框中使用自动完成功能连接到自定义服务
- javascript - 我的列表功能在 javascript 中不起作用