• Advertisement
Sign in to follow this  

Display an STL file in iOS?

This topic is 1573 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement

You should tell more about your problem. I wouldn't suggest using any external libraries just for STL, because it's quite simple format.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement