Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 来自.ply文件的垃圾面相关信息_C++_Opengl_Mesh_3d Modelling_Assimp - Fatal编程技术网

C++ 来自.ply文件的垃圾面相关信息

C++ 来自.ply文件的垃圾面相关信息,c++,opengl,mesh,3d-modelling,assimp,C++,Opengl,Mesh,3d Modelling,Assimp,我试图使用从ply文件中提取顶点/法线/面信息,然后使用OpenGL进行渲染。代码如下: void PLYParser::importFile(std::string sFilePath) { const aiScene* scene = aiImportFile (sFilePath.c_str(), aiProcess_Triangulate); // TRIANGLES! if (!scene) { std::cerr << "ERRO

我试图使用从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 ;
}
Q1.我在人脸相关代码中是否做错了什么

Q2.此外,我解析的任何ply文件中似乎都没有正常的相关信息。我必须手动计算所有的正常值。你根本没有正常的信息吗

p.S.:我在几个不同的ply文件上尝试了该代码,但仍然会得到面部信息的垃圾值


编辑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]);
                      }
                  }
              }
          }
        }
A1

第一期:

printf ("      vf (%f,%f,%f)\n", vf->mIndices[0], vf->mIndices[1], vf->mIndices[2]);
vf->mIndices
的类型是
unsigned int*
,因此格式说明符
%f
是错误的,它应该是
%u
。请尝试以下方法:

printf ("      vf (%u,%u,%u)\n", vf->mIndices[0], vf->mIndices[1], vf->mIndices[2]);
第二期:

您需要迭代网格的面列表,就像当前对顶点列表所做的一样。只需删除处理顶点循环中的面的当前代码,然后为面添加另一个循环(与顶点的循环级别相同),如下所示:

for (unsigned int v_i = 0; v_i < mesh->mNumVertices; 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]);
        }
    }
}
for(无符号整数v_i=0;v_imNumVertices;v_i++)
{
// ...
}
如果(网格->HasFaces())
{
对于(无符号整数f_i=0;f_imNumFaces;f_i++)
{
const struct aiFace*vf=mesh->mFaces+f_i;
如果(vf->mNumIndices==3)
{
printf(“vf(%u,%u,%u)\n”,vf->mIndices[0],vf->mIndices[1],vf->mIndices[2]);
}
}
}
A2


在PLY文件中,可以为每个顶点指定法线信息(每个名为
nx
ny
nz
的顶点元素有3个附加的
float
属性)。由于格式灵活,每个面的法线也可以用类似的方式指定。这完全取决于用于生成此文件的工具导出的内容。

现在它只为每个面打印此值:
vf(0,1,2)
@AmitTomar我遗漏了代码中的另一个主要问题,请查看最新编辑。我做了必要的修改,但现在打印了备用编号。请检查编辑。@AmitTomar是什么让你认为这些数字是错误的?您是否与PLY文件中存储的数据进行了比较?@AmitTomar 1。你真的应该将切面的索引与PLY文件中的索引进行比较(否则你怎么知道结果是否正确?)。这些数字是指顶点列表的索引,因此这些索引按顺序排列并不令人震惊。3.检查OpenGL示例(第200-223行):
printf ("      vf (%u,%u,%u)\n", vf->mIndices[0], vf->mIndices[1], vf->mIndices[2]);
for (unsigned int v_i = 0; v_i < mesh->mNumVertices; 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]);
        }
    }
}