- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
所以,过去一周半我一直在研究这个 .OBJ/.MTL 网格解析器。在这段时间里,我一直在追踪/修复很多错误、清理代码、记录代码等等。
问题是,每修复一个错误,仍然会出现这个问题,而且一张图片胜过一千个字......
使用 GL_LINE_LOOP
(注意:右侧的金字塔从球体向外倾斜是这里的问题)
使用 GL_TRIANGLES
更有趣的是,当这个“坏”顶点数据漂浮在场景周围时,它似乎会随着相机移动......只不过它会缩放并粘在网格之外。
这里奇怪的是,虽然我确信问题与内存有关,但我一直在检查与解析算法是否正常工作相矛盾的问题。经过一些单元测试,它似乎工作正常。
所以,我认为这可能是 Linux nVidia 驱动程序问题。我把驱动更新到下一个版本,重新启动,还是没有骰子。
经过深思熟虑,我一直在尝试找出以下代码中的错误。
//! every 3 vertices should represent a triangle, therefore we'll want to
//! use the indices to grab their corresponding vertices. Since the cross product
//! of two sides of every triangle (where one side = Vn - Vm, 'n' and 'm' being on the range of 1..3),
//! we first grab the three vertices, and then compute the normal using the their differences.
const uInt32 length = mesh->vertices.size();
//! declare a pointer to the vector so we can perform simple
//! memory copies to get the indices for each triangle within the
//! iteration.
GLuint* const pIndexBuf = &mesh->indices[ 0 ];
for ( uInt32 i = 0; i < length; i += 3 )
{
GLuint thisTriIndices[ 3 ];
memcpy( thisTriIndices, pIndexBuf + i, sizeof( GLuint ) * 3 );
vec3 vertexOne = vec3( mesh->vertices[ thisTriIndices[ 0 ] ] );
vec3 vertexTwo = vec3( mesh->vertices[ thisTriIndices[ 1 ] ] );
vec3 vertexThree = vec3( mesh->vertices[ thisTriIndices[ 2 ] ] );
vec3 sideOne = vertexTwo - vertexOne;
vec3 sideTwo = vertexThree - vertexOne;
vec3 surfaceNormal = glm::cross( sideOne, sideTwo );
mesh->normals.push_back( surfaceNormal );
}
图中当前显示的甚至没有法线数据,因此我们的想法是计算它的表面法线,因此有了上面的代码。虽然我已经进行了一些检查以查看索引数据是否在循环内正确加载,但我还没有找到任何内容。
我认为我布置内存的方式也可能有问题,但我不太清楚问题出在哪里。如果我错过了一些东西,我会加入 glVertexAttribPointer 调用:
//! Gen some buf handles
glGenBuffers( NUM_BUFFERS_PER_MESH, mesh->buffers );
//! Load the respective buffer data for the mesh
__LoadVec4Buffer( mesh->buffers[ BUFFER_VERTEX ], mesh->vertices ); //! positons
__LoadVec4Buffer( mesh->buffers[ BUFFER_COLOR ], mesh->colors ); //! material colors
__LoadVec3Buffer( mesh->buffers[ BUFFER_NORMAL ], mesh->normals ); //! normals
__LoadIndexBuffer( mesh->buffers[ BUFFER_INDEX ], mesh->indices ); //! indices
//! assign the vertex array a value
glGenVertexArrays( 1, &mesh->vertexArray );
//! Specify the memory layout for each attribute
glBindVertexArray( mesh->vertexArray );
//! Position and color are both stored in BUFFER_VERTEX.
glBindBuffer( GL_ARRAY_BUFFER, mesh->buffers[ BUFFER_VERTEX ] );
glEnableVertexAttribArray( meshProgram->attributes[ "position" ] );
glVertexAttribPointer( meshProgram->attributes[ "position" ], //! index
4, //! num vals
GL_FLOAT, GL_FALSE, //! value type, normalized?
sizeof( vec4 ), //! number of bytes until next value in the buffer
( void* ) 0 ); //! offset of the memory in the buffer
glBindBuffer( GL_ARRAY_BUFFER, mesh->buffers[ BUFFER_COLOR ] );
glEnableVertexAttribArray( meshProgram->attributes[ "color" ] );
glVertexAttribPointer( meshProgram->attributes[ "color" ],
4,
GL_FLOAT, GL_FALSE,
sizeof( vec4 ),
( void* ) 0 );
//! Now we specify the layout for the normals
glBindBuffer( GL_ARRAY_BUFFER, mesh->buffers[ BUFFER_NORMAL ] );
glEnableVertexAttribArray( meshProgram->attributes[ "normal" ] );
glVertexAttribPointer( meshProgram->attributes[ "normal" ],
3,
GL_FLOAT, GL_FALSE,
sizeof( vec3 ),
( void* )0 );
//! Include the index buffer within the vertex array
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, mesh->buffers[ BUFFER_INDEX ] );
glBindVertexArray( 0 );
至少任何方向正确的观点都会受到赞赏:我不知道这些问题的常见原因是什么。
编辑:根据请求发布抽奖代码
glBindVertexArray( mMeshes[ i ]->vertexArray );
UBO::LoadMatrix4( UBO::MATRIX_MODELVIEW, modelView.top() );
UBO::LoadMatrix4( UBO::MATRIX_PROJECTION, camera.projection() );
glDrawElements( GL_TRIANGLES, mMeshes[ i ]->indices.size(), GL_UNSIGNED_INT, ( void* )0 );
glBindVertexArray( 0 );
1 Câu trả lời
我找到了最终的罪魁祸首,结合@radical7的建议,这些解决了大部分问题。
// round mesh->indices.size() down if it's not already divisible by 3.
// the rounded value is stored in numTris
std::vector< vec4 > newVertices;
uInt32 indicesLen = Math_FloorForMultiple( mesh->indices.size(), 3 );
// declare a pointer to the vector so we can perform simple
// memory copies to get the indices for each triangle within the
// iteration.
newVertices.reserve( indicesLen );
const GLuint* const pIndexBuf = &mesh->indices[ 0 ];
for ( uInt32 i = 0; i < indicesLen; i += 3 )
{
const GLuint* const thisTriIndices = pIndexBuf + i;
vec4 vertexOne = mesh->vertices[ thisTriIndices[ 0 ] - 1 ];
vec4 vertexTwo = mesh->vertices[ thisTriIndices[ 1 ] - 1 ];
vec4 vertexThree = mesh->vertices[ thisTriIndices[ 2 ] - 1 ];
vec4 sideOne = vertexTwo - vertexOne;
vec4 sideTwo = vertexThree - vertexOne;
vec3 surfaceNormal = glm::cross( vec3( sideOne ), vec3( sideTwo ) );
mesh->normals.push_back( surfaceNormal );
mesh->normals.push_back( surfaceNormal + vec3( sideOne ) );
mesh->normals.push_back( surfaceNormal + vec3( sideTwo ) );
newVertices.push_back( vertexOne );
newVertices.push_back( vertexTwo );
newVertices.push_back( vertexThree );
}
mesh->vertices.clear();
mesh->vertices = newVertices;
请注意,当在循环中抓取顶点时,通过调用 mesh->vertices[ thisTriIndices[ x ] - 1 ]
,- 1
非常重要:OBJ 网格文件存储从 1...N 索引开始的面索引,而不是 0...N-1 索引。
索引本身也不应该用于绘制网格,而是作为从已经临时的顶点缓冲区中获取新的顶点缓冲区的一种方法:您使用索引来访问临时顶点中的元素,然后对于从临时缓冲区中获取的每个顶点,您将该顶点添加到新的缓冲区中。这样,您将获得以正确的绘制顺序指定的顶点数。因此,您只想使用顶点数组来绘制它们。
关于c++ - 不良顶点数据的常见陷阱/原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17333942/
我对cassandra并使用1.2.10非常陌生。我有一个时间戳数据类型的主键列。现在,我正在尝试检索日期范围的数据。由于我们知道不能在cassandra中使用,因此我使用的是大于()来获取日期范围。
我正在尝试进行有条件的转场。但我得到: Terminating app due to uncaught exception 'NSInvalidArgumentException', reas
我有一个游戏项目,在调试和发布模式下在设备上运行得非常好。我有两个版本。旧版本和新版本具有更多(后来我添加了)功能,并且两者的 bundle ID、版本相同。当我构建旧版本时,之前没有安装“myGam
这个问题已经有答案了: 奥 git _a (2 个回答) 已关闭 5 年前。 我正在获取 ClassCastException 。这两个类来自不同的 jar,但是JettyContinuationPr
以下代码行抛出异常: HttpResponse response = client.execute(request); // actual HTTP request 我能够捕获它并打印: Log
Hiện tại, câu hỏi này không phù hợp với định dạng Hỏi & Đáp của chúng tôi. Chúng tôi mong đợi câu trả lời được hỗ trợ bởi các sự kiện, tài liệu tham khảo hoặc chuyên môn, nhưng câu hỏi này có thể gây ra tranh luận, tranh cãi, thăm dò ý kiến hoặc thảo luận mở rộng. Nếu bạn cảm thấy câu hỏi này có thể được cải thiện và có thể mở lại, hãy truy cập
public class TwoThreads { private static Object resource = new Object(); private static void
当我输入 6 (int) 作为值时,运行此命令会出现段错误 (gcc filename.c -lm)。请帮助我解决这个问题。预期的功能尚未实现,但我需要知道为什么我已经陷入段错误。 谢谢! #incl
所以,过去一周半我一直在研究这个 .OBJ/.MTL 网格解析器。在这段时间里,我一直在追踪/修复很多错误、清理代码、记录代码等等。 问题是,每修复一个错误,仍然会出现这个问题,而且一张图片胜过一千个
我正在运行一个代码,它基本上围绕 3 个维度旋转一个大数据数组(5000 万行)。但是,我遇到了一个奇怪的问题,我已将其缩小到如何评估旋转矩阵。基本上,对于除绕 x 轴以外的任何旋转,python 代
就在你说这是重复之前,我已经看到了其他问题,但我仍然想发布这个。 所以我正在阅读 Thinking in Java -Bruce Eckel 这篇文章是关于小写命名约定的: In Java 1.0 a
我想在我的应用程序中使用 REST API。它为我从这个应用程序发出的所有请求抛出 SocketTimeoutException。 Logcat 输出:(您也可以在此处看到带有漂亮格式的输出:http
我知道 raise ... from None 并已阅读 How can I more easily suppress previous exceptions when I raise my own
在未能找到各种Unix工具(例如xargs和whatnot)的最新独立二进制文件(this version很好,但需要外部DLL)后,我承担了自己进行编译的挑战。 ...这是痛苦的。 最终,尽管如此,
我有一个用PHP编写的流套接字服务器。 为了查看一次可以处理多少个连接,我用C语言编写了一个模拟器来创建1000个不同的客户端以连接到服务器。 stream_socket_accept几次返回fals
我的Android Studio昨天运行良好,但是今天当我启动Android Studio并想在移动设备上运行应用程序时,发生了以下错误, 我在互联网和stackoverflow上进行了搜索,但没有解
默认情况下,grails似乎为Java域对象的toString()返回:。那当然不是我想要的,所以我尝试@Override toString()返回我想要的。当我尝试grails generate-a
尝试通过LDAP通过LDAP对用户进行身份验证时,出现以下错误。 Reason: Cannot pass null or empty values to constructor. 谁能告诉我做错了什么
我正在尝试使用应用程序附带的 Houdini Python 模块,该模块是 Houdini 安装文件夹的一部分,位于标准 Python 路径之外。按照安装说明操作后,运行 Houdini Termin
简单地说,我正在为基本数据库编写单链表的原始实现。当用户请求打印索引下列出的元素高于数据库中当前记录数量时,我不断出现段错误,但仅当差值为 1 时。对于更高的数字,它只会触发我在那里编写的错误系统。
Tôi là một lập trình viên xuất sắc, rất giỏi!