C++ Assimp opengl加载模型顶点某些值大于1
我从learnopengl.com获得以下代码C++ Assimp opengl加载模型顶点某些值大于1,c++,opengl,assimp,C++,Opengl,Assimp,我从learnopengl.com获得以下代码 void Model::load_model(string path) { //read file via ASSIMP Assimp::Importer Importer; const aiScene* scene = Importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs); //check for err
void Model::load_model(string path)
{
//read file via ASSIMP
Assimp::Importer Importer;
const aiScene* scene = Importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
//check for errors
if(!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)// if not zero
{
cout << "error, assimp ," << Importer.GetErrorString() << endl;
return;
}
//retrieve the directory path of the filepath
directory = path.substr(0, path.find_first_of('/'));
process_node(scene->mRootNode, scene);
}
/*
* Process a node in a recursive fashion . Process each individual mesh located at the node and repeat this process on its children nodes (if any)
*/
void Model::process_node(aiNode* node, const aiScene* scene)
{
for( GLuint i = 0; i < node->mNumMeshes; i++ )
{
//the node object only contains indices to index the actual objects of the scene.
//The scene contains all the data , node is just to keep stuff organized( like relations between nodes )
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
meshes.push_back(process_mesh(mesh, scene));
}
//after we've processed all the meshes ( if any ) we then recusrsively process each of the children nodes
for(GLuint i = 0; i < node->mNumChildren; i++)
{
process_node(node->mChildren[i], scene);
}
}
Mesh Model::process_mesh(aiMesh* mesh, const aiScene* scene)
{
//data to fill
vector<Mesh::Vertex> vertices;
vector<GLuint> indices;
vector<Mesh::Texture> textures;
//walk through each of the meshes vertices
for(GLuint i = 0; i < mesh->mNumVertices; i++)
{
Mesh::Vertex vertex;
// we declare a placeholder vector since assimp uses its own vector class that doesn't directly convert to glm's vec3 class
//so we transfter the data to this placeholder glm::vec3 first
glm::vec3 vector;
//positions
vector.x = mesh->mVertices[i].x;
vector.y = mesh->mVertices[i].y;
vector.z = mesh->mVertices[i].z;
vertex.position = vector;
//normals
vector.x = mesh->mNormals[i].x;
vector.y = mesh->mNormals[i].y;
vector.z = mesh->mNormals[i].z; ...
我导入的obj文件没有任何大于1的值,这将导致渲染失败。问题可能在哪里?模型的位置与其模型坐标系相关。所以它们可以变得更大,小于1,-1或其他。OpenGL对于任何值都不限于[0…1]的范围。因此,当渲染器需要从0到1的范围时,您需要:
或者重写渲染器,使其能够渲染任意坐标。opengl也可以渲染值大于1的顶点?看起来与C完全不同:P3D模型不限于任何特定大小。OpenGL在这方面也没有限制。它唯一的限制是投影后的顶点必须在所有轴上的[-1,1]范围内才能可见。我再次检查了3D模型,是的,存在大于1的值,因此上述代码按预期工作。使用renderdoc,我可以看到位置的缓冲区内容以小数字结尾,如
1.1204E-44
。所有缓冲区内容都以某种方式设置为如此小的指数数字。
x1: 1.58967 Y1: -0.618526 z1: -0.683333
x1: 1.58939 Y1: -0.626895 z1: -0.681676