I want to use this image as a material for a SCKSphere:
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:
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:
In the simplest possible terms, texture mapping means taking an image and stretching it over the surface of a 3D object. We refer to an image used in this manner as a texture, and we can use textures to represent material properties like color, roughness, and opacity.
If you select an appearance after it is applied to your model you will see a texture mapping tab, which contains a Mode dropdown box to alter the way that the texture is applied to a model. There are several settings here to alter the way Visualize maps the appearance onto the model.
Using UV mapping, we divide the texture up into a 2D grid with the point (0,0) at the bottom left and the point (1,1) at the top right. Then, the point (0.5,0.5) will be at the exact center of the image.
This will make working with the textures easier. If you select an appearance after it is applied to your model you will see a texture mapping tab, which contains a Mode dropdown box to alter the way that the texture is applied to a model. There are several settings here to alter the way Visualize maps the appearance onto the model.
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.
Real-time texture mapping is generally done with 'UV' texture coordinates that define which pixel in the image is pinned to which vertex in the mesh. Between these pins, the image is just stretched linearly. For a curved surface, this approximation will result in visible artifacts if the flat polygons approximating the surface are too coarse. That's why increasing the segments (and thus smoothness) in the sphere made the image look better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With