Hi all
I'm trying to write a simple viewer that can display stl files. and example of an stl file is:
solid square.stl
facet normal -1 0 0
outer loop
vertex 50 50 0
vertex 250 250 0
vertex 50 250 0
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 50 50 0
vertex 250 50 0
vertex 250 250 0
endloop
endfacet
endsolid square.stl
So far my program can read in all the normals and vertices fine. However when it comes to displaying it sometimes you can see the back parts through the front parts, or parts appear flat instead of being solid.
The rendering options I'm using are:
Dim presentParams As New PresentParameters()
presentParams.Windowed = True
presentParams.SwapEffect = SwapEffect.Discard
' for lighting
presentParams.EnableAutoDepthStencil = True
presentParams.AutoDepthStencilFormat = DepthFormat.D16
device = New Device(0, DeviceType.Hardware, Me.DirectXScreen, CreateFlags.SoftwareVertexProcessing, presentParams)
device.RenderState.Lighting = True
device.RenderState.ZBufferEnable = True
device.RenderState.CullMode = Cull.CounterClockwise
All the vertices are stored in a vertex buffer and rendered like this:
setuplights()
SetupMatrices()
device.SetStreamSource(0, VertexBuffer, 0)
device.VertexFormat = CustomVertex.PositionNormal.Format
device.DrawPrimitives(PrimitiveType.TriangleList, 0, Me.FacetList.Count)
The problem with STL files is that the facets are not declared in any order. i.e. you could have the head declared first, then the toes, then the neck, then fingernail, then torso etc..
Is it likely that because of this there is some problem with the rendering?
If anyone needs more code or can already spot an error, I would be really grateful for some advice.
Many thanks
DRB2k2