taktoa
taktoa

Reputation: 554

Texturing a sphere primitive

I'm using Mathematica 8 and I am struggling with texturing. Although texturing of polyhedral objects has proved to be relatively simple, I hit a problem trying to texture a sphere. In the documentation, the only way to texture a sphere shown is using SphericalPlot3D, which, IMHO, is a kludgey solution, especially since I'm trying to perform operations (e.g.: translation) on the sphere. In toto, my question is: is there any way to texture a sphere primitive?

Upvotes: 11

Views: 2311

Answers (3)

Artes
Artes

Reputation: 1133

Something like this will be helpful :

enter image description here

enter image description here

sphere = SphericalPlot3D[1, {u, 0, Pi}, {v, 0, 2 Pi},
                             TextureCoordinateFunction -> ({2 #5, 1 - 2 #4} &), 
                             PlotStyle -> { Lighting -> "Neutral", Axes -> False,
                             Boxed -> False, Texture[texture]},     Mesh -> None][[1]];

F[k_] := Graphics3D[ Rotate[ sphere, k, {2, 1, 6}, {0, 0, 0}], Boxed -> False]

Now, we can animate a textured sphere rotating (around the vector {2, 1, 6} anchored at the point {0,0,0} ) :

Animate[F[k], {k, 0, 2 Pi}]

enter image description here

Upvotes: 6

cormullion
cormullion

Reputation: 1672

Just for completeness, you can also generate spheres with textures using ParametricPlot3D.

map = ExampleData[{"TestImage", "Lena"}];
sphere = ParametricPlot3D[{Cos[u] Sin[v], Sin[u] Sin[v], Cos[v]}, {u, 
  0, 2 Pi}, {v, 0, Pi}, Mesh -> None, 
TextureCoordinateFunction -> ({#4, 1 - #5} &), 
Lighting -> "Neutral", Axes -> False, Boxed -> False, 
PlotStyle -> Texture[Show[map]]]

lenasphere

If I understand correctly, Heike's answer shows that the first part of the result is a GraphicsComplex, which is a graphics primitive.

Upvotes: 3

Heike
Heike

Reputation: 24420

You can't texture a Sphere directly, but you could create a textured sphere using e.g. SphericalPlot3D and extract the first part to get a primitive which you can manipulate with Translate. For example

sphere = SphericalPlot3D[1, th, phi, Mesh -> False, PlotPoints -> 25,
  PlotStyle -> {Opacity[1], Texture[ExampleData[{"ColorTexture", "GiraffeFur"}]]},
  TextureCoordinateFunction -> ({#4, #5} &)][[1]];

Graphics3D[Translate[sphere, {{0, 0, 0}, {2, 2, 2}}]]

textured spheres

Upvotes: 12

Related Questions