Texture
Texture[image_]wraps an Image (or any raster data) to be used as a surface texture in Graphics and Graphics3D primitives.
Examples
Texture on a 2D polygon
Only GraphicsComplex is suppored for texturing in the context of Graphics
Texture a triangle using GraphicsComplex:
img = ExampleData[{"TestImage", "Mandrill"}];
Graphics[{
Texture[img],
GraphicsComplex[{{0,0},{2,0},{1,2}}, Polygon[
{1,2,3}
], VertexTextureCoordinates -> {{0,0},{1,0},{0.5,1}}]
}]Automatic texture mapping:
Graphics[{
Texture[Array[BitXor, {128,128}]//Rescale//Image],
GraphicsComplex[RandomReal[{-1,1}, {3,2}], Polygon[{1,2,3}]]
}, Axes->True]Animation
Texture itself does not support updates, however texture coordinates as well as vertices and indices do (see GraphicsComplex):
vert2 = CirclePoints[0.7, 50]//N;
f = (*VB[*)(Uncompress["1:eJxTTMoPSmNkYGAo5gASbqV5ySWZ +XlpTCARFiARnlmSgeD5ZBaXQHjMQCI4taQYpLUAYgBIQXBOfkkmiIepqiSNASTEAyQck4 rzc0pLUkMyc1MRhgfklBZDzUOxMJMBbh4rkABpKi76s/LjJd +kAntU7RCHgG3NzEOTQjUgkwvFkS75JVitBolB7GdG1f4fCDJByqB +Q3OeMRg8tifBQXxEOQjkFkgAY3MQG9xBAJbbXNw="])(*,*) (*"1:eJxTTMoPSmNmYGAo5gUSYZmp5S6pyflFiSX5RcEcQBHP5Py8zKrUlEwBRgaGNCaQQ hYgEVSakxrMCmT4JCal5oBVJpXmpSfm5JcDACoeE98="*)(*]VB*);
Graphics[{
GraphicsComplex[vert2//Offload, {
LightBlue, Polygon[Range[1,50]], Red, Point[Range[1,50]]
}],
EventHandler[AnimationFrameListener[vert2//Offload],
Function[Null, vert2 = f /@ vert2]
]
}, PlotRange->{{-1,1}, {-1,1}}]
Texture on a 3D Sphere
img = ExampleData[{"TestImage", "Lena"}];
Graphics3D[{
Texture[img],
Sphere[]
}]Texture on a 3D Cube
img = ExampleData[{"TestImage", "Mandrill"}];
Graphics3D[{
Texture[img],
Cuboid[]
}]VertexTextureCoordinates on a 3D polygon
Manually control UV mapping on a 3D quad using VertexTextureCoordinates:
img = ExampleData[{"TestImage", "Lena"}];
Graphics3D[{
Texture[img],
Polygon[
{{-1, -1, 0}, {1, -1, 0}, {1, 1, 0}, {-1, 1, 0}}
]
}]Control UV mapping explicitly using GraphicsComplex:
img = ExampleData[{"TestImage", "Lena"}];
Graphics3D[{
Texture[img],
GraphicsComplex[
{{-1, -1, 0}, {1, -1, 0}, {1, 1, 0}, {-1, 1, 0}},
Polygon[{1, 2, 3, 4}],
VertexTextureCoordinates -> {{0, 1}, {0, 0}, {1, 0}, {1, 1}}
]
}]Animation
Texture itself does not support updates, however texture coordinates as well as vertices and indices do. See GraphicsComplex
Plot3D with texture as PlotStyle
Use a texture image as the surface colour via PlotStyle:
img = ExampleData[{"TestImage", "Lena"}];
Plot3D[Sin[x] Cos[y], {x, -Pi, Pi}, {y, -Pi, Pi},
PlotStyle -> Texture[img],
Mesh -> None
]ParametricPlot with texture (2D)
Map a texture onto a 2D parametric curve region by supplying Texture through PlotStyle:
img = ExampleData[{"TestImage", "Lena"}];
ParametricPlot[
{(1 + 0.3 s Cos[5 t]) Cos[t], (1 + 0.3 s Sin[5 t]) Sin[t]},
{t, 0, 2 Pi}, {s, 0, 1},
PlotStyle -> Texture[img],
Mesh -> None
]Texture from computed image data
Generate a procedural texture and apply it to a 3D surface:
data = Table[{Sin[x]^2, Cos[y]^2, 0.5}, {y, 0, Pi, Pi/99}, {x, 0, Pi, Pi/99}];
img = Image[data];
Graphics3D[{
Texture[img],
Sphere[]
}]Something isn't working? Report an issue.
Please visit the official Wolfram Language Reference for more details.