c++ - 如何计算导入模型的顶点法线?
问题描述
我正在使用 Assimp 导入 3D 模型数据,但是网格提供的法线看起来不像在任何其他 3D 应用程序中那样。虽然我不知道其他 3d 应用程序是计算法线还是只是从文件中导入法线,但我无法确定问题出在我的渲染方式还是 normlas 上。
无论其他应用程序是使用网格提供的法线还是计算它们,我都必须实现一个 ComputeNormal 方法。
据我所知,我的渲染管道很好,因为在我使用硬编码顶点数据渲染立方体之前,我工作得很好。
CMesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene)
{
std::vector<Vertex> vertices;
std::vector<short> indices;
for (UINT i = 0; i < mesh->mNumVertices; i++)
{
Vertex vertex;
vertex.x = mesh->mVertices[i].x;
vertex.y = mesh->mVertices[i].y;
vertex.z = mesh->mVertices[i].z;
if (mesh->mNormals)
{
vertex.NormalX = mesh->mNormals->x;
vertex.NormalY = mesh->mNormals->y;
vertex.NormalZ = mesh->mNormals->z;
}
vertices.push_back(vertex);
}
for (unsigned int i = 0; i < mesh->mNumFaces; i++)
{
aiFace face = mesh->mFaces[i];
for (UINT j = 0; j < face.mNumIndices; j++)
indices.push_back(face.mIndices[j]);
}
CMesh ret = CMesh(vertices, indices);
return ret;
}
虽然法线加载正确,但模型看起来不像它在任何其他 3D 应用程序中应该或应该的样子。
解决方案
推荐阅读
- ocr - 从特定的 bbox 中读取数据
- python - 为什么conda切换环境后python版本没有切换?
- svelte - 在第 3 方库中复制后缓慢的 rollup.js 捆绑
- javascript - Electron / Angular 保存 desktopCapturer 抓取的图像
- android - 如何在 android studio 中使用 androidx.constraintLayout 文本修复灰屏
- regex - 右端第十个符号为 1 的所有 0 和 1 字符串集合的正则表达式是什么?
- python - django 数据库查询或条件
- c# - 身份提供者在数据库中时的 AddWsFederation() (ASP.NET Core 3.1/5.0)
- vhdl - Vivado 2020.1 错误“fixed_pkg”未在库“ieee_proposed”中编译
- string - 用后缀树查找两个单词中最长的子串