Jump to content

  • Log In with Google      Sign In   
  • Create Account


Display an STL file in iOS?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 CamaroSS   Members   -  Reputation: 102

Like
0Likes
Like

Posted 24 September 2013 - 12:33 PM

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?



Sponsor:

#2 Sponji   Members   -  Reputation: 1138

Like
0Likes
Like

Posted 24 September 2013 - 01:31 PM

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


Derp

#3 CamaroSS   Members   -  Reputation: 102

Like
0Likes
Like

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?



#4 mawigator   Members   -  Reputation: 367

Like
0Likes
Like

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.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS