I am totally scrambled by UV.
mesh = new Mesh();
for (int i = 0; i < VERTS.Count; i++)
{
VERTS[i] = VERTS[i] * 0.01f; // THIS IS THE SCALE;
var X = VERTS[i].x;
var Y = VERTS[i].y;
var Z = VERTS[i].z;
VERTS[i] = new Vector3(X, -Z, Y); // THIS IS THE ROTATION
// WHAT IS THE SCIENCE HERE?
if (i >= NORMALS.Count) // COMPLETE THE NORMALS
NORMALS.Add(NORMALS[FACES[i].z]); // Gives useable Normals
if (i >= SORTEDUVS.Count)
{
SORTEDUVS.Add(CUBEMAP(0, VERTS[i].y, VERTS[i].z) * 5); // RIGHT LEFT
//SORTEDUVS.Add(CUBEMAP(1, VERTS[i].x, VERTS[i].y) * 5); // FRONT BACK
//SORTEDUVS.Add(CUBEMAP(2, VERTS[i].x, VERTS[i].z) * 5); // TOP BOTTOM;
}
}
for (int i = 0; i < TRIANGLES.Count; i++)
{
TRIANGLES[i] = TRIANGLES[i] - 1;
}
mesh.SetVertices(VERTS.ToArray());
mesh.SetTriangles(TRIANGLES.ToArray(), 0);
mesh.SetNormals(SORTEDNORMS.ToArray());
mesh.SetUVs(0,SORTEDUVS.ToArray());
FILTER.mesh = mesh;
Vector2 CUBEMAP(int TEXTURE_SECTION, float X, float Y)
{
Vector2 UVOFFSET = Vector2.zero;
if (TEXTURE_SECTION == 0)
{
if (X < 0)
X = -X;
if (Y < 0)
Y = -Y;
UVOFFSET = new Vector2(0 + X, 0 + Y);
}
if (TEXTURE_SECTION == 1)
{
if (X < 0)
X = -X;
if (Y < 0)
Y = -Y;
UVOFFSET = new Vector2(1 - X, 1 - Y);
}
if (TEXTURE_SECTION == 2)
{
if (X < 0)
X = -X;
if (Y < 0)
Y = -Y;
UVOFFSET = new Vector2(1 + X, 0 + Y);
}
return UVOFFSET;
}
So I really only wanted to copy my UV from my OBJ file data. But i wound up not being able to figure out how, so I went down this crazy route of generating UV’s instead. And as you can see the result isn’t half bad, but its also not ideal either.
Ultimately I have reduced the verts from 75 if checked from project folder after Unity Import, to 21 if imported from desktop at runtime. But as you can see, I am heavily limited in UV coordinates, as truth be told, I look for a pattern in how to apply the UV list saved in the .OBJ data, and I search and search all day long, and i am just at this point where I am completely lost.
If any info you have, any logic, or guidance, expertise, any clue or suggestion, anything to drill into my head, or correct me on. Please you are quite welcome. If you need the long OBJ importing list code, i have a custom one not like the free version on the asset store, and unlike the github one online. I did analyze both files but i continue to fail to understand the way the UV Vert and Norm are assembled from the OBJ data. I am only able to do the side of the object which mirrors both sides.