I am creating a Graphics3D object for a box using 6 Polygons (1 per side). I can use one single Texture on one or more sides but I can not find a way to use different Textures for different sides of the box. Is there any way to achieve this?
Answer
You can set Texture
before each polygon
t = ImageResize[ExampleData@#, {100, 100}] & /@
ExampleData["ColorTexture"][[;; 6]];
vtc = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
coords = {{{0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}}, {{0, 0,
0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1}}, {{1, 0, 0}, {1, 1, 0}, {1,
1, 1}, {1, 0, 1}}, {{1, 1, 0}, {0, 1, 0}, {0, 1, 1}, {1, 1,
1}}, {{0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {0, 1, 1}}, {{1, 0,
1}, {1, 1, 1}, {0, 1, 1}, {0, 0, 1}}};
Graphics3D[{Table[{Texture@t[[i]],
Polygon[coords[[i]], VertexTextureCoordinates -> vtc]}, {i, 6}]}]
Or you can use one texture with proper texture coordinates like in cube maps
cubemap = ImageResize[#, Scaled[0.5]] &@ Import@"http://i.stack.imgur.com/hSCfz.jpg";
vtccm = {{##}, {# + 1, #2}, {# + 1, #2 + 1}, {#, #2 + 1}} & @@@ {{1,
1}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, {1, 3}}/4;
α = 0.;
Graphics3D[{EdgeForm[], Texture[cubemap],
Polygon[coords, VertexTextureCoordinates -> vtccm]},
Lighting -> {{"Ambient", White}}, Boxed -> False, ViewAngle -> 1,
ViewCenter -> {1, 1, 1}/2,
ViewVector -> {1, 1, 1}/2 + {Cos[α], Sin[α], 0}/8,
RotationAction -> "Clip", ImageSize -> 500,
ViewVertical -> {0, 0, 1}]
There is no visible joints!
Related: Implementing a first person view of 3D objects in a scene
Comments
Post a Comment