stonesam92 stonesam92 - 11 months ago 117
iOS Question

What is the correct way to map textures onto SCNSphere

I want to use this image as a material for a SCKSphere:

enter image description here

I can do this as follows:

SCNSphere *sphereGeometry = [SCNSphere sphereWithRadius:5];
sphereGeometry.firstMaterial.diffuse.contents = [UIImage imageNamed:@"navball.png"];

However, when I run the application, the image has been distorted as it is mapped onto the sphere, and the lines that run from the top to the bottom of the sphere are no longer straight:

enter image description here

Is there any way to ensure that the material is mapped onto the sphere correctly and the lines remain straight?

This image on the left below shows what I was expecting, and the image on the right shows what I'm experiencing - wavy lines when I would expect them to be straight:

enter image description here


I solved the problem by increasing the sphere geometry's segmentCount value, which increases the detail of the polygon mesh used to render the shape, making it appear "smoother".

For more details see the SCNSphere documentation.