<p>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:</p>

<p><a href="https://i.sstatic.net/V9Szm.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/V9Szm.jpg" alt="enter image description here"></a>
(MeshLab)</p>

<p>So far, rendering using <a href="https://en.m.wikipedia.org/wiki/Ray_casting" rel="nofollow noreferrer">ray casting</a> 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.</p>

<p>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.</p>

<p>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 <a href="http://viewstl.com" rel="nofollow noreferrer">viewstl.com</a> being perfectly adequate.</p>

CC BY-SA 3.0
2017-08-04T18:39:55.130Z
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.
joojaa
CC BY-SA 3.0
2017-08-04T19:42:56.700Z
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)
Involute
CC BY-SA 3.0
2017-08-04T21:18:23.617Z
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.
joojaa
CC BY-SA 3.0
2017-08-04T21:49:33.047Z
I second joojaa's comments. Give triangles to OpenGL. You're right that ray casting would be way to computationally expensive.
PeteUK
<rendering><3d>
Rendering of large STL files
Involute
# Rendering of large STL files

(Asked by: username_0 on 2017-08-04)

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](https://i.sstatic.net/V9Szm.jpg)](https://i.sstatic.net/V9Szm.jpg)
(MeshLab)

So far, rendering using [ray casting](https://en.m.wikipedia.org/wiki/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](http://viewstl.com) being perfectly adequate.

**Tags:** rendering, 3d

> **Comments:**
> **username_1**: 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.  
> **username_0**: Hi username_1. 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)  
> **username_1**: 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.  
> **username_2**: I second username_1's comments. Give triangles to OpenGL. You're right that ray casting would be way to computationally expensive.  

---

## 0 answers

