Working with .obj files. Need some help!

Started by
2 comments, last by Dark_Nebula 17 years, 4 months ago
Hello. I have a small app that can load and display given obj file, but my boss says that we need to optimize the displaying function. Currently it just go trough the all objects and drawing all the faces. He wants to optimize it by checking each triangle for visibility, and only if it visible - draw it. My problem is that i'm new in 3D. I don't know how to do that. So, from my point of view, i need to take a triangle and check if it visible on the screen. If i'm right, the problem can be solved by adding a routine that checks if my triangle fits or intersects with the screen rectangle. But i don't know this 3d math, so i can't undrstand how to "project" this triangle to the screen and how to check if it fits or intersects with the screen rectangle. Please help.
Advertisement
look into 'frustum culling'. It s basically a check to see if what you want to draw is in the view frustum. If it is not then don't draw it.

Hope it helps.
regards/thallishI don't care if I'm known, I'd rather people know me
Hmm.

I've just done reading some info about "frustum culling", and now i have some question about it since some things are not clear for me.

All this articles and tutorials shows how to cull whole objects not single triangles. So, if i will check every triangle for visibility it will be faster than just drawing it with glVertex3f, so openGl will do this culling for me?

My scene is a single big object and my target "as i understand" is to minimize calls to the glVertex3f by skipping invisible triangles (i'm not talking about backface culling here) so the camera can be set inside of this object. So i don't have any objects that i can cull, only triangles and triangles. And for me is not clear if my math for culling will be faster in the result than just pass this all triangles to the openGL, since openGL will not draw invisible triangles.




Quote:And for me is not clear if my math for culling will be faster in the result than just pass this all triangles to the openGL, since openGL will not draw invisible triangles.

You're on the right track. Culling of individual triangles on the CPU will be MUCH slower than just sending all triangles to the the graphics hardware directly. The GPU will perform screen-space clipping, back-face culling and depth culling for you.

There are a few things you might look into:
1) Use hardware Vertex Buffer Objects (VBO) (I think that's the OpenGL term, I'm a DX guy:)). This way you send the vertex data to the GPU once and not every frame like with glVertex3f(). Will probably give you a nice speedup depending on the triangle count of your mesh,
2) If your mesh (object) consists of many many triangles, you should consider preprosessing you mesh into a octtree, ABT or what ever spatial structure that suits your need and perform frustum culling using that structure.

And once again: NO per-tri culling on the CPU. Your boss is wrong.

Edit: cleared up the VBO thing.

This topic is closed to new replies.

Advertisement