我正在尝试使用ASSIMP从 ply 文件中提取顶点/法线/面信息,然后使用 OpenGL 渲染它。以下是代码:
void PLYParser::importFile(std::string sFilePath)
{
const aiScene* scene = aiImportFile (sFilePath.c_str(), aiProcess_Triangulate); // TRIANGLES!
if (!scene)
{
std::cerr << "ERROR: reading mesh %s\n" << sFilePath << std::endl;
return;
}
printf (" %i animations\n", scene->mNumAnimations);
printf (" %i cameras\n", scene->mNumCameras);
printf (" %i lights\n", scene->mNumLights);
printf (" %i materials\n", scene->mNumMaterials);
printf (" %i meshes\n", scene->mNumMeshes);
printf (" %i textures\n", scene->mNumTextures);
for (unsigned int m_i = 0; m_i < scene->mNumMeshes; m_i++)
{
const aiMesh* mesh = scene->mMeshes[m_i];
printf (" %i vertices in mesh\n", mesh->mNumVertices);
g_point_count = mesh->mNumVertices;
for (unsigned int v_i = 0; v_i < mesh->mNumVertices; v_i++)
{
if (mesh->HasPositions ())
{
const aiVector3D* vp = &(mesh->mVertices[v_i]);
printf (" vp %i (%f,%f,%f)\n", v_i, vp->x, vp->y, vp->z);
}
if (mesh->HasNormals ())
{
const aiVector3D* vn = &(mesh->mNormals[v_i]);
printf (" vn %i (%f,%f,%f)\n", v_i, vn->x, vn->y, vn->z);
}
if (mesh->HasTextureCoords (0))
{
const aiVector3D* vt = &(mesh->mTextureCoords[0][v_i]);
printf (" vt %i (%f,%f)\n", v_i, vt->x, vt->y);
}
if (mesh->HasTangentsAndBitangents ())
{
// NB: could store/print tangents here
}
if( mesh->HasFaces() )
{
const struct aiFace * vf = &(mesh->mFaces[m_i]);
if (vf->mNumIndices == 3)
{
printf (" vf (%f,%f,%f)\n", vf->mIndices[0],vf->mIndices[1], vf->mIndices[2]);
}
}
}
}
std::cout << "Parsing over" << std::endl ;
}
顶点值打印得很好,但是与面部相关的信息是一种垃圾,这种东西:
vp 5107 (0.003326,0.079200,0.001920)
vf (0.000000,-0.000000,26815622223676999148426976713858144581866377154979840994523259353566101584147672957460702289212360863380556296293016572911077072166495943380764853993996288.000000)
Q1。我在面部相关代码中做错了吗?
Q2。此外,我解析的任何 ply 文件中似乎都没有正常的相关信息。我必须手动计算一切的正常值。ply 根本没有正常信息吗?
PS:我已经在几个不同的层文件上尝试了代码,我仍然得到面部信息的垃圾值。
编辑 1:
for (unsigned int m_i = 0; m_i < scene->mNumMeshes; m_i++)
{
const aiMesh* mesh = scene->mMeshes[m_i];
printf (" %i vertices in mesh\n", mesh->mNumVertices);
g_point_count = mesh->mNumVertices;
for (unsigned int v_i = 0; v_i < mesh->mNumFaces; v_i++)
{
if (mesh->HasFaces())
{
for (unsigned int f_i = 0; f_i < mesh->mNumFaces; f_i++)
{
const struct aiFace* vf = mesh->mFaces + f_i;
if (vf->mNumIndices == 3)
{
printf(" vf (%u,%u,%u)\n", vf->mIndices[0], vf->mIndices[1], vf->mIndices[2]);
}
}
}
}
}
通过将代码更改为以上,我将备用数字作为输出 -
vf (0,1,2)
vf (3,4,5)
vf (6,7,8)
vf (9,10,11)
vf (12,13,14)
vf (15,16,17)
..
..
and so on.