- Home /
answered
Box Projection UV Mapping on single vertex mesh?
I'm making a procedural generator, for example in the picture doing some caves, and I'm texturing using box projection/cubic projection, which is awesome, but it leaves a line of triangles with wonky texture.
you can see the areas below the yellow dots are UVmapped with a side texture and areas above the red dots are mapped to a top texture.
I want to make a 2nd vertex on all the red dots so that the distance between the yellow dots and the red dot is 0, and there is a seam at that point.
Do you have a clear mind about what the task is? do I have to make a new triangle for every wonky triangle? And a new vertex for each corner of the triangle? how could I measure it, and make the triangles, and do all the comparisons? are there some tricks I could use?
//Box Projection textures
var mesh : Mesh = GetComponent(MeshFilter).mesh;
var vertices : Vector3[] = mesh.vertices;
var normals : Vector3[] = mesh.normals;
var uvs : Vector2[] = new Vector2[vertices.Length];
for (var i = 0 ; i < uvs.Length; i++){
if ( Mathf.Abs(normals[i].x) > Mathf.Abs(normals[i].y) && Mathf.Abs(normals[i].x) > Mathf.Abs(normals[i].z) ){
uvs[i] = Vector2 (vertices[i].y, vertices[i].z);}
if ( Mathf.Abs(normals[i].y) > Mathf.Abs(normals[i].x) && Mathf.Abs(normals[i].y) > Mathf.Abs(normals[i].z) ){
uvs[i] = Vector2 (vertices[i].x, vertices[i].z);}
if ( Mathf.Abs(normals[i].z) > Mathf.Abs(normals[i].x) && Mathf.Abs(normals[i].z) > Mathf.Abs(normals[i].y) ){
uvs[i] = Vector2 (vertices[i].x, vertices[i].y);}
Debug.Log( " vertex "+vertices[i] + " uvs " +uvs[i] );
mesh.uv = uvs;
}
sorry I understood now! Triangles aren't so complicated! I have to go through the triangles and find the ones which have different facing vertices, and change the top vertex of each one to a new vertex which is a copy of the old top vertex, keeping the same aspect is lower vertices. I'm so happy I love these puzzles!!!
Having the same problem as you had, by your comment it seems you have solved it. Would you be willing to share the fixed code or give a few pointers to how to solve it? Thanks!
Hi @$$anonymous$$enneyWings , it looks like he went through every triangle searching for vertices with incorrect locations (ie belonged to another triangle) and duplicated it and replaced it with a correctly located UV.
Does this help?: https://stackoverflow.com/questions/22773066/texture-stretching-ins$$anonymous$$d-of-tiling-when-applied-to-a-mesh
Follow this Question
Related Questions
Procedurally Generated UVs Seams 0 Answers
Projection Mapping a texture, into UV of objects 0 Answers
UV Mapping / Lightmap Problem 1 Answer
Textures - n00b questions 3 Answers
Is it possible for a player to add upload/import photo/map? 2 Answers