I'm trying to figure out a way to display an STL file in iOS. This has turned out to be much harder than expected. Does anyone have any ideas? Would I be able to post some code here, or is everyone going to tell me to use ASSIMP?
Display an STL file in iOS?
Members - Reputation: 102
Posted 24 September 2013 - 03:52 PM
Cool. Let's talk about this then. It has really been holding up my current project. I am the only developer on the project. Basically it's my baby. I'm trying to display an STL file in OPENGL for both Mac and iOS. I don't really have any OPENGL code yet because I have not even gotten past extracting the data from the file.
Really, I have no idea where to even start, and I could be just deluding myself. I'm not even sure if the suggestions I have seen will even work. Can anyone here help me?
Members - Reputation: 436
Posted 30 September 2013 - 02:15 AM
Let's better start with OpenGL and then try to load file. A good point is the xcode opengl game template (look at it for details). Basically you will need to load all triangles from the file into a float array. This will be quite easy as the file is pure text. The array should contain vertices of the triangles, it will look like that: x00,y00,z00,nx0,ny0,nz0, x01,y01,z01,nx0,ny0,nz0, x02,y02,z02,nx0,ny0,nz0, x10,y10,... - where x,y,z are position points of each triangle and nx,ny,nz are normal vectors (at each point). Look that in STL normal is per triangle but in OpenGL it is per vertex (you need to duplicate it). Then you need to go to opengl. Create and bind Vertex Object Array (glGenVertexArraysOES, glBindVertexArrayOES) in which you generate OpenGL buffer (glGenBuffers), bind it (glBindBuffer), copy all data to GPU (glBufferData), setup the vertex attributes (glEnableVertexAttribArray, glVertexAttribPointer) to match the format in the array. On the end close array (glBindVertexArrayOES(0)). Then you may bind it again (glBindVertexArrayOES) and draw all (glDrawArrays).
Edited by mawigator, 30 September 2013 - 02:19 AM.