Jump to content
  • Advertisement
Sign in to follow this  
EricM81

Fast Thumbnail Generator

This topic is 869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am out of my depth here and just wanted to get some feedback before I spend a few days building this thing.
 
I need to generate thumbnail previews for a large high poly STL library (500k is my average triangle count). It needs to be light and fast, not accurate.  My plan is to sudo ray trace the mesh with an orthogonal view (-30deg X, 30deg Z).
 
As I read the STL, for each triangle I check the dot product of the facet normal and my orthogonal view normal and if it's >=0, I know it's forward facing and to keep it. I save the dot product (4 bytes - later used for shading) and vertex1 (3pts x 4bytes = 12bytes). I figure that since I'm translating 500k triangles into 200 pixels, 1 vertex is as good as 3. That drops the number of subsequent operations and the 500k mesh's memory footprint from 24MB down to 4MB ((4 + 12) x 250k vs 12 x 4byte points x 500k).
 
Next I'll do a matrix transformation on all the vertex points to convert them to my desired orthogonal view. Then search to find the XY bounding box and divide that up based on my resolution into pixel boundaries. For each pixel boundary, I grab my saved dot product for the point that is nearest to the camera and use that to assign each pixel's color.
 
Thoughts?

Share this post


Link to post
Share on other sites
Advertisement

Sorry, I've never done any rendering before, only basic vertex math.  After skimming a rasterization algorithm, am I not doing a version of that?  

 

I said sudo ray tracing because I'm not casting a ray to find the triangle.  I will have many triangles per pixel, which is why I thought it would be okay to just transform a single vertex point of each triangle onto an orthogonal plane.  Then I divide the plane into pixel boundaries and pick the closest point to the camera to represent that pixel.  The dot product of the facet normal and the orthogonal view is normalized, so I'd just convert that 0-1 value to grayscale.

Edited by EricM81

Share this post


Link to post
Share on other sites
What if you have a triangle with a vertex in one pixel and a vertex in a different pixel? I'm not clear on how your approach handles that case.

Share this post


Link to post
Share on other sites
I'm ignoring that case. I know it's unorthodox, but I need speed over accuracy. The only way I can get sub 1 sec renders of 500k meshes is with a novel approach.


I'm hoping you guys with experience can tell me if this is a novel solution or flat out stupid.

Another idea I had was a background indexing service that generated sidecar renders, but that seemed like overkill. It would be more straightforward, though. I could just use OpenGL and grab the first frame from the GPU.

Share this post


Link to post
Share on other sites

You should create a thumbnail cache, create thumbnails for all files and then only display the cached image. Update them when the STL file changes or when new files are added.

 

Also I was a bit bored and needed some practice, so I created an STL thumbnail generator. It also seems to be fast enough. I have tried it with a >1M triangle file and it took only 0.7s. And that includes reading the file, recalculating all normals, uploading it to the GPU, rendering it and saving it as a PNG. Maybe you can use some of my code take some ideas from it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!