smooth normals

Ive put together a simple *.stl viewer. Im loading a std::vector in
the format:

stlVertices[0] == normal
stlVertices[1] == vertex1
stlVertices[2] == vertex2
stlVertices[3] == vertex3
stlVertices[4] == normal
stlVertices[5] == vertex1
stlVertices[6] == vertex2
stlVertices[7] == vertex3


then I loop thru rendering each:

glBegin(GL_TRIANGLES);
for (int i=0; i<stlVertices.size(); i+=4)
{
glNormal3f( stlVertices[i]->m_pt[X] ,
stlVertices[i]->m_pt[Y],
stlVertices[i]->m_pt[Z]);

		glVertex3f(	stlVertices[i+1]-&gt;m_pt[X] ,
					stlVertices[i+1]-&gt;m_pt[Y],
					stlVertices[i+1]-&gt;m_pt[Z]);
		
		glVertex3f(	stlVertices[i+2]-&gt;m_pt[X] ,
					stlVertices[i+2]-&gt;m_pt[Y],
					stlVertices[i+2]-&gt;m_pt[Z]);
		
		glVertex3f(	stlVertices[i+3]-&gt;m_pt[X] ,
					stlVertices[i+3]-&gt;m_pt[Y],
					stlVertices[i+3]-&gt;m_pt[Z]);
	}

glEnd();

This will give you an idea of what Im looking at: http://personal.lig.bellsouth.net/lig/s/_/s_dolan/stl_capture.jpg

Do I have to use a normal on a per vertex basis to get a smoother
model, instead of a per triangle basis? I sort of understand how to do
this. You average the normals of the surrounding faces per vertex,
correct?

I think the stl formats triangle winding is reverse of what OpenGL
uses by default. If I reverse the winding as I load the vector and
remove the normal,is there a way OpenGL will smooth the normals for
me?

Sean

>Do I have to use a normal on a per vertex
>basis to get a smoother model, instead of
>a per triangle basis?

Yes, if you want smooth lighting. Note that
you can get the normal for a triangle by
just taking the cross product, so saving the
normals of vertexes is oftentimes better.
Also, if you save the actual vertex data of
each triangle, you get lots of duplicated
data; better save all the vertexes once, and
then a list of which vertexes make up each
triangle.

>I sort of understand how to do this. You
>average the normals of the surrounding
>faces per vertex, correct?

And normalize once you’re done. Also, this
works best if your triangles are “close” in
angle versus the viewer. If there is a sharp
corner, the arithmetic mean isn’t going to
cut it. Of course, for sharp corners, you
probably don’t want a smooth surface anyway
(and thus need multiple instances of the
same vertex, with different normals).

As far as winding order goes, I didn’t know
that STL defined any winding order at all.
Instead, I think it is whatever is giving
you the data in the first place which has
some winding order in it.

Thanks bgl, for clearning those questions up for me That model in my link has ~7k triangles in it. It’s actually an assymbly I exported out of SolidWorks. I think I’ll export something a bit simpler to work with Testing for the angles has to be kind of tough to implement. You’d have to know where to set the break angle between adjacent triangles. Something like an extruded block letter ‘D’ would be simple. Set the break angle at say > 80deg. This would give you boundaries for the face sets that make up the solid. But take something with more complex surfaces, and it would get a bit more complicated to find the boundaries. A lot of work ahead it looks like

Sean

i need your help … i also writing a stl viewer , i would like to know how you implement the smooth shading on the stl model
???

read above