2
$\begingroup$

I am in the process of creating some software in Java for generating 3D gear geometry and saving it as an STL file. I am looking at a means of drawing the geometry so that the user can view the geometry before saving as an STL file. The intended result should appear along the lines of the following:

enter image description here (MeshLab)

So far, rendering using ray casting appears to be the best way to approach this. For each pixel, a ray is extended out from the camera in the appropriate direction and its intersection with the triangles that make up the geometry is tested, keeping the closest intersection: simple in concept, doesn't mess around with unnecessary effects, and seems like it should run fast.

My main concern is: will it render fast enough? In my program, it should be possible to rotate and pan the visualisation, and have it render on the fly. My concern stems from this: the largest screen I want to draw the visualisation on will be 1280px by 800px (although in general use it may be somewhat less than this), which means up to 1024,000 pixels need to be processed, and so an equal number of rays will be projected. In each 3D geometric part, there could easily be upward of thousands of triangular facets. That already means have to perform at least $10^9$ operations, a number similar to the order of magnitude of operations per second. Surely it appears ray-casting won't run fast enough, especially if you want to refresh the visualisation at a rate of 10Hz.

What is done to ensure that the rendering is done quickly enough? Is it a matter of using a single ray for every 2x2, 3x3 or larger sub-array of pixels? Is an alternative algorithm to ray casting used? There certainly appears to be a solution to this, as STL visualisation software is not a new thing, with the app MeshLab and the site viewstl.com being perfectly adequate.

$\endgroup$
  • 4
    $\begingroup$ Hi and welcome. Why would you use ray casting? Why not just dump the triangles to opengl and let it render with a rasterizer? Its not like you need reflections or have complex transparency sorting. Even your geometry is not very complex. $\endgroup$ – joojaa Aug 4 '17 at 18:39
  • $\begingroup$ Hi joojaa. I'm not very experienced with coding (I'm a mechanical engineer by trade); I know the basics to Java coding, but outside of using Java swing, I have no experience with computer graphics. What I'm getting about opengl is that it's to do with writing graphics code that takes better of advantage of the screen's hardware. If you could point me in the write direction, I'd really appreciate that. :) (I've been getting by using Java with Eclipse) $\endgroup$ – SprocketsAreNotGears Aug 4 '17 at 19:42
  • 3
    $\begingroup$ So am I, a mechanical engineer that is. You should really take your time to go through some modern OpenGL (but not legacy opengl) tutorial to understand the concepts. $\endgroup$ – joojaa Aug 4 '17 at 21:18
  • 3
    $\begingroup$ I second joojaa's comments. Give triangles to OpenGL. You're right that ray casting would be way to computationally expensive. $\endgroup$ – PeteUK Aug 4 '17 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.