- Home /
How can i paint texture on Mesh Runtime?
Hi! I want to paint texture on Mesh like I am making game in which i have to use nail Polish. I want to make realistic Nail Polish effect. I which i have to paint mesh on small small portions of nail. User can put different type of nail art/polish on one nail. It might b done with shaders bit I dont have any idea, which and how it could be done. Any package or shader anyone could recommend? I would be very thankful. I have attached image for refrence.
you wouldn't paint the mesh, you would paint the texture. if i had this task i would use a UI image for the hand. and paint/adjust an overlaying texture based on mouse position. this happens with lining up mouse position with texture coodinates.
here is a script example that uses the pixels from one image to draw another. it only paints where the hand image is not transparent but you could also check other colors or get the check from another textrue map for borders. any ways i hope this points you in the right direction!
Color c;
// import settings of Textures must me marked = read/write enabled!!
public Texture2D paint;//<image to take color from
public Texture2D hand;// <image of your hand.
public float mx,my;
int x,y,i,i2;
void Start () {
if (paint == null) {
hand = new Texture2D (400, 300);
//just making some randome noise for background im
// for example
x=hand.width;y=hand.height;
paint = new Texture2D (x, y);
while(x>0){x--;
y=hand.height;while(y>0){y--;
hand.SetPixel(x,y,Color.white);
if(i>20){i=0;}
i++;if(i>10){
paint.SetPixel(x,y,new Color(1,0,1));}
else{paint.SetPixel(x,y,new Color(.2f,0,0));}
}}}
paint.Apply ();
hand.Apply ();
}
void Update () {
mx = Input.mousePosition.x;
my = Input.mousePosition.y;
if (Input.Get$$anonymous$$ouseButton (0)) {
mx=(mx/Screen.width)*paint.width;
my=(my/Screen.height)*paint.height;
x=10;
while(x>0){x--;
y=10;
while(y>0){y--;
c = paint.GetPixel((int)mx+x,(int)my+y);
//transparent pixesl in hand do not get painted!!!
//or set any color requirement here!
if(hand.GetPixel((int)mx+x,(int)my+y).a>.5f){
hand.SetPixel ((int)mx+x,(int)my+y,c);}} }
hand.Apply();}}
void OnGUI(){
GUI.DrawTexture (new Rect(0, 0, Screen.width, Screen.height),hand);}
}
thank you so much for your reply and really sorry for late reply didn't check on weekend. Just trying your method.