Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 970
stonesam92 Avatar asked Mar 25 '15 22:03

stonesam92


People also ask

What is texture mapping?

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.

How do I change the way a texture is applied to models?

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.

How do you find the exact center of a texture?

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.

How do I make working with the textures easier?

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.


Video Answer


2 Answers

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.

like image 96
stonesam92 Avatar answered Oct 08 '22 18:10

stonesam92


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.

like image 24
bonnie lapin Avatar answered Oct 08 '22 18:10

bonnie lapin