I've created a small piece of code which draws a 3D cube in my SWT application allowing to rotate it.
Now, I want to change each face/side of the cube and draw a different image on it, but I can't find how to do it (or at least, in an easy way, if that's possible).
I was able to change the complete texture of the cube to an image, but it change all the faces and I want to set a different image to each face. Is this possible? Any code example?
Thanks
Ok, based on the previous answer and some other forums I reach the following code that allows to set a different texture to each face of a cube:
Basically the line that allows to do that is the following one:
Taking into account that:
textureCube:
(defaultAppearance is just a basic Appearance object: Appearance defaultAppearance = new Appearance();)
The position is given by, as vembutech pointed out, TextureCubeMap class and their values for each face: POSITIVE_X, POSITIVE_Y, POSITIVE_Z, NEGATIVE_X, NEGATIVE_Y, NEGATIVE_Z.
And the appearance object is just an appearance object. I created mine appearance objects with this method:
This method creates an appearance based on an input file (f).
Cheers
Use TextureCubeMap class which is a sub class of Texture. The texture mapping can be used to apply images to faces of the cube.
You can do it by specifying the cube faces using xyz coordinates as positive and negative.
Refer the below link for its complete documentation.