c# - How to set up UVs for Texture borders -
i'm generating plane able scale without edges of texture being affected pixel wise. plane needs able keep border proportion able stretch size. mesh has 8 vertices , 10 triangles make border. anyway here get. ignore numbers on mesh geometry.
is possible edit uvs desired result? here's code:
mesh mesh = new mesh(); var renderer = mesh.addrenderer(); //create verticies mesh.vertices = new vector3[] { //vertices in order convienience manager.gui.screentoworldpoint(new vector3(0f,0f,0f)), //0 manager.gui.screentoworldpoint(new vector3(padding,padding,0)), //1 manager.gui.screentoworldpoint(new vector3(width - padding, padding,0f)), //2 manager.gui.screentoworldpoint(new vector3(width,0f,0f)), //3 manager.gui.screentoworldpoint(new vector3(width - padding, height - padding,0f)),//4 manager.gui.screentoworldpoint(new vector3(width,height,0f)), //5 manager.gui.screentoworldpoint(new vector3(padding, height - padding, 0f)), //6 manager.gui.screentoworldpoint(new vector3(0f,height,0f)), //7 }; //create triangles mesh.triangles = new int[] { 7,5,6, 6,5,4, 4,5,3, 2,4,3, 0,2,3, 0,1,2, 0,7,6, 0,6,1, 1,6,4, 1,4,2 }; //create uv's uvs in order of creation convienience mesh.uv = new vector2[] { new vector2(0f,0f), new vector2(padding/width, padding/height), new vector2((width-padding)/width, padding/height), new vector2(1f,0f), new vector2((width - padding)/width,(height-padding)/height), new vector2(1f,1f), new vector2(padding/width,(height-padding)/height), new vector2(0f,1f) }; mesh.calculatenormals(); mesh.calculatebounds(); renderer.texture = mytex; return plane; }
padding defined pixels around the texture ignores scaling, while height , width dimensions of shape.
as george said, mesh generating made impossible to scale image without interesting. fix the mesh had remade works. code now
mesh mesh = new mesh(); var renderer = mesh.addrenderer(); mesh.vertices = new vector3[] { //vertices in order convienience manager.gui.screentoworldpoint(new vector3(0f,0f,0f)), //0 manager.gui.screentoworldpoint(new vector3(padding,0f,0f)), //1 manager.gui.screentoworldpoint(new vector3(padding,padding,0)), //2 manager.gui.screentoworldpoint(new vector3(width - padding, 0f,0f)), //3 manager.gui.screentoworldpoint(new vector3(width - padding, padding,0f)), //4 manager.gui.screentoworldpoint(new vector3(width,0f,0f)), //5 manager.gui.screentoworldpoint(new vector3(width,padding,0f)), //6 manager.gui.screentoworldpoint(new vector3(width , height - padding,0f)), //7 manager.gui.screentoworldpoint(new vector3(width - padding, height - padding,0f)),//8 manager.gui.screentoworldpoint(new vector3(width,height,0f)), //9 manager.gui.screentoworldpoint(new vector3(width - padding,height,0f)), //10 manager.gui.screentoworldpoint(new vector3(padding, height, 0f)), //11 manager.gui.screentoworldpoint(new vector3(padding, height - padding, 0f)), //12 manager.gui.screentoworldpoint(new vector3(0f,height,0f)), //13 manager.gui.screentoworldpoint(new vector3(0f,height - padding,0f)), //14 manager.gui.screentoworldpoint(new vector3(0f,padding,0f)), //15 }; //create triangles mesh.triangles = new int[] { 15,2,0, 1,0,2, 1,2,4, 1,4,3, 3,4,6, 3,6,5, 4,8,7, 4,7,6, 8,10,9, 8,9,7, 12,10,8, 12,11,10, 14,11,12, 14,13,11, 15,14,12, 15,12,2, 2,12,8, 2,8,4 }; //create uv's uvs in order of creation convienience mesh.uv = new vector2[] { new vector2(0f,0f), //0 new vector2(padding / width, 0f), //1 new vector2(padding/width, padding/height), //2 new vector2((width-padding)/width, 0f), //3 new vector2((width-padding)/width, padding/height), //4 new vector2(1f,0f), //5 new vector2(1f,padding / height), //6 new vector2(1f, (height - padding) / height), //7 new vector2((width - padding)/width,(height-padding)/height),//8 new vector2(1f,1f), //9 new vector2((width -padding)/width,1f), //10 new vector2(padding/width,1f), //11 new vector2(padding/width,(height-padding)/height), //12 new vector2(0f,1f), //13 new vector2(0f,(height - padding) / height), //14 new vector2(0f,padding / height) //15 }; mesh.recalculatenormals(); mesh.recalculatebounds(); return plane;
hope helps other programmers out there
Comments
Post a Comment