- Home /
Change a cube face with another texture
Hello,
My question is hard for me to explain so please, do not hesitate to ask me for more details.
I work with a cube. This cube has a texture applied thanks to UV mapping in order to have a different color for each face of the cube. While the game is running I'd like to change one of the face of this cube to another texture (for example replacing the blue face by the "skull" texture). Then, this new face has to behave like it's actually a face of the cube (ie: when I rotate the cube, the face rotate as it's the actual blue face).
I looked for a solution and the simplest seems to be:
Instantiate a quad
Change the quad material to "skull texture"
Change rotation / position (minus very small number in order to avoid z-fight) to make it appear in front of the right face of the cube
Change the transform.parent to the cube transform property
Because the original cube on what I try to change a face may have already rotate (several time), I can't manage to correctly align the quad on the right face.
I hope my question is clear enough. If you have some other way to proceed and achieve the same thing, do not hesitate to share it.
Thank you.
I woul manipulate the uv or make the cube to have six submeshes and six materials to access them independently - or alternatively assembly the cube fom six planes and you could have individual colliders for individual mouse interaction as well
I think @Fattie is right. I can't manage to use decal yet... so playing with uv sounds too hard for me right now.
Answer by Fattie · Jul 01, 2012 at 02:25 PM
PS --- in an actual game you knwo how I would do this? Just swap it to ANOTHER DIFFERENT CUBE! it's that simple. Heh!
YES. what you're doing is just called a
Decal
it's a great idea! Go for it.
i suggest you search on "decal" and read all about the various techniques thereof.
Note that you could also use a "projector", if you like, for a different effect.
I can't find informations usefull about coordinates and how to correctly put the decal in the right spot.
About your PS: Changing the actual cube by another with the face would mean that you would need 6 different cubes for 1 changing face (1 per different face)... if you have to deal with a lot of "new faces" it would mean a lot of extra cubes. Also, you wouldn't be able to rotate the texture in order to have it in the "right" way.
Answer by Ashkan_gc · Jul 01, 2012 at 03:30 PM
Create a cube in max with 6 materials and submeshes and then easily assign different textures at runtime to different materials or just use a texture for the material with 6 defined parts for each side and change the data for that part at runtime using SetPixels method of Texture2d class. The first method is faster in some ways and slower in some other, If it's not a common thing to change texture use the SetPixels method because rendering one material is faster than 6 ones.
Using SetPixel should be fine... however, does it work if I intend to use some render to texture on my quad?
Answer by reptilebeats · Jul 01, 2012 at 05:11 PM
one trick i sometimes use, never for changing objects though is to use lights with a cookie. i mainly use it for graffiti as you get a nice effect after its baked blends in like graffitie would.
depending on what your doing you could do that, or have seperate cube textures with transparent sides over the cube, probably best bet is just to have flat images parented to the cube that are either enabled or disabled at run time, a bit like gui