如果我有一个顶点数组,如何以适合循环并绘制三角形带的方式对它们进行排序?
我开始学习如何读取 Collada 文件 (.dae) 中打包的数据。我已经有了特定网格的顶点。现在,我只是在调用 glBegin 和 glEnd 之间循环遍历它们,我注意到并非所有的面都被渲染。我认为这可能是因为顶点的顺序不正确,无法形成有效的三角形带。我意识到也许这个问题应该针对 Blender .dae 导出器,因为这就是我正在使用的。
这是我正在使用的确切代码:
//Vertices is a vector of vertices that I pulled from the collada file.
glBegin(GL_TRIANGLE_STRIP);
for(int i = 0; i != Vertices.size(); i++)
{
glVertex3f(Vertices[i]->x, Vertices[i]->y, Vertices[i]->z);
}
glEnd();
我尝试加载的模型是一个简单的平面。这是顶点的内容:
1: 1, 1, 0
2: 1, -1, 0
3: -1, -1, 0
4: -1, 1, 0
I started learning about reading the data packed in a Collada file (.dae). I'm to the point where I have the vertices of a specific mesh. Right now, I'm just looping through them between calls to glBegin and glEnd, and I noticed that not all of the faces were being rendered. I think it might be because the vertices aren't in the correct order to form a valid triangle strip. I realized that maybe this question should be aimed at the blender .dae exporter, since that's what I'm using.
This is the exact code I'm using:
//Vertices is a vector of vertices that I pulled from the collada file.
glBegin(GL_TRIANGLE_STRIP);
for(int i = 0; i != Vertices.size(); i++)
{
glVertex3f(Vertices[i]->x, Vertices[i]->y, Vertices[i]->z);
}
glEnd();
The model I'm trying to load is a simple plane. Here's the contents of Vertices:
1: 1, 1, 0
2: 1, -1, 0
3: -1, -1, 0
4: -1, 1, 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的,如果你想绘制一个简单的平面,这不是一个有效的三角形带。
您应该按该顺序绘制顶点:
您正在绘制的是:
看起来导出器中存在问题..
You're right this is not a valid triangle strip if you want to draw a simple plane.
You should draw your vertices in that orders:
What you are drawing is that:
Looks like a problem in the exporter..