Tom van Zummeren
Tom van Zummeren

Reputation: 9220

I need help to draw an icosahedron 3D object in an UIKit app

Although I am quite experienced with most frameworks in iOS, I have no clue when it comes to 3D modelling. I even worked with SpriteKit, but never with something like SceneKit.

Now a customer wants a very ambitious menu involving a 3D object, an 'icosahedron' to be exact. I want it to look something like this:

Icosahedron shape example

So I just want to draw the lines, and grey out the 'see-through' lines on the back. Eventually I want the user to be able to freely rotate the object in 3D.

I already found this question with an example project attached, but this just draws a simple cube: Stroke Width with a SceneKit line primitive type

I have no clue how to approach a more complex shape.

Any help in the right direction would be appreciated! I don't even need to use SceneKit, but it seemed like the best approach to me. Any other suggestions are welcome.

Upvotes: 2

Views: 3525

Answers (1)

mnuages
mnuages

Reputation: 13462

to build an icosahedron you can use SCNSphere and set its geodesic property to YES.

Using shader modifiers to draw the wireframe (as described in Stroke Width with a SceneKit line primitive type) is a good idea.

But in your case lines are not always plain or dotted — it depends on the orientation of the icosahedron. To solve that you can rely on gl_FrontFacing to determine whether the edge belongs to a front-facing or back-facing triangle.

Upvotes: 3

Related Questions